Пример #1
0
        public PluginConfigEntryCollection GetEnabledPlugins()
        {
            PluginConfigEntryCollection result = new PluginConfigEntryCollection();

            result.AddRange(FindAll(plugin => plugin.Enabled));

            return(result);
        }
Пример #2
0
        public static PluginConfigEntryCollection ReadFromDirectory(string directoryPath, int?recursionDepth, ILogger logger)
        {
            if (recursionDepth <= 0)
            {
                throw new ArgumentOutOfRangeException("recursionDepth", recursionDepth, "recursionDepth can not be 0 or less than 0.");
            }

            List <string> settingsFilePathList = GetSettingsFilePaths(directoryPath, recursionDepth);
            PluginConfigEntryCollection result = new PluginConfigEntryCollection();

            foreach (string settingsFilePath in settingsFilePathList)
            {
                XElement pluginSettingsElement;

                try
                {
                    pluginSettingsElement = XElement.Load(settingsFilePath);
                }
                catch (Exception ex)
                {
                    if (logger != null && !(logger is IUILogger))
                    {
                        logger.Error(string.Format("Couldn't load settings from  plugin settings path '{0}'. File is not a valid xml file.", settingsFilePath), ex);
                    }

                    if (logger != null && logger is IUILogger)
                    {
                        ((IUILogger)logger).ErrorToUI(string.Format("Couldn't load settings from  plugin settings path '{0}'. File is not a valid xml file.", settingsFilePath), ex);
                    }

                    continue;
                }

                try
                {
                    result.Add(PluginConfigEntry.ReadFromXElement(pluginSettingsElement, Path.GetDirectoryName(settingsFilePath)));
                }
                catch (Exception ex)
                {
                    if (logger != null && !(logger is IUILogger))
                    {
                        logger.Error(string.Format("Couldn't load settings from  plugin settings path '{0}'. File is missing some settings.", settingsFilePath), ex);
                    }

                    if (logger != null && logger is IUILogger)
                    {
                        ((IUILogger)logger).ErrorToUI(string.Format("Couldn't load settings from  plugin settings path '{0}'. File is missing some settings.", settingsFilePath), ex);
                    }
                }
            }

            result.Sort((p1, p2) => p1.Order - p2.Order);

            return(result);
        }