コード例 #1
0
        private static void Initialize()
        {
            if (_isInitialized)
            {
                return;
            }

            lock (_padLock)
            {
                if (_isInitialized)
                {
                    return;
                }

                try
                {
                    MetaDataFilepath = ConfigurationManager.AppSettings[PC_METADATA_FILEPATH_TAG];

                    if (MetaDataFilepath.IsNullOrWhiteSpace() || !File.Exists(MetaDataFilepath))
                    {
                        MetaDataFilepath = ChoPath.AddExtension(Path.ChangeExtension(Path.Combine(Path.GetDirectoryName(ChoApplication.ApplicationConfigFilePath), Path.GetFileNameWithoutExtension(ChoApplication.ApplicationConfigFilePath)), "perf"),
                                                                ChoReservedFileExt.MetaData);
                    }

                    ChoXmlDocument.CreateXmlFileIfEmpty(MetaDataFilepath);
                    Refresh();
                }
                finally
                {
                    _isInitialized = true;
                }
            }
        }
コード例 #2
0
        private void Initialize()
        {
            if (_isInitialized)
            {
                return;
            }

            lock (_padLock)
            {
                if (_isInitialized)
                {
                    return;
                }

                try
                {
                    ChoXmlDocument.CreateXmlFileIfEmpty(MetaDataFilePath);
                    Refresh();
                }
                finally
                {
                    _isInitialized = true;
                }
            }
        }
コード例 #3
0
        private static void Refresh()
        {
            try
            {
                LoadFile();
            }
            catch (Exception ex)
            {
                ChoTrace.Error(ex);

                try
                {
                    string newFile = ChoPath.AddExtension(MetaDataFilepath, ChoReservedFileExt.Err);
                    if (File.Exists(newFile))
                    {
                        File.Delete(newFile);
                    }
                    File.Move(MetaDataFilepath, newFile);

                    ChoXmlDocument.CreateXmlFileIfEmpty(MetaDataFilepath);
                    LoadFile();
                }
                catch (Exception innerEx)
                {
                    ChoTrace.Error(innerEx);
                }
            }
        }
コード例 #4
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);
                }
            }
        }
コード例 #5
0
ファイル: ChoConfigStorage.cs プロジェクト: commodus/Cinchoo
        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);
        }
コード例 #6
0
        private static void Refresh()
        {
            try
            {
                lock (_padLock)
                {
                    //_propDict.Clear();
                }

                if (ChoMetaDataFilePathSettings.Me != null)
                {
                    _pbsDataFilepath = ChoMetaDataFilePathSettings.Me.OverridenPBSDataFilePath;
                }

                if (!ChoAppFrxSettings.Me.DisableMetaDataConfig)
                {
                    ChoXmlDocument.CreateXmlFileIfEmpty(_pbsDataFilepath);
                    _pbsDataChangeWatcher = new ChoAppConfigurationChangeFileWatcher(PBS_DATA_KEY, _pbsDataFilepath, _includeFiles);
                    _pbsDataChangeWatcher.SetConfigurationChangedEventHandler(PBS_DATA_FILE_WATCHER_KEY,
                                                                              (sender, e) =>
                    {
                        Refresh();
                    });
                }

                if (!_pbsDataFilepath.IsNullOrWhiteSpace() && File.Exists(_pbsDataFilepath))
                {
                    using (ChoXmlDocument xmlDocument = new ChoXmlDocument(_pbsDataFilepath))
                    {
                        _rootNode     = xmlDocument.XmlDocument.DocumentElement;
                        _includeFiles = xmlDocument != null ? xmlDocument.IncludeFiles : null;
                    }
                }

                BuildProfileBackingStores();
            }
            catch (Exception ex)
            {
                ChoTrace.Error(ex.ToString());
                //throw;
            }
        }
コード例 #7
0
        private static void Refresh()
        {
            try
            {
                lock (_padLock)
                {
                    _propDict.Clear();
                }

                if (ChoMetaDataFilePathSettings.Me != null)
                {
                    _metaDataFilepath = ChoMetaDataFilePathSettings.Me.OverridenConfigurationMetaDataFilePath;
                }

                if (!ChoAppFrxSettings.Me.DisableMetaDataConfig)
                {
                    ChoXmlDocument.CreateXmlFileIfEmpty(_metaDataFilepath);
                    _configurationChangeWatcher = new ChoAppConfigurationChangeFileWatcher("meta-data_configurations", _metaDataFilepath, _includeFiles);
                    _configurationChangeWatcher.SetConfigurationChangedEventHandler("ChoMetaDataManager_Watcher",
                                                                                    (sender, e) =>
                    {
                        Refresh();
                    });
                }

                if (!_metaDataFilepath.IsNullOrWhiteSpace() && File.Exists(_metaDataFilepath))
                {
                    using (ChoXmlDocument xmlDocument = new ChoXmlDocument(_metaDataFilepath))
                    {
                        _rootNode     = xmlDocument.XmlDocument.DocumentElement;
                        _includeFiles = xmlDocument != null ? xmlDocument.IncludeFiles : null;
                    }
                }
            }
            catch (Exception ex)
            {
                ChoTrace.Error(ex.ToString());
                //throw;
            }
        }
コード例 #8
0
ファイル: ChoMetaDataManager.cs プロジェクト: lanicon/Cinchoo
        private void Refresh()
        {
            if (ChoAppFrxSettings.Me.DisableMetaDataConfig)
            {
                return;
            }

            try
            {
                LoadFile();
            }
            catch (ChoFatalApplicationException)
            {
                throw;
            }
            catch (Exception ex)
            {
                ChoTrace.Error(ex);

                try
                {
                    string newFile = ChoPath.AddExtension(MetaDataFilePath, ChoReservedFileExt.Err);
                    if (File.Exists(newFile))
                    {
                        File.Delete(newFile);
                    }
                    File.Move(MetaDataFilePath, newFile);

                    ChoXmlDocument.CreateXmlFileIfEmpty(MetaDataFilePath);
                    LoadFile();
                }
                catch (Exception innerEx)
                {
                    ChoTrace.Error(innerEx);
                }
            }
        }
コード例 #9
0
ファイル: ChoConfigStorage.cs プロジェクト: commodus/Cinchoo
        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);
                }
            }
        }
コード例 #10
0
        private static void OpenConfiguration(string appConfigPath, bool doBackup)
        {
            if (_appConfigPath != appConfigPath)
            {
                Trace.TraceInformation("Using AppConfigPath: {0}".FormatString(appConfigPath));
            }

            _appConfigPath = appConfigPath;

            if (_appConfigPath.IsNullOrWhiteSpace())
            {
                Trace.TraceError("Empty AppConfigPath passed.");
                return;
            }

            ChoFile.SetReadOnly(_appConfigPath, false);

            if (_configurationChangeWatcher != null)
            {
                RestoreAppConfig();
                //_configurationChangeWatcher.StopWatching();
            }
            //if (_systemConfigurationChangeWatcher != null)
            //{
            //    _systemConfigurationChangeWatcher.StopWatching();
            //    _systemConfigurationChangeWatcher = null;
            //}

            ChoXmlDocument.CreateXmlFileIfEmpty(_appConfigPath);

            //backup the current configuration
            string backupConfigFilePath = String.Format("{0}.{1}", _appConfigPath, ChoReservedFileExt.Cho);

            try
            {
                LoadConfigurationFile();

                if (doBackup)
                {
                    if (File.Exists(backupConfigFilePath))
                    {
                        File.SetAttributes(backupConfigFilePath, FileAttributes.Archive);
                    }
                    File.Copy(_appConfigPath, backupConfigFilePath, true);
                    if (File.Exists(backupConfigFilePath))
                    {
                        File.SetAttributes(backupConfigFilePath, FileAttributes.Hidden);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                if (_appXmlDocument != null)
                {
                    _appXmlDocument.Dispose();
                    _appXmlDocument = null;
                }

                try
                {
                    //Rollback the configuration file
                    if (doBackup)
                    {
                        File.Copy(backupConfigFilePath, _appConfigPath, true);
                    }

                    LoadConfigurationFile();
                }
                catch
                {
                }
            }
            finally
            {
                if (_configurationChangeWatcher != null)
                {
                    _configurationChangeWatcher.StartWatching();
                }
                if (_systemConfigurationChangeWatcher != null)
                {
                    _systemConfigurationChangeWatcher.StartWatching();
                }
            }
        }