/// <summary>
        /// The overlayer used by the plugin loader. Meant to take a (plugin)settings
        /// and overlay the core configuration with a (plugin)settings.
        /// </summary>
        /// <param name="filename">
        /// The filename.
        /// </param>
        /// <returns>
        /// The <see cref="Section"/>.
        /// </returns>
        public Section OverLay(string filename)
        {
            var overLayer        = new OverLayer();
            var stfConfiguration = new StfConfiguration();
            var overlay          = stfConfiguration.LoadConfig(filename);

            // the overlayer handles if arguments are null
            currentlyLoadedSection = overLayer.OverLay(currentlyLoadedSection, overlay);
            Environment            = DefaultEnvironment;

            return(currentlyLoadedSection);
        }
Exemple #2
0
        /// <summary>
        /// The set config.
        /// </summary>
        /// <param name="userConfig">
        /// The user config.
        /// </param>
        /// <param name="stfConfiguration">
        /// The stf configuration.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        internal object SetConfig(Dictionary <string, StfConfigurationAttribute> userConfig, StfConfiguration stfConfiguration)
        {
            var type = currentFieldSet.GetType();

            if (userConfig == null)
            {
                return(currentFieldSet);
            }

            foreach (var uc in userConfig)
            {
                var property = type.GetProperty(uc.Key);
                var newValue = stfConfiguration.GetConfigValue(uc.Value.ConfigKeyPath, uc.Value.DefaultValue);

                if (property.PropertyType == typeof(string))
                {
                    property.SetValue(currentFieldSet, newValue);
                    continue;
                }

                try
                {
                    var valueToSet = string.IsNullOrEmpty(newValue)
                                   ? TypeDescriptor.GetDefaultProperty(property.PropertyType)
                                   : TypeDescriptor.GetConverter(property.PropertyType).ConvertFromInvariantString(newValue);

                    property.SetValue(currentFieldSet, valueToSet);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

            return(currentFieldSet);
        }