From 9469aa368cbc892f1cc6d70d8aedf4cf61399c9d Mon Sep 17 00:00:00 2001 From: MakesYT <2696703792@qq.com> Date: Fri, 19 Jul 2024 20:45:16 +0800 Subject: [PATCH] =?UTF-8?q?*[WIP]=E9=87=8D=E6=9E=84=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F2/3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/SDKs/CustomScenario/CustomScenario.cs | 277 +----------------- Core/SDKs/CustomScenario/ScenarioException.cs | 5 + ...cenarioMethodInfo.cs => ScenarioMethod.cs} | 32 +- .../ScenarioMethodCategoryGroup.cs | 49 +++- .../SDKs/CustomScenario/ScenarioMethodNode.cs | 210 ++++++++++++- .../SDKs/CustomScenario/ScenarioMethodType.cs | 13 + Core/SDKs/Services/Plugin/Plugin.cs | 61 ++-- PluginCore | 2 +- 8 files changed, 324 insertions(+), 325 deletions(-) create mode 100644 Core/SDKs/CustomScenario/ScenarioException.cs rename Core/SDKs/CustomScenario/{ScenarioMethodInfo.cs => ScenarioMethod.cs} (87%) create mode 100644 Core/SDKs/CustomScenario/ScenarioMethodType.cs diff --git a/Core/SDKs/CustomScenario/CustomScenario.cs b/Core/SDKs/CustomScenario/CustomScenario.cs index a234688..589c8cc 100644 --- a/Core/SDKs/CustomScenario/CustomScenario.cs +++ b/Core/SDKs/CustomScenario/CustomScenario.cs @@ -3,19 +3,15 @@ using System.Collections.ObjectModel; using System.Collections.Specialized; using System.ComponentModel; -using System.Reflection; using System.Text.Json.Serialization; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Messaging; using Core.SDKs.CustomType; using Core.SDKs.HotKey; using Core.SDKs.Services; -using Core.SDKs.Services.Plugin; using Core.SDKs.Tools; using log4net; -using Microsoft.Extensions.DependencyInjection; using PluginCore; -using PluginCore.Attribute; #endregion @@ -528,278 +524,7 @@ private void ParsePointItem(Dictionary threads, { try { - if (nowScenarioMethodNode.Plugin == "Kitopia") - { - switch (nowScenarioMethodNode.MerthodName) - { - case "判断": - { - if (nowScenarioMethodNode.Input[1].InputObject is true) - { - nowScenarioMethodNode.Output[0].InputObject = "当前流"; - nowScenarioMethodNode.Output[0].IsNotUsed = false; - nowScenarioMethodNode.Output[1].IsNotUsed = true; - nowScenarioMethodNode.Output[1].InputObject = "未使用的流"; - } - else - { - nowScenarioMethodNode.Output[1].InputObject = "当前流"; - nowScenarioMethodNode.Output[0].InputObject = "未使用的流"; - nowScenarioMethodNode.Output[0].IsNotUsed = true; - nowScenarioMethodNode.Output[1].IsNotUsed = false; - } - - break; - } - case "一对二": - { - nowScenarioMethodNode.Output[0].InputObject = "流1"; - nowScenarioMethodNode.Output[1].InputObject = "流2"; - break; - } - case "一对N": - { - for (var i = 0; i < nowScenarioMethodNode.Output.Count; i++) - { - nowScenarioMethodNode.Output[i].InputObject = $"流{i + 1}"; - } - - break; - } - case "相等": - { - if (nowScenarioMethodNode.Input[1].InputObject is null) - { - nowScenarioMethodNode.Output[0].InputObject = false; - } - else if (nowScenarioMethodNode.Input[2].InputObject is null) - { - nowScenarioMethodNode.Output[0].InputObject = false; - } - else - { - nowScenarioMethodNode.Output[0].InputObject = - nowScenarioMethodNode.Input[1].InputObject!.Equals(nowScenarioMethodNode.Input[2] - .InputObject); - } - - foreach (var item in nowScenarioMethodNode.Output[0] - .GetSourceOrNextConnectorItems(connections)) - { - item.InputObject = nowScenarioMethodNode.Output[0].InputObject; - MakeSourcePointState(item, nowScenarioMethodNode); - } - - break; - } - case "valueSet": - { - if (Values.ContainsKey(nowScenarioMethodNode.ValueRef!)) - { - Values.SetValueWithoutNotify(nowScenarioMethodNode.ValueRef!, - nowScenarioMethodNode.Input[1].InputObject!); - } - - break; - } - case "valueGet": - { - if (Values.ContainsKey(nowScenarioMethodNode.ValueRef!)) - { - foreach (var item in nowScenarioMethodNode.Output[0] - .GetSourceOrNextConnectorItems(connections)) - { - item.InputObject = Values[nowScenarioMethodNode.ValueRef!]; - MakeSourcePointState(item, nowScenarioMethodNode); - } - } - - break; - } - case "打开/运行本地项目": - { - if (nowScenarioMethodNode.Input.Count() >= 3) - { - List parameterList = new(); - for (var index = 2; index < nowScenarioMethodNode.Input.Count; index++) - { - parameterList.Add(nowScenarioMethodNode.Input[index].InputObject); - } - - ServiceManager.Services.GetService() - .OpenSearchItemByOnlyKey((string)nowScenarioMethodNode.Input[1].InputObject, - parameterList.ToArray()); - } - else - { - ServiceManager.Services.GetService() - .OpenSearchItemByOnlyKey((string)nowScenarioMethodNode.Input[1].InputObject); - } - - break; - } - case "Main": - { - for (var i = 1; i < nowScenarioMethodNode.Output.Count; i++) - { - foreach (var sourceOrNextConnectorItem in nowScenarioMethodNode.Output[i] - .GetSourceOrNextConnectorItems(connections)) - { - sourceOrNextConnectorItem.InputObject = nowScenarioMethodNode.Output[i].InputObject; - } - } - - break; - } - default: - { - var userInputConnector = nowScenarioMethodNode.Input.FirstOrDefault(); - - - if (userInputConnector is null) - { - break; - } - - if (userInputConnector.Title == "流输入") - { - userInputConnector = nowScenarioMethodNode.Input[1]; - } - - var userInputData = userInputConnector.InputObject; - if (userInputData is null or "") - { - throw new NullReferenceException(); - } - - if (nowScenarioMethodNode.MerthodName == "System.Int32") - { - userInputData = int.Parse(userInputData.ToString()!); - } - - nowScenarioMethodNode.Output[0].InputObject = userInputData; - foreach (var item in nowScenarioMethodNode.Output[0] - .GetSourceOrNextConnectorItems(connections)) - { - item.InputObject = userInputData; - MakeSourcePointState(item, nowScenarioMethodNode); - } - - break; - } - } - } - else - { - var plugin = PluginManager.EnablePlugin[nowScenarioMethodNode.Plugin]; - var customScenarioNodeMethod = - PluginOverall.CustomScenarioNodeMethods[nowScenarioMethodNode.Plugin]; - - var methodInfo = customScenarioNodeMethod[nowScenarioMethodNode.MerthodName].Item1; - List list = new(); - var index = 1; - foreach (var parameterInfo in methodInfo.GetParameters()) - { - if (parameterInfo.ParameterType.GetCustomAttribute(typeof(AutoUnbox)) is not null) - { - var autoUnboxIndex = nowScenarioMethodNode.Input[index].AutoUnboxIndex; - var parameterList = new List(); - List parameterTypesList = new(); - while (nowScenarioMethodNode.Input.Count >= index && - nowScenarioMethodNode.Input[index].AutoUnboxIndex == autoUnboxIndex) - { - var item = nowScenarioMethodNode.Input[index].InputObject; - if (item != null) - { - parameterList.Add(item); - parameterTypesList.Add(item.GetType()); - } - else - { - valid = false; - goto finnish; - } - - index++; - } - - var instance = parameterInfo.ParameterType.GetConstructor(parameterTypesList.ToArray()) - ?.Invoke(parameterList.ToArray()); - if (instance != null) - { - list.Add(instance); - } - else - { - valid = false; - goto finnish; - } - - continue; - } - - if (index == nowScenarioMethodNode.Input.Count) - { - list.Add(cancellationToken); - break; - } - - var inputObject = nowScenarioMethodNode.Input[index].InputObject; - if (inputObject != null) - { - list.Add(inputObject); - } - else - { - valid = false; - goto finnish; - } - - index++; - } - - var invoke = methodInfo.Invoke(plugin.ServiceProvider!.GetService(methodInfo.DeclaringType!), - list.ToArray()); - - if (methodInfo.ReturnParameter.ParameterType.GetCustomAttribute(typeof(AutoUnbox)) is not null) - { - var type = methodInfo.ReturnParameter.ParameterType; - foreach (var memberInfo in type.GetProperties()) - { - foreach (var connectorItem in nowScenarioMethodNode.Output) - { - if (connectorItem.Type == memberInfo.PropertyType) - { - var value = invoke.GetType() - .InvokeMember(memberInfo.Name, - BindingFlags.Instance | BindingFlags.IgnoreCase | - BindingFlags.Public | BindingFlags.NonPublic | - BindingFlags.GetProperty, null, invoke, null); - - connectorItem.InputObject = value; - foreach (var item in connectorItem.GetSourceOrNextConnectorItems(connections)) - { - item.InputObject = value; - } - - break; - } - } - } - } - else - { - if (nowScenarioMethodNode.Output.Any()) - { - nowScenarioMethodNode.Output[0].InputObject = invoke; - foreach (var item in nowScenarioMethodNode.Output[0] - .GetSourceOrNextConnectorItems(connections)) - { - item.InputObject = invoke; - } - } - } - } + nowScenarioMethodNode.Invoke(cancellationToken, connections, Values); } catch (Exception e) { diff --git a/Core/SDKs/CustomScenario/ScenarioException.cs b/Core/SDKs/CustomScenario/ScenarioException.cs new file mode 100644 index 0000000..619efe7 --- /dev/null +++ b/Core/SDKs/CustomScenario/ScenarioException.cs @@ -0,0 +1,5 @@ +namespace Core.SDKs.CustomScenario; + +public class ScenarioException(string empty) : Exception +{ +} \ No newline at end of file diff --git a/Core/SDKs/CustomScenario/ScenarioMethodInfo.cs b/Core/SDKs/CustomScenario/ScenarioMethod.cs similarity index 87% rename from Core/SDKs/CustomScenario/ScenarioMethodInfo.cs rename to Core/SDKs/CustomScenario/ScenarioMethod.cs index 0cc2de4..9efcc1e 100644 --- a/Core/SDKs/CustomScenario/ScenarioMethodInfo.cs +++ b/Core/SDKs/CustomScenario/ScenarioMethod.cs @@ -9,17 +9,27 @@ namespace Core.SDKs.CustomScenario; -public class ScenarioMethodInfo +public class ScenarioMethod { - public ScenarioMethodInfo(MethodInfo method, PluginInfo pluginInfo, ScenarioMethodAttribute attribute) + public ScenarioMethod(MethodInfo method, PluginInfo pluginInfo, ScenarioMethodAttribute attribute, + ScenarioMethodType type) { Method = method; PluginInfo = pluginInfo; Attribute = attribute; + Type = type; } + + public IServiceProvider ServiceProvider => PluginManager.EnablePlugin[PluginInfo.ToPlgString()].ServiceProvider; + public bool IsFromPlugin => PluginInfo is not null; + + public ScenarioMethodType Type { get; } + + //某些特殊的类型需要存储一定的数据,例如(变量读取/设置 需要对应的变量名) + public object TypeDate { get; set; } public MethodInfo Method { get; } - public PluginInfo PluginInfo { get; } + public PluginInfo? PluginInfo { get; } public ScenarioMethodAttribute Attribute { get; } public string MethodAbsolutelyName @@ -42,7 +52,7 @@ public string MethodAbsolutelyName continue; } - sb.Append($"{plugin.ToPlgString()} {genericArgument.ParameterType.FullName}"); + sb.Append($"{PluginInfo.ToPlgString()} {genericArgument.ParameterType.FullName}"); sb.Append("|"); } @@ -61,7 +71,7 @@ public ScenarioMethodNode GenerateNode() { var pointItem = new ScenarioMethodNode() { - ScenarioMethodInfo = this, + ScenarioMethod = this, Title = MethodTitle }; ObservableCollection inpItems = new(); @@ -132,8 +142,7 @@ public ScenarioMethodNode GenerateNode() connectorItem.IsSelf = true; try { - var service = PluginManager.EnablePlugin[PluginInfo.ToPlgString()].ServiceProvider - .GetService(customNodeInputType.Type); + var service = ServiceProvider.GetService(customNodeInputType.Type); connectorItem.PluginInputConnector = service as INodeInputConnector; } catch (Exception e) @@ -152,6 +161,14 @@ public ScenarioMethodNode GenerateNode() if (Method.ReturnParameter.ParameterType != typeof(void)) { ObservableCollection outItems = new(); + inpItems.Add(new ConnectorItem() + { + Source = pointItem, + IsOut = true, + Type = typeof(NodeConnectorClass), + Title = "流输出", + TypeName = "节点" + }); if (Method.ReturnParameter.ParameterType.GetCustomAttribute(typeof(AutoUnbox)) is not null) { autoUnboxIndex++; @@ -208,6 +225,7 @@ public ScenarioMethodNode GenerateNode() pointItem.Input = inpItems; + return pointItem; } } \ No newline at end of file diff --git a/Core/SDKs/CustomScenario/ScenarioMethodCategoryGroup.cs b/Core/SDKs/CustomScenario/ScenarioMethodCategoryGroup.cs index c2ee9f0..2d5b187 100644 --- a/Core/SDKs/CustomScenario/ScenarioMethodCategoryGroup.cs +++ b/Core/SDKs/CustomScenario/ScenarioMethodCategoryGroup.cs @@ -1,8 +1,45 @@ -namespace Core.SDKs.CustomScenario; +using PluginCore.Attribute.Scenario; + +namespace Core.SDKs.CustomScenario; public class ScenarioMethodCategoryGroup { public static ScenarioMethodCategoryGroup RootScenarioMethodCategoryGroup = new(); + + public static ScenarioMethodCategoryGroup GetScenarioMethodCategoryGroupByAttribute( + ScenarioMethodCategoryAttribute attribute, ScenarioMethodCategoryGroup? scenarioMethodCategoryGroup = null) + { + var strings = attribute.Name.Split("/"); + var nowScenarioMethodCategoryGroup = attribute.IsMixinOrTopCategory + ? RootScenarioMethodCategoryGroup + : scenarioMethodCategoryGroup ?? RootScenarioMethodCategoryGroup; + for (var index = 0; index < strings.Length; index++) + { + var se = strings[index]; + if (nowScenarioMethodCategoryGroup.Childrens.ContainsKey(se)) + { + nowScenarioMethodCategoryGroup = nowScenarioMethodCategoryGroup.Childrens[se]; + } + else + { + var newScenarioMethodCategoryGroup = new ScenarioMethodCategoryGroup() + { + Name = se, + Parent = nowScenarioMethodCategoryGroup + }; + nowScenarioMethodCategoryGroup = newScenarioMethodCategoryGroup; + if (index == strings.Length - 1) + { + nowScenarioMethodCategoryGroup.DisplayName = attribute.Name; + } + + nowScenarioMethodCategoryGroup.Childrens.Add(se, nowScenarioMethodCategoryGroup); + } + } + + return nowScenarioMethodCategoryGroup; + } + public List MixinInfos = new(); public ScenarioMethodCategoryGroup? Parent { get; set; } public string Name { get; set; } @@ -11,7 +48,7 @@ public class ScenarioMethodCategoryGroup // public Dictionary Childrens { get; set; } = new(); - public Dictionary Methods { get; set; } = new(); + public Dictionary Methods { get; set; } = new(); public ScenarioMethodCategoryGroup? GetParent() => Parent; public ScenarioMethodCategoryGroup GetRoot() => Parent?.GetRoot() ?? this; @@ -24,7 +61,11 @@ public void RemoveMethodsByPluginName(string pluginName) var nowScenarioMethodCategoryGroup = RootScenarioMethodCategoryGroup; for (var i1 = 0; i1 < target.Length - 1; i1++) { - nowScenarioMethodCategoryGroup = nowScenarioMethodCategoryGroup.Childrens[target[i1]]; + if (nowScenarioMethodCategoryGroup.Childrens.ContainsKey(target[i1])) + { + nowScenarioMethodCategoryGroup = nowScenarioMethodCategoryGroup.Childrens[target[i1]]; + } + else throw new ScenarioException("路径不存在"); } nowScenarioMethodCategoryGroup.Methods.Remove(target.Last()); @@ -34,7 +75,7 @@ public void RemoveMethodsByPluginName(string pluginName) /// /// -/// 其他插件名称/分类1/.../方法绝对名称 +/// 其他插件名称/分类1/.../方法绝对名称 /// /// public struct MixinInfo diff --git a/Core/SDKs/CustomScenario/ScenarioMethodNode.cs b/Core/SDKs/CustomScenario/ScenarioMethodNode.cs index 7e4ab78..a927c48 100644 --- a/Core/SDKs/CustomScenario/ScenarioMethodNode.cs +++ b/Core/SDKs/CustomScenario/ScenarioMethodNode.cs @@ -1,8 +1,12 @@ using System.Collections.ObjectModel; +using System.Reflection; using System.Text.Json.Serialization; using Avalonia; using CommunityToolkit.Mvvm.ComponentModel; +using Core.SDKs.CustomType; using Core.SDKs.Services.Config; +using PluginCore; +using PluginCore.Attribute; namespace Core.SDKs.CustomScenario; @@ -26,7 +30,209 @@ public partial class ScenarioMethodNode : ObservableRecipient [ObservableProperty] private ObservableCollection output = new(); [ObservableProperty] private s节点状态 status = s节点状态.未验证; - public ScenarioMethodInfo ScenarioMethodInfo { get; set; } + public ScenarioMethod ScenarioMethod { get; set; } - public string? ValueRef { get; set; } + public bool Invoke(CancellationToken cancellationToken, ObservableCollection connections, + ObservableDictionary values) + { + //生成本节点所有数据 + switch (ScenarioMethod.Type) + { + case ScenarioMethodType.插件方法: + { + List list = new(); + var index = 1; + foreach (var parameterInfo in ScenarioMethod.Method.GetParameters()) + { + if (parameterInfo.ParameterType.GetCustomAttribute(typeof(AutoUnbox)) is not null) + { + var autoUnboxIndex = Input[index].AutoUnboxIndex; + var parameterList = new List(); + List parameterTypesList = new(); + while (Input.Count >= index && Input[index].AutoUnboxIndex == autoUnboxIndex) + { + var item = Input[index].InputObject; + if (item != null) + { + parameterList.Add(item); + parameterTypesList.Add(item.GetType()); + } + else + { + return false; + } + + index++; + } + + var instance = parameterInfo.ParameterType.GetConstructor(parameterTypesList.ToArray()) + ?.Invoke(parameterList.ToArray()); + if (instance != null) + { + list.Add(instance); + } + else + { + return false; + } + + continue; + } + + if (index == Input.Count) + { + list.Add(cancellationToken); + break; + } + + var inputObject = Input[index].InputObject; + if (inputObject != null) + { + list.Add(inputObject); + } + else + { + return false; + } + + index++; + } + + var invoke = ScenarioMethod.Method.Invoke( + ScenarioMethod.ServiceProvider!.GetService(ScenarioMethod.Method.DeclaringType!), + list.ToArray()); + if (invoke is null) + return false; + if (ScenarioMethod.Method.ReturnParameter.ParameterType.GetCustomAttribute(typeof(AutoUnbox)) is not + null) + { + var type = ScenarioMethod.Method.ReturnParameter.ParameterType; + foreach (var memberInfo in type.GetProperties()) + { + foreach (var connectorItem in Output) + { + if (connectorItem.Type == memberInfo.PropertyType) + { + var value = invoke.GetType() + .InvokeMember(memberInfo.Name, + BindingFlags.Instance | BindingFlags.IgnoreCase | + BindingFlags.Public | BindingFlags.NonPublic | + BindingFlags.GetProperty, null, invoke, null); + + connectorItem.InputObject = value; + break; + } + } + } + } + else + { + if (Output.Any()) + { + Output[1].InputObject = invoke; + } + } + + break; + } + case ScenarioMethodType.一对二: + { + Output[0].InputObject = "流1"; + Output[1].InputObject = "流2"; + break; + } + case ScenarioMethodType.一对多: + { + for (var i = 0; i < Output.Count; i++) + { + Output[i].InputObject = $"流{i + 1}"; + } + + break; + } + case ScenarioMethodType.相等: + { + if (Input[1].InputObject is null) + { + Output[0].InputObject = false; + } + else if (Input[2].InputObject is null) + { + Output[0].InputObject = false; + } + else + { + Output[0].InputObject = Input[1].InputObject!.Equals(Input[2].InputObject); + } + + break; + } + case ScenarioMethodType.变量设置: + { + if (values.ContainsKey((string)ScenarioMethod.TypeDate)) + { + values.SetValueWithoutNotify((string)ScenarioMethod.TypeDate!, Input[1].InputObject!); + } + + break; + } + case ScenarioMethodType.变量获取: + { + if (values.ContainsKey((string)ScenarioMethod.TypeDate)) + { + Output[0].InputObject = values[(string)ScenarioMethod.TypeDate]; + } + + break; + } + case ScenarioMethodType.判断: + { + if (Input[1].InputObject is bool b1) + { + if (b1) + { + Output[0].IsNotUsed = false; + Output[0].InputObject = "当前流"; + Output[1].IsNotUsed = true; + Output[1].InputObject = "未使用的流"; + } + else + { + Output[0].IsNotUsed = true; + Output[0].InputObject = "未使用的流"; + Output[1].IsNotUsed = false; + Output[1].InputObject = "当前流"; + } + } + + break; + } + case ScenarioMethodType.默认: + { + var connectorItem = Input.First(e => e.RealType != typeof(NodeConnectorClass)); + foreach (var item in Output) + { + item.InputObject = connectorItem.InputObject; + } + + break; + } + } + + //将节点数据赋值给下一个节点 + foreach (var connectorItem in Output) + { + if (connectorItem.RealType == typeof(NodeConnectorClass)) + { + continue; + } + + foreach (var sourceOrNextConnectorItem in connectorItem.GetSourceOrNextConnectorItems(connections)) + { + sourceOrNextConnectorItem.InputObject = connectorItem.InputObject; + } + } + + return true; + } } \ No newline at end of file diff --git a/Core/SDKs/CustomScenario/ScenarioMethodType.cs b/Core/SDKs/CustomScenario/ScenarioMethodType.cs new file mode 100644 index 0000000..8fa1f47 --- /dev/null +++ b/Core/SDKs/CustomScenario/ScenarioMethodType.cs @@ -0,0 +1,13 @@ +namespace Core.SDKs.CustomScenario; + +public enum ScenarioMethodType +{ + 插件方法, + 判断, + 一对二, + 一对多, + 相等, + 变量设置, + 变量获取, + 默认 +} \ No newline at end of file diff --git a/Core/SDKs/Services/Plugin/Plugin.cs b/Core/SDKs/Services/Plugin/Plugin.cs index fb81385..d63b492 100644 --- a/Core/SDKs/Services/Plugin/Plugin.cs +++ b/Core/SDKs/Services/Plugin/Plugin.cs @@ -2,7 +2,6 @@ using System.Reflection; using System.Runtime.CompilerServices; -using System.Text; using System.Text.Json; using Core.SDKs.CustomScenario; using Core.SDKs.HotKey; @@ -10,6 +9,7 @@ using log4net; using PluginCore; using PluginCore.Attribute; +using PluginCore.Attribute.Scenario; using PluginCore.Config; #endregion @@ -77,7 +77,9 @@ public Plugin(string path) .Last() + "_plugin"); Log.Debug($"加载插件:{path}"); var t = _dll.GetExportedTypes(); - Dictionary methodInfos = new(); + //Dictionary methodInfos = new(); + ScenarioMethodCategoryGroup pluginMainScenarioMethodCategoryGroup = new(); + List> searchViews = new(); foreach (var type in t) { @@ -97,6 +99,14 @@ public Plugin(string path) } } + if (PluginInfo is null) + { + Log.Error("未找到插件信息"); + return; + } + + pluginMainScenarioMethodCategoryGroup.Name = PluginInfo.PluginName; + foreach (var type in t) { if (type.BaseType == typeof(ConfigBase)) @@ -119,16 +129,25 @@ public Plugin(string path) foreach (var methodInfo in type.GetMethods()) { - if (methodInfo.GetCustomAttributes(typeof(ScenarioMethodAttribute)) - .Any()) //情景的可用节点 + ScenarioMethodCategoryGroup scenarioMethodCategoryGroup = pluginMainScenarioMethodCategoryGroup; + if (type.GetCustomAttribute() is { } scenarioMethodCategoryAttribute) + { + scenarioMethodCategoryGroup = + ScenarioMethodCategoryGroup.GetScenarioMethodCategoryGroupByAttribute( + scenarioMethodCategoryAttribute, pluginMainScenarioMethodCategoryGroup); + } + + if (methodInfo.GetCustomAttribute() is { } scenarioMethodAttribute) //情景的可用节点 { if (methodInfo.GetParameters()[^1].ParameterType.FullName != "System.Threading.CancellationToken") { continue; } - methodInfos.Add(ToMtdString(methodInfo), - (methodInfo, GetPointItemByMethodInfo(methodInfo))); + var scenarioMethodInfo = new ScenarioMethod(methodInfo, PluginInfo, scenarioMethodAttribute, + ScenarioMethodType.插件方法); + scenarioMethodCategoryGroup.Methods.Add(scenarioMethodInfo.MethodAbsolutelyName, + scenarioMethodInfo); } if (methodInfo.GetCustomAttributes(typeof(SearchMethod)) @@ -150,41 +169,13 @@ public Plugin(string path) } } - PluginOverall.SearchActions.Add(ToPlgString(), searchViews); - PluginOverall.CustomScenarioNodeMethods.Add(ToPlgString(), methodInfos); + PluginOverall.SearchActions.Add(PluginInfo.ToPlgString(), searchViews); } public Assembly? _dll => _plugin.Assembly; public PluginInfo PluginInfo { set; get; } - public string ToPlgString() => $"{PluginInfo.Author}_{PluginInfo.PluginId}"; - - public string ToMtdString(MethodInfo methodInfo) - { - StringBuilder sb = new StringBuilder(); - sb.Append("|"); - foreach (var genericArgument in methodInfo.GetParameters()) - { - var plugin = PluginManager.EnablePlugin - .FirstOrDefault((e) => e.Value._dll == genericArgument.ParameterType.Assembly) - .Value; - // type.Assembly. - // var a = PluginManager.GetPlugnNameByTypeName(type.FullName); - if (plugin is null) - { - sb.Append($"System {genericArgument.ParameterType.FullName}"); - sb.Append("|"); - continue; - } - - sb.Append($"{plugin.ToPlgString()} {genericArgument.ParameterType.FullName}"); - sb.Append("|"); - } - - sb.Remove(sb.Length - 1, 1); - return $"{PluginInfo.Author}_{PluginInfo.PluginId}/{methodInfo.DeclaringType!.FullName}/{methodInfo.Name}{sb}"; - } public Type GetType(string typeName) { diff --git a/PluginCore b/PluginCore index 216a81c..af44cde 160000 --- a/PluginCore +++ b/PluginCore @@ -1 +1 @@ -Subproject commit 216a81c6c749e2d7242a560f66c0bfcdda1e903b +Subproject commit af44cdea5c0e259aa637f477b13446ec8be28d56