/// <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> /// Loads the <see cref="AssemblyInfo"/>, if not loaded yet. /// </summary> /// <param name="funcOnDone">Executed after loading (or skipping) the item, on the UI thread.</param> public void Load([NotNull] Action funcOnDone) { // Don't start second time if ((AssemblyInfo.IsLoaded) || (_isBusyLoading)) { funcOnDone(); return; } _isBusyLoading = true; // Load async Assembly assembly = null; List <Type> plugintypes = null; Action funcPreloadOnOtherThread = delegate { assembly = _funcLoadAssembly(); // Plugin types in this assembly plugintypes = new List <Type>(); foreach (Type type in assembly.GetExportedTypes()) { if (PluginLoader.IsOmeaPluginType(type)) { plugintypes.Add(type); } } }; Action funcRenderOnUiThread = delegate { _isBusyLoading = false; // Create visual objects on the UI thread try { if ((assembly != null) && (plugintypes != null)) { AssemblyInfo = OmeaPluginsPageAssemblyInfo.CreateFromAssembly(assembly, plugintypes, PluginFileInfo, _sRuntimeLoadError); } } catch (Exception ex) { Core.ReportBackgroundException(ex); } funcOnDone(); }; // Schedulle Core.NetworkAP.QueueJob(Stringtable.JobLoadPluginAssemblyInfo, delegate { try { funcPreloadOnOtherThread(); } finally { // Commit on the home thread Core.UserInterfaceAP.QueueJob(Stringtable.JobLoadPluginAssemblyInfo, funcRenderOnUiThread); } }); }