コード例 #1
0
        /// <summary>
        /// Load all the widgets from the extension assemblies.
        /// </summary>
        /// <param name="assembliesDelimited"></param>
        public void Load(string assembliesDelimited)
        {
            string[] assemblies = assembliesDelimited.Split(',');
            var      widgets    = new List <KeyValuePair <Type, Widget> >();

            // 1. Process each assembly to find widgets.
            foreach (var assemblyname in assemblies)
            {
                widgets.AddRange(LoadFromAssembly(assemblyname));
            }

            // 2. Now get list of all the properties for each widget.
            var optiondefs = Convert(widgets);

            optiondefs.AddRange(LoadWidgetCommonProperties());

            // 4. Create the widget definitions.
            var widgetdefs = new List <Widget>();

            widgets.ForEach(pair => widgetdefs.Add(pair.Value));
            Widget.Create(widgetdefs, w => w.Name);

            // 5. Create the optiondefs
            OptionDef.Repository.Delete(Query <OptionDef> .New().Where(o => o.Section).Like("W_", false, true));
            OptionDef.Create(optiondefs, o => o.Section, o => o.Key);
        }
コード例 #2
0
        /// <summary>
        /// Converts a widgetattribute to a widget definition.
        /// </summary>
        /// <param name="attribute"></param>
        /// <returns></returns>
        public static OptionDef Convert(PropertyDisplayAttribute attribute)
        {
            OptionDef option = new OptionDef();

            option.AppId        = attribute.AppId;
            option.DefaultValue = attribute.DefaultValue;
            option.DisplayStyle = attribute.DisplayStyle;
            option.IsBasicType  = true;
            option.Key          = attribute.Name;
            option.Section      = attribute.Group;
            option.SortIndex    = attribute.Order;
            option.ValType      = attribute.DataType;
            return(option);
        }
コード例 #3
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
            });
        }
コード例 #4
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);
        }