Exemple #1
0
        /// <inheritdoc />
        public object GetByKey(string key, string plugin = "", string environment = "")
        {
            IContainsSettings pluginObject = null;

            if (string.IsNullOrWhiteSpace(environment))
            {
                environment = "Default";
            }

            if (!string.IsNullOrWhiteSpace(plugin))
            {
                pluginObject = ApplicationContext.Application?.Plugins
                               .FirstOrDefault(x => x.Name == plugin && x is IContainsSettings) as IContainsSettings;
            }

            if (pluginObject == null)
            {
                throw new ArgumentNullException(nameof(plugin));
            }

            var settings = PluginHelper.GetSettings(pluginObject);

            return(settings?.SoluiNetEnvironment
                   .FirstOrDefault(x => x.name == environment)?
                   .SoluiNetSettingEntry
                   .FirstOrDefault(x => x.name == key)?
                   .Value);
        }
        /// <summary>
        /// Get the effective settings for the overgiven plugin.
        /// </summary>
        /// <param name="plugin">The plugin for which the settings should be provided.</param>
        /// <returns>An instance of <see cref="Settings.SoluiNetSettingType"/> which contains all effective settings for the plugin.</returns>
        public static Settings.SoluiNetSettingType GetSettings(IContainsSettings plugin)
        {
            if (plugin == null)
            {
                return(null);
            }

            var settingsXml = string.Empty;

            var folderPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            if (string.IsNullOrEmpty(folderPath))
            {
                return(null);
            }

            var generalSettings = Path.Combine(folderPath, "Settings.xml");

            if (System.IO.File.Exists(generalSettings))
            {
                var generalSettingsXml = FileHelper.StringFromFile(generalSettings);

                settingsXml = generalSettingsXml;
            }

            var embeddedSettings = GetEmbeddedResources(plugin, "Settings");

            var settingsContainer = embeddedSettings.FirstOrDefault();

            if (settingsContainer != null)
            {
                var settingsStream = plugin.GetType().Assembly.GetManifestResourceStream(settingsContainer);

                if (settingsStream == null)
                {
                    return(null);
                }

                var embeddedResourceXml = StreamHelper.StreamToString(settingsStream);
                settingsXml = XmlHelper.Merge(settingsXml, embeddedResourceXml, "SoluiNet.Settings");
            }

            var settingsPathForPlugin = Path.Combine(folderPath, "Plugins", string.Format(CultureInfo.InvariantCulture, "Settings.{0}.xml", plugin.Name));

            if (System.IO.File.Exists(settingsPathForPlugin))
            {
                var localSavedXml = FileHelper.StringFromFile(settingsPathForPlugin);

                settingsXml = XmlHelper.Merge(settingsXml, localSavedXml, "SoluiNet.Settings");
            }

            var settings = XmlHelper.Deserialize <Settings.SoluiNetSettingType>(settingsXml);

            return(settings);
        }
        /// <summary>
        /// Get the effective settings for the overgiven plugin as dictionary.
        /// </summary>
        /// <param name="plugin">The plugin for which the settings should be provided.</param>
        /// <returns>A <see cref="Dictionary{TKey, TValue}"/> which contains all effective settings for the plugin.</returns>
        public static IDictionary <string, object> GetSettingsAsDictionary(IContainsSettings plugin)
        {
            var settings = GetSettings(plugin);

            if (settings == null)
            {
                return(null);
            }

            var preparedSettings = settings.SoluiNetEnvironment
                                   .SelectMany(x => x.SoluiNetSettingEntry.Select(y => new { SettingName = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", x.name, y.name), SettingValue = y.Value }));

            return(preparedSettings.ToDictionary(x => x.SettingName, x => (object)x.SettingValue));
        }
 /// <summary>
 /// Retrieve settings for the plugin as dictionary.
 /// </summary>
 /// <param name="plugin">The plugin.</param>
 /// <returns>A <see cref="Dictionary{TKey, TValue}"/> which contains all effective settings for the plugin.</returns>
 public static IDictionary <string, object> RetrieveSettingsAsDictionary(this IContainsSettings plugin)
 {
     return(GetSettingsAsDictionary(plugin));
 }
 /// <summary>
 /// Retrieve settings for the plugin.
 /// </summary>
 /// <param name="plugin">The plugin.</param>
 /// <returns>An instance of <see cref="Settings.SoluiNetSettingType"/> which contains all effective settings for the plugin.</returns>
 public static Settings.SoluiNetSettingType RetrieveSettings(this IContainsSettings plugin)
 {
     return(GetSettings(plugin));
 }