public static void AddPlugin <T>(string[] args) { Type type = typeof(T); Plugin plugin = Activator.CreateInstance(type) as Plugin; InsertPlugin(plugin, args); }
private static void InsertPlugin(Plugin plugin, string[] args) { switch (plugin.PluginType) { case PluginType.Application: ApplicationList.Add((ApplicationPlugin)plugin); Logger.Origin($"应用 \"{plugin.Name}\" 已经加载完毕。"); break; case PluginType.Service: default: ServicePlugin svcPlugin = (ServicePlugin)plugin; svcPlugin.Execute(args); ServiceList.Add(svcPlugin); Logger.Origin($"服务 \"{svcPlugin.Name}\" 已经加载完毕。"); break; } }
private static void InsertPlugin(Type type, string[] args) { try { Plugin plugin = Activator.CreateInstance(type) as Plugin; if (plugin.PluginType != PluginType.Command) { InsertPlugin(plugin, args); } else { CommandPlugin cmdPlugin = (CommandPlugin)plugin; cmdPlugin.Initialize(args); string str = ""; if (cmdPlugin.Commands != null) { str = "("; foreach (var cmd in cmdPlugin.Commands) { //CommandMap.TryAdd(cmd, (CommandApp)plugin); CommandMap.TryAdd(cmd, type); CommandMapStatic.TryAdd(cmd, cmdPlugin); str += cmd + ","; } str = str.TrimEnd(',') + ") "; } Logger.Origin($"命令 \"{plugin.Name}\" {str}已经加载完毕。"); } } catch (Exception ex) { Logger.Exception(ex.InnerException ?? ex); Logger.Error($"加载插件{type.Name}失败。"); } }