Example #1
0
 /// <summary>
 /// 编译本配置节,将执行一些配置命令,具有配置命令的配置节需执行本方法后才可以使用
 /// </summary>
 /// <param name="current">当前配置节</param>
 /// <param name="settings">配置命令集合</param>
 /// <returns>编译后的配置节</returns>
 protected static ConfigSetting Compile(ConfigSetting current, ConfigSettingCollection settings)
 {
     if (settings.Count > 0) {
         var currentSettings = current.childSettings;
         for (var i = 0; i < settings.Count; i++) {
             var setting = settings[i].Clone();
             setting.Parent = current;
             var logicName = setting.GetName();
             switch(setting.SettingOperator) {
                 case ConfigSettingOperator.Add:
                     if (currentSettings.Contains(logicName)) {
                         throw new ConfigException(string.Format("已存在子配置节 {0}", logicName));
                     }
                     currentSettings.Add(setting).Parent = current;
                     break;
                 case ConfigSettingOperator.Remove:
                     currentSettings.Remove(logicName);
                     break;
                 case ConfigSettingOperator.Move:
                     ConfigSetting moveSetting = currentSettings[logicName];
                     if(moveSetting != null) {
                         currentSettings.Remove(logicName);
                         currentSettings.Add(moveSetting);
                     }
                     break;
                 case ConfigSettingOperator.Clear:
                     currentSettings.Clear();
                     break;
                 case ConfigSettingOperator.Update:
                     if (currentSettings.Contains(logicName)) {
                         currentSettings[logicName].Merge(setting);
                     }
                     break;
                 default:
                     if (currentSettings.Contains(logicName)) {
                         currentSettings[logicName].Merge(setting);
                     } else {
                         currentSettings.Add(setting).Parent = current;
                     }
                     break;
             }
         }
     }
     return current;
 }
Example #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;
 }
Example #3
0
        internal virtual ConfigSetting CopyFrom(ConfigSetting setting)
        {
            this.Version++;
            this.Property.CopyFrom(setting.Property);

            var opts = this.operatorSettings;
            this.operatorSettings =	setting.operatorSettings.Clone(this);
            this.childSettings = setting.childSettings.Clone(this);
            Compile(this, opts);

            return this;
        }