private ClientSettingsSection GetConfigSection(System.Configuration.Configuration config, string sectionName, bool declare)
 {
     string str = "userSettings/" + sectionName;
     ClientSettingsSection section = null;
     if (config != null)
     {
         section = config.GetSection(str) as ClientSettingsSection;
         if ((section == null) && declare)
         {
             this.DeclareSection(config, sectionName);
             section = config.GetSection(str) as ClientSettingsSection;
         }
     }
     return section;
 }
 public static SecurityTokenServicesSection GetCurrent(System.Configuration.Configuration config)
 {
     var section = config.GetSection(SectionName) as SecurityTokenServicesSection;
     if (null == section)
         throw new InvalidOperationException("Configuration section for Security Token Services not found.");
     return section;
 }
Exemplo n.º 3
0
        private void Init(System.Configuration.Configuration config)
        {
            HotkeysSection hotkeys;
            if (config.GetSection("Hotkeys") == null)
            {
                hotkeys = new HotkeysSection();
                hotkeys.SectionInformation.ForceSave = true;
                config.Sections.Add("Hotkeys", hotkeys);
            }
            else
            {

                hotkeys = config.Sections["Hotkeys"] as HotkeysSection;
            }

            if (hotkeys.Select.Key == "")
            {
                hotkeys.Select = new HotkeyElement("R", "Alt+Shift");
            }

            StoragesSection storages;
            if (config.GetSection("Storages") == null)
            {
                storages = new StoragesSection();
                storages.SectionInformation.ForceSave = true;
                config.Sections.Add("Storages", storages);
            }
        }
 public static StandardEndpointsSection GetSection(System.Configuration.Configuration config)
 {
     if (config == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("config");
     }
     return (StandardEndpointsSection) config.GetSection(ConfigurationStrings.StandardEndpointsSectionPath);
 }
 public static BindingsSection GetSection(System.Configuration.Configuration config)
 {
     if (config == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("config");
     }
     return (BindingsSection) config.GetSection(ConfigurationStrings.BindingsSectionGroupPath);
 }
		internal static MemcachedDistributeCacheProvider CreateDefaultProvider(System.Configuration.Configuration configuration)
		{
			MemcachedDistributeCacheProvider provider = new MemcachedDistributeCacheProvider(configuration);

			IMemcachedClientConfiguration section = (IMemcachedClientConfiguration)configuration.GetSection("memcachedClient");
			if (section == null)
			{
				throw new ConfigurationErrorsException(String.Format("未找到适用于 MemcachedDistributeCacheProvider 的配置节 {0}", "memcachedClient"));
			}

			provider.client = new CustomMemcachedClient(section);

			return provider;
		}
 public override void Configure(IServiceCollection services, System.Configuration.Configuration moduleConfiguration)
 {
     IAuthorizationRulesService authorizationRuleService = services.Get<IAuthorizationRulesService>();
     if (authorizationRuleService != null)
     {
         AuthorizationConfigurationSection authorizationSection = moduleConfiguration.GetSection(AuthorizationSection) as AuthorizationConfigurationSection;
         if (authorizationSection != null)
         {
             foreach (AuthorizationRuleElement ruleElement in authorizationSection.ModuleRules)
             {
                 authorizationRuleService.RegisterAuthorizationRule(ruleElement.AbsolutePath, ruleElement.RuleName);
             }
         }
     }
 }
        public IEnumerable<BuiltComponents> Build(System.Configuration.Configuration configuration)
        {
            var components = new List<BuiltComponents>();

            var simpleCounterConfiguration = configuration.GetSection("simplePerformanceCounterSources") as SimplePerformanceCounterSourceConfiguration;

            if (simpleCounterConfiguration != null)
            {
                foreach (SimpleCounterElement config in simpleCounterConfiguration.Counters)
                {
                    components.Add(Build(config));
                }
            }

            return components;
        }
        public IEnumerable<BuiltComponents> Build(System.Configuration.Configuration configuration)
        {
            var components = new List<BuiltComponents>();

            var simpleProcessUptimeConfiguration = configuration.GetSection("simpleProcessUptimeSources") as SimpleProcessUptimeConfiguration;

            if (simpleProcessUptimeConfiguration != null)
            {
                foreach (SimpleProcessElement config in simpleProcessUptimeConfiguration.Processes)
                {
                    components.Add(Build(config));
                }
            }

            return components;
        }
        public IEnumerable<BuiltComponents> Build(System.Configuration.Configuration configuration)
        {
            var schedules = new List<BuiltComponents>();

            var simpleProcessCounterConfiguration = configuration.GetSection("simpleProcessCountingSources") as SimpleProcessCountingConfiguration;

            if (simpleProcessCounterConfiguration != null)
            {
                foreach (SimpleProcessElement config in simpleProcessCounterConfiguration.Processes)
                {
                    schedules.Add(Build(config));
                }
            }

            return schedules;
        }
Exemplo n.º 11
0
        private static void AddWebModules(System.Configuration.Configuration config, string name, string type)
        {
            // Get the <httpModules> section.
            HttpModulesSection sectionSystemWeb = (HttpModulesSection)config.GetSection("system.web/httpModules");

            // Create a new module action object.
            HttpModuleAction myHttpModuleAction = new HttpModuleAction(name, type);

            int indexOfHttpModule = sectionSystemWeb.Modules.IndexOf(myHttpModuleAction);
            if (indexOfHttpModule == -1)
            {
                sectionSystemWeb.Modules.Add(myHttpModuleAction);
                if (!sectionSystemWeb.SectionInformation.IsLocked)
                {
                    config.Save();
                }
            }
        }
        public IEnumerable<ISchedule> Build(System.Configuration.Configuration configuration, IEnumerable<ISnapshotProvider> sources)
        {
            var simplePlotterConfiguration = configuration.GetSection("simplePlotters") as SimplePlotterConfiguration;

            var schedules = new List<ISchedule>();

            if (simplePlotterConfiguration != null)
            {
                var copiedSources = sources;

                foreach (SimplePlotterElement config in simplePlotterConfiguration.Plotters)
                {
                    schedules.Add(Build(config, copiedSources));
                }

            }

            return schedules;
        }
 private Dictionary<string, SettingElement> ReadSettings(System.Configuration.Configuration clientConfig, string sectionName)
 {
     Dictionary<string, SettingElement> dictionary = new Dictionary<string, SettingElement>();
     ClientSettingsSection section = this.ReadClientSettingsSection(clientConfig.GetSection(sectionName));
     if (section != null)
     {
         foreach (SettingElement element in section.Settings)
         {
             dictionary.Add(element.Name, element);
         }
     }
     return dictionary;
 }
Exemplo n.º 14
0
		private void InitFromConfiguration(System.Configuration.Configuration configuration)
		{
			if (configuration != null)
			{
				CacheSettingsSection section = (CacheSettingsSection)configuration.GetSection("cacheSettings");

				if (section != null)
				{
					this.DefaultCacheName = section.DefaultCache.Name;
					this.EnableDistributeCache = section.EnableDistributeCache.Value;

					if (!String.IsNullOrEmpty(section.Failover.RetryingInterval))
					{
						this.FailoverRetryingInterval = TimeSpan.Parse(section.Failover.RetryingInterval);
					}

					if (!String.IsNullOrEmpty(section.Failover.ToLocalCache))
					{
						this.FailoverToLocalCache = Boolean.Parse(section.Failover.ToLocalCache);
					}

					for (int i = 0; i < section.Caches.Count; i++)
					{
						bool isAbsoluteLocalCache = section.Caches[i].CacheName.ToLower().Equals("local");

						CacheSetting cacheSetting = new CacheSetting();
						CachePosition cachePosition = isAbsoluteLocalCache ? CachePosition.Local : (CachePosition)Enum.Parse(typeof(CachePosition), section.Caches[i].Position, true);
						if (cachePosition == CachePosition.Inherit)
						{
							cachePosition = this.defaultPosition;
						}
						cacheSetting.Position = cachePosition;
						if (!String.IsNullOrEmpty(section.Caches[i].DependencyFile))
						{
							cacheSetting.DependencyFile = AppDomain.CurrentDomain.MapPhysicalPath("conf/", section.Caches[i].DependencyFile);
						}

						cacheSetting.Capacity = String.IsNullOrEmpty(section.Caches[i].Capacity) ? defaultCacheCapacity : Int32.Parse(section.Caches[i].Capacity);

						cacheSetting.AsyncUpdateInterval = String.IsNullOrEmpty(section.Caches[i].AsyncUpdateInterval) ? defaultAsyncUpdateInterval : (int)TimeSpan.Parse(section.Caches[i].AsyncUpdateInterval).TotalSeconds;

						RegionElementCollection regionElements = section.Caches[i].Regions;

						if (regionElements.Count > 0)
						{
							for (int j = 0; j < regionElements.Count; j++)
							{
								RegionSetting regionSetting = new RegionSetting();
								CachePosition regionPosition = isAbsoluteLocalCache ? CachePosition.Local : (CachePosition)Enum.Parse(typeof(CachePosition), regionElements[j].Position, true);
								if (regionPosition == CachePosition.Inherit)
								{
									regionPosition = cachePosition;
								}

								regionSetting.Position = regionPosition;

								regionSetting.DependencyFile = String.IsNullOrEmpty(regionElements[j].DependencyFile) ? cacheSetting.DependencyFile : AppDomain.CurrentDomain.MapPhysicalPath("conf/", regionElements[j].DependencyFile);
								regionSetting.Capacity = String.IsNullOrEmpty(regionElements[j].Capacity) ? cacheSetting.Capacity : Int32.Parse(regionElements[j].Capacity);
								regionSetting.AsyncUpdateInterval = String.IsNullOrEmpty(regionElements[j].AsyncUpdateInterval) ? cacheSetting.AsyncUpdateInterval : (int)TimeSpan.Parse(regionElements[j].AsyncUpdateInterval).TotalSeconds;

								cacheSetting.Regions.Add(regionElements[j].RegionName, regionSetting);
							}
						}

						this.Caches.Add(section.Caches[i].CacheName, cacheSetting);
					}

				}
			}

			if (!this.Caches.ContainsKey(this.DefaultCacheName))
			{
				this.Caches.Add(this.DefaultCacheName, new CacheSetting(this.defaultPosition, this.defaultCacheCapacity, this.defaultAsyncUpdateInterval));
			}

			if (!this.Caches.ContainsKey("local"))
			{
				this.Caches.Add("local", new CacheSetting(CachePosition.Local, this.defaultCacheCapacity, this.defaultAsyncUpdateInterval));
			}
		}
        // Helper method to parse and check the module name in the system.webServer section
        private void CheckWebServerModule(System.Configuration.Configuration cfg, string moduleName)
        {
            IgnoreSection webServerSection = cfg.GetSection("system.webServer") as IgnoreSection;
            if (webServerSection != null)
            {
                SectionInformation sectionInformation = webServerSection.SectionInformation;
                string rawXml = sectionInformation == null ? null : sectionInformation.GetRawXml();
                Assert.IsFalse(string.IsNullOrEmpty(rawXml), "Did not expect empty system.webServer xml");

                XDocument xdoc = null;
                using (StringReader sr = new StringReader(rawXml))
                {
                    using (XmlReader xmlReader = XmlReader.Create(sr))
                    {
                        xdoc = XDocument.Load(xmlReader);
                    }
                }

                XElement xelem = xdoc.Element("system.webServer");
                Assert.IsNotNull(xelem, "system.webServer Xelement was null");

                xelem = xelem.Element("modules");
                Assert.IsNotNull(xelem, "system.webServer modules Xelement was null");

                XAttribute runAllManagedAttr = xelem.Attribute("runAllManagedModulesForAllRequests");
                Assert.IsNotNull(runAllManagedAttr, "Did not find attribute for runAllManagedModulesForAllRequests");
                Assert.AreEqual("true", runAllManagedAttr.Value, "runAllManagedModulesForAllRequests should have been true");

                IEnumerable<XElement> xelems = xelem.Elements("add");
                Assert.IsNotNull(xelems, "system.webServer modules add elements null");
                xelem = xelems.FirstOrDefault(e => (string)e.Attribute("name") == BusinessLogicClassConstants.DomainServiceModuleName);
                Assert.IsNotNull(xelem, "Did not find DomainServiceModule attribute");
                Assert.AreEqual(moduleName, (string)xelem.Attribute("type"), "DomainServiceModule name is incorrect");
            }
        }
        // Helper method to parse ValidateIntegratedMode and verify correct
        private void CheckValidateIntegratedMode(System.Configuration.Configuration cfg)
        {
            IgnoreSection webServerSection = cfg.GetSection("system.webServer") as IgnoreSection;
            if (webServerSection != null)
            {
                SectionInformation sectionInformation = webServerSection.SectionInformation;
                string rawXml = sectionInformation == null ? null : sectionInformation.GetRawXml();
                Assert.IsFalse(string.IsNullOrEmpty(rawXml), "Did not expect empty system.webServer xml");

                XDocument xdoc = null;
                using (StringReader sr = new StringReader(rawXml))
                {
                    using (XmlReader xmlReader = XmlReader.Create(sr))
                    {
                        xdoc = XDocument.Load(xmlReader);
                    }
                }

                XElement xelem = xdoc.Element("system.webServer");
                Assert.IsNotNull(xelem, "system.webServer Xelement was null");

                xelem = xelem.Element("validation");
                Assert.IsNotNull(xelem, "system.webServer validation element was null");

                XAttribute attr = xelem.Attribute("validateIntegratedModeConfiguration");
                Assert.IsNotNull(attr, "system.webServer validateIntegratedMode attribute was null");
                Assert.AreEqual(attr.Value, "false", "validateIntegrateModel value was incorrect");
            }
        }
Exemplo n.º 17
0
		/// <summary>
		/// Returns a reference to a read/write instance of the membership configuration section in web.config.
		/// To save changes to the config file, call the <see cref="System.Configuration.Configuration.Save" /> method on the <see cref="System.Configuration.Configuration" /> object
		/// used in the parameter list. For web applications, one can use System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~")
		/// to get a reference to the Configuration object to use for the parameter.
		/// </summary>
		/// <param name="configuration">An instance of a <see cref="System.Configuration.Configuration" /> object.</param>
		/// <returns>Returns a read/write <see cref="GalleryServerPro.Configuration.GalleryServerProConfigSettings" /> object.</returns>
		public static MembershipSection OpenMembershipConfigSection(System.Configuration.Configuration configuration)
		{
			return (MembershipSection)configuration.GetSection("system.web/membership");
		}
Exemplo n.º 18
0
                public static WebServicesSection GetSection (System.Configuration.Configuration config)
                {
			return (WebServicesSection) config.GetSection ("webServices");
                }
Exemplo n.º 19
0
        private static void SetPathsFromConfiguration(System.Configuration.Configuration config, string locationPath)
        {
            if (config == null)
                return;

            //standard config
            var handlersSection = config.GetSection("system.web/httpHandlers") as HttpHandlersSection;
            if (handlersSection != null)
            {
                for (var i = 0; i < handlersSection.Handlers.Count; i++)
                {
                    var httpHandler = handlersSection.Handlers[i];
                    if (!httpHandler.Type.StartsWith("ServiceStack"))
                        continue;

                    SetPaths(httpHandler.Path, locationPath);
                    break;
                }
            }

            //IIS7+ integrated mode system.webServer/handlers
            var pathsNotSet = instance.MetadataRedirectPath == null;
            if (pathsNotSet)
            {
                var webServerSection = config.GetSection("system.webServer");
                if (webServerSection != null)
                {
                    var rawXml = webServerSection.SectionInformation.GetRawXml();
                    if (!string.IsNullOrEmpty(rawXml))
                    {
                        SetPaths(ExtractHandlerPathFromWebServerConfigurationXml(rawXml), locationPath);
                    }
                }

                //In some MVC Hosts auto-inferencing doesn't work, in these cases assume the most likely default of "/api" path
                pathsNotSet = instance.MetadataRedirectPath == null;
                if (pathsNotSet)
                {
                    var isMvcHost = Type.GetType("System.Web.Mvc.Controller") != null;
                    if (isMvcHost)
                    {
                        SetPaths("api", null);
                    }
                }
            }
        }
Exemplo n.º 20
0
		/// <summary>
		/// Returns a reference to a read/write instance of the roleManager configuration section in web.config.
		/// To save changes to the config file, call the <see cref="System.Configuration.Configuration.Save" /> method on the <see cref="System.Configuration.Configuration" /> object
		/// used in the parameter list. For web applications, one can use System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~")
		/// to get a reference to the Configuration object to use for the parameter.
		/// </summary>
		/// <param name="configuration">An instance of a <see cref="System.Configuration.Configuration" /> object.</param>
		/// <returns>Returns a read/write <see cref="GalleryServerPro.Configuration.GalleryServerProConfigSettings" /> object.</returns>
		public static RoleManagerSection OpenRoleConfigSection(System.Configuration.Configuration configuration)
		{
			return (RoleManagerSection)configuration.GetSection("system.web/roleManager");
		}
Exemplo n.º 21
0
 public static Config GetSection(System.Configuration.Configuration config)
 {
     return (config.GetSection("wms") as Config);
 }
 /// <summary>
 /// Gets the config section.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <returns>The OrderPage configuration section.</returns>
 public static PublicOrderConfigurationSection GetConfig(System.Configuration.Configuration configuration)
 {
     return (PublicOrderConfigurationSection)configuration.GetSection("publicOrderConfigurationSection");
 }
 private ConfigurationSection GetConfigSection(string configSection, string appPath, string site, string location, bool useMachineConfig, out System.Configuration.Configuration config)
 {
     if (string.IsNullOrEmpty(appPath))
     {
         appPath = null;
     }
     if (string.IsNullOrEmpty(location))
     {
         location = null;
     }
     try
     {
         if (useMachineConfig)
         {
             config = WebConfigurationManager.OpenMachineConfiguration(location);
         }
         else
         {
             config = WebConfigurationManager.OpenWebConfiguration(appPath, site, location);
         }
     }
     catch (Exception exception)
     {
         if (useMachineConfig)
         {
             throw new Exception(System.Web.SR.GetString("Configuration_for_machine_config_not_found"), exception);
         }
         throw new Exception(System.Web.SR.GetString("Configuration_for_path_not_found", new object[] { appPath, string.IsNullOrEmpty(site) ? System.Web.SR.GetString("DefaultSiteName") : site }), exception);
     }
     return config.GetSection(configSection);
 }
 private ConfigurationSection GetConfigSectionFile(string configSection, string dirName, out System.Configuration.Configuration config)
 {
     if (dirName == ".")
     {
         dirName = Environment.CurrentDirectory;
     }
     else
     {
         if (!Path.IsPathRooted(dirName))
         {
             dirName = Path.Combine(Environment.CurrentDirectory, dirName);
         }
         if (!Directory.Exists(dirName))
         {
             throw new Exception(System.Web.SR.GetString("Configuration_for_physical_path_not_found", new object[] { dirName }));
         }
     }
     WebConfigurationFileMap fileMap = new WebConfigurationFileMap();
     string virtualDirectory = dirName.Replace('\\', '/');
     if ((virtualDirectory.Length > 2) && (virtualDirectory[1] == ':'))
     {
         virtualDirectory = virtualDirectory.Substring(2);
     }
     else if (virtualDirectory.StartsWith("//", StringComparison.Ordinal))
     {
         virtualDirectory = "/";
     }
     fileMap.VirtualDirectories.Add(virtualDirectory, new VirtualDirectoryMapping(dirName, true));
     try
     {
         config = WebConfigurationManager.OpenMappedWebConfiguration(fileMap, virtualDirectory);
     }
     catch (Exception exception)
     {
         throw new Exception(System.Web.SR.GetString("Configuration_for_physical_path_not_found", new object[] { dirName }), exception);
     }
     return config.GetSection(configSection);
 }
 /// <summary>
 /// Retrieves the connection strings section from the given file.
 /// </summary>
 public static ConnectionStringsSection GetSection(string fileName, out System.Configuration.Configuration configurationRoot)
 {
     ExeConfigurationFileMap map = new ExeConfigurationFileMap();
     map.RoamingUserConfigFilename = fileName;
     map.ExeConfigFilename = fileName;
     configurationRoot = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
     return (ConnectionStringsSection)configurationRoot.GetSection("connectionStrings");
 }
Exemplo n.º 26
0
		/// <summary>
		/// Returns a reference to a read/write instance of the profile configuration section in web.config.
		/// To save changes to the config file, call the <see cref="System.Configuration.Configuration.Save" /> method on the <see cref="System.Configuration.Configuration" /> object
		/// used in the parameter list. For web applications, one can use System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~")
		/// to get a reference to the Configuration object to use for the parameter.
		/// </summary>
		/// <param name="configuration">An instance of a <see cref="System.Configuration.Configuration" /> object.</param>
		/// <returns>Returns a read/write <see cref="GalleryServerPro.Configuration.GalleryServerProConfigSettings" /> object.</returns>
		public static ProfileSection OpenProfileConfigSection(System.Configuration.Configuration configuration)
		{
			return (ProfileSection)configuration.GetSection("system.web/profile");
		}
Exemplo n.º 27
0
        private static void SetPathsFromConfiguration(System.Configuration.Configuration config, string locationPath)
        {
            //standard config
            var handlersSection = config.GetSection("system.web/httpHandlers") as HttpHandlersSection;
            if (handlersSection != null)
            {
                for (var i = 0; i < handlersSection.Handlers.Count; i++)
                {
                    var httpHandler = handlersSection.Handlers[i];
                    if (!httpHandler.Type.StartsWith("ServiceStack"))
                        continue;

                    SetPaths(httpHandler.Path, locationPath);
                    break;
                }
            }

            //IIS7+ integrated mode system.webServer/handlers
            if (instance.MetadataRedirectPath == null)
            {
                var webServerSection = config.GetSection("system.webServer");
                if (webServerSection != null)
                {
                    var rawXml = webServerSection.SectionInformation.GetRawXml();
                    if (!string.IsNullOrEmpty(rawXml))
                    {
                        SetPaths(ExtractHandlerPathFromWebServerConfigurationXml(rawXml), locationPath);
                    }
                }
            }
        }
Exemplo n.º 28
0
		/// <summary>
		/// Returns a reference to a read/write instance of the galleryServerPro custom configuration section in galleryserverpro.config.
		/// To save changes to the config file, call the <see cref="System.Configuration.Configuration.Save" /> method on the <see cref="System.Configuration.Configuration" /> object
		/// used in the parameter list. For web applications, one can use System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~")
		/// to get a reference to the Configuration object to use for the parameter.
		/// </summary>
		/// <param name="configuration">An instance of a <see cref="System.Configuration.Configuration" /> object.</param>
		/// <returns>Returns a read/write <see cref="GalleryServerPro.Configuration.GalleryServerProConfigSettings" /> object.</returns>
		public static GalleryServerProConfigSettings OpenGalleryServerProConfigSection(System.Configuration.Configuration configuration)
		{
			return (GalleryServerProConfigSettings)configuration.GetSection("system.web/galleryServerPro");
		}
Exemplo n.º 29
0
        /// <summary>
        /// Replaces an existing section with the name provided with a new one.
        /// </summary>
        /// <param name="section">The definintion of the section.</param>
        /// <param name="configuration">The configuration it's being replaced within.</param>
        private static bool SetConfigurationSection(ConfigurationSection section, System.Configuration.Configuration configuration)
        {
            ConfigurationSection existingSection = configuration.GetSection(section.SectionInformation.SectionName);

            // Remove the existing section if it exists.
            if (existingSection != null &&
                existingSection.GetType() == section.GetType())
            {
                foreach (string key in existingSection.ElementInformation.Properties.Keys)
                    existingSection.ElementInformation.Properties[key].Value =
                        section.ElementInformation.Properties[key].Value;
                configuration.Save(ConfigurationSaveMode.Modified);
                return true;
            }
            return false;
        }
 public static WebServicesSection GetSection(System.Configuration.Configuration config)
 {
     if (config == null)
     {
         throw new ArgumentNullException("config");
     }
     return (WebServicesSection) config.GetSection("system.web/webServices");
 }