예제 #1
0
        public EntityCacheGeneric <string, SettingItem> GetAllSettingItems(string name)
        {
            Type settingsType = this.GetType();
            List <SettingItem> settingItems = new List <SettingItem>();

            foreach (PropertyInfo p in settingsType.GetProperties())
            {
                object[] categoryAttributes = p.GetCustomAttributes(typeof(SettingInfoAttribute), true);
                if (categoryAttributes == null)
                {
                    continue;
                }
                foreach (SettingInfoAttribute c in categoryAttributes)
                {
                    SettingItem settingItem = new SettingItem(
                        c.Category,
                        p.Name,
                        EntityReader.GetPropertyValue(p.Name, this, false),
                        p.PropertyType,
                        c.AutoFormatDisplayName,
                        c.DisplayName,
                        c.Description,
                        c.CategorySequenceId,
                        c.PasswordChar,
                        null,
                        new SettingsCategoryInfo(this, c.Category));
                    settingItems.Add(settingItem);
                }
            }
            string entityCacheName = string.IsNullOrEmpty(name) ? DataShaper.ShapeCamelCaseString(this.GetType().Name) : name;
            EntityCacheGeneric <string, SettingItem> result = new EntityCacheGeneric <string, SettingItem>(entityCacheName);

            settingItems.OrderBy(p => p.Category).ToList().ForEach(p => result.Add(p.SettingName, p));
            return(result);
        }
예제 #2
0
        public SettingItem(
            string category,
            string settingName,
            object settingValue,
            Type settingType,
            bool autoFormatDisplayName,
            string settingDisplayName,
            string settingDescription,
            int categorySequenceId,
            char passwordChar,
            SettingsControlWindows settingControl,
            SettingsCategoryInfo settingsCategoryInfo)
        {
            _category             = category;
            _settingName          = settingName;
            _settingValue         = settingValue;
            _settingType          = settingType;
            _settingsCategoryInfo = settingsCategoryInfo;
            if (string.IsNullOrEmpty(settingDisplayName))
            {
                _settingDisplayName = autoFormatDisplayName ? DataShaper.ShapeCamelCaseString(settingName) : settingName;
            }
            else
            {
                _settingDisplayName = settingDisplayName;
            }
            _settingDescription = settingDescription;
            _categorySequenceId = categorySequenceId;
            _passwordChar       = passwordChar;

            _listViewItem = new ListViewItem(_settingDisplayName);
            if (_passwordChar != '\0')
            {
                _listViewItem.SubItems.Add(DataShaperWindows.MaskPasswordString(_settingValue.ToString(), _passwordChar));
            }
            else
            {
                _listViewItem.SubItems.Add(_settingValue != null ? _settingValue.ToString() : null);
            }
            _listViewItem.SubItems.Add(_settingDescription);
            _listViewItem.Tag = this;
            _settingControl   = settingControl;
        }
예제 #3
0
        public EntityCacheGeneric <string, SettingItem> GetSettingsByCategory(SettingsCategoryInfo settingsCategoryInfo)
        {
            string             categoryLower = settingsCategoryInfo.Category.Trim().ToLower();
            Type               settingsType  = this.GetType();
            List <SettingItem> settingItems  = new List <SettingItem>();

            foreach (PropertyInfo p in settingsType.GetProperties())
            {
                object[] categoryAttributes = p.GetCustomAttributes(typeof(SettingInfoAttribute), true);
                if (categoryAttributes == null)
                {
                    continue;
                }
                foreach (SettingInfoAttribute c in categoryAttributes)
                {
                    if (c.Category.Trim().ToLower() == categoryLower)
                    {
                        SettingItem settingItem = new SettingItem(
                            c.Category,
                            p.Name,
                            EntityReader.GetPropertyValue(p.Name, this, false),
                            p.PropertyType,
                            c.AutoFormatDisplayName,
                            c.DisplayName,
                            c.Description,
                            c.CategorySequenceId,
                            c.PasswordChar,
                            null,
                            settingsCategoryInfo);
                        settingItems.Add(settingItem);
                    }
                }
            }
            string entityCacheName = string.Format("{0} {1} Settings", DataShaper.ShapeCamelCaseString(settingsType.Name).Replace("Settings", "").Trim(), settingsCategoryInfo.Category);
            EntityCacheGeneric <string, SettingItem> result = new EntityCacheGeneric <string, SettingItem>(entityCacheName);

            settingItems.OrderBy(p => p.CategorySequenceId).ToList().ForEach(p => result.Add(p.SettingName, p));
            return(result);
        }