Ejemplo n.º 1
0
        /// <summary>
        /// Gets the settings.
        /// </summary>
        /// <returns></returns>
        private ConfigViewModel GetSettings()
        {
            // Get the name of the config from either url params for from form.
            string configName = this.Request.Params["configname"];

            if (string.IsNullOrEmpty(configName))
            {
                configName = this.Request.Form["confignameInForm"];
            }

            var configData = CMS.Configs.Get(configName);
            var config     = configData.Config as IConfigSourceDynamic;

            // This is the list of option definitions ( from the /config/data/optiondefs.csv ) file.
            var optionDefs = OptionDef.BySection(configName);

            // Resource file for the name of the setting, description, example values. These are localized.
            var resources = Resource.BySection(configName);

            return(new ConfigViewModel()
            {
                Name = configName, Description = configData.Description, Config = config, OptionDefs = optionDefs, Resources = resources
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads the specified config section.
        /// </summary>
        /// <param name="configSection">The config section. This can be comma delimited. "Post"</param>
        /// <param name="resourceSection">The resource sections. This can be comma delimited. "Post"</param>
        /// <param name="language">The language. e.g. "english"</param>
        public void Load(string configSection, string resourceSection, string language)
        {
            _language = language;

            // This is the list of option definitions ( from the /config/data/optiondefs.csv ) file.
            IList <OptionDef> optionDefs = null;

            if (configSection.Contains(","))
            {
                string[] configNames = configSection.Split(',');
                optionDefs = OptionDef.BySection(configNames);
            }
            else
            {
                optionDefs = OptionDef.BySection(configSection);
            }

            bool hasInstanceExcludes = _excludes != null;

            _hasOptionDefs = optionDefs != null && optionDefs.Count > 0;
            _propNames     = new List <string>();

            // This can be optimzed.
            ToDo.Optimize(ToDo.Priority.Normal, "Kishore", "The optiondefs, propsToExclude, resources can be cached.", () =>
            {
                if (_hasOptionDefs)
                {
                    _optionDefs    = new List <OptionDef>();
                    _optionDefsMap = new Dictionary <string, OptionDef>();
                    foreach (var optionDef in optionDefs)
                    {
                        // Only store if ok to process the option.
                        if (!_propsToExclude.ContainsKey(optionDef.Key) && (!hasInstanceExcludes || (hasInstanceExcludes && !_excludes.ContainsKey(optionDef.Key))))
                        {
                            _optionDefsMap[optionDef.Key] = optionDef;
                            _optionDefs.Add(optionDef);
                            _propNames.Add(optionDef.Key);
                        }
                    }
                }
                else
                {
                    foreach (var pair in _props)
                    {
                        // Only store if ok to process the option.
                        if (!_propsToExclude.ContainsKey(pair.Key) && (!hasInstanceExcludes || (hasInstanceExcludes && !_excludes.ContainsKey(pair.Key))))
                        {
                            _propNames.Add(pair.Key);
                        }
                    }
                }
            });

            // Resource file for the name of the setting, description, example values. These are localized.
            if (resourceSection.Contains(","))
            {
                string[] resourceNames = resourceSection.Split(',');
                _resources = Resource.BySection(resourceNames);
            }
            else
            {
                _resources = Resource.BySection(resourceSection);
            }

            _hasResources = _resources != null && _resources.Count > 0;

            // Loading all the public/instance/get-set properties.
            LoadProperties(_model);
        }