示例#1
0
        public void AddProperty()
        {
            Expand();
            ConfigProperty pr       = new ConfigProperty();
            int            n        = 1;
            string         nameBase = "Property";

            pr.DataName = nameBase + n.ToString();
            bool b = true;

            while (b)
            {
                b = false;
                for (int i = 0; i < Nodes.Count; i++)
                {
                    TreeNodeConfigProperty cn = Nodes[i] as TreeNodeConfigProperty;
                    if (cn != null)
                    {
                        ConfigProperty p = cn.Property;
                        if (string.Compare(pr.DataName, p.DataName, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            n++;
                            pr.DataName = nameBase + n.ToString();
                            b           = true;
                        }
                    }
                }
            }
            TreeNodeConfigProperty tc = new TreeNodeConfigProperty(pr, false);

            Nodes.Add(tc);
            this.Expand();
            this.TreeView.SelectedNode = tc;
        }
        public void VerifyConfigCategory(ConfigCategory defCat)
        {
            ConfigCategory cat = FindCategoryByName(defCat.CategoryName);

            if (cat == null)
            {
                cat = CreateSection(defCat.CategoryName);
            }
            if (defCat.Properties.Properties.Count > 0)
            {
                foreach (ConfigProperty p in defCat.Properties.Properties)
                {
                    ConfigProperty p0 = cat.GetConfigProperty(p.DataName);
                    if (p0 == null)
                    {
                        p0             = cat.CreateConfigProperty(p.DataName);
                        p0.DataType    = p.DataType;
                        p0.DefaultData = p.DefaultData;
                    }
                    else
                    {
                        if (!p0.DataType.Equals(p.DataType))
                        {
                            p0.DataType    = p.DataType;
                            p0.DefaultData = p.DefaultData;
                        }
                    }
                }
            }
        }
 public PropertyDescriptorConfig(string name, Attribute[] attrs, ApplicationConfiguration config, ConfigCategory category, ConfigProperty property)
     : base(name, attrs)
 {
     _config = config;
     _cat    = category;
     _prop   = property;
 }
 public object this[string name]
 {
     get
     {
         ConfigProperty p = this.GetPropertyByName(name);
         if (p != null)
         {
             return(p.DefaultData);
         }
         else
         {
             throw new ConfigException("Error getting property. Property {0} not found. Invalid configuration file: [{1}]. Deleting this file may fix the problem.", name, ApplicationConfiguration.ConfigFilePath);
         }
     }
     set
     {
         ConfigProperty p = this.GetPropertyByName(name);
         if (p != null)
         {
             p.DefaultData = value;
             _dirty        = true;
         }
         else
         {
             throw new ConfigException("Error setting property. Property {0} not found. Invalid configuration file: [{1}]. Deleting this file may fix the problem.", name, ApplicationConfiguration.ConfigFilePath);
         }
     }
 }
        public void SetPropertyValueByIndex(int index, object value)
        {
            ConfigProperty p = GetPropertyByIndex(index);

            if (p != null)
            {
                p.SetSetting(value);
                _dirty = true;
            }
        }
        public object GetPropertyValueByIndex(int index)
        {
            ConfigProperty p = GetPropertyByIndex(index);

            if (p != null)
            {
                return(p.DefaultData);
            }
            return(null);
        }
        public string GetPropertyValueNameByIndex(int index)
        {
            ConfigProperty p = GetPropertyByIndex(index);

            if (p != null)
            {
                return(p.DataName);
            }
            return(null);
        }
        public object GetPropertyValueByName(string name)
        {
            ConfigProperty p = GetPropertyByName(name);

            if (p != null)
            {
                return(p.DefaultData);
            }
            return(null);
        }
        public ConfigProperty CreateConfigProperty(string name)
        {
            ConfigProperty p = GetConfigProperty(name);

            if (p == null)
            {
                p = _properties.CreateConfigProperty(name, typeof(string));
            }
            return(p);
        }
        public object Clone()
        {
            ConfigProperty p = new ConfigProperty();

            p._name     = _name;
            p._type     = _type;
            p._xmlNode  = _xmlNode;
            p.Encrypted = Encrypted;
            p._data     = _data;
            return(p);
        }
        public ConfigProperty CreateConfigProperty(string name, Type type)
        {
            ConfigProperty p = new ConfigProperty();

            p.DataName = name;
            p.DataType = type;
            XmlNode nd = _catNode.OwnerDocument.CreateElement(XML_CONFIG);

            _catNode.AppendChild(nd);
            p.Save(nd);
            _properties.Add(p);
            return(p);
        }
示例#12
0
        public TreeNodeConfigProperty(ConfigProperty property, bool dataOnly)
        {
            _isDataOnly          = dataOnly;
            _property            = property;
            _property.IsDataOnly = dataOnly;
            Text               = _property.DataName;
            ImageIndex         = TreeNodeCat.IMG_PRO;
            SelectedImageIndex = TreeNodeCat.IMG_PRO;
            this.ContextMenu   = new ContextMenu();
            MenuItem mi = new MenuItem("Delete Property", mnu_delProp);

            ContextMenu.MenuItems.Add(mi);
            _property.NameChanging = nameChanging;
        }
        public ConfigProperty GetPropertyByName(string name)
        {
            if (_properties == null)
            {
                _properties = new ConfigPropertyList();
            }
            foreach (ConfigProperty p in _properties.Properties)
            {
                if (string.CompareOrdinal(p.DataName, name) == 0)
                {
                    return(p);
                }
            }
            ConfigProperty p0 = CreateConfigProperty(name);

            return(p0);
        }
        public void SetSetting(string name, object value)
        {
            ConfigProperty p = GetConfigProperty(name);

            if (p == null)
            {
                if (value != null && value != DBNull.Value)
                {
                    Type t = typeof(string);
                    p = _properties.CreateConfigProperty(name, t);
                }
                else
                {
                    return;
                }
            }
            p.SetSetting(value);
        }
示例#15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="name">it is the category name</param>
 /// <param name="attrs"></param>
 public PropertyDescriptorConfig(string name, Attribute[] attrs, ConfigProperty property, ApplicationConfiguration owner)
     : base(name, attrs)
 {
     _owner    = owner;
     _property = property;
 }