当前位置: 首页>>代码示例>>C#>>正文


C# ConfigurationUserLevel类代码示例

本文整理汇总了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;
            }
        }
开发者ID:gthardy,项目名称:EncryptedConnectionStrings,代码行数:26,代码来源:Program.cs

示例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;
 }
开发者ID:gthardy,项目名称:EncryptedConnectionStrings,代码行数:8,代码来源:Program.cs

示例3: InitialiseConfigurationWith

        protected void InitialiseConfigurationWith(ConfigurationUserLevel userLevel, string configurationFileContents)
        {
            File.WriteAllText(ConfigurationFileTemporaryFilePath, configurationFileContents);

            var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = ConfigurationFileTemporaryFilePath };

            Configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, userLevel);
        }
开发者ID:pleb,项目名称:Tank,代码行数:8,代码来源:BaseTest.cs

示例4: GetClientConfig

 private System.Configuration.Configuration GetClientConfig(ConfigurationUserLevel userLevel)
 {
     if (UseDefaultConfig(SettingsFileMap, userLevel))
     {
         return ConfigurationManager.OpenExeConfiguration(userLevel);
     }
     return ConfigurationManager.OpenMappedExeConfiguration(SettingsFileMap, userLevel);
 }
开发者ID:shankithegreat,项目名称:commanderdotnet,代码行数:8,代码来源:ConfigurableSettingsProvider.cs

示例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);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:ConfigurationManager.cs

示例6: GetDefaultExeConfigPath

 public static string GetDefaultExeConfigPath(ConfigurationUserLevel userLevel) {
     try {
         var UserConfig = ConfigurationManager.OpenExeConfiguration(userLevel);
         return UserConfig.FilePath;
     }
     catch (ConfigurationException e) {
         return e.Filename;
     }
 }
开发者ID:coolinc,项目名称:XWall,代码行数:9,代码来源:Settings.cs

示例7: GetDefaultExeConfigPath

 public static string GetDefaultExeConfigPath(ConfigurationUserLevel userLevel)
 {
     try
     {
         return ConfigurationManager.OpenExeConfiguration(userLevel).FilePath;
     }
     catch (ConfigurationException exception)
     {
         return exception.Filename;
     }
 }
开发者ID:shankithegreat,项目名称:commanderdotnet,代码行数:11,代码来源:ConfigurableSettingsProvider.cs

示例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);
		}
开发者ID:lwhitelock,项目名称:Websitepanel,代码行数:13,代码来源:AppConfig.cs

示例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");
 }
开发者ID:voltagex,项目名称:junkcode,代码行数:14,代码来源:ConfigurationHelper.cs

示例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);
            }
        }
开发者ID:ramarag,项目名称:XTask,代码行数:20,代码来源:ClientSettingsView.cs

示例11: GetSection

        /// <summary>
        /// Gets the current applications &lt;OlapConfigSection&gt; section.
        /// </summary>
        /// <param name="ConfigLevel">
        /// The &lt;ConfigurationUserLevel&gt; that the config file
        /// is retrieved from.
        /// </param>
        /// <returns>
        /// The configuration file's &lt;OlapConfigSection&gt; section.
        /// </returns>
        public static OlapConfigSectionSettings GetSection(ConfigurationUserLevel ConfigLevel)
        {
            /*
             * This class is setup using a factory pattern that forces you to
             * name the section &lt;OlapConfigSection&gt; 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;
        }
开发者ID:arman-arian,项目名称:NSimpleOLAP,代码行数:32,代码来源:OlapConfigSectionSettings.cs

示例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);
		}
开发者ID:rabink,项目名称:mono,代码行数:38,代码来源:ConfigurationManager.cs

示例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);
 }
开发者ID:shankithegreat,项目名称:commanderdotnet,代码行数:38,代码来源:ConfigurableSettingsProvider.cs

示例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);
     }
 }
开发者ID:shankithegreat,项目名称:commanderdotnet,代码行数:30,代码来源:ConfigurableSettingsProvider.cs

示例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;
        }
开发者ID:shankithegreat,项目名称:commanderdotnet,代码行数:18,代码来源:ConfigurableSettingsProvider.cs


注:本文中的ConfigurationUserLevel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。