internal static bool TryConfigDefaultValue(ChoBaseConfigurationElement configElement, string propName, ChoPropertyInfoAttribute memberInfoAttribute, out object configDefaultValue) { configDefaultValue = null; ChoGuard.ArgumentNotNull(configElement, "ConfigElement"); ChoGuard.ArgumentNotNull(propName, "PropertyName"); ChoPropertyInfos propertyInfo = GetPropertyInfos(configElement); if (propertyInfo != null) { ChoPropertyInfo propInfo = propertyInfo[propName]; if (propInfo == null) { return(false); } configDefaultValue = propInfo != null ? propInfo.DefaultValue : null; return(propInfo != null ? propInfo.IsDefaultValueSpecified : false); } else if (memberInfoAttribute != null && memberInfoAttribute.IsDefaultValueSpecified) { configDefaultValue = memberInfoAttribute.DefaultValue; return(memberInfoAttribute.IsDefaultValueSpecified); } return(false); }
public ChoIniSectionInfo(XmlNode node, ChoBaseConfigurationElement configElement) { if (node != null) { XPathNavigator navigator = node.CreateNavigator(); IniSectionName = (string)navigator.Evaluate(String.Format("string(@{0})", IniSectionToken), ChoXmlDocument.NameSpaceManager); IniFilePath = (string)navigator.Evaluate(String.Format("string(@{0})", IniPathToken), ChoXmlDocument.NameSpaceManager); } if (IniSectionName.IsNullOrWhiteSpace()) { IniSectionName = configElement[ChoIniConfigurationSectionAttribute.INI_SECTION_NAME] as string; } else { configElement[ChoIniConfigurationSectionAttribute.INI_SECTION_NAME] = IniSectionName; } if (IniFilePath.IsNullOrWhiteSpace()) { IniFilePath = configElement[ChoIniConfigurationSectionAttribute.INI_FILE_PATH] as string; } else { configElement[ChoIniConfigurationSectionAttribute.INI_FILE_PATH] = IniFilePath; } }
public ChoDictionaryAdapterSectionInfo(XmlNode node, ChoBaseConfigurationElement configElement) { if (node != null) { XPathNavigator navigator = node.CreateNavigator(); ConfigObjectAdapterTypeString = (string)navigator.Evaluate(String.Format("string(@{0})", ConfigObjectAdapterTypeToken), ChoXmlDocument.NameSpaceManager); XPathNavigator paramsNode = navigator.SelectSingleNode(String.Format("//{0}", ConfigObjectAdapterParamsToken), ChoXmlDocument.NameSpaceManager); if (paramsNode != null) { ConfigObjectAdapterParamsString = paramsNode.InnerXml.Trim(); } } if (ConfigObjectAdapterTypeString.IsNullOrWhiteSpace()) { ConfigObjectAdapterTypeString = configElement[ChoDictionaryAdapterConfigurationSectionAttribute.CONFIG_OBJECT_ADAPTER_TYPE] as string; } else { configElement[ChoDictionaryAdapterConfigurationSectionAttribute.CONFIG_OBJECT_ADAPTER_TYPE] = ConfigObjectAdapterTypeString; } if (ConfigObjectAdapterParamsString.IsNullOrWhiteSpace()) { ConfigObjectAdapterParamsString = configElement[ChoDictionaryAdapterConfigurationSectionAttribute.CONFIG_OBJECT_ADAPTER_PARAMS] as string; } else { configElement[ChoDictionaryAdapterConfigurationSectionAttribute.CONFIG_OBJECT_ADAPTER_PARAMS] = ConfigObjectAdapterParamsString; } }
public override object Load(ChoBaseConfigurationElement configElement, XmlNode node) { base.Load(configElement, node); node = ConfigNode; string typeName = null; Type objectType = ConfigObjectType; if (objectType == null) { throw new ChoConfigurationException(String.Format(CultureInfo.InvariantCulture, Resources.ES1004, typeName)); } if (node == null) { return(null); } XmlAttributeOverrides overrides = GetXmlAttributeOverrides(objectType, node.Name); XmlSerializer serializer = overrides != null ? new XmlSerializer(objectType, overrides) : XmlSerializer.FromTypes(new[] { objectType }).GetNValue(0); return(serializer.Deserialize(new XmlNodeReader(node))); }
protected override void Initialize(ChoBaseConfigurationElement configElement) { base.Initialize(configElement); configElement[INI_SECTION_NAME] = _iniSectionName; configElement[INI_FILE_PATH] = _iniFilePath; }
public static string GetHelpText(Type configObjectType) { if (configObjectType == null) { return(null); } if (!typeof(ChoConfigurableObject).IsAssignableFrom(configObjectType)) { return(null); } ChoConfigurationSectionAttribute configurationElementAttribute = ChoType.GetAttribute(configObjectType, typeof(ChoConfigurationSectionAttribute)) as ChoConfigurationSectionAttribute; if (configurationElementAttribute == null) { return(null); } ChoBaseConfigurationElement ele = configurationElementAttribute.GetMe(configObjectType); if (ele == null) { return(null); } return(ele.GetHelpText(configObjectType)); }
protected override void Initialize(ChoBaseConfigurationElement configElement) { base.Initialize(configElement); configElement[CONFIG_OBJECT_ADAPTER_TYPE] = _configObjectAdapterType; configElement[CONFIG_OBJECT_ADAPTER_PARAMS] = _configObjectAdapterParams; }
private void InitializeConfigElement(ChoBaseConfigurationElement configElement, Type type) { if (configElement == null) { return; } configElement.DefaultConfigSectionHandlerType = ConfigSectionHandlerType; configElement.ConfigFilePath = ConfigFilePath; ChoStandardConfigurationMetaDataInfo standardConfigurationMetaDataInfo = new ChoStandardConfigurationMetaDataInfo(); standardConfigurationMetaDataInfo.BindingMode = BindingMode; if (ConfigStorageType != null) { standardConfigurationMetaDataInfo.ConfigStorageType = ConfigStorageType.AssemblyQualifiedName; } standardConfigurationMetaDataInfo.ConfigurationMetaDataLogInfo = new ChoConfigurationMetaDataLogInfo(); standardConfigurationMetaDataInfo.ConfigurationMetaDataLogInfo.LogCondition = LogCondition; standardConfigurationMetaDataInfo.ConfigurationMetaDataLogInfo.LogTimeStampFormat = LogTimeStampFormat; standardConfigurationMetaDataInfo.ConfigurationMetaDataLogInfo.LogDirectory = LogDirectory; standardConfigurationMetaDataInfo.ConfigurationMetaDataLogInfo.LogFileName = LogFileName.IsNullOrEmpty() ? ChoPath.AddExtension(type.FullName, ChoReservedFileExt.Log) : LogFileName; standardConfigurationMetaDataInfo.Defaultable = Defaultable; standardConfigurationMetaDataInfo.IgnoreCase = IgnoreCase; standardConfigurationMetaDataInfo.Silent = Silent; configElement.MetaDataInfo = standardConfigurationMetaDataInfo; LoadParameters(configElement); ChoConfigurationMetaDataManager.SetDefaultMetaDataInfo(configElement); }
internal static bool TryGetFallbackValue(ChoBaseConfigurationElement configElement, string propName, ChoPropertyInfoAttribute memberInfoAttribute, out string configFallbackValue) { configFallbackValue = null; ChoGuard.ArgumentNotNull(configElement, "ConfigElement"); ChoGuard.ArgumentNotNull(propName, "PropertyName"); ChoPropertyInfos propertyInfo = GetPropertyInfos(configElement); if (propertyInfo != null) { ChoPropertyInfoMetaData propInfo = propertyInfo[propName]; if (propInfo == null) { if (memberInfoAttribute != null && memberInfoAttribute.IsFallbackValueSpecified) { configFallbackValue = memberInfoAttribute.FallbackValue; return(memberInfoAttribute.IsFallbackValueSpecified); } } configFallbackValue = propInfo != null && propInfo.FallbackValue != null ? propInfo.FallbackValue.Value : null; return(propInfo != null ? propInfo.IsFallbackValueSpecified : false); } else if (memberInfoAttribute != null && memberInfoAttribute.IsFallbackValueSpecified) { configFallbackValue = memberInfoAttribute.FallbackValue; return(memberInfoAttribute.IsFallbackValueSpecified); } return(false); }
public static ChoBaseConfigurationMetaDataInfo GetMetaDataSection(ChoBaseConfigurationElement configElement) { if (configElement == null) { return(null); } Type configurationMetaDataType = configElement.ConfigurationMetaDataType; string configElementPath = configElement.ConfigElementPath; XmlNode node = null; if (_rootNode != null && !configElementPath.IsNullOrWhiteSpace()) { node = _rootNode.SelectSingleNode(@"//{0}".FormatString(configElementPath)); } if (node != null) { XmlAttributeOverrides overrides = new XmlAttributeOverrides(); XmlAttributes attr = new XmlAttributes(); attr.XmlRoot = new XmlRootAttribute(node.Name); overrides.Add(configurationMetaDataType, attr); ChoBaseConfigurationMetaDataInfo metaDataInfo = node.ToObject(configurationMetaDataType, overrides) as ChoBaseConfigurationMetaDataInfo; return(metaDataInfo); } //configElement.ForcePersist(true); return(null); }
public ChoODBCSectionInfo(XmlNode node, ChoBaseConfigurationElement configElement) { int configDataColumnSize = 0; if (node != null) { XPathNavigator navigator = node.CreateNavigator(); ConnectionString = (string)navigator.Evaluate(String.Format("string(@{0})", ConnectionStringToken), ChoXmlDocument.NameSpaceManager); TableName = (string)navigator.Evaluate(String.Format("string(@{0})", TableNameToken), ChoXmlDocument.NameSpaceManager); Int32.TryParse((string)navigator.Evaluate(String.Format("string(@{0})", ConfigDataColumnSizeToken), ChoXmlDocument.NameSpaceManager), out configDataColumnSize); } if (ConnectionString.IsNullOrWhiteSpace()) { ConnectionString = configElement[CONNECTION_STRING] as string; } if (TableName.IsNullOrWhiteSpace()) { TableName = configElement[TABLE_NAME] as string; } if (configDataColumnSize <= 0) { Int32.TryParse(configElement[CONFIG_DATA_COLUMN_SIZE] as string, out configDataColumnSize); } if (configDataColumnSize > 0) { ConfigDataColumnSize = configDataColumnSize; } //Normalize the ConnectionString ConnectionString = ConnectionString.Replace("'", ""); }
public override object Load(ChoBaseConfigurationElement configElement, XmlNode node) { base.Load(configElement, node); _iniSectionInfo = new ChoIniSectionInfo(ConfigNode, ConfigElement); _iniSectionInfo.Validate(); return(_iniSectionInfo.GetData()); }
public override object Load(ChoBaseConfigurationElement configElement, XmlNode node) { base.Load(configElement, node); _registrySectionInfo = new ChoRegistrySectionInfo(ConfigNode, ConfigObjectType, ConfigElement); _registrySectionInfo.Validate(); return(_registrySectionInfo.LoadRegistryInfo()); }
internal static void SetDefaultMetaDataInfo(ChoBaseConfigurationElement configElement) { if (configElement == null) { return; } _defaultMetaDataCache.SetValue(configElement.ConfigElementPath, configElement.MetaDataInfo); }
internal static ChoBaseConfigurationMetaDataInfo GetDefaultMetaDataInfo(ChoBaseConfigurationElement configElement) { if (configElement == null) { return(null); } return(_defaultMetaDataCache.GetValue(configElement.ConfigElementPath)); }
public static void DisposeWatcher(ChoBaseConfigurationElement configElement) { if (configElement == null) { return; } ConfigurationChangeWatcher.SetConfigurationChangedEventHandler("{0}_MetaData_WatcherHandler".FormatString(configElement.ConfigElementPath), NullConfigurationChangedEventHandler); }
internal static bool IsMetaDataModified(ChoBaseConfigurationElement configElement) { if (configElement == null) { return(false); } ChoBaseConfigurationMetaDataInfo newConfigurationMetaDataInfo = GetMetaDataSection(configElement); return(!ChoObject.Equals <ChoBaseConfigurationMetaDataInfo>(newConfigurationMetaDataInfo, configElement.MetaDataInfo)); }
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); }
public override object Load(ChoBaseConfigurationElement configElement, XmlNode node) { base.Load(configElement, node); LoadODBCInfoFromXml(ConfigNode); if (_odbcSectionInfo != null) { return(_odbcSectionInfo.GetData()); } return(null); }
public override object Load(ChoBaseConfigurationElement configElement, XmlNode node) { base.Load(configElement, node); SectionInfo = configElement.StateInfo["DICT_ADAPTER"] as ChoDictionaryAdapterSectionInfo; ChoDictionaryAdapterSectionInfo sectionInfo = new ChoDictionaryAdapterSectionInfo(ConfigNode, configElement); if (SectionInfo != sectionInfo) { configElement.StateInfo["DICT_ADAPTER"] = SectionInfo = sectionInfo; SectionInfo.Initialize(configElement); } return(SectionInfo.GetData()); }
public override object Load(ChoBaseConfigurationElement configElement, XmlNode node) { base.Load(configElement, node); ConfigurationManager.RefreshSection(APP_SETTINGS_SECTION_NAME); ConfigFilePath = _configuration.FilePath; _appSettingsFilePath = ChoPath.GetFullPath(GetAppSettingsFilePathIfAnySpecified()); if (!_appSettingsFilePath.IsNullOrWhiteSpace()) { _hasAppSettingsFilePath = true; } ConfigSectionName = APP_SETTINGS_SECTION_NAME; return(ConfigurationManager.AppSettings); }
private void InvokeOverrideConfigurationMetaDataInfo(ChoBaseConfigurationElement configElement) { ChoBaseConfigurationMetaDataInfo standardConfigurationMetaDataInfo = configElement.MetaDataInfo; Type type = configElement.ConfigbObjectType; if (standardConfigurationMetaDataInfo == null || type == null) { return; } if (configElement.ConfigObject is ChoConfigurableObject) { ((ChoConfigurableObject)configElement.ConfigObject).InvokeOverrideMetaDataInfo(standardConfigurationMetaDataInfo); } }
public override object Load(ChoBaseConfigurationElement configElement, XmlNode node) { base.Load(configElement, node); ConfigurationManager.RefreshSection(APP_SETTINGS_SECTION_NAME); ChoConfigurationManager.Refresh(); ConfigFilePath = ChoConfigurationManager.ApplicationConfigurationFilePath; string appSettingsFilePath = GetAppSettingsFilePathIfAnySpecified(); configElement[ChoConfigurationConstants.FORCE_PERSIST] = CanForcePersist(appSettingsFilePath); ConfigSectionName = APP_SETTINGS_SECTION_NAME; RefreshSection(appSettingsFilePath); return(ChoConfigurationManager.ApplicationConfiguration.AppSettings.Settings.ToNameValueCollection()); }
private void LoadParameters(ChoBaseConfigurationElement configurationElement) { if (configurationElement == null) { return; } if (Parameters.IsNullOrEmpty()) { return; } Parameters = Parameters.ExpandProperties(); foreach (Tuple <string, string> keyValue in Parameters.ToKeyValuePairs()) { configurationElement[keyValue.Item1] = keyValue.Item2; } }
private static ChoPropertyInfos GetPropertyInfos(ChoBaseConfigurationElement configElement) { string configElementPath = configElement.ConfigElementPath; if (configElementPath.IsNullOrWhiteSpace()) { return(null); } Dictionary <string, ChoPropertyInfos> propDict = _propDict; if (!propDict.ContainsKey(configElementPath)) { lock (_padLock) { if (!propDict.ContainsKey(configElementPath)) { string xpath = @"//{0}/propertyInfos".FormatString(configElementPath); XmlNode node = null; if (_rootNode != null) { node = _rootNode.SelectSingleNode(xpath); } if (node != null) { propDict.Add(configElementPath, ChoPropertyInfos.Default); ChoPropertyInfos propertyInfos = node.ToObject(typeof(ChoPropertyInfos)) as ChoPropertyInfos; propertyInfos.Initialize(); propDict[configElementPath] = propertyInfos; } else { propDict[configElementPath] = ConstructPropertyInfos(configElement); } } } } return(propDict[configElementPath]); }
public static void SetMetaDataSection(ChoBaseConfigurationElement configElement) { if (configElement == null) { return; } if (ChoObject.Equals <ChoBaseConfigurationMetaDataInfo>(configElement.MetaDataInfo, GetMetaDataSection(configElement))) { return; } string configElementPath = configElement.ConfigElementPath; ChoBaseConfigurationMetaDataInfo configurationMetaDataInfo = configElement.MetaDataInfo; configurationMetaDataInfo = ChoObject.Merge <ChoBaseConfigurationMetaDataInfo>(configurationMetaDataInfo, GetDefaultMetaDataInfo(configElement)); if (configurationMetaDataInfo == null) { return; } using (ChoXmlDocument xmlDocument = new ChoXmlDocument(_metaDataFilepath)) { if (configElementPath.IsNullOrEmpty()) { return; } XmlNode node = xmlDocument.XmlDocument.SelectSingleNode(configElementPath); if (node == null) { node = xmlDocument.XmlDocument.MakeXPath(configElementPath); } if (node != null) { ChoXmlDocument.SetOuterXml(node, configurationMetaDataInfo.ToXml()); xmlDocument.XmlDocument.InnerXml = ChoXmlDocument.AppendToInnerXml(node, GetPropertyInfos(configElement).ToXml()); xmlDocument.Save(); } } }
public static void SetWatcher(ChoBaseConfigurationElement configElement) { if (configElement == null) { return; } //if (configElement.WatchChange) //{ ConfigurationChangeWatcher.SetConfigurationChangedEventHandler("{0}_MetaData_WatcherHandler".FormatString(configElement.ConfigElementPath), (sender, e) => { if (ChoConfigurationMetaDataManager.IsMetaDataModified(configElement)) { configElement.Refresh(); } }); //} }
public virtual object Load(ChoBaseConfigurationElement configElement, XmlNode node) { ChoGuard.ArgumentNotNull(configElement, "ConfigElement"); ConfigElement = configElement; //ConfigElement.LastLoadedTimeStamp = DateTime.Now; ConfigObjectType = ConfigElement.ConfigbObjectType; ConfigSectionName = configElement.ConfigSectionName; RootConfigNode = ConfigNode = node; //ChoMetaDataManager.SetWatcher(this); if (ConfigObjectType == null) { throw new ChoConfigurationException("Missing configuration object type."); } return(null); }
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); }
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); }