Beispiel #1
0
        protected void PersistAsNameSpaceAwareXml(object data, ChoDictionaryService <string, object> stateInfo)
        {
            string configFilePath = stateInfo[UNDERLYING_CONFIG_PATH] as string;

            if (configFilePath.IsNullOrWhiteSpace())
            {
                return;
            }

            ChoXmlDocument.CreateXmlFileIfEmpty(configFilePath);

            using (ChoXmlDocument xmlDocument = new ChoXmlDocument(GetFullPath(configFilePath)))
            {
                PersistConfigSectionDefinition(xmlDocument.XmlDocument, data);
                XmlNode configNode = xmlDocument.XmlDocument.MakeXPath(ConfigElement.ConfigElementPath);
                if (configNode != null)
                {
                    string configXml = ToXml(data);
                    if (configXml.IsNull())
                    {
                        return;
                    }

                    ChoXmlDocument.SetNamespaceAwareOuterXml(configNode, configXml, ChoXmlDocument.CinchooNSURI);
                }
            }
        }
Beispiel #2
0
        public override void Persist(object data, ChoDictionaryService <string, object> stateInfo)
        {
            ChoXmlDocument.CreateXmlFileIfEmpty(ConfigFilePath);

            string backupConfigFilePath = String.Format("{0}.{1}", ConfigFilePath, ChoReservedFileExt.Cho);

            try
            {
                //Write meta-data info
                ChoConfigurationMetaDataManager.SetMetaDataSection(ConfigElement);
                if (!IsAppConfigFile)
                {
                    if (File.Exists(backupConfigFilePath))
                    {
                        File.SetAttributes(backupConfigFilePath, FileAttributes.Archive);
                    }
                    File.Copy(ConfigFilePath, backupConfigFilePath, true);
                    if (File.Exists(backupConfigFilePath))
                    {
                        File.SetAttributes(backupConfigFilePath, FileAttributes.Hidden);
                    }
                }
            }
            catch (ChoFatalApplicationException)
            {
                throw;
            }
            catch (Exception ex)
            {
                ConfigElement.Log(ex.ToString());
            }

            try
            {
                //if seperate config file maintained, make a link in the application configuration
                if (IsConfigReferenceDataChanged(stateInfo))
                {
                    using (ChoXmlDocument xmlDocument = new ChoXmlDocument(ChoGlobalApplicationSettings.Me.ApplicationConfigFilePath))
                    {
                        XmlNode configNode = xmlDocument.XmlDocument.MakeXPath(ConfigElement.ConfigElementPath);
                        if (configNode != null)
                        {
                            if (!IsAppConfigFile)
                            {
                                string configXml = @"<{0} {1}=""{2}"" {3}=""{4}"" />".FormatString(ConfigSectionName, ChoConfigurationManager.PathToken, UnderlyingConfigFilePath, ChoXmlDocument.CinchoNSToken, ChoXmlDocument.CinchooNSURI);
                                ChoXmlDocument.SetNamespaceAwareOuterXml(configNode, configXml, ChoXmlDocument.CinchooNSURI);
                            }
                        }
                    }
                }

                PersistConfigData(data, stateInfo);
            }
            catch (ChoFatalApplicationException)
            {
                throw;
            }
            catch (Exception ex)
            {
                ConfigElement.Log(ex.ToString());

                if (!IsAppConfigFile)
                {
                    File.Copy(backupConfigFilePath, ConfigFilePath, true);
                }
            }
        }