Esempio n. 1
0
        private void EnablePlugin(PluginDescriptor plugin, HashSet <PluginDescriptor> enabledPlugins, bool enableHidden)
        {
            if (plugin.IsHidden && !enableHidden)
            {
                throw new RecoverableException(string.Format("This plugin cannot be enabled directly: {0}.", plugin.FullName));
            }

            var availablePlugins = TypeManager.Instance.AvailablePlugins;

            if (!availablePlugins.Contains(plugin))
            {
                throw new RecoverableException(string.Format("There is no plugin named {0}.", plugin.FullName));
            }
            if (!activePlugins.ContainsKey(plugin))
            {
                enabledPlugins.Add(plugin);
                if (plugin.Dependencies != null)
                {
                    foreach (var referencedPlugin in plugin.Dependencies)
                    {
                        var referencedPluginDescriptor = availablePlugins.SingleOrDefault(x => typeComparer.Equals(x.ThisType, referencedPlugin));
                        if (referencedPluginDescriptor == null)
                        {
                            throw new RecoverableException("Plugin {0} not found.".FormatWith(referencedPlugin.GetFullNameOfMember()));
                        }
                        if (enabledPlugins.Contains(referencedPluginDescriptor))
                        {
                            throw new RecoverableException("Circular plugin dependency between {0} and {1}.".FormatWith(plugin.FullName, referencedPluginDescriptor.FullName));
                        }
                        EnablePlugin(referencedPluginDescriptor, enabledPlugins, true);
                    }
                }
                activePlugins[plugin] = plugin.CreatePlugin();
                enabledPlugins.Remove(plugin);
                SaveConfiguration();
            }
        }