private static void InitializeCommandsAndIcons() { foreach (KeyValuePair <Assembly, List <IPluginClient> > Entry in LoadedPluginTable) { foreach (IPluginClient Plugin in Entry.Value) { List <ICommand> PluginCommandList = Plugin.CommandList; if (PluginCommandList != null) { List <ICommand> FullPluginCommandList = new List <ICommand>(); FullCommandList.Add(FullPluginCommandList, Plugin.Name); foreach (ICommand Command in PluginCommandList) { FullPluginCommandList.Add(Command); if (!IsSeparatorCommand(Command)) { CommandTable.Add(Command, Plugin); } } } Icon PluginIcon = Plugin.Icon; if (PluginIcon != null) { ConsolidatedPluginList.Add(Plugin); } } } }
public static bool Init(bool isElevated, string embeddedPluginName, Guid embeddedPluginGuid, Dispatcher dispatcher, IPluginLogger logger) { PluginInterfaceType = typeof(IPluginClient); Assembly CurrentAssembly = Assembly.GetExecutingAssembly(); string Location = CurrentAssembly.Location; string AppFolder = Path.GetDirectoryName(Location); int AssemblyCount = 0; int CompatibleAssemblyCount = 0; Dictionary <Assembly, List <Type> > PluginClientTypeTable = new Dictionary <Assembly, List <Type> >(); Assembly PluginAssembly; List <Type> PluginClientTypeList; if (embeddedPluginName != null) { AssemblyName[] AssemblyNames = CurrentAssembly.GetReferencedAssemblies(); foreach (AssemblyName name in AssemblyNames) { if (name.Name == embeddedPluginName) { FindPluginClientTypesByName(name, out PluginAssembly, out PluginClientTypeList); if (PluginAssembly != null && PluginClientTypeList != null && PluginClientTypeList.Count > 0) { PluginClientTypeTable.Add(PluginAssembly, PluginClientTypeList); } } } } string[] Assemblies = Directory.GetFiles(AppFolder, "*.dll"); foreach (string AssemblyPath in Assemblies) { FindPluginClientTypesByPath(AssemblyPath, out PluginAssembly, out PluginClientTypeList); if (PluginAssembly != null && PluginClientTypeList != null) { PluginClientTypeTable.Add(PluginAssembly, PluginClientTypeList); } } foreach (KeyValuePair <Assembly, List <Type> > Entry in PluginClientTypeTable) { AssemblyCount++; PluginAssembly = Entry.Key; PluginClientTypeList = Entry.Value; if (PluginClientTypeList.Count > 0) { CompatibleAssemblyCount++; CreatePluginList(PluginAssembly, PluginClientTypeList, embeddedPluginGuid, logger, out List <IPluginClient> PluginList); if (PluginList.Count > 0) { LoadedPluginTable.Add(PluginAssembly, PluginList); } } } if (LoadedPluginTable.Count > 0) { foreach (KeyValuePair <Assembly, List <IPluginClient> > Entry in LoadedPluginTable) { foreach (IPluginClient Plugin in Entry.Value) { IPluginSettings Settings = new PluginSettings(GuidToString(Plugin.Guid), logger); Plugin.Initialize(isElevated, dispatcher, Settings, logger); if (Plugin.RequireElevated) { RequireElevated = true; } } } foreach (KeyValuePair <Assembly, List <IPluginClient> > Entry in LoadedPluginTable) { foreach (IPluginClient Plugin in Entry.Value) { List <ICommand> PluginCommandList = Plugin.CommandList; if (PluginCommandList != null) { List <ICommand> FullPluginCommandList = new List <ICommand>(); FullCommandList.Add(FullPluginCommandList, Plugin.Name); foreach (ICommand Command in PluginCommandList) { FullPluginCommandList.Add(Command); if (Command != null) { CommandTable.Add(Command, Plugin); } } } Icon PluginIcon = Plugin.Icon; if (PluginIcon != null) { ConsolidatedPluginList.Add(Plugin); } } } foreach (IPluginClient Plugin in ConsolidatedPluginList) { if (Plugin.HasClickHandler) { PreferredPlugin = Plugin; break; } } if (PreferredPlugin == null && ConsolidatedPluginList.Count > 0) { PreferredPlugin = ConsolidatedPluginList[0]; } return(true); } else { logger.AddLog($"Could not load plugins, {AssemblyCount} assemblies found, {CompatibleAssemblyCount} are compatible."); return(false); } }