diff --git a/Core/SDKs/CustomScenario/ConnectorItem.cs b/Core/SDKs/CustomScenario/ConnectorItem.cs index fd17914..dfb9e14 100644 --- a/Core/SDKs/CustomScenario/ConnectorItem.cs +++ b/Core/SDKs/CustomScenario/ConnectorItem.cs @@ -4,13 +4,16 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Messaging; using Core.SDKs.Services.Config; +using PluginCore; namespace Core.SDKs.CustomScenario; -public partial class ConnectorItem : ObservableRecipient +public partial class ConnectorItem : ObservableRecipient, IConnectorItem { [JsonConverter(typeof(PointJsonConverter))] + #pragma warning disable CS0657 // 不是此声明的有效特性位置 [property: JsonConverter(typeof(PointJsonConverter))] + #pragma warning restore CS0657 // 不是此声明的有效特性位置 [ObservableProperty] private Point _anchor; @@ -37,10 +40,6 @@ public partial class ConnectorItem : ObservableRecipient [JsonConverter(typeof(TypeJsonConverter))] public Type Type { get; set; } - /// - /// - /// - /// [JsonConverter(typeof(TypeJsonConverter))] public Type RealType { @@ -81,4 +80,8 @@ partial void OnInputObjectChanged(object? value) { WeakReferenceMessenger.Default.Send(new CustomScenarioChangeMsg() { PointItem = Source, ConnectorItem = this }); } + + //插件自定义输入连接器 + public bool isPluginInputConnector { get; set; } + public INodeInputConnector PluginInputConnector { get; set; } } \ No newline at end of file diff --git a/Core/SDKs/CustomScenario/CustomScenario.cs b/Core/SDKs/CustomScenario/CustomScenario.cs index 7c16d19..fa4e1d9 100644 --- a/Core/SDKs/CustomScenario/CustomScenario.cs +++ b/Core/SDKs/CustomScenario/CustomScenario.cs @@ -325,14 +325,8 @@ private void TickMethod(object sender, long JumpPeriod, long interval) return; } - var connectionItem = connections.FirstOrDefault((e) => e.Source == nodes[1] - .Output[0]); - var firstNodes = connectionItem.Target.Source; - nodes[1].Status = s节点状态.已验证; - _tickTasks.Add(nodes[0], null); - _tickTasks.Add(nodes[1], null); - _tickTasks.Add(firstNodes, null); - ParsePointItem(_tickTasks, firstNodes, false, true, _cancellationTokenSource.Token); + var nowPointItem = nodes[1]; + ParsePointItem(_tickTasks, nowPointItem, false, true, _cancellationTokenSource.Token); while (true) { diff --git a/Core/SDKs/Services/Plugin/Plugin.cs b/Core/SDKs/Services/Plugin/Plugin.cs index 839e2c5..b7f2af4 100644 --- a/Core/SDKs/Services/Plugin/Plugin.cs +++ b/Core/SDKs/Services/Plugin/Plugin.cs @@ -247,7 +247,6 @@ private object GetPointItemByMethodInfo(MethodInfo methodInfo) } } - inpItems.Add(new ConnectorItem() { Source = pointItem, @@ -262,14 +261,32 @@ private object GetPointItemByMethodInfo(MethodInfo methodInfo) } else { - inpItems.Add(new ConnectorItem() + var connectorItem = new ConnectorItem() { Source = pointItem, Type = parameterInfo.ParameterType, IsSelf = IsSelf, Title = customAttribute.GetParameterName(parameterInfo.Name), TypeName = BaseNodeMethodsGen.GetI18N(parameterInfo.ParameterType.FullName) - }); + }; + if (parameterInfo.ParameterType.GetCustomAttribute() is not null + and var customNodeInputType) + { + connectorItem.isPluginInputConnector = true; + connectorItem.IsSelf = true; + try + { + var service = ServiceProvider.GetService(customNodeInputType.Type); + connectorItem.PluginInputConnector = service as INodeInputConnector; + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + + inpItems.Add(connectorItem); } //Log.Debug($"参数{index}:类型为{parameterInfo.ParameterType}"); @@ -337,6 +354,11 @@ private object GetPointItemByMethodInfo(MethodInfo methodInfo) return pointItem; } + private ObservableCollection getConnectorItemsBy() + { + return new ObservableCollection(); + } + [MethodImpl(MethodImplOptions.NoInlining)] public static void UnloadByPluginInfo(string pluginInfoEx, out WeakReference weakReference) diff --git a/Core/SDKs/Services/Plugin/PluginAvaloniaResourceManager.cs b/Core/SDKs/Services/Plugin/PluginAvaloniaResourceManager.cs new file mode 100644 index 0000000..1b94743 --- /dev/null +++ b/Core/SDKs/Services/Plugin/PluginAvaloniaResourceManager.cs @@ -0,0 +1,28 @@ +using Avalonia.Styling; + +namespace Core.SDKs.Services.Plugin; + +public static class PluginAvaloniaResourceManager +{ + private static Dictionary _resources = new(); + + public static IStyle GetStyle(string key) + { + if (_resources.ContainsKey(key)) + { + return _resources[key]; + } + + return null; + } + + public static IStyle AddStyle(string key, IStyle style) + { + if (!_resources.ContainsKey(key)) + { + _resources.Add(key, style); + } + + return style; + } +} \ No newline at end of file diff --git a/Core/SDKs/Tools/ScreenCapture.cs b/Core/SDKs/Tools/ScreenCapture.cs index 7d8c648..fadcd16 100644 --- a/Core/SDKs/Tools/ScreenCapture.cs +++ b/Core/SDKs/Tools/ScreenCapture.cs @@ -2,6 +2,8 @@ using Avalonia; using Avalonia.Media.Imaging; using Avalonia.Platform; +using Core.SDKs.Services; +using Microsoft.Extensions.DependencyInjection; using PluginCore; using ScreenCapture.NET; using SixLabors.ImageSharp; @@ -175,6 +177,7 @@ private static Configuration CreateDefaultInstance() public ScreenCaptureInfo GetScreenCaptureInfoByUserManual() { - throw new NotImplementedException(); + return ServiceManager.Services.GetService()!.GetScreenCaptureInfo() + .Result; } } \ No newline at end of file diff --git a/Core/ViewModel/TaskEditor/TaskEditorViewModel.cs b/Core/ViewModel/TaskEditor/TaskEditorViewModel.cs index 09b57cd..269b509 100644 --- a/Core/ViewModel/TaskEditor/TaskEditorViewModel.cs +++ b/Core/ViewModel/TaskEditor/TaskEditorViewModel.cs @@ -328,7 +328,9 @@ private void AddNodes(PointItem pointItem) AutoUnboxIndex = connectorItem.AutoUnboxIndex, IsSelf = connectorItem.IsSelf, SelfInputAble = connectorItem.SelfInputAble, - IsOut = connectorItem.IsOut + IsOut = connectorItem.IsOut, + isPluginInputConnector = connectorItem.isPluginInputConnector, + PluginInputConnector = connectorItem.PluginInputConnector }); var plugin = PluginManager.EnablePlugin.FirstOrDefault((e) => e.Value._dll == connectorItem.Type.Assembly) .Value; @@ -427,7 +429,9 @@ private void CopyNode(PointItem pointItem) AutoUnboxIndex = connectorItem.AutoUnboxIndex, IsSelf = connectorItem.IsSelf, SelfInputAble = connectorItem.SelfInputAble, - IsOut = connectorItem.IsOut + IsOut = connectorItem.IsOut, + isPluginInputConnector = connectorItem.isPluginInputConnector, + PluginInputConnector = connectorItem.PluginInputConnector }); } diff --git a/KitopiaAvalonia/Pages/MyDataTemplateSelector.cs b/KitopiaAvalonia/Pages/MyDataTemplateSelector.cs index c45fce0..1513f6d 100644 --- a/KitopiaAvalonia/Pages/MyDataTemplateSelector.cs +++ b/KitopiaAvalonia/Pages/MyDataTemplateSelector.cs @@ -1,5 +1,6 @@ #region +using System; using System.Collections.Generic; using Avalonia.Controls; using Avalonia.Controls.Templates; @@ -27,6 +28,14 @@ public class MyDataTemplateSelector : IDataTemplate .Build(item); } + if (pointItem.isPluginInputConnector) + { + var control = pointItem.PluginInputConnector.IDataTemplate.Build(item); + pointItem.PluginInputConnector.Value.Subscribe(x => { pointItem.InputObject = x; }); + control!.Styles.Add(pointItem.PluginInputConnector.Style); + return control; + } + return (pointItem.RealType.FullName! switch { "System.String" => Templates["StringTemplate"] diff --git a/KitopiaEx/KitopiaEx.cs b/KitopiaEx/KitopiaEx.cs index c8cf722..98a8e0e 100644 --- a/KitopiaEx/KitopiaEx.cs +++ b/KitopiaEx/KitopiaEx.cs @@ -39,6 +39,7 @@ public static IServiceProvider GetServiceProvider() services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); return services.BuildServiceProvider(); } } \ No newline at end of file diff --git a/KitopiaEx/NodeInputConnector1.cs b/KitopiaEx/NodeInputConnector1.cs new file mode 100644 index 0000000..45987bf --- /dev/null +++ b/KitopiaEx/NodeInputConnector1.cs @@ -0,0 +1,22 @@ +using System; +using Avalonia.Controls.Templates; +using Avalonia.Markup.Xaml.Styling; +using PluginCore; + +namespace KitopiaEx; + +public class NodeInputConnector1 : INodeInputConnector +{ + public StyleInclude Style => + new(new Uri("avares://KitopiaEx")) + { Source = new Uri("NodeInputConnector1Style.axaml", UriKind.Relative) }; + + public IDataTemplate IDataTemplate => + new ResourceInclude(new Uri("avares://KitopiaEx")) + { Source = new Uri("NodeInputConnector1DataTemple.axaml", UriKind.Relative) } + .TryGetResource("Template", null, out var variant) + ? (IDataTemplate)variant + : null; + + public ObservableValue Value { get; } = new ObservableValue(); +} \ No newline at end of file diff --git a/KitopiaEx/NodeInputConnector1DataTemple.axaml b/KitopiaEx/NodeInputConnector1DataTemple.axaml new file mode 100644 index 0000000..71e6c7f --- /dev/null +++ b/KitopiaEx/NodeInputConnector1DataTemple.axaml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/KitopiaEx/NodeInputConnector1Style.axaml b/KitopiaEx/NodeInputConnector1Style.axaml new file mode 100644 index 0000000..358363b --- /dev/null +++ b/KitopiaEx/NodeInputConnector1Style.axaml @@ -0,0 +1,16 @@ + + + + + + + \ No newline at end of file diff --git a/KitopiaEx/NodeInputConnector1Style.axaml.cs b/KitopiaEx/NodeInputConnector1Style.axaml.cs new file mode 100644 index 0000000..888a702 --- /dev/null +++ b/KitopiaEx/NodeInputConnector1Style.axaml.cs @@ -0,0 +1,7 @@ +using Avalonia.Controls.Primitives; + +namespace KitopiaEx; + +public class NodeInputConnector1Style : TemplatedControl +{ +} \ No newline at end of file diff --git a/KitopiaEx/NodeInputType1.cs b/KitopiaEx/NodeInputType1.cs new file mode 100644 index 0000000..6feeff2 --- /dev/null +++ b/KitopiaEx/NodeInputType1.cs @@ -0,0 +1,9 @@ +using PluginCore.Attribute; + +namespace KitopiaEx; + +[CustomNodeInputType(typeof(NodeInputConnector1))] +public class NodeInputType1 +{ + public string Name { get; set; } +} \ No newline at end of file diff --git a/KitopiaEx/Styles1.axaml b/KitopiaEx/Styles1.axaml new file mode 100644 index 0000000..d82cdbc --- /dev/null +++ b/KitopiaEx/Styles1.axaml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/KitopiaEx/Test1.cs b/KitopiaEx/Test1.cs index fbb6235..c031a31 100644 --- a/KitopiaEx/Test1.cs +++ b/KitopiaEx/Test1.cs @@ -7,7 +7,7 @@ public class Test1 { [PluginMethod("Test", $"{nameof(item)}=本地项目", "return=返回参数")] - public void OpenSearchViewItem(Test1 item, CancellationToken cancellationToken) + public void OpenSearchViewItem(NodeInputType1 item, CancellationToken cancellationToken) { } } \ No newline at end of file diff --git a/KitopiaTest/UnitTest1.cs b/KitopiaTest/UnitTest1.cs index e3c4786..e4b8df8 100644 --- a/KitopiaTest/UnitTest1.cs +++ b/KitopiaTest/UnitTest1.cs @@ -1,3 +1,5 @@ +using System.Management; + namespace KitopiaTest; public class Tests @@ -10,6 +12,21 @@ public void Setup() [Test] public void Test1() { + try + { + ManagementObjectSearcher searcher = + new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_OperatingSystem"); + + foreach (ManagementObject queryObj in searcher.Get()) + { + Console.WriteLine("Caption: {0}", queryObj["Caption"]); + } + } + catch (ManagementException e) + { + Console.WriteLine("An error occurred while querying for WMI data: " + e.Message); + } + Assert.Pass(); } } \ No newline at end of file diff --git a/PluginCore b/PluginCore index fb8f0c2..4682831 160000 --- a/PluginCore +++ b/PluginCore @@ -1 +1 @@ -Subproject commit fb8f0c29732deddc05f9e5524b78a7db69017ad2 +Subproject commit 4682831c9496ff1c681f883a1b8930e85951a585