Пример #1
0
        public override void Merge(ChoBaseConfigurationMetaDataInfo source)
        {
            base.Merge(source);

            ChoStandardConfigurationMetaDataInfo other = source as ChoStandardConfigurationMetaDataInfo;

            if (other != null)
            {
                ConfigurationMetaDataLogInfo = ChoObject.Merge(ConfigurationMetaDataLogInfo, other.ConfigurationMetaDataLogInfo);
            }
        }
        public static void SetMetaDataSection(ChoBaseConfigurationElement configElement)
        {
            if (configElement == null)
            {
                return;
            }
            if (ChoObject.Equals <ChoBaseConfigurationMetaDataInfo>(configElement.MetaDataInfo, GetMetaDataSection(configElement)))
            {
                return;
            }

            string configElementPath = configElement.ConfigElementPath;
            ChoBaseConfigurationMetaDataInfo configurationMetaDataInfo = configElement.MetaDataInfo;

            configurationMetaDataInfo = ChoObject.Merge <ChoBaseConfigurationMetaDataInfo>(configurationMetaDataInfo, GetDefaultMetaDataInfo(configElement));

            if (configurationMetaDataInfo == null)
            {
                return;
            }

            using (ChoXmlDocument xmlDocument = new ChoXmlDocument(_metaDataFilepath))
            {
                if (configElementPath.IsNullOrEmpty())
                {
                    return;
                }

                XmlNode node = xmlDocument.XmlDocument.SelectSingleNode(configElementPath);
                if (node == null)
                {
                    node = xmlDocument.XmlDocument.MakeXPath(configElementPath);
                }

                if (node != null)
                {
                    ChoXmlDocument.SetOuterXml(node, configurationMetaDataInfo.ToXml());
                    xmlDocument.XmlDocument.InnerXml = ChoXmlDocument.AppendToInnerXml(node, GetPropertyInfos(configElement).ToXml());

                    xmlDocument.Save();
                }
            }
        }
Пример #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);
            }
        }