Exemplo n.º 1
0
        /// <summary>
        /// 创建配置节实例
        /// </summary>
        /// <param name="setting">被复制的配置节</param>
        /// <param name="deep">是否深度复制</param>
        /// <returns>配置节</returns>
        protected virtual ConfigSetting CreateConfigSetting(ConfigSetting setting, bool deep)
        {
            ConfigSetting newSetting = this.CreateConfigSetting();

            newSetting.@readonly   = setting.ReadOnly;
            newSetting.settingName = setting.settingName;
            if (deep)
            {
                newSetting.value            = setting.Value.Clone();
                newSetting.property         = setting.Property.Clone(this.@readonly, deep);
                newSetting.childSettings    = setting.childSettings.Clone();
                newSetting.operatorSettings = setting.operatorSettings.Clone();
            }
            else
            {
                newSetting.value            = setting.Value;
                newSetting.property         = setting.Property;
                newSetting.childSettings    = setting.childSettings;
                newSetting.operatorSettings = setting.operatorSettings;
            }
            return(newSetting);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 编译本配置节,将执行一些配置命令,具有配置命令的配置节需执行本方法后才可以使用
        /// </summary>
        /// <param name="current">当前配置节</param>
        /// <param name="settings">配置命令集合</param>
        /// <returns>编译后的配置节</returns>
        protected static ConfigSetting Compile(ConfigSetting current, ConfigSettingCollection settings)
        {
            ConfigSettingCollection currentSettings = current.childSettings;

            if (settings.Count > 0)
            {
                for (int i = 0; i < settings.Count; i++)
                {
                    ConfigSetting setting = settings[i];
                    switch (setting.SettingOperator)
                    {
                    case ConfigSettingOperator.Add:
                        if (currentSettings.Contains(setting.Name))
                        {
                            throw new ConfigException(string.Format("已存在子配置节 {0}", setting.Name));
                        }
                        else
                        {
                            currentSettings.Add(setting).Parent = current;
                        }
                        break;

                    case ConfigSettingOperator.Remove:
                        currentSettings.Remove(setting.Name);
                        break;

                    case ConfigSettingOperator.Move:
                        ConfigSetting moveSetting = currentSettings[setting.Name];
                        if (moveSetting != null)
                        {
                            currentSettings.Remove(moveSetting.Name);
                            currentSettings.Add(moveSetting);
                        }
                        break;

                    case ConfigSettingOperator.Clear:
                        currentSettings.Clear();
                        break;

                    case ConfigSettingOperator.Update:
                        if (currentSettings.Contains(setting.Name))
                        {
                            currentSettings[setting.Name].Merge(setting);
                        }
                        break;

                    case ConfigSettingOperator.Set:
                        if (currentSettings.Contains(setting.Name))
                        {
                            currentSettings[setting.Name].Merge(setting);
                        }
                        else
                        {
                            currentSettings.Add(setting).Parent = current;
                        }
                        break;

                    default:
                        if (currentSettings.Contains(setting.Name))
                        {
                            currentSettings[setting.Name].Merge(setting);
                        }
                        else
                        {
                            currentSettings.Add(setting).Parent = current;
                        }
                        break;
                    }
                }
            }
            return(current);
        }
Exemplo n.º 3
0
 /// <summary>
 /// ���뱾���ýڣ���ִ��һЩ�����������������������ý���ִ�б�������ſ���ʹ��
 /// </summary>
 /// <param name="current">��ǰ���ý�</param>
 /// <param name="settings">���������</param>
 /// <returns>���������ý�</returns>
 protected static ConfigSetting Compile(ConfigSetting current, ConfigSettingCollection settings)
 {
     ConfigSettingCollection currentSettings = current.childSettings;
     if (settings.Count > 0) {
         for (int i = 0; i < settings.Count; i++) {
             ConfigSetting setting = settings[i];
             switch(setting.SettingOperator) {
                 case ConfigSettingOperator.Add:
                     if (currentSettings.Contains(setting.Name)) {
                         throw new ConfigException(string.Format("�Ѵ��������ý� {0}", setting.Name));
                     } else {
                         currentSettings.Add(setting).Parent = current;
                     }
                     break;
                 case ConfigSettingOperator.Remove:
                     currentSettings.Remove(setting.Name);
                     break;
                 case ConfigSettingOperator.Move:
                     ConfigSetting moveSetting = currentSettings[setting.Name];
                     if(moveSetting != null) {
                         currentSettings.Remove(moveSetting.Name);
                         currentSettings.Add(moveSetting);
                     }
                     break;
                 case ConfigSettingOperator.Clear:
                     currentSettings.Clear();
                     break;
                 case ConfigSettingOperator.Update:
                     if (currentSettings.Contains(setting.Name)) {
                         currentSettings[setting.Name].Merge(setting);
                     }
                     break;
                 case ConfigSettingOperator.Set:
                     if (currentSettings.Contains(setting.Name)) {
                         currentSettings[setting.Name].Merge(setting);
                     } else {
                         currentSettings.Add(setting).Parent = current;
                     }
                     break;
                 default:
                     if (currentSettings.Contains(setting.Name)) {
                         currentSettings[setting.Name].Merge(setting);
                     } else {
                         currentSettings.Add(setting).Parent = current;
                     }
                     break;
             }
         }
     }
     return current;
 }
Exemplo n.º 4
0
 /// <summary>
 /// �������ý�ʵ��
 /// </summary>
 /// <param name="setting">�����Ƶ����ý�</param>
 /// <param name="deep">�Ƿ���ȸ���</param>
 /// <returns>���ý�</returns>
 protected virtual ConfigSetting CreateConfigSetting(ConfigSetting setting, bool deep)
 {
     ConfigSetting newSetting = this.CreateConfigSetting();
     newSetting.@readonly = setting.ReadOnly;
     newSetting.settingName = setting.settingName;
     if (deep) {
         newSetting.value = setting.Value.Clone();
         newSetting.property = setting.Property.Clone(this.@readonly, deep);
         newSetting.childSettings = setting.childSettings.Clone();
         newSetting.operatorSettings = setting.operatorSettings.Clone();
     } else {
         newSetting.value = setting.Value;
         newSetting.property = setting.Property;
         newSetting.childSettings = setting.childSettings;
         newSetting.operatorSettings = setting.operatorSettings;
     }
     return newSetting;
 }
Exemplo n.º 5
0
        /// <summary>
        /// �ϲ����ý�
        /// </summary>
        /// <param name="setting">�豻�ϲ������ý�</param>
        /// <returns>�ϲ�������ý�</returns>
        public virtual ConfigSetting Merge(ConfigSetting setting)
        {
            if(setting == null || string.Compare(this.Name, setting.Name, true) != 0) {
                return this;
            }
            this.Property.Merge(setting.Property);
            this.value = setting.Value.Clone(this.ReadOnly);

            foreach(ConfigSetting configSetting in setting.operatorSettings.Values) {
                this.operatorSettings.Add(configSetting).Parent = this;
            }

            Compile(this, setting.operatorSettings);
            return this;
        }