Exemplo n.º 1
0
        public virtual bool CanPersist(object data, ChoDictionaryService <string, object> stateInfo)
        {
            DateTime persistTimeStamp = GetPersistTimeStamp(stateInfo);

            if (persistTimeStamp < ConfigElement.LastLoadedTimeStamp)
            {
                ConfigElement.Log("SKIPPING Persist: Stale config data [ {0} - {1} ]".FormatString(persistTimeStamp.Ticks, ConfigElement.LastLoadedTimeStamp.Ticks));
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 2
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);
            }
        }