Esempio n. 1
0
 protected override void CheckValidConfigStoragePassed(IChoConfigStorage configStorage)
 {
     if (!(ConfigStorage is IChoDictionaryConfigStorage))
     {
         throw new ChoConfigurationException("ConfigStorage [{0}] is not a IChoDictionaryConfigStorage type.".FormatString(ConfigStorage.GetType().FullName));
     }
 }
Esempio n. 2
0
        public virtual void Persist(string configSectionFullPath, ChoDictionaryService <string, object> stateInfo)
        {
            ChoQueuedExecutionService.Global.Enqueue(() =>
            {
                object state = null;

                lock (_padLock)
                {
                    state = PersistableState;
                }

                if (state != null)
                {
                    IChoConfigStorage configStorage = ConfigStorage;
                    if (configStorage != null)
                    {
                        if (ConfigStorage.CanPersist(state, stateInfo))
                        {
                            StopWatching();

                            try
                            {
                                ConfigStorage.Persist(state, stateInfo);

                                //Call AfterConfigurationMemberPersist for each member
                                if (ConfigObject is ChoConfigurableObject)
                                {
                                    ((ChoConfigurableObject)ConfigObject).CallAfterConfigurationMemberPersist();
                                }

                                if (ConfigObject is ChoConfigurableObject)
                                {
                                    ((ChoConfigurableObject)ConfigObject).RaiseAfterConfigurationObjectPersisted();
                                }
                            }
                            finally
                            {
                                //Reset Watcher
                                ResetWatching();

                                StartWatching();
                            }
                        }
                    }
                }
            }
                                                     );
        }
Esempio n. 3
0
        private ChoBaseConfigurationMetaDataInfo InitDefaultMetaDataInfo(ChoBaseConfigurationElement configElement)
        {
            ChoBaseConfigurationMetaDataInfo defaultMetaDataInfo = ChoConfigurationMetaDataManager.GetDefaultMetaDataInfo(configElement);

            if (defaultMetaDataInfo.ConfigStorageType.IsNullOrEmpty())
            {
                if (DefaultConfigStorage != null)
                {
                    defaultMetaDataInfo.ConfigStorageType = DefaultConfigStorage.GetType().AssemblyQualifiedName;
                }
                else
                {
                    IChoConfigStorage configStorage = ChoConfigStorageManagerSettings.Me.GetDefaultConfigStorage();
                    if (configStorage != null)
                    {
                        defaultMetaDataInfo.ConfigStorageType = configStorage.GetType().AssemblyQualifiedName;
                    }
                }
            }
            return(defaultMetaDataInfo);
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
 protected virtual void CheckValidConfigStoragePassed(IChoConfigStorage configStorage)
 {
 }