Esempio n. 1
0
 public override void InitForConfiguration(ref string locationSubPath, out string configPath,
     out string locationConfigPath, IInternalConfigRoot configRoot, params object[] hostInitConfigurationParams)
 {
     // Stash the filemap so we can see if the machine config was explicitly specified
     _fileMap = (ConfigurationFileMap)hostInitConfigurationParams[0];
     base.InitForConfiguration(ref locationSubPath, out configPath, out locationConfigPath, configRoot, hostInitConfigurationParams);
 }
        public void TestConfigOverrides()
        {
            var fileMap = new ConfigurationFileMap(Path.GetFullPath(@"Configs\EdbOverridesConfig.config"));
            var configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
            var config = configuration.GetSection("LogSearchShipperGroup/LogSearchShipper") as LogSearchShipperSection;

            {
                var edbItem = config.EDBFileWatchers[0];
                var overrideConfig = edbItem.OverrideConfigs.First();
                var edbFileWatchParser = new EDBFileWatchParser(edbItem);
                var fileWatchItems = edbFileWatchParser.ToFileWatchCollection();
                Assert.AreEqual(5, fileWatchItems.Count);

                var matchedItems = fileWatchItems.Where(item => item.Files.Contains("Price")).ToArray();
                Assert.AreEqual(2, matchedItems.Count());
                Assert.IsTrue(matchedItems.All(item => item.CloseWhenIdle == false));
                Assert.IsTrue(matchedItems.All(item => item.CustomNxlogConfig.Value == overrideConfig.CustomNxlogConfig.Value));
                Assert.IsTrue(matchedItems.All(item => item.SourceTailer == TailerType.MT));
                Assert.IsTrue(matchedItems.All(item => item.Fields["environment"].Value == "CUSTOM_VALUE"));

                var notMatchedItems = fileWatchItems.ToList();
                foreach (var item in matchedItems)
                {
                    notMatchedItems.Remove(item);
                }

                Assert.IsTrue(notMatchedItems.Count > 0);
                Assert.IsTrue(notMatchedItems.All(item => item.CloseWhenIdle == true));
                Assert.IsTrue(notMatchedItems.All(item => string.IsNullOrEmpty(item.CustomNxlogConfig.Value)));
                Assert.IsTrue(notMatchedItems.All(item => item.SourceTailer == TailerType.Normal));
                Assert.IsTrue(notMatchedItems.All(item => item.Fields["environment"].Value == "QAT"));
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            if(args.Length < 1)
            {
                Console.WriteLine("cryptWebConfig filename ");
                Console.ReadKey();
                return;
            }
            string filename = System.AppDomain.CurrentDomain.BaseDirectory  + args[0];
            ConfigurationFileMap filemap = new ConfigurationFileMap(filename);
               // System.Configuration.Configuration webConf = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(filename);
            System.Configuration.Configuration webConf = System.Configuration.ConfigurationManager.OpenExeConfiguration(filename);
            AppSettingsSection appSettings = webConf.AppSettings;

            ConnectionStringsSection connStrings = webConf.ConnectionStrings;
            if (connStrings.SectionInformation.IsProtected)
            {

                Console.WriteLine("Decrypting Section ");
                connStrings.SectionInformation.UnprotectSection();
                webConf.Save();
            }
            else
            {
                Console.WriteLine("Encyprting Section ");
                webConf.ConnectionStrings.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
                webConf.Save();
            }
        }
 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);
 }
Esempio n. 5
0
 public string Customsection(string pathtoconfigfile)
 {
     var fileMap = new ConfigurationFileMap(pathtoconfigfile);
     var configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
     var sectionGroup = configuration.GetSectionGroup("applicationSettings"); // This is the section group name, change to your needs
     var section = (ClientSettingsSection)sectionGroup.Sections.Get("MyTarget.Namespace.Properties.Settings"); // This is the section name, change to your needs
     var setting = section.Settings.Get("SettingName"); // This is the setting name, change to your needs
     return setting.Value.ValueXml.InnerText;
 }
        public void CanReadConfiguration()
        {
            System.Configuration.ConfigurationFileMap fileMap = new ConfigurationFileMap("App.test.config"); // path to test config file
            System.Configuration.Configuration configuration = System.Configuration.ConfigurationManager.OpenMappedMachineConfiguration(fileMap);

            var serviceConfig = configuration.GetSection(ServiceSection.SectionName) as ServiceSection;

            Assert.NotNull(serviceConfig);
        }
        private static System.Configuration.Configuration CreateConfiguration(string configurationFileNameIdentity)
        {
            ConfigurationFileMap configurationFileMap = new ConfigurationFileMap
            {
                MachineConfigFilename = string.Format(CultureInfo.InvariantCulture, @"{0}\Configuration\Test-configurations\HtmlTransformerElementCollectionTest.{1}.Web.config", AppDomain.CurrentDomain.BaseDirectory, configurationFileNameIdentity)
            };

            return ConfigurationManager.OpenMappedMachineConfiguration(configurationFileMap);
        }
        public static NHamlConfigurationSection GetConfiguration(string configFile)
        {
            if (!File.Exists(configFile))
                throw new FileNotFoundException("Unable to find configuration file " + configFile, configFile);

            var map = new ConfigurationFileMap(configFile);
            var config = ConfigurationManager.OpenMappedMachineConfiguration(map);
            var result = (NHamlConfigurationSection)config.GetSection("NHaml");
            return result ?? new NHamlConfigurationSection();
        }
Esempio n. 9
0
        public void TestLoadingExcludedAssemblies()
        {
            var fileMap = new ConfigurationFileMap("WithExcludedAssemblyConfig.config");
            var config = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
            var section = config.GetSection("specBind") as ConfigurationSectionHandler;

            Assert.IsNotNull(section);
            var assemblies = section.Application.ExcludedAssemblies.Cast<AssemblyElement>().ToList();
            Assert.AreEqual(1, assemblies.Count);
            Assert.AreEqual("MyCoolApp, Version=1.2.3.0, Culture=neutral, PublicKeyToken=null", assemblies[0].Name);
        }
        /// <summary>
        ///     Opens a config file on disk.
        /// </summary>
        /// <param name="configFilePath">Path to external config file.</param>
        /// <param name="log">Log4Net ILog implementation</param>
        /// <returns>
        ///     Settings parsed from <paramref name="configFilePath" />.
        /// </returns>
        private static Settings LoadConfigurationFromFile(string configFilePath, ILog log)
        {
            log.DebugFormat("Attempting to load settings from external configuration file '{0}'", configFilePath);
            var fileMap = new ConfigurationFileMap(configFilePath);
            var configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
            var section = (NewRelicConfigurationSection) configuration.GetSection("newRelic");
            var settingsFromConfig = Settings.FromConfigurationSection(section, log);
            log.DebugFormat("Settings loaded successfully");

            return settingsFromConfig;
        }
Esempio n. 11
0
 private static Configuration ReadConfiguration()
 {
     var appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
     if (appPath == null)
         throw new InvalidDataException("Could not get the config path!!!");
     appPath = appPath.Replace("file:\\", "");
     //var currentDomainPath = AppDomain.CurrentDomain.RelativeSearchPath + "\\" + "ColloSys.config";
     var currentDomainPath = appPath + "\\" + "GridMvc.config";
     var fileMap = new ConfigurationFileMap(currentDomainPath); //Path to your config file
     var configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
     return configuration;
 }
 internal UserMapPath(ConfigurationFileMap fileMap, bool pathsAreLocal)
 {
     this._pathsAreLocal = pathsAreLocal;
     if (!string.IsNullOrEmpty(fileMap.MachineConfigFilename))
     {
         if (this._pathsAreLocal)
         {
             this._machineConfigFilename = Path.GetFullPath(fileMap.MachineConfigFilename);
         }
         else
         {
             this._machineConfigFilename = fileMap.MachineConfigFilename;
         }
     }
     if (string.IsNullOrEmpty(this._machineConfigFilename))
     {
         this._machineConfigFilename = HttpConfigurationSystem.MachineConfigurationFilePath;
         this._rootWebConfigFilename = HttpConfigurationSystem.RootWebConfigurationFilePath;
     }
     else
     {
         this._rootWebConfigFilename = Path.Combine(Path.GetDirectoryName(this._machineConfigFilename), "web.config");
     }
     this._webFileMap = fileMap as WebConfigurationFileMap;
     if (this._webFileMap != null)
     {
         if (!string.IsNullOrEmpty(this._webFileMap.Site))
         {
             this._siteName = this._webFileMap.Site;
             this._siteID = this._webFileMap.Site;
         }
         else
         {
             this._siteName = WebConfigurationHost.DefaultSiteName;
             this._siteID = "1";
         }
         if (this._pathsAreLocal)
         {
             foreach (string str in this._webFileMap.VirtualDirectories)
             {
                 this._webFileMap.VirtualDirectories[str].Validate();
             }
         }
         VirtualDirectoryMapping mapping2 = this._webFileMap.VirtualDirectories[null];
         if (mapping2 != null)
         {
             this._rootWebConfigFilename = Path.Combine(mapping2.PhysicalDirectory, mapping2.ConfigFileBaseName);
             this._webFileMap.VirtualDirectories.Remove(null);
         }
     }
 }
Esempio n. 13
0
        internal UserMapPath(ConfigurationFileMap fileMap, bool pathsAreLocal) {
            _pathsAreLocal = pathsAreLocal;


            if (!String.IsNullOrEmpty(fileMap.MachineConfigFilename)) {
                if (_pathsAreLocal) {
                    _machineConfigFilename = Path.GetFullPath(fileMap.MachineConfigFilename);
                }
                else {
                    _machineConfigFilename = fileMap.MachineConfigFilename;
                }
            }

            if (string.IsNullOrEmpty(_machineConfigFilename)) {
                // Defaults for machine.config and root web.config if not supplied by user
                _machineConfigFilename = HttpConfigurationSystem.MachineConfigurationFilePath;
                _rootWebConfigFilename = HttpConfigurationSystem.RootWebConfigurationFilePath;
            } else {
                _rootWebConfigFilename = Path.Combine(Path.GetDirectoryName(_machineConfigFilename), "web.config");
            }

            _webFileMap = fileMap as WebConfigurationFileMap;
            if (_webFileMap != null) {

                // Use the site if supplied, otherwise use the default.
                if (!String.IsNullOrEmpty(_webFileMap.Site)) {
                    _siteName = _webFileMap.Site;
                    _siteID = _webFileMap.Site;
                }
                else {
                    _siteName = WebConfigurationHost.DefaultSiteName;
                    _siteID = WebConfigurationHost.DefaultSiteID;
                }

                if (_pathsAreLocal) {
                    // validate mappings
                    foreach (string virtualDirectory in _webFileMap.VirtualDirectories) {
                        VirtualDirectoryMapping mapping = _webFileMap.VirtualDirectories[virtualDirectory];
                        mapping.Validate();
                    }
                }

                // Get the root web.config path
                VirtualDirectoryMapping rootWebMapping = _webFileMap.VirtualDirectories[null];
                if (rootWebMapping != null) {
                    _rootWebConfigFilename = Path.Combine(rootWebMapping.PhysicalDirectory, rootWebMapping.ConfigFileBaseName);
                    _webFileMap.VirtualDirectories.Remove(null);
                }

            }
        }
        //
        // *************************************************
        // ** Static Management Functions to edit config **
        // *************************************************
        //

        private static Configuration OpenWebConfigurationImpl(
                WebLevel webLevel, ConfigurationFileMap fileMap, string path, string site, string locationSubPath, 
                string server, string userName, string password, IntPtr userToken) {

            // In the hosted case, we allow app relative (~/....).  Otherwise, it must be absolute
            VirtualPath virtualPath;
            if (HostingEnvironment.IsHosted) {
                virtualPath = VirtualPath.CreateNonRelativeAllowNull(path);
            }
            else {
                virtualPath = VirtualPath.CreateAbsoluteAllowNull(path);
            }

            return WebConfigurationHost.OpenConfiguration(webLevel, fileMap, virtualPath, site, locationSubPath, 
                    server, userName, password, userToken);
        }
        private IMembaseClientConfiguration Load(string path, string sectionName)
        {
            var cfm = new ConfigurationFileMap();
            cfm.MachineConfigFilename = path;

            var cfg = ConfigurationManager.OpenMappedMachineConfiguration(cfm);
            if (cfg == null) throw new InvalidOperationException("The config file '" + path + "' cannot be loaded.");

            if (String.IsNullOrEmpty(sectionName))
                sectionName = "membase";

            var section = cfg.GetSection(sectionName) as IMembaseClientConfiguration;
            if (section == null) throw new InvalidOperationException("The config section '" + sectionName + "' cannot be found in the config file: '" + path + "'.");

            return section;
        }
Esempio n. 16
0
        public static object GetSectionByName(string sectionName)
        {
            CacheManager configCache = CacheFactory.GetCacheManager();
            ConfigurationSection site = configCache.GetData(sectionName) as ConfigurationSection;
            if (site == null)
            {
                ConfigurationFileMap fileMap = new ConfigurationFileMap();
                string configFileName = GetAbsoluteFilePath(ConfigurationManager.AppSettings["CustomConfigFile"]);
                fileMap.MachineConfigFilename = configFileName;
                Configuration config = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
                site = config.GetSection(sectionName) as ConfigurationSection;

                configCache.Add(sectionName, site, CacheItemPriority.Normal, null, new FileDependency(configFileName));
            }
            return site;
        }
    private static ClousotViaService()
    {
      var configFileName = "Microsoft.Research.CodeAnalysis.app.config";

      // It is not possible to load a resource as a configuration file
      // it has to be a real file on disk, that's why we use a temporary file
      var assembly = Assembly.GetExecutingAssembly();
      string contents;
      using (var configFileReader = new StreamReader(assembly.GetManifestResourceStream(configFileName)))
        contents = configFileReader.ReadToEnd();
      var tempFileName = Path.GetTempFileName();
      using (var tempFileWriter = new StreamWriter(tempFileName))
        tempFileWriter.Write(contents);

      var configFileMap = new ConfigurationFileMap(tempFileName);
      configuration = ConfigurationManager.OpenMappedMachineConfiguration(configFileMap);
    }
        private IMemcachedClientConfiguration Load(string path, string sectionName)
        {
            if (!File.Exists(path)) throw new InvalidOperationException("The config file '" + path + "' cannot be found.");
            var cfm = new ConfigurationFileMap();
            cfm.MachineConfigFilename = path;

            var cfg = ConfigurationManager.OpenMappedMachineConfiguration(cfm);
            if (cfg == null) if (!File.Exists(path)) throw new InvalidOperationException("The config file '" + path + "' cannot be found.");

            if (String.IsNullOrEmpty(sectionName))
                sectionName = "enyim.com/memcached";

            var section = cfg.GetSection(sectionName) as IMemcachedClientConfiguration;
            if (section == null) if (!File.Exists(path)) throw new InvalidOperationException("The config section '" + sectionName + "' cannot be found.");

            return section;
        }
 private void ChooseAndInitConfigMapPath(bool useConfigMapPath, IConfigMapPath configMapPath, ConfigurationFileMap fileMap)
 {
     if (useConfigMapPath)
     {
         this._configMapPath = configMapPath;
     }
     else if (fileMap != null)
     {
         this._configMapPath = new UserMapPath(fileMap);
     }
     else if (HostingEnvironment.IsHosted)
     {
         this._configMapPath = HostingPreferredMapPath.GetInstance();
     }
     else
     {
         this._configMapPath = IISMapPath.GetInstance();
     }
     this._configMapPath2 = this._configMapPath as IConfigMapPath2;
 }
            public void WriteOnly()
            {
                var filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "writeonly.config");
                var fileMap = new ConfigurationFileMap(filename);
                var configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
                var section = configuration.Sections.Get("BB.Caching");
                var connectionGroups = Cache.LoadFromConfig(section, false);

                var connectionString = string.Format("{0}:{1},allowAdmin=True", "12.34.56.78", "1234");

                Assert.Equal(1, connectionGroups.Count);

                var connectionGroup = connectionGroups.First();

                Assert.Equal("node-0", connectionGroup.Name);
                Assert.Equal(0, connectionGroup.ReadConnections.Count);

                Assert.Equal(connectionString, connectionGroup.WriteConnection);
                Assert.False(connectionGroup.IsAnalytics);
            }
        public void Config()
        {
            string configSetting = ConfigurationManager.AppSettings["simpleDB.config"];

            if (string.IsNullOrEmpty(configSetting))
            {
                Configuration = SimpleDBConfigurationSection.GetConfig();
            }
            else
            {
                string filePath = configSetting;

                if (!Path.IsPathRooted(filePath))
                {
                    string configurationFileLocation = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

                    filePath = Path.Combine(Path.GetDirectoryName(configurationFileLocation), configSetting);
                }

                if (File.Exists(filePath))
                {
                    var fileMap = new ConfigurationFileMap(filePath);

                    var configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);

                    Configuration = configuration.GetSection("simpleDB") as SimpleDBConfigurationSection;
                }
                else
                {
                    throw new ConfigurationErrorsException("找不到配置文件:" + filePath);
                }
            }

            if (null == Configuration)
            {
                throw new ConfigurationErrorsException("配置文件中找不到数据库信息配置节点 simpleDB");
            }
        }
Esempio n. 22
0
        private static Configuration OpenExeConfigurationImpl(ConfigurationFileMap fileMap, bool isMachine,
                                                              ConfigurationUserLevel userLevel, string exePath, bool preLoad = false)
        {
            // exePath must be specified if not running inside ClientConfigurationSystem
            if (!isMachine &&
                (((fileMap == null) && (exePath == null)) ||
                 ((fileMap != null) && (((ExeConfigurationFileMap)fileMap).ExeConfigFilename == null))))
            {
                if ((s_configSystem != null) &&
                    (s_configSystem.GetType() != typeof(ClientConfigurationSystem)))
                {
                    throw new ArgumentException(SR.Config_configmanager_open_noexe);
                }
            }

            Configuration config = ClientConfigurationHost.OpenExeConfiguration(fileMap, isMachine, userLevel, exePath);

            if (preLoad)
            {
                PreloadConfiguration(config);
            }
            return(config);
        }
 public override void Init(IInternalConfigRoot configRoot, params object[] hostInitParams)
 {
     // Stash the filemap so we can see if the machine config was explicitly specified
     _fileMap = hostInitParams[0] as ConfigurationFileMap;
     base.Init(configRoot, hostInitParams);
 }
 public static Configuration OpenMappedMachineConfiguration(ConfigurationFileMap fileMap)
 {
     return(default(Configuration));
 }
Esempio n. 25
0
        public static Configuration OpenMappedMachineConfiguration(ConfigurationFileMap fileMap)
        {
            Contract.Ensures(Contract.Result <System.Configuration.Configuration>() != null);

            return(default(Configuration));
        }
Esempio n. 26
0
 static void readConfig()
 {
     ConfigurationFileMap fileMap = new ConfigurationFileMap(System.Environment.CurrentDirectory + "\\Emulator.config");
     Configuration a = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
 }
Esempio n. 27
0
        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);

            string targetDir = Context.Parameters[Arguments.TargetDir].TrimEnd('\\');
            string configFile = Path.Combine(targetDir, Assembly.GetExecutingAssembly().Location + ".config");

            System.Configuration.ConfigurationFileMap fileMap = new ConfigurationFileMap(configFile);
            System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenMappedMachineConfiguration(fileMap);

            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(delegate(object sender, ResolveEventArgs args)
            {
                return Assembly.LoadFile(Path.Combine(targetDir, args.Name + ".dll"));
            });

            UhuruSection section = (UhuruSection)config.GetSection("uhuru");
            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.BaseDir]))
            {
                section.DEA.BaseDir = Context.Parameters[Arguments.BaseDir];
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.EnforceUlimit]))
            {
                section.DEA.EnforceUsageLimit = Convert.ToBoolean(Context.Parameters[Arguments.EnforceUlimit], CultureInfo.InvariantCulture);
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.FilerPort]))
            {
                int port = Convert.ToInt32(Context.Parameters[Arguments.FilerPort], CultureInfo.InvariantCulture);
                section.DEA.FilerPort = port;
                FirewallTools.OpenPort(port, "DEA FileServer");
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.StatusPort]))
            {
                int port = Convert.ToInt32(Context.Parameters[Arguments.StatusPort], CultureInfo.InvariantCulture);
                section.DEA.StatusPort = port;
                FirewallTools.OpenPort(port, "DEA Status");
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.ForceHttpSharing]))
            {
                section.DEA.ForceHttpSharing = Convert.ToBoolean(Context.Parameters[Arguments.ForceHttpSharing], CultureInfo.InvariantCulture);
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.HeartBeatInterval]))
            {
                section.DEA.HeartbeatInterval = Convert.ToInt32(Context.Parameters[Arguments.HeartBeatInterval], CultureInfo.InvariantCulture);
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.LocalRoute]))
            {
                section.DEA.LocalRoute = Context.Parameters[Arguments.LocalRoute];
            }
            else
            {
                string ip = string.Empty;
                foreach (IPAddress address in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
                {
                    if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        ip = address.ToString();
                        break;
                    }
                }

                section.DEA.LocalRoute = ip;
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.MaxMemory]))
            {
                section.DEA.MaxMemory = Convert.ToInt32(Context.Parameters[Arguments.MaxMemory], CultureInfo.InvariantCulture);
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.MessageBus]))
            {
                section.DEA.MessageBus = Context.Parameters[Arguments.MessageBus];
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.MultiTenant]))
            {
                section.DEA.Multitenant = Convert.ToBoolean(Context.Parameters[Arguments.MultiTenant], CultureInfo.InvariantCulture);
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.Secure]))
            {
                section.DEA.Secure = Convert.ToBoolean(Context.Parameters[Arguments.Secure], CultureInfo.InvariantCulture);
            }

            section.Service = null;
            config.Save();

            using (ServerManager serverManager = new ServerManager())
            {
                Microsoft.Web.Administration.Configuration authenticationConfig = serverManager.GetApplicationHostConfiguration();

                Microsoft.Web.Administration.ConfigurationSection anonymousAuthenticationSection = authenticationConfig.GetSection("system.webServer/security/authentication/anonymousAuthentication");
                anonymousAuthenticationSection["enabled"] = true;
                anonymousAuthenticationSection["userName"] = string.Empty;
                anonymousAuthenticationSection["password"] = string.Empty;
                anonymousAuthenticationSection["logonMethod"] = @"ClearText";

                serverManager.CommitChanges();
            }
        }
        public static Configuration OpenMachineConfiguration()
        {
            ConfigurationFileMap map = new ConfigurationFileMap();

            return(ConfigurationFactory.Create(typeof(MachineConfigurationHost), map));
        }
Esempio n. 29
0
 // copy ctor used only for cloning
 private ConfigurationFileMap(ConfigurationFileMap other)
 {
     _getFilenameThunk = other._getFilenameThunk;
 }
Esempio n. 30
0
        // Access the machine configuration file using mapping.
        // The function uses the OpenMappedMachineConfiguration
        // method to access the machine configuration.
        /// <summary>
        /// ObjectType of Operation : 
        ///     C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config
        /// </summary>
        public static void MapMachineConfiguration()
        {
            // Get the machine.config file.
            Configuration machineConfig =
              ConfigurationManager.OpenMachineConfiguration();
            // Get the machine.config file path.
            ConfigurationFileMap configFile =
              new ConfigurationFileMap(machineConfig.FilePath);

            // Map the application configuration file to the machine
            // configuration file.
            Configuration config =
              ConfigurationManager.OpenMappedMachineConfiguration(
                configFile);

            // Get the AppSettings section.
            AppSettingsSection appSettingSection =
              (AppSettingsSection)config.GetSection("appSettings");
            appSettingSection.SectionInformation.AllowExeDefinition =
                ConfigurationAllowExeDefinition.MachineToRoamingUser;

            // Display the configuration file sections.
            ConfigurationSectionCollection sections =
              config.Sections;

            Console.WriteLine();
            Console.WriteLine("Using OpenMappedMachineConfiguration.");
            Console.WriteLine("Sections in machine.config:");

            // Get the sections in the machine.config.
            foreach (ConfigurationSection section in sections)
            {
                string name = section.SectionInformation.Name;
                Console.WriteLine("Name: {0}", name);
            }
        }
        //
        // Create a Configuration object.
        //
        internal static Configuration OpenExeConfiguration(ConfigurationFileMap fileMap, bool isMachine, ConfigurationUserLevel userLevel, string exePath)
        {
            // validate userLevel argument
            switch (userLevel)
            {
                default:
                    throw ExceptionUtil.ParameterInvalid("userLevel");

                case ConfigurationUserLevel.None:
                case ConfigurationUserLevel.PerUserRoaming:
                case ConfigurationUserLevel.PerUserRoamingAndLocal:
                    break;
            }

            // validate fileMap arguments
            if (fileMap != null)
            {
                if (String.IsNullOrEmpty(fileMap.MachineConfigFilename))
                {
                    throw ExceptionUtil.ParameterNullOrEmpty("fileMap.MachineConfigFilename");
                }

                ExeConfigurationFileMap exeFileMap = fileMap as ExeConfigurationFileMap;
                if (exeFileMap != null)
                {
                    switch (userLevel)
                    {
                        case ConfigurationUserLevel.None:
                            if (String.IsNullOrEmpty(exeFileMap.ExeConfigFilename))
                            {
                                throw ExceptionUtil.ParameterNullOrEmpty("fileMap.ExeConfigFilename");
                            }

                            break;

                        case ConfigurationUserLevel.PerUserRoaming:
                            if (String.IsNullOrEmpty(exeFileMap.RoamingUserConfigFilename))
                            {
                                throw ExceptionUtil.ParameterNullOrEmpty("fileMap.RoamingUserConfigFilename");
                            }

                            goto case ConfigurationUserLevel.None;

                        case ConfigurationUserLevel.PerUserRoamingAndLocal:
                            if (String.IsNullOrEmpty(exeFileMap.LocalUserConfigFilename))
                            {
                                throw ExceptionUtil.ParameterNullOrEmpty("fileMap.LocalUserConfigFilename");
                            }

                            goto case ConfigurationUserLevel.PerUserRoaming;
                    }
                }
            }

            string configPath = null;
            if (isMachine)
            {
                configPath = MachineConfigPath;
            }
            else
            {
                switch (userLevel)
                {
                    case ConfigurationUserLevel.None:
                        configPath = ExeConfigPath;
                        break;

                    case ConfigurationUserLevel.PerUserRoaming:
                        configPath = RoamingUserConfigPath;
                        break;

                    case ConfigurationUserLevel.PerUserRoamingAndLocal:
                        configPath = LocalUserConfigPath;
                        break;
                }
            }

            Configuration configuration = new Configuration(null, typeof(ClientConfigurationHost), fileMap, exePath, configPath);

            return configuration;
        }
Esempio n. 32
0
        public override void Init(IInternalConfigRoot configRoot, params object[] hostInitParams)
        {
            try {
                ConfigurationFileMap fileMap = (ConfigurationFileMap)hostInitParams[0];
                _exePath = (string)hostInitParams[1];

                Host.Init(configRoot, hostInitParams);

                // Do not complete initialization in runtime config, to avoid expense of
                // loading user.config files that may not be required.
                _initComplete = configRoot.IsDesignTime;

                if (fileMap != null && !String.IsNullOrEmpty(_exePath))
                {
                    throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::Init");
                }

                if (String.IsNullOrEmpty(_exePath))
                {
                    _exePath = null;
                }

                // Initialize the fileMap, if provided.
                if (fileMap != null)
                {
                    _fileMap = new ExeConfigurationFileMap();
                    if (!String.IsNullOrEmpty(fileMap.MachineConfigFilename))
                    {
                        _fileMap.MachineConfigFilename = Path.GetFullPath(fileMap.MachineConfigFilename);
                    }

                    ExeConfigurationFileMap exeFileMap = fileMap as ExeConfigurationFileMap;
                    if (exeFileMap != null)
                    {
                        if (!String.IsNullOrEmpty(exeFileMap.ExeConfigFilename))
                        {
                            _fileMap.ExeConfigFilename = Path.GetFullPath(exeFileMap.ExeConfigFilename);
                        }

                        if (!String.IsNullOrEmpty(exeFileMap.RoamingUserConfigFilename))
                        {
                            _fileMap.RoamingUserConfigFilename = Path.GetFullPath(exeFileMap.RoamingUserConfigFilename);
                        }

                        if (!String.IsNullOrEmpty(exeFileMap.LocalUserConfigFilename))
                        {
                            _fileMap.LocalUserConfigFilename = Path.GetFullPath(exeFileMap.LocalUserConfigFilename);
                        }
                    }
                }
            }
            catch (SecurityException) {
                // Lets try to give them some information telling them
                // they don't have enough security privileges
                throw new ConfigurationErrorsException(
                          SR.GetString(SR.Config_client_config_init_security));
            }
            catch {
                throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::Init");
            }
        }
Esempio n. 33
0
 public sc.Configuration OpenMappedMachineConfiguration(sc.ConfigurationFileMap fileMap)
 {
     return(sc.ConfigurationManager.OpenMappedMachineConfiguration(fileMap));
 }
        internal static System.Configuration.Configuration OpenExeConfiguration(ConfigurationFileMap fileMap, bool isMachine, ConfigurationUserLevel userLevel, string exePath)
        {
            ExeConfigurationFileMap map;
            string str;
            ConfigurationUserLevel level = userLevel;

            if (((level != ConfigurationUserLevel.None) && (level != ConfigurationUserLevel.PerUserRoaming)) && (level != ConfigurationUserLevel.PerUserRoamingAndLocal))
            {
                throw ExceptionUtil.ParameterInvalid("userLevel");
            }
            if (fileMap != null)
            {
                if (string.IsNullOrEmpty(fileMap.MachineConfigFilename))
                {
                    throw ExceptionUtil.ParameterNullOrEmpty("fileMap.MachineConfigFilename");
                }
                map = fileMap as ExeConfigurationFileMap;
                if (map != null)
                {
                    switch (userLevel)
                    {
                    case ConfigurationUserLevel.None:
                        goto Label_0059;

                    case ConfigurationUserLevel.PerUserRoaming:
                        goto Label_0071;

                    case ConfigurationUserLevel.PerUserRoamingAndLocal:
                        if (string.IsNullOrEmpty(map.LocalUserConfigFilename))
                        {
                            throw ExceptionUtil.ParameterNullOrEmpty("fileMap.LocalUserConfigFilename");
                        }
                        goto Label_0071;
                    }
                }
            }
            goto Label_00A1;
Label_0059:
            if (!string.IsNullOrEmpty(map.ExeConfigFilename))
            {
                goto Label_00A1;
            }
            throw ExceptionUtil.ParameterNullOrEmpty("fileMap.ExeConfigFilename");
Label_0071:
            if (!string.IsNullOrEmpty(map.RoamingUserConfigFilename))
            {
                goto Label_0059;
            }
            throw ExceptionUtil.ParameterNullOrEmpty("fileMap.RoamingUserConfigFilename");
Label_00A1:
            str = null;
            if (isMachine)
            {
                str = "MACHINE";
            }
            else
            {
                switch (userLevel)
                {
                case ConfigurationUserLevel.None:
                    str = "MACHINE/EXE";
                    break;

                case ConfigurationUserLevel.PerUserRoaming:
                    str = "MACHINE/EXE/ROAMING_USER";
                    break;

                case ConfigurationUserLevel.PerUserRoamingAndLocal:
                    str = "MACHINE/EXE/ROAMING_USER/LOCAL_USER";
                    break;
                }
            }
            return(new System.Configuration.Configuration(null, typeof(ClientConfigurationHost), new object[] { fileMap, exePath, str }));
        }
Esempio n. 35
0
 // copy ctor used only for cloning
 private ConfigurationFileMap(ConfigurationFileMap other)
 {
     _getFilenameThunk = other._getFilenameThunk;
 }
 /// <inheritdoc />
 public global::System.Configuration.Configuration OpenMappedMachineConfiguration(ConfigurationFileMap pConfigurationFileMap)
 {
     return ConfigurationManager.OpenMappedMachineConfiguration(pConfigurationFileMap);
 }
Esempio n. 37
0
        internal static Configuration OpenExeConfiguration(ConfigurationFileMap fileMap, bool isMachine,
                                                           ConfigurationUserLevel userLevel, string exePath)
        {
            // validate userLevel argument
            switch (userLevel)
            {
            case ConfigurationUserLevel.None:
            case ConfigurationUserLevel.PerUserRoaming:
            case ConfigurationUserLevel.PerUserRoamingAndLocal:
                break;

            default:
                throw ExceptionUtil.ParameterInvalid(nameof(userLevel));
            }

            // validate fileMap arguments
            if (fileMap != null)
            {
                if (string.IsNullOrEmpty(fileMap.MachineConfigFilename))
                {
                    throw ExceptionUtil.ParameterNullOrEmpty(nameof(fileMap) + "." + nameof(fileMap.MachineConfigFilename));
                }

                ExeConfigurationFileMap exeFileMap = fileMap as ExeConfigurationFileMap;
                if (exeFileMap != null)
                {
                    switch (userLevel)
                    {
                    case ConfigurationUserLevel.None:
                        if (string.IsNullOrEmpty(exeFileMap.ExeConfigFilename))
                        {
                            throw ExceptionUtil.ParameterNullOrEmpty(nameof(fileMap) + "." + nameof(exeFileMap.ExeConfigFilename));
                        }
                        break;

                    case ConfigurationUserLevel.PerUserRoaming:
                        if (string.IsNullOrEmpty(exeFileMap.RoamingUserConfigFilename))
                        {
                            throw ExceptionUtil.ParameterNullOrEmpty(nameof(fileMap) + "." + nameof(exeFileMap.RoamingUserConfigFilename));
                        }
                        goto case ConfigurationUserLevel.None;

                    case ConfigurationUserLevel.PerUserRoamingAndLocal:
                        if (string.IsNullOrEmpty(exeFileMap.LocalUserConfigFilename))
                        {
                            throw ExceptionUtil.ParameterNullOrEmpty(nameof(fileMap) + "." + nameof(exeFileMap.LocalUserConfigFilename));
                        }
                        goto case ConfigurationUserLevel.PerUserRoaming;
                    }
                }
            }

            string configPath = null;

            if (isMachine)
            {
                configPath = MachineConfigPath;
            }
            else
            {
                switch (userLevel)
                {
                case ConfigurationUserLevel.None:
                    configPath = ExeConfigPath;
                    break;

                case ConfigurationUserLevel.PerUserRoaming:
                    configPath = RoamingUserConfigPath;
                    break;

                case ConfigurationUserLevel.PerUserRoamingAndLocal:
                    configPath = LocalUserConfigPath;
                    break;
                }
            }

            Configuration configuration = new Configuration(null, typeof(ClientConfigurationHost), fileMap, exePath, configPath);

            return(configuration);
        }
Esempio n. 38
0
		public void mapped_MachineConfig ()
		{
			ConfigurationFileMap map = new ConfigurationFileMap ();
			map.MachineConfigFilename = "machineconfig";

			SysConfig config = ConfigurationManager.OpenMappedMachineConfiguration (map);
			Console.WriteLine("mapped machine config path: {0}", config.FilePath);

			FileInfo fi = new FileInfo (config.FilePath);
			Assert.AreEqual ("machineconfig", fi.Name);
		}
Esempio n. 39
0
 public override void Init(IInternalConfigRoot root, params object[] hostInitParams)
 {
     map = (ConfigurationFileMap)hostInitParams [0];
 }
Esempio n. 40
0
 public static Configuration OpenMappedMachineConfiguration(ConfigurationFileMap fileMap)
 {
     return(OpenExeConfigurationImpl(fileMap, true, ConfigurationUserLevel.None, null));
 }
		public override void Init (IInternalConfigRoot root, params object[] hostInitParams)
		{
			map = (ConfigurationFileMap) hostInitParams [0];
		}
 public static Configuration OpenMappedMachineConfiguration(ConfigurationFileMap fileMap)
 {
     return(ConfigurationFactory.Create(typeof(MachineConfigurationHost), fileMap));
 }
Esempio n. 43
0
        public static void MyClassInitialize(TestContext testContext)
        {
            var fileMap = new System.Configuration.ConfigurationFileMap("Configuration\\ConfigurationTests.config");

            _configuration = System.Configuration.ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
        }
		public override void InitForConfiguration (ref string locationSubPath, out string configPath, out string locationConfigPath, IInternalConfigRoot root, params object[] hostInitConfigurationParams)
		{
			map = (ConfigurationFileMap) hostInitConfigurationParams [0];
			locationSubPath = null;
			configPath = null;
			locationConfigPath = null;
		}
 /// <summary>
 /// Opens the mapped machine configuration. See the doc of ConfigurationManager to know exactly what it does.
 /// </summary>
 /// <param name="fileMap">The file map.</param>
 /// <returns>
 /// A configuration object
 /// </returns>
 public virtual Configuration OpenMappedMachineConfiguration(ConfigurationFileMap fileMap)
 {
     return(ConfigurationManager.OpenMappedMachineConfiguration(fileMap));
 }