本文整理汇总了C#中ConfigurationUserLevel类的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationUserLevel类的具体用法?C# ConfigurationUserLevel怎么用?C# ConfigurationUserLevel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurationUserLevel类属于命名空间,在下文中一共展示了ConfigurationUserLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DecryptEncryptConnectionString
private static bool DecryptEncryptConnectionString(string path)
{
ExeConfigurationFileMap file = new ExeConfigurationFileMap();
file.ExeConfigFilename = path;
ConfigurationUserLevel level = new ConfigurationUserLevel();
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(file, level);
ConfigurationSection section = config.GetSection("connectionStrings");
// Encrypt Configuration ConnectionString
if (!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
section.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Modified);
return true;
}
// Decrypt Configuration ConnectionString
else
{
section.SectionInformation.UnprotectSection();
config.Save();
return false;
}
}
示例2: OpenRemoteConnectionString
private static string OpenRemoteConnectionString(string path, string name)
{
ExeConfigurationFileMap file = new ExeConfigurationFileMap();
file.ExeConfigFilename = path;
ConfigurationUserLevel level = new ConfigurationUserLevel();
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(file, level);
return config.ConnectionStrings.ConnectionStrings[name].ConnectionString;
}
示例3: InitialiseConfigurationWith
protected void InitialiseConfigurationWith(ConfigurationUserLevel userLevel, string configurationFileContents)
{
File.WriteAllText(ConfigurationFileTemporaryFilePath, configurationFileContents);
var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = ConfigurationFileTemporaryFilePath };
Configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, userLevel);
}
示例4: GetClientConfig
private System.Configuration.Configuration GetClientConfig(ConfigurationUserLevel userLevel)
{
if (UseDefaultConfig(SettingsFileMap, userLevel))
{
return ConfigurationManager.OpenExeConfiguration(userLevel);
}
return ConfigurationManager.OpenMappedExeConfiguration(SettingsFileMap, userLevel);
}
示例5: OpenExeConfigurationImpl
private static System.Configuration.Configuration OpenExeConfigurationImpl(ConfigurationFileMap fileMap, bool isMachine, ConfigurationUserLevel userLevel, string exePath)
{
if ((!isMachine && (((fileMap == null) && (exePath == null)) || ((fileMap != null) && (((ExeConfigurationFileMap) fileMap).ExeConfigFilename == null)))) && ((s_configSystem != null) && (s_configSystem.GetType() != typeof(ClientConfigurationSystem))))
{
throw new ArgumentException(System.Configuration.SR.GetString("Config_configmanager_open_noexe"));
}
return ClientConfigurationHost.OpenExeConfiguration(fileMap, isMachine, userLevel, exePath);
}
示例6: GetDefaultExeConfigPath
public static string GetDefaultExeConfigPath(ConfigurationUserLevel userLevel) {
try {
var UserConfig = ConfigurationManager.OpenExeConfiguration(userLevel);
return UserConfig.FilePath;
}
catch (ConfigurationException e) {
return e.Filename;
}
}
示例7: GetDefaultExeConfigPath
public static string GetDefaultExeConfigPath(ConfigurationUserLevel userLevel)
{
try
{
return ConfigurationManager.OpenExeConfiguration(userLevel).FilePath;
}
catch (ConfigurationException exception)
{
return exception.Filename;
}
}
示例8: LoadConfiguration
public static void LoadConfiguration(ExeConfigurationFileMap FnMap = null, ConfigurationUserLevel CuLevel = ConfigurationUserLevel.None)
{
if (FnMap == null)
appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationPath);
else
appConfig = ConfigurationManager.OpenMappedExeConfiguration(FnMap, CuLevel);
ConfigurationSection section = appConfig.Sections["installer"];
if (section == null)
throw new ConfigurationErrorsException("installer section not found in " + appConfig.FilePath);
string strXml = section.SectionInformation.GetRawXml();
xmlConfig = new XmlDocument();
xmlConfig.LoadXml(strXml);
}
示例9: SetAndSave
public static void SetAndSave(string name, string value, ConfigurationUserLevel level = ConfigurationUserLevel.None)
{
var config = ConfigurationManager.OpenExeConfiguration(level);
if (!config.AppSettings.Settings.AllKeys.Contains(name))
{
config.AppSettings.Settings.Add(name, value);
}
else
{
config.AppSettings.Settings[name].Value = value;
}
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
}
示例10: GetConfiguration
protected IConfiguration GetConfiguration(ConfigurationUserLevel userLevel)
{
// Configuration flows from Machine.config -> exe.config -> roaming user.config -> local user.config with
// latter definitions trumping earlier (e.g. local trumps roaming, which trumps exe, etc.).
//
// Opening configuration other than None will provide a combined view of with roaming or roaming and local.
// As we want to handle the consolodation ourselves we need to open twice. Once to get the actual user config
// path, then again with the path explicitly specified with "None" for our user level. (Values are lazily
// loaded so this isn't a terrible perf issue.)
IConfiguration configuration = this.ConfigurationManager.OpenConfiguration(userLevel);
if (userLevel == ConfigurationUserLevel.None)
{
return configuration;
}
else
{
return this.ConfigurationManager.OpenConfiguration(configuration.FilePath);
}
}
示例11: GetSection
/// <summary>
/// Gets the current applications <OlapConfigSection> section.
/// </summary>
/// <param name="ConfigLevel">
/// The <ConfigurationUserLevel> that the config file
/// is retrieved from.
/// </param>
/// <returns>
/// The configuration file's <OlapConfigSection> section.
/// </returns>
public static OlapConfigSectionSettings GetSection(ConfigurationUserLevel ConfigLevel)
{
/*
* This class is setup using a factory pattern that forces you to
* name the section <OlapConfigSection> in the config file.
* If you would prefer to be able to specify the name of the section,
* then remove this method and mark the constructor public.
*/
System.Configuration.Configuration Config = ConfigurationManager.OpenExeConfiguration
(ConfigLevel);
OlapConfigSectionSettings oOlapConfigSectionSettings;
oOlapConfigSectionSettings =
(OlapConfigSectionSettings)Config.GetSection("OlapConfigSectionSettings");
if (oOlapConfigSectionSettings == null) {
oOlapConfigSectionSettings = new OlapConfigSectionSettings();
Config.Sections.Add("OlapConfigSectionSettings", oOlapConfigSectionSettings);
}
oOlapConfigSectionSettings._Config = Config;
return oOlapConfigSectionSettings;
}
示例12: OpenExeConfigurationInternal
internal static Configuration OpenExeConfigurationInternal (ConfigurationUserLevel userLevel, Assembly calling_assembly, string exePath)
{
ExeConfigurationFileMap map = new ExeConfigurationFileMap ();
/* Roaming and RoamingAndLocal should be different
On windows,
PerUserRoaming = \Documents and Settings\<username>\Application Data\...
PerUserRoamingAndLocal = \Documents and Settings\<username>\Local Settings\Application Data\...
*/
switch (userLevel) {
case ConfigurationUserLevel.None:
if (exePath == null || exePath.Length == 0) {
map.ExeConfigFilename = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
} else {
if (!Path.IsPathRooted (exePath))
exePath = Path.GetFullPath (exePath);
if (!File.Exists (exePath)) {
Exception cause = new ArgumentException ("The specified path does not exist.", "exePath");
throw new ConfigurationErrorsException ("Error Initializing the configuration system:", cause);
}
map.ExeConfigFilename = exePath + ".config";
}
break;
case ConfigurationUserLevel.PerUserRoaming:
map.RoamingUserConfigFilename = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData), GetAssemblyInfo(calling_assembly));
map.RoamingUserConfigFilename = Path.Combine (map.RoamingUserConfigFilename, "user.config");
goto case ConfigurationUserLevel.None;
case ConfigurationUserLevel.PerUserRoamingAndLocal:
map.LocalUserConfigFilename = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData), GetAssemblyInfo(calling_assembly));
map.LocalUserConfigFilename = Path.Combine (map.LocalUserConfigFilename, "user.config");
goto case ConfigurationUserLevel.PerUserRoaming;
}
return ConfigurationFactory.Create (typeof(ExeConfigurationHost), map, userLevel);
}
示例13: GetPreviousUserConfigPath
private static string GetPreviousUserConfigPath(ConfigurationUserLevel userLevel)
{
Version version;
if (userLevel == ConfigurationUserLevel.None)
{
return null;
}
string defaultExeConfigPath = GetDefaultExeConfigPath(userLevel);
string directoryName = Path.GetDirectoryName(defaultExeConfigPath);
defaultExeConfigPath = Path.GetFileName(defaultExeConfigPath);
string path = Path.GetDirectoryName(directoryName);
if (!Directory.Exists(path))
{
return null;
}
if (!VersionHelper.TryParse(Path.GetFileName(directoryName), VersionStyles.AllowMajorMinorBuildRevision, out version))
{
return null;
}
List<Version> source = new List<Version>();
foreach (string str4 in Directory.GetDirectories(path))
{
Version version2;
if (VersionHelper.TryParse(Path.GetFileName(str4), VersionStyles.AllowMajorMinorBuildRevision, out version2) && (version2 != version))
{
source.Add(version2);
}
}
if (source.Count == 0)
{
return null;
}
if (source.Count > 1)
{
source.Sort();
}
return Path.Combine(Path.Combine(path, source.Last<Version>().ToString()), defaultExeConfigPath);
}
示例14: WriteSettings
private void WriteSettings(string sectionName, ConfigurationUserLevel userLevel, List<SettingsPropertyValue> newSettings)
{
System.Configuration.Configuration clientConfig = this.GetClientConfig(userLevel);
ClientSettingsSection section = this.GetUserSection(clientConfig, sectionName, true);
if (section == null)
{
throw new ConfigurationErrorsException("Failed to save settings. No settings section found");
}
foreach (SettingsPropertyValue value2 in newSettings)
{
SettingElement element = section.Settings.Get(value2.Name);
if (element == null)
{
element = new SettingElement {
Name = value2.Name
};
section.Settings.Add(element);
}
element.SerializeAs = value2.Property.SerializeAs;
element.Value.ValueXml = this.SerializeToXmlElement(value2.Property, value2);
}
try
{
clientConfig.Save();
}
catch (ConfigurationErrorsException exception)
{
throw new ConfigurationErrorsException(string.Format("Failed to save settings. {0}", exception.Message), exception);
}
}
示例15: UseDefaultConfig
private static bool UseDefaultConfig(ExeConfigurationFileMap fileMap, ConfigurationUserLevel userLevel)
{
if (fileMap != null)
{
switch (userLevel)
{
case ConfigurationUserLevel.None:
return string.IsNullOrEmpty(fileMap.ExeConfigFilename);
case ConfigurationUserLevel.PerUserRoaming:
return string.IsNullOrEmpty(fileMap.RoamingUserConfigFilename);
case ConfigurationUserLevel.PerUserRoamingAndLocal:
return string.IsNullOrEmpty(fileMap.LocalUserConfigFilename);
}
}
return true;
}