public override void OK() { base.OK(); // Apply the enabled state var disabledplugins = new PluginLoader.DisabledPlugins(); bool bChanged = false; foreach (OmeaPluginsPageListEntry item in _arItems) { if (item is OmeaPluginsPageListEntryPlugin) { bChanged |= ((OmeaPluginsPageListEntryPlugin)item).Commit(disabledplugins); } } // Require restart to apply changes // (Note: even if loading a new plugin, should better restart, as others might depend on its registration) if (bChanged) { NeedRestart = true; } }
/// <summary> /// Applies the edited changes. /// </summary> public bool Commit(PluginLoader.DisabledPlugins disabledplugins) { // Not changed? if (IsEnabled == _bIsEnabledInitially) { return(false); } // Apply the new state if (IsEnabled) { disabledplugins.Remove(AssemblyInfo.PluginAssemblyName); } else { disabledplugins.Add(AssemblyInfo.PluginAssemblyName); } // Mark as non-dirty _bIsEnabledInitially = IsEnabled; return(true); // Were changes }
/// <summary> /// Ctor. /// </summary>) /// <param name="sPluginAssemblyName">Raw name of the plugin assembly.</param> /// <param name="funcLoadAssembly">A funtion to load the assembly on-demand.</param> /// <param name="disabledplugins">A cached <see cref="PluginLoader.DisabledPlugins"/> instance for getting the initial <see cref="OmeaPluginsPageListEntry.IsEnabled"/> value.</param> /// <param name="pluginfileinfo">Info about the file the plugin were loaded from.</param> /// <param name="sRuntimeLoadError">If the plugin failed to be loaded at runtime, records the load error.</param> public OmeaPluginsPageListEntryPlugin([NotNull] string sPluginAssemblyName, [NotNull] Func <Assembly> funcLoadAssembly, PluginLoader.PossiblyPluginFileInfo pluginfileinfo, [NotNull] string sRuntimeLoadError, [NotNull] PluginLoader.DisabledPlugins disabledplugins) { if (sPluginAssemblyName == null) { throw new ArgumentNullException("sPluginAssemblyName"); } if (funcLoadAssembly == null) { throw new ArgumentNullException("funcLoadAssembly"); } if (disabledplugins == null) { throw new ArgumentNullException("disabledplugins"); } if (sRuntimeLoadError == null) { throw new ArgumentNullException("sRuntimeLoadError"); } _funcLoadAssembly = funcLoadAssembly; _pluginfileinfo = pluginfileinfo; _sRuntimeLoadError = sRuntimeLoadError; _assemblyinfo = OmeaPluginsPageAssemblyInfo.CreateNotLoaded(sPluginAssemblyName, _pluginfileinfo, _sRuntimeLoadError); _bIsEnabledInitially = !disabledplugins.Contains(sPluginAssemblyName); IsEnabled = _bIsEnabledInitially; }
/// <summary> /// Harvest the plugins, both loaded and not. /// </summary> private void FillPluginsList() { _arItems.Clear(); _queueItemsToLoad.Clear(); var disabledplugins = new PluginLoader.DisabledPlugins(); var hashDisoveredPluginAssemblies = new HashSet <string>(); var pluginloader = (PluginLoader)Core.PluginLoader; // Stage 1: loaded plugins foreach (IPlugin plugin in pluginloader.GetLoadedPlugins()) { try { string asmname = plugin.GetType().Assembly.GetName().Name; if (!hashDisoveredPluginAssemblies.Add(asmname)) { continue; } // Submit IPlugin pluginConst = plugin; PluginLoader.PossiblyPluginFileInfo pluginfile = pluginloader.GetPluginFileInfo(plugin); _arItems.Add(new OmeaPluginsPageListEntryPlugin(asmname, () => pluginConst.GetType().Assembly, pluginfile, pluginloader.GetPluginLoadRuntimeError(pluginfile.File), disabledplugins)); } catch (Exception ex) { Core.ReportBackgroundException(ex); } } // Stage 2: not loaded plugins (and non-plugins in Debug mode) foreach (PluginLoader.PossiblyPluginFileInfo file in pluginloader.GetAllPluginFiles()) { try { if (file.IsPlugin) { string asmname = Path.GetFileNameWithoutExtension(file.File.FullName); if (!hashDisoveredPluginAssemblies.Add(asmname)) { continue; } // Submit FileInfo fileConst = file.File; _arItems.Add(new OmeaPluginsPageListEntryPlugin(asmname, () => PluginLoader.LoadPluginAssembly(fileConst), file, pluginloader.GetPluginLoadRuntimeError(file.File), disabledplugins)); } else if (ShowDebugInfo) { _arItems.Add(new OmeaPluginsPageListEntryNonPlugin(file)); } } catch (Exception ex) { Core.ReportBackgroundException(ex); } } // Create the view for this collection that supports sorting, grouping and sharing the selection if (_arItemsView == null) // Reuse afterwards, as it takes part in databinding { _arItemsView = CollectionViewSource.GetDefaultView(_arItems); _arItemsView.SortDescriptions.Add(new SortDescription("IsEnabledInitially", ListSortDirection.Descending)); _arItemsView.SortDescriptions.Add(new SortDescription("Title", ListSortDirection.Ascending)); _arItemsView.GroupDescriptions.Add(new PropertyGroupDescription("IsEnabledInitially", ValueConverter.Create((bool b) => b ? Stringtable.Enabled : Stringtable.Disabled))); } else { _arItemsView.Refresh(); } // Shedulle loading of the items foreach (OmeaPluginsPageListEntry item in _arItems) { if (item is OmeaPluginsPageListEntryPlugin) { _queueItemsToLoad.Enqueue((OmeaPluginsPageListEntryPlugin)item); } } if (_queueItemsToLoad.Count > 0) { Core.UserInterfaceAP.QueueJob(Stringtable.JobLoadPluginAssemblies, PumpLoadQueue); } }