Ejemplo n.º 1
0
        public override object Load(ChoBaseConfigurationElement configElement, XmlNode node)
        {
            base.Load(configElement, node);

            //if (configElement.ConfigFilePath.IsNullOrWhiteSpace())
            //    UnderlyingConfigFilePath = ChoConfigurationManager.GetConfigFile(node);
            //else
            //    UnderlyingConfigFilePath = configElement.ConfigFilePath;

            UnderlyingConfigFilePath = ChoConfigurationManager.GetConfigFile(node);
            if (UnderlyingConfigFilePath.IsNullOrWhiteSpace())
            {
                configElement[ChoConfigurationConstants.FORCE_PERSIST] = true;
                UnderlyingConfigFilePath = configElement.ConfigFilePath;
            }

            ConfigElement[UNDERLYING_CONFIG_PATH] = UnderlyingConfigFilePath;

            ConfigFilePath = GetFullPath(UnderlyingConfigFilePath);

            if (IsAppConfigFile)
            {
                if (!configElement.ConfigFilePath.IsNullOrWhiteSpace())
                {
                    UnderlyingConfigFilePath = configElement.ConfigFilePath;
                    ConfigFilePath           = GetFullPath(UnderlyingConfigFilePath);
                }
            }

            if (node != null && !IsAppConfigFile)
            {
                if (configElement.Persistable)
                {
                    ChoXmlDocument.CreateXmlFileIfEmpty(ConfigFilePath);
                }

                using (ChoXmlDocument document = new ChoXmlDocument(ConfigFilePath))
                {
                    string nodeName = configElement.ConfigElementPath;
                    IncludeFilePaths = document.IncludeFiles;
                    if (document.XmlDocument != null && document.XmlDocument.DocumentElement != null)
                    {
                        ChoConfiguration configuration = document.XmlDocument.DocumentElement.ToObject <ChoConfiguration>();
                        if (configuration != null)
                        {
                            ConfigNode = ChoXmlDocument.GetXmlNode(nodeName, configuration.RestOfXmlDocumentElements);
                        }
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public static bool IsConfigXmlModified(string configSectionPath, XmlNode oldNode)
        {
            XmlNode node = ChoXmlDocument.GetXmlNode(configSectionPath, _configuration.RestOfXmlDocumentElements);

            if (object.ReferenceEquals(node, oldNode))
            {
                return(false);
            }
            if (object.ReferenceEquals(oldNode, null))
            {
                return(true);
            }
            if (object.ReferenceEquals(node, null))
            {
                return(true);
            }
            return(node.OuterXml != oldNode.OuterXml);
        }
Ejemplo n.º 3
0
        internal static object GetConfig(Type configObjectType, string configSectionPath, Type defaultConfigSectionHandlerType,
                                         ChoBaseConfigurationElement configElement)
        {
            if (_configuration == null)
            {
                return(null);
            }

            ChoConfigurationSection configurationSection = ChoConfigurationManager.GetConfigSection(configSectionPath);

            XmlNode[] restOfXmlElements = null;

            Type configSectionHandlerType = defaultConfigSectionHandlerType;

            if (configurationSection != null)
            {
                restOfXmlElements = configurationSection.RestOfXmlElements;
                if (!configurationSection.Type.IsNullOrWhiteSpace())
                {
                    configSectionHandlerType = ChoType.GetType(configurationSection.Type);
                }
            }

            configElement.ConfigSectionHandlerType = configSectionHandlerType;
            if (!typeof(IChoConfigurationSectionHandler).IsAssignableFrom(configSectionHandlerType))
            {
                throw new ChoConfigurationException("Configuration section handler type should be of IChoConfigurationSectionHandler type.");
            }

            if (typeof(IChoNullConfigurationSectionableHandler).IsAssignableFrom(configSectionHandlerType))
            {
                return(ChoType.CreateInstance <IChoConfigurationSectionHandler>(configSectionHandlerType).Create(configObjectType, null, restOfXmlElements, configElement));
            }
            else
            {
                XmlNode node = ChoXmlDocument.GetXmlNode(configSectionPath, _configuration.RestOfXmlDocumentElements);
                //if (node != null)
                return(ChoType.CreateInstance <IChoConfigurationSectionHandler>(configSectionHandlerType).Create(configObjectType, node, restOfXmlElements, configElement));
            }
            //return new ChoDefaultApplicationConfigSection(configObjectType);
        }
Ejemplo n.º 4
0
        public override object Load(ChoBaseConfigurationElement configElement, XmlNode node)
        {
            base.Load(configElement, node);

            //if (configElement.ConfigFilePath.IsNullOrWhiteSpace())
            //    UnderlyingConfigFilePath = ChoConfigurationManager.GetConfigFile(node);
            //else
            //    UnderlyingConfigFilePath = configElement.ConfigFilePath;

            UnderlyingConfigFilePath = ChoConfigurationManager.GetConfigFile(node);

            if (UnderlyingConfigFilePath.IsNullOrWhiteSpace() ||
                UnderlyingConfigFilePath != configElement.ConfigFilePath)
            {
                if (!configElement.ConfigFilePath.IsNullOrWhiteSpace() && UnderlyingConfigFilePath.IsNullOrWhiteSpace())
                {
                    configElement[ChoConfigurationConstants.FORCE_PERSIST] = true;
                    UnderlyingConfigFilePath = configElement.ConfigFilePath;
                }
            }

            ConfigElement[UNDERLYING_CONFIG_PATH] = UnderlyingConfigFilePath;
            if (ChoConfigurationManager.IsSeperateConfigFileSpecified(node))
            {
                ConfigElement[PREV_UNDERLYING_CONFIG_PATH] = UnderlyingConfigFilePath;
            }

            ConfigFilePath = GetFullPath(UnderlyingConfigFilePath);

            if (IsAppConfigFile)
            {
                if (!configElement.ConfigFilePath.IsNullOrWhiteSpace())
                {
                    UnderlyingConfigFilePath = configElement.ConfigFilePath;
                    ConfigFilePath           = GetFullPath(UnderlyingConfigFilePath);

                    ConfigElement[UNDERLYING_CONFIG_PATH] = ConfigFilePath;
                }
            }

            if (/*node != null && */ !IsAppConfigFile)
            {
                if (!IsCustomFormatDataStorage)
                {
                    if (File.Exists(ConfigFilePath))
                    {
                        using (ChoXmlDocument document = new ChoXmlDocument(ConfigFilePath))
                        {
                            string nodeName = configElement.ConfigElementPath;
                            IncludeFilePaths = document.IncludeFiles;
                            if (document.XmlDocument != null && document.XmlDocument.DocumentElement != null)
                            {
                                ChoConfiguration configuration = document.XmlDocument.DocumentElement.ToObject <ChoConfiguration>();
                                if (configuration != null)
                                {
                                    ConfigNode = ChoXmlDocument.GetXmlNode(nodeName, configuration.RestOfXmlDocumentElements);
                                }
                            }
                        }
                    }
                }
                //if (configElement.Persistable)
                //    ChoXmlDocument.CreateXmlFileIfEmpty(ConfigFilePath);

                //using (ChoXmlDocument document = new ChoXmlDocument(ConfigFilePath))
                //{
                //    string nodeName = configElement.ConfigElementPath;
                //    IncludeFilePaths = document.IncludeFiles;
                //    if (document.XmlDocument != null && document.XmlDocument.DocumentElement != null)
                //    {
                //        ChoConfiguration configuration = document.XmlDocument.DocumentElement.ToObject<ChoConfiguration>();
                //        if (configuration != null)
                //        {
                //            ConfigNode = ChoXmlDocument.GetXmlNode(nodeName, configuration.RestOfXmlDocumentElements);
                //        }
                //    }
                //}
            }

            return(null);
        }