public override void GetConfig(bool refresh, ChoConfigSectionObjectMap configSectionObjectMap)
 {
     _configSection = ChoConfigurationManager.GetConfig(ConfigElementName, refresh) as IChoConfigSectionable;
     if (_configSection != null)
     {
         _configSection.Init(configSectionObjectMap);
     }
 }
Пример #2
0
        private void LoadConfig(bool refresh)
        {
            object configObject = _configObject;

            //Set default trace output file name
            _traceOutputFileName = configObject.GetType().Name;

            MemberInfo[] memberInfos = ChoType.GetMembers(configObject.GetType(), typeof(ChoMemberInfoAttribute));
            if (memberInfos == null || memberInfos.Length == 0)
            {
                return;
            }

            _configSection = GetConfig();
            if (_configSection == null)
            {
                throw new ChoConfigurationConstructionException("Missing configuration section.");
            }

            if (!refresh)
            {
                //Hookup the configuration watch job
                ChoConfigurationChangeWatcherManager.SetWatcherForConfigSource(_configSection.ConfigurationChangeWatcher);
                ChoConfigurationChangeWatcherManager.ConfigurationChanged += new ChoConfigurationChangedEventHandler(ChoConfigurationChangeWatcherManager_ConfigurationChanged);
            }
            else
            {
                _configSection.ConfigurationChangeWatcher.StopWatching();
            }

            ErrMsg = _configSection.ErrMsg;

            if (!IgnoreError && ErrMsg != null)
            {
                throw new ApplicationException(ErrMsg);
            }

            Hashtable hashTable = _configSection.ToHashtable();
            //Set member values
            string name;
            ChoMemberInfoAttribute memberInfoAttribute = null;

            foreach (MemberInfo memberInfo in memberInfos)
            {
                memberInfoAttribute = (ChoMemberInfoAttribute)ChoType.GetMemberAttribute(memberInfo, typeof(ChoMemberInfoAttribute));
                if (memberInfoAttribute == null)
                {
                    continue;
                }

                name = memberInfoAttribute.Name;

                try
                {
                    //Set the config values
                    if (hashTable[name] != null)
                    {
                        ChoType.SetMemberValue(configObject, memberInfo.Name, hashTable[name]);
                    }
                    //Set default values
                    else if (memberInfoAttribute.DefaultValue != null)
                    {
                        ChoType.SetMemberValue(configObject, memberInfo.Name, memberInfoAttribute.DefaultValue);
                    }
                }
                catch (Exception ex)
                {
                    if (IgnoreError)
                    {
                        SetMemberError(configObject, memberInfo.Name, String.Format(Resources.ConfigConstructMsg, ChoString.ToString(hashTable[name]), ex.Message));
                    }
                    else
                    {
                        throw new ChoConfigurationConstructionException(String.Format(Resources.ConfigConstructExceptionMsg, ChoString.ToString(hashTable[name]), configObject.GetType().Name,
                                                                                      memberInfo.Name), ex);
                    }
                }

                //try
                //{
                //    //Validate the member with associated attributes
                //    foreach (IChoMemberValidator memberValidator in ChoType.GetMemberAttributesByBaseInterface(memberInfo, typeof(IChoMemberValidator)))
                //    {
                //        memberValidator.Validate(configObject, memberInfo);
                //    }
                //    foreach (ChoConfigurationValidatorAttribute memberValidator in ChoType.GetMemberAttributesByBaseInterface(memberInfo, typeof(ChoConfigurationValidatorAttribute)))
                //    {
                //        if (memberValidator.ValidatorInstance.CanValidate(ChoType.GetMemberType(memberInfo)))
                //            memberValidator.ValidatorInstance.Validate(ChoType.GetMemberValue(configObject, memberInfo.Name));
                //    }
                //}
                //catch (Exception ex)
                //{
                //    if (IgnoreError)
                //        SetMemberError(configObject, memberInfo.Name, String.Format(Resources.ConfigConstructValidationMsg, ChoString.ToString(ChoType.GetMemberValue(configObject, memberInfo.Name)),
                //            ex.Message));
                //    else
                //        throw new ChoConfigurationConstructionException(String.Format(Resources.ConfigConstructValidationExceptionMsg, ChoString.ToString(ChoType.GetMemberValue(configObject, memberInfo.Name))), ex);
                //}
            }

            _configSection.ConfigurationChangeWatcher.StartWatching();

            //Print the output to file
            TraceOutput(configObject);
        }
Пример #3
0
 public abstract void SaveConfig(IChoConfigSectionable _configSection);