Beispiel #1
0
        // REVIEW: need review. switch to notify changed schema
        public void PropagateVersionToUsages(IProjectReference projectReference)
        {
            bool usageUpdated = false;

            if (HasProjectAsParent(projectReference, false))
            {
                if (_project.Parent.Version != projectReference.Version)
                {
                    _project.Parent.Version = projectReference.Version;
                    usageUpdated            = true;
                }
            }

            foreach (var dependency in AllDependencies.Where(d => d.ReferenceOperations().ReferenceEqualTo(projectReference, false)))
            {
                if (dependency.Version.IsDefined && dependency.Version != projectReference.Version)
                {
                    dependency.Version = projectReference.Version;
                    usageUpdated       = true;
                }
            }

            foreach (var plugin in AllPlugins.Where(d => d.ReferenceOperations().ReferenceEqualTo(projectReference, false)))
            {
                if (plugin.Version.IsDefined && plugin.Version != projectReference.Version)
                {
                    plugin.Version = projectReference.Version;
                    usageUpdated   = true;
                }
            }

            // TODO: Changed = usageUpdated;
        }
Beispiel #2
0
        /// <summary>
        /// Removes all plugins, of every kind. Logs any errors encountered. (Not all plugins support uninstallation)
        /// </summary>
        public void RemoveAll()
        {
            //Follow uninstall protocol
            foreach (IPlugin p in AllPlugins)
            {
                if (!p.Uninstall(c))
                {
                    this.AcceptIssue(new Issue("Uninstall of " + p.ToString() + " reported failure.", IssueSeverity.Error));
                }
            }

            IList[] collections = new IList[] { AllPlugins.GetCollection(), QuerystringPlugins.GetCollection(), FileExtensionPlugins.GetCollection()
                                                , CachingSystems.GetCollection(), ImageEncoders.GetCollection(), ImageBuilderExtensions.GetCollection() };
            //Then check all collections, logging an issue if they aren't empty.
            foreach (IList coll in collections)
            {
                if (coll.Count > 0)
                {
                    string items = "";
                    foreach (object item in coll)
                    {
                        items += item.ToString() + ", ";
                    }

                    this.AcceptIssue(new Issue("Collection " + coll.ToString() + " was not empty after RemoveAllPlugins() executed!",
                                               "Remaining items: " + items, IssueSeverity.Error));
                }
            }
        }
Beispiel #3
0
 // Lastly, allow plugin modules to register services specific to their implementation.
 private void RegisterPluginServices(IServiceCollection services)
 {
     foreach (IPluginModule module in AllPlugins.SelectMany(p => p.Modules))
     {
         module.RegisterServices(services);
     }
 }
Beispiel #4
0
        /// <summary>
        /// ExcuteAllInstallEvent
        /// </summary>
        public static void ExcuteAllInstallEvent()
        {
            var pls = AllPlugins.ToList().FindAll(a => a.Installed && a.NeedInstalled);

            foreach (var a in pls)
            {
                // 如果已安装过则跳过,未安装过的往下走,如果未安装的发现自己有Dependence则先安装Dependence,深度优先安装
                if (a.IsEnabled)
                {
                    continue;
                }
                a.NeedInstalled = false;
                a.IsEnabled     = false;
                a.Installed     = true;

                // 安装dependences
                foreach (var p in a.Dependences)
                {
                    var dp = pls.FirstOrDefault(x => x.SystemName == p);
                    if (dp == null)
                    {
                        // 找不到自己dependence的情况。。。
                        a.RuntimeInformation = string.Format("Plugin '{0}' start up failed, Dependence {1} can't be found.", a.SystemName, p);
                        LoggerMan.Error(a.RuntimeInformation);
                        break;
                    }

                    InstallPlugin(dp);
                }

                // 安装自己
                InstallPlugin(a);
            }
        }
Beispiel #5
0
        /// <summary>
        ///   Attempts to update plugin <paramref name="packageId" />. If no
        ///   <paramref name="version" /> is specified, the latest available version will be installed.
        /// </summary>
        /// <param name="packageId">The plugin package id to update</param>
        /// <param name="version">Optional version to install</param>
        /// <param name="allowPrereleaseVersions">Whether to include pre-release versions</param>
        /// <param name="cancellationToken"></param>
        /// <returns>Success of operation</returns>
        /// <exception cref="ArgumentException"><paramref name="packageId" /> is empty</exception>
        /// <exception cref="ArgumentException">Plugin <paramref name="packageId" /> is not installed</exception>
        /// <exception cref="ArgumentNullException"></exception>
        public async Task <bool> UpdatePluginAsync(
            string packageId,
            NuGetVersion version                = null,
            bool allowPrereleaseVersions        = false,
            CancellationToken cancellationToken = default)
        {
            var pluginInstance = AllPlugins.FirstOrDefault(pi => pi.Package.Id == packageId);

            if (await StopPlugin(pluginInstance) == false)
            {
                LogAdapter.Warning($"Failed to stop plugin {packageId}, aborting update.");
                return(false);
            }

            using (await PMLock.WriterLockAsync())
            {
                var success = await PackageManager.UpdateAsync(
                    packageId,
                    version,
                    allowPrereleaseVersions,
                    cancellationToken);

                UISynchronizationContext.Send(() => PackageManager.FindInstalledPluginById(packageId)?.RaiseVersionChanged());

                return(success);
            }
        }
Beispiel #6
0
        private void CategorizePlugins(IEnumerable <IPlugin> plugins)
        {
            AllPlugins = plugins.ToArray();

            HostPlugin  = AllPlugins.FirstOrDefault(p => p.PluginType == PluginTypes.HostPlugin);
            AppPlugins  = AllPlugins.Where(p => p.PluginType == PluginTypes.ApplicationPlugin).ToArray();
            CorePlugins = AllPlugins.Where(p => p.PluginType == PluginTypes.CorePlugin).ToArray();

            LogPlugins(AllPlugins);
        }
Beispiel #7
0
        /// <summary>
        /// Returns types associated with a specific category of plug-in.
        /// </summary>
        /// <param name="pluginTypes">The category of plug-ins to limit the return types.</param>
        /// <returns>List of limited plug in types or all plug-in types if no category is specified.</returns>
        public IEnumerable <Type> GetPluginTypes(params PluginTypes[] pluginTypes)
        {
            if (pluginTypes == null)
            {
                throw new ArgumentNullException(nameof(pluginTypes),
                                                "List of Plug-in types cannot be null.");
            }

            return(pluginTypes.Length == 0 ? AllPlugins.SelectMany(p => p.Types)
                : AllPlugins.Where(p => pluginTypes.Contains(p.PluginType)).SelectMany(p => p.Types));
        }
        /// <summary>Start plugin <paramref name="packageId" /></summary>
        /// <param name="packageId">The plugin's package id to start</param>
        /// <returns>Success of operation</returns>
        public async Task <bool> StartPlugin(string packageId)
        {
            var pluginInstance = AllPlugins.FirstOrDefault(p => p.Package.Id == packageId);

            if (pluginInstance == null)
            {
                return(false);
            }

            return(await StartPlugin(pluginInstance).ConfigureAwait(false));
        }
Beispiel #9
0
        private IEnumerable <Type> FilteredTypesByPluginType(IPlugin plugin)
        {
            // Core plug-in can access types from all other plug-in types.
            if (plugin.PluginType == PluginTypes.CorePlugin)
            {
                return(AllPlugins.SelectMany(p => p.Types));
            }

            // Application centric plug-in can only access types contained in
            // other application plugs.
            return(AppPlugins.SelectMany(p => p.Types));
        }
Beispiel #10
0
        /// <summary>
        /// Only for use by plugins during IPlugin.Install. Call Plugin.Install instead of this method, since plugins often must perform other initialization actions.
        /// Adds the specified plugin to AllPlugins, QuerystringPlugins, CachingSystems, ImageEncoders, and ImageBuilderExtensions, based
        /// on which interfaces the instance implements. For ICache and IEncoder, the plugin is inserted at the beginning of CachingSystems and ImageEncoders respectively.
        /// To reiterate, plugins may register event handlers and modify settings - thus you should use the plugin's method to uninstall them vs. using this method.
        /// Will not register a plugin that is already installed, unless it implements IMultiInstancePlugin.
        /// </summary>
        /// <param name="plugin"></param>
        public void add_plugin(IPlugin plugin)
        {
            if (!(plugin is IMultiInstancePlugin) && HasPlugin(plugin.GetType()))
            {
                AcceptIssue(new Issue("An instance of the specified plugin (" + plugin.GetType().ToString() + ") has already been registered.",
                                      "The plugin should implement IMultiInstancePlugin to support multiple instances.", IssueSeverity.Error));
                return;
            }

            AllPlugins.Add(plugin);
            if (plugin is IQuerystringPlugin)
            {
                QuerystringPlugins.Add(plugin as IQuerystringPlugin);
            }
            if (plugin is IFileExtensionPlugin)
            {
                FileExtensionPlugins.Add(plugin as IFileExtensionPlugin);
            }
            if (plugin is ICache)
            {
                CachingSystems.AddFirst(plugin as ICache);
            }
            if (plugin is IEncoder)
            {
                ImageEncoders.AddFirst(plugin as IEncoder);
            }
            if (plugin is BuilderExtension)
            {
                ImageBuilderExtensions.Add(plugin as BuilderExtension);
            }
            if (plugin is IVirtualImageProvider)
            {
                VirtualProviderPlugins.Add(plugin as IVirtualImageProvider);
            }
            if (plugin is ISettingsModifier)
            {
                SettingsModifierPlugins.Add(plugin as ISettingsModifier);
            }
            if (plugin is ICurrentConfigProvider)
            {
                ConfigProviders.Add(plugin as ICurrentConfigProvider);
            }
            if (plugin is ILogManager)
            {
                LogManager = plugin as ILogManager;
            }
            if (plugin is ILicensedPlugin || plugin is ILicenseProvider)
            {
                FireLicensePluginsChange();
            }
        }
Beispiel #11
0
 /// <summary>
 /// For use only by plugins during .Uninstall.
 /// Removes the specified plugin from AllPlugins, QuerystringPlugins, CachingSystems, ImageEncoders, and ImageBuilderExtensions, based
 /// on which interfaces the instance implements.
 /// Plugins may register event handlers and modify settings - thus you should use the plugin's method to uninstall them vs. using this method.
 /// </summary>
 /// <param name="plugin"></param>
 public void remove_plugin(object plugin)
 {
     if (plugin is IPlugin)
     {
         AllPlugins.Remove(plugin as IPlugin);
     }
     if (plugin is IQuerystringPlugin)
     {
         QuerystringPlugins.Remove(plugin as IQuerystringPlugin);
     }
     if (plugin is IFileExtensionPlugin)
     {
         FileExtensionPlugins.Remove(plugin as IFileExtensionPlugin);
     }
     if (plugin is ICache)
     {
         CachingSystems.Remove(plugin as ICache);
     }
     if (plugin is IEncoder)
     {
         ImageEncoders.Remove(plugin as IEncoder);
     }
     if (plugin is BuilderExtension)
     {
         ImageBuilderExtensions.Remove(plugin as BuilderExtension);
     }
     if (plugin is IVirtualImageProvider)
     {
         VirtualProviderPlugins.Remove(plugin as IVirtualImageProvider);
     }
     if (plugin is ISettingsModifier)
     {
         SettingsModifierPlugins.Remove(plugin as ISettingsModifier);
     }
     if (plugin is ICurrentConfigProvider)
     {
         ConfigProviders.Remove(plugin as ICurrentConfigProvider);
     }
     if (plugin is ILogManager && LogManager == plugin)
     {
         LogManager = null;
     }
     if (plugin is ILicensedPlugin || plugin is ILicenseProvider)
     {
         FireLicensePluginsChange();
     }
 }
Beispiel #12
0
        /// <summary>
        /// Initializes the List of Plugins by collecting Plugins from the project and given .dll files.
        /// </summary>
        public PluginManager()
        {
            string wdir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            var lst = Directory.GetFiles(wdir)
                      .Where(i => new[] { ".dll", ".exe" }.Contains(Path.GetExtension(i)))
                      .SelectMany(i => Assembly.LoadFrom(i).GetTypes())
                      .Where(myType => myType.IsClass &&
                             !myType.IsAbstract &&
                             myType.GetCustomAttributes(true).Any(i => i.GetType() == typeof(AutoLoadPluginAttribute)) &&
                             myType.GetInterfaces().Any(i => i == typeof(IPlugin)));

            foreach (Type type in lst)
            {
                AllPlugins.Add((IPlugin)Activator.CreateInstance(type));
            }
        }
Beispiel #13
0
        public static void EnablePlugin(PluginPair plugin)
        {
            var actionKeywords = plugin.Metadata.ActionKeywords;

            if (actionKeywords == null || actionKeywords.Count == 0 || actionKeywords[0] == Query.GlobalPluginWildcardSign)
            {
                GlobalPlugins.Add(plugin);
            }
            else
            {
                foreach (var actionkeyword in plugin.Metadata.ActionKeywords)
                {
                    NonGlobalPlugins[actionkeyword] = plugin;
                }
            }
            AllPlugins.Add(plugin);
        }
Beispiel #14
0
        /// <summary>Uninstall <paramref name="pluginPackage" />. The plugin will be stopped if it is running.</summary>
        /// <param name="pluginPackage">The plugin to be uninstalled</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException">
        ///   When <paramref name="pluginPackage" /> is a Development
        ///   plugin
        /// </exception>
        public Task <bool> UninstallPluginAsync(LocalPluginPackage <TMeta> pluginPackage)
        {
            if (pluginPackage == null)
            {
                throw new ArgumentNullException(nameof(pluginPackage));
            }

            if (pluginPackage is LocalDevPluginPackage <TMeta> )
            {
                throw new ArgumentException($"Cannot uninstall a development plugin");
            }

            var pluginInstance = AllPlugins.FirstOrDefault(pi => pi.Package == pluginPackage);

            if (pluginInstance == null)
            {
                throw new InvalidOperationException($"Cannot find a matching PluginInstance for LocalPluginPackage {pluginPackage.Id}");
            }

            return(UninstallPluginAsync(pluginInstance));
        }
Beispiel #15
0
        private static void MarkPlugin(string systemName, bool bolIn)
        {
            if (String.IsNullOrEmpty(systemName))
            {
                throw new ArgumentNullException("systemName");
            }
            var pl = AllPlugins.ToList().Find(a => a.SystemName == systemName);

            if (pl.Installed != bolIn)
            {
                pl.Installed     = bolIn;
                pl.NeedInstalled = bolIn;
                try
                {
                    PluginFileParser.SavePluginDescriptionFile(pl);
                }
                catch (Exception ex)
                {
                    pl.Installed = !bolIn;
                    LoggerMan.Error(ex);
                }
            }
        }
Beispiel #16
0
        internal static Task CommitTransaction(StateTransitionTransaction transaction)
        {
            if (!UnityGame.OnMainThread)
            {
                return(UnityMainThreadTaskScheduler.Factory.StartNew(() => CommitTransaction(transaction)).Unwrap());
            }

            lock (commitTransactionLockObject)
            {
                if (transaction.CurrentlyEnabled.Except(AllPlugins)
                    .Concat(AllPlugins.Except(transaction.CurrentlyEnabled)).Any() ||
                    transaction.CurrentlyDisabled.Except(DisabledPlugins)
                    .Concat(DisabledPlugins.Except(transaction.CurrentlyDisabled)).Any())
                { // ensure that the transaction's base state reflects the current state, otherwise throw
                    throw new InvalidOperationException("Transaction no longer resembles the current state of plugins");
                }

                var toEnable  = transaction.ToEnable;
                var toDisable = transaction.ToDisable;
                transaction.Dispose();

                using var disabledChangeTransaction = DisabledConfig.Instance.ChangeTransaction();
                {
                    // first enable the mods that need to be
                    void DeTree(List <PluginMetadata> into, IEnumerable <PluginMetadata> tree)
                    {
                        foreach (var st in tree)
                        {
                            if (toEnable.Contains(st) && !into.Contains(st))
                            {
                                DeTree(into, st.Dependencies);
                                into.Add(st);
                            }
                        }
                    }

                    var enableOrder = new List <PluginMetadata>();
                    DeTree(enableOrder, toEnable);

                    foreach (var meta in enableOrder)
                    {
                        var executor = runtimeDisabledPlugins.FirstOrDefault(e => e.Metadata == meta);
                        if (meta.RuntimeOptions == RuntimeOptions.DynamicInit)
                        {
                            if (executor != null)
                            {
                                runtimeDisabledPlugins.Remove(executor);
                            }
                            else
                            {
                                executor = PluginLoader.InitPlugin(meta, AllPlugins);
                            }

                            if (executor == null)
                            {
                                continue;                   // couldn't initialize, skip to next
                            }
                        }

                        PluginLoader.DisabledPlugins.Remove(meta);
                        DisabledConfig.Instance.DisabledModIds.Remove(meta.Id ?? meta.Name);

                        PluginEnabled?.Invoke(meta, meta.RuntimeOptions != RuntimeOptions.DynamicInit);

                        if (meta.RuntimeOptions == RuntimeOptions.DynamicInit)
                        {
                            _bsPlugins.Add(executor);

                            try
                            {
                                executor.Enable();
                            }
                            catch (Exception e)
                            {
                                Logger.loader.Error($"Error while enabling {meta.Id}:");
                                Logger.loader.Error(e);
                                // this should still be considered enabled, hence its position
                            }
                        }
                    }
                }

                Task result;
                {
Beispiel #17
0
 private bool UsesPlugin(IProjectReference projectReference, bool strictVersion)
 {
     return(AllPlugins.Any(d => d.ReferenceOperations().ReferenceEqualTo(projectReference, strictVersion)));
 }
Beispiel #18
0
 /// <summary>
 /// get specified plugin, return null if not found
 /// </summary>
 /// <param name="id">id of plugin</param>
 /// <returns>plugin</returns>
 public static PluginPair GetPluginForId(string id)
 {
     return(AllPlugins.FirstOrDefault(o => o.Metadata.ID == id));
 }
Beispiel #19
0
 /// <summary>Registers the plugin.</summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="plugin">The plugin.</param>
 /// <returns></returns>
 public T RegisterPlugin <T>(T plugin) where T : IHzPlugin
 {
     // ExecuteEvent += plugin.OnExcecuteAsync;
     AllPlugins.Add(plugin);
     return(plugin);
 }
Beispiel #20
0
 /// <summary>
 /// SavePlugins
 /// </summary>
 /// <param name="pluginDescriptor"></param>
 public static void SavePlugins(
     PluginDescriptor pluginDescriptor)
 {
     AllPlugins.ToList().Add(pluginDescriptor);
 }
Beispiel #21
0
 public static IEnumerable <PluginPair> GetPluginsForInterface <T>()
 {
     return(AllPlugins.Where(p => p.Plugin is T));
 }
 public PluginsListWnd()
 {
     InitializeComponent();
     AllPlugins.AddRange(Plugins.GetPlugins <IPostDbRestore>().Select(r => r.Value.PluginName));
     AllPlugins.AddRange(Plugins.GetPlugins <IDbUtility>().Select(r => r.Value.PluginName));
 }