public static bool SaveConfig <T>(T t) where T : class, new() { ConfigFileAttribute attribute = AttributeHelper.GetConfigAttribute <ConfigFileAttribute>(typeof(T)); if (attribute == null) { ConfigThrowHelper.ThrowConfigException( R.ConfigError_NoConfigAttribute, typeof(T).FullName, typeof(ConfigFileAttribute).FullName); } ConfigSettings configSettings = FrameworkConfig.GetConfig <ConfigSettings>(); string configFilePath = string.Empty; switch (attribute.ConfigPathType) { case ConfigPathType.FullPhysicalPath: configFilePath = attribute.FileName; break; case ConfigPathType.ServerPath: configFilePath = HttpContext.Current.Server.MapPath(attribute.FileName); break; default: configFilePath = configSettings.GetConfigFilePath <T>(); break; } XmlConfigGetParameter getParameter = new XmlConfigGetParameter(configFilePath, attribute.IncludeSubdirectories); return(ObjectXmlSerializer.SaveXmlToFlie <T>(getParameter.FilePaths, t)); }
/// <summary> /// 处理配置文件更改。 /// </summary> /// <param name="sender">事件源。</param> /// <param name="e">包含事件数据的 <see cref="ConfigChangedEventArgs"/>。</param> private void OnConfigChanged(object sender, ConfigChangedEventArgs e) { bool appDomainRestarted = false; if (e.RestartAppDomainOnChange) { appDomainRestarted = FrameworkConfig.RestartAppDomain(); } if (!appDomainRestarted) { RemoveConfigFromCache(e.GetParameter); NotifyConfigChanged(e); } }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <returns></returns> public static IConfigSource Create(string name) { Check.Argument.IsNotNull("name", name); ConfigSettings configSettings = FrameworkConfig.GetConfig <ConfigSettings>(); ConfigProviderMapping providerMapping = configSettings.GetProviderMapping(name); IConfigSource configSource = MethodCaller.CreateInstance(providerMapping.Type) as IConfigSource; if (configSource == null) { ConfigThrowHelper.ThrowConfigException(R.ConfigSourceNotFound, name); } return(configSource); }