예제 #1
0
 public override string ToString()
 {
     return(ChoObject.ToString(this));
 }
예제 #2
0
 public void ResetObject()
 {
     ChoObject.ResetObject(ConfigObject);
 }
예제 #3
0
        public ChoConfigSection(Type configObjectType, XmlNode node, XmlNode[] contextNodes, ChoBaseConfigurationElement configElement)
            : this()
        {
            _configElement = configElement;

            if (configElement != null)
            {
                //Get and Set MetaDataFileName
                configElement.ConfigurationMetaDataType = ConfigurationMetaDataType;
                IChoConfigStorage attrDefinedConfigStorage = configElement.MetaDataInfo != null ? configElement.MetaDataInfo.ConfigStorage : null;

                ChoBaseConfigurationMetaDataInfo defaultMetaDataInfo = InitDefaultMetaDataInfo(configElement);

                configElement.MetaDataInfo = ChoObject.Merge <ChoBaseConfigurationMetaDataInfo>(ChoConfigurationMetaDataManager.GetMetaDataSection(configElement), defaultMetaDataInfo);
                ConfigStorage = configElement.MetaDataInfo != null && configElement.MetaDataInfo.ConfigStorage != null ?
                                configElement.MetaDataInfo.ConfigStorage : attrDefinedConfigStorage;

                if (ConfigStorage == null)
                {
                    configElement.Log("Missing configuration storage, assigning to configSection default storage.");
                    ConfigStorage = DefaultConfigStorage;
                    if (ConfigStorage == null)
                    {
                        configElement.Log("Missing configuration storage, assigning to system default storage.");
                        ConfigStorage = ChoConfigStorageManagerSettings.Me.GetDefaultConfigStorage();
                    }
                }

                if (ConfigStorage != null)
                {
                    try
                    {
                        CheckValidConfigStoragePassed(ConfigStorage);
                    }
                    catch (ChoFatalApplicationException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        if (configElement.Silent)
                        {
                            ConfigElement.Log(ex.Message);
                            ConfigStorage = ChoConfigStorageManagerSettings.Me.GetDefaultConfigStorage();
                            if (ConfigStorage != null)
                            {
                                ConfigElement.Log("Using default [{0}] config storage.".FormatString(ConfigStorage.GetType().FullName));
                            }
                        }
                        else
                        {
                            throw;
                        }
                    }
                }

                if (ConfigStorage == null)
                {
                    throw new ChoConfigurationException("Missing configuration storage.");
                }

                IsMetaDataDefinitionChanged = !ChoObject.Equals <ChoBaseConfigurationMetaDataInfo>(ChoConfigurationMetaDataManager.GetMetaDataSection(configElement), defaultMetaDataInfo);
                configElement.MetaDataInfo.ConfigStorage = ConfigStorage;

                try
                {
                    ConfigData = ConfigStorage.Load(_configElement, node);
                }
                catch (ChoFatalApplicationException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    _configLoadExceptions.Add(ex);
                }
            }

            //if (ConfigStorage == null)
            //{
            //    try
            //    {
            //        ConfigStorage = DefaultConfigStorage;
            //        if (ConfigStorage == null)
            //            ConfigStorage = ChoConfigStorageManagerSettings.Me.GetDefaultConfigStorage();
            //    }
            //    catch (Exception ex)
            //    {
            //        _configLoadExceptions.Add(ex);
            //    }
            //}

            try
            {
                ConfigurationChangeWatcher = ConfigStorage.ConfigurationChangeWatcher;
                if (ConfigurationChangeWatcher != null)
                {
                    ConfigurationChangeWatcher.StartWatching();
                }
            }
            catch (Exception ex)
            {
                _configLoadExceptions.Add(ex);
            }
        }
예제 #4
0
 public string ToStringL()
 {
     return(ChoObject.ToString(this));
 }
예제 #5
0
 public override string ToString()
 {
     return(Payload != null?ChoObject.ToString(Payload) : null);
 }
 //
 // Summary:
 //     Writes the text representation of the specified object to the standard output
 //     stream.
 //
 // Parameters:
 //   value:
 //     The value to write, or null.
 //
 // Exceptions:
 //   System.IO.IOException:
 //     An I/O error occurred.
 public void Write(object value)
 {
     Write(ChoObject.ToString(value));
 }
예제 #7
0
 public new static string ToString()
 {
     return(ChoObject.ToString(_instance));
 }
예제 #8
0
        public static string ToString(object configObject)
        {
            if (configObject == null)
            {
                return(String.Empty);
            }

            string configObjectString = ChoObject.ToString(configObject);

            ChoConfigurationElementMapAttribute configurationElementMap = ChoType.GetAttribute(configObject.GetType(), typeof(ChoConfigurationElementMapAttribute)) as ChoConfigurationElementMapAttribute;

            if (configurationElementMap == null)
            {
                return(configObjectString);
            }
            else if (configObjectString == configObject.GetType().FullName)
            {
                ChoStringMsgBuilder msg = new ChoStringMsgBuilder(configurationElementMap.Description);

                MemberInfo[] memberInfos = ChoType.GetMembers(configObject.GetType(), typeof(ChoMemberInfoAttribute));
                if (memberInfos == null || memberInfos.Length == 0)
                {
                    msg.AppendLine(ChoStringMsgBuilder.Empty);
                }
                else
                {
                    string errMsg;
                    foreach (MemberInfo memberInfo in memberInfos)
                    {
                        errMsg = ChoType.GetAttributeNameParameterValue(configObject.GetType(), memberInfo.Name, typeof(ChoMemberInfoAttribute), "ErrMsg") as string;
                        if (errMsg == null)
                        {
                            msg.AppendFormatLine("{0}: {1}", memberInfo.Name, ChoType.GetMemberValue(configObject, memberInfo.Name));
                        }
                        else
                        {
                            msg.AppendFormatLine("{0}: {1} [ERROR: {2}]", memberInfo.Name, ChoType.GetMemberValue(configObject, memberInfo.Name), errMsg);
                        }
                    }
                }
                msg.AppendNewLine();
                return(msg.ToString());
            }
            else
            {
                StringBuilder msg = new StringBuilder(configObjectString);

                MemberInfo[]  memberInfos = ChoType.GetMembers(configObject.GetType(), typeof(ChoMemberInfoAttribute));
                List <string> errMsgs     = new List <string>();
                if (memberInfos != null && memberInfos.Length >= 0)
                {
                    string errMsg;
                    foreach (MemberInfo memberInfo in memberInfos)
                    {
                        errMsg = ChoType.GetAttributeNameParameterValue(configObject.GetType(), memberInfo.Name, typeof(ChoMemberInfoAttribute), "ErrMsg") as string;
                        if (errMsg != null)
                        {
                            errMsgs.Add(String.Format("{0}: {1}", memberInfo.Name, errMsg));
                        }
                    }
                }

                if (errMsgs.Count > 0)
                {
                    ChoStringMsgBuilder errReport = new ChoStringMsgBuilder("Following errors produced while construction");

                    foreach (string errMsg in errMsgs)
                    {
                        errReport.AppendFormatLine(errMsg);
                    }

                    msg.AppendLine(errReport.ToString());
                }

                return(msg.ToString());
            }
        }