/// <summary> /// Pops a section that was previously push into the current configuration. /// </summary> /// <param name="name">The name of the section to restore.</param> /// <returns>An instance of the <see cref="GeneralConfigurator"/>.</returns> public GeneralConfigurator PopSection(string name) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } if (_sections.ContainsKey(name)) { ConfigurationSection section = _configuration.GetSection(name); if (section != null) { _configuration.Sections.Remove(name); } ConfigurationSectionInfo info = _sections[name]; section = new DefaultSection(); section.SectionInformation.SetRawXml(info.Xml); section.SectionInformation.Type = info.Type; _configuration.Sections.Add(name, section); MarkDirty(); } return(this); }
public void ElementInformation_validator() { /* pick a Configuration class that doesn't * specify an ElementInformation override */ DefaultSection sect = new DefaultSection(); ElementInformation info = sect.ElementInformation; Assert.AreEqual(typeof(DefaultValidator), info.Validator.GetType(), "A1"); }
public override int GetHashCode() { unchecked { var hashCode = 36 + Sections.GetHashCode(); hashCode = (hashCode * 397) ^ DefaultSection.GetHashCode(); hashCode = (hashCode * 397) ^ Reference.GetHashCode(); return(hashCode); } }
/// <summary> /// Pushes the section on a persisted section stack. /// </summary> /// <param name="name">The name of the section to save.</param> /// <returns>An instance of the <see cref="GeneralConfigurator"/>.</returns> /// <remarks>If a section is pushed multiple times only the last instance is persisted.</remarks> public GeneralConfigurator PushSection(string name) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } DefaultSection section = _configuration.Sections[name] as DefaultSection; if (section != null) { _sections[name] = new ConfigurationSectionInfo(section); } return(this); }
public void Initialize() { _repository = new Mock <INStackRepository>(MockBehavior.Strict); _repository.Setup(r => r.DoRequestAsync <DataAppOpenWrapper>(It.Is <RestRequest>(s => s.Resource.EndsWith("api/v2/open")), It.IsAny <Action <HttpStatusCode> >())) .Returns(GetAppOpenMock); var danish = new TranslationData(); var defaultSection = new DefaultSection(); defaultSection.TryAdd("text", "Jeg er på dansk"); danish.TryAdd("default", defaultSection); _danish = new DataMetaWrapper <TranslationData> { Data = danish, Meta = new MetaData { Language = new Language { Direction = LanguageDirection.LRM, Id = LanguageId, IsBestFit = true, IsDefault = true, Locale = LanguageLocale, Name = "Danish" }, Platform = new ResourcePlatform { Id = LanguageId, Slug = NStackPlatform.Web } } }; _localizeService = new Mock <INStackLocalizeService>(MockBehavior.Strict); _localizeService.Setup(r => r.GetResourceAsync <TranslationData>(It.Is <int>(id => id == LanguageId))) .Returns(Task.FromResult(_danish)); var services = new ServiceCollection(); services.AddMemoryCache(); var serviceProvider = services.BuildServiceProvider(); _memoryCache = serviceProvider?.GetService <IMemoryCache>() ?? throw new ArgumentNullException(); _service = new NStackAppService(_repository.Object, _localizeService.Object, _memoryCache); }
public void SetUp() { _repository = new Mock <INStackRepository> { DefaultValue = DefaultValue.Empty }; _repository.Setup(r => r.DoRequestAsync <DataWrapper <List <ResourceData> > >(It.Is <RestRequest>(s => s.Resource.EndsWith("platforms/backend")), It.IsAny <Action <HttpStatusCode> >())) .Returns(GetLanguageMock); _english = new TranslationData(); var defaultSection = new DefaultSection(); defaultSection.TryAdd("text", "I'm in English"); _english.TryAdd("default", defaultSection); _repository.Setup(r => r.DoRequestAsync <DataMetaWrapper <TranslationData> >(It.Is <RestRequest>(s => s.Resource.EndsWith($"resources/{_englishLanguage.Id}")), It.IsAny <Action <HttpStatusCode> >())) .Returns(Task.FromResult(new DataMetaWrapper <TranslationData> { Data = _english })); _repository.Setup(r => r.DoRequestAsync <DataMetaWrapper <ResourceItem> >(It.Is <RestRequest>(s => s.Resource.EndsWith($"resources/{_englishLanguage.Id}")), It.IsAny <Action <HttpStatusCode> >())) .Returns(Task.FromResult(new DataMetaWrapper <ResourceItem> { Data = _english })); _danish = new TranslationData(); var defaultDanishSection = new DefaultSection(); defaultDanishSection.TryAdd("text", "Jeg er på dansk"); _danish.TryAdd("default", defaultDanishSection); _repository.Setup(r => r.DoRequestAsync <DataMetaWrapper <TranslationData> >(It.Is <RestRequest>(s => s.Resource.EndsWith($"resources/{_danishLanguage.Id}")), It.IsAny <Action <HttpStatusCode> >())) .Returns(Task.FromResult(new DataMetaWrapper <TranslationData> { Data = _danish })); _repository.Setup(r => r.DoRequestAsync <DataMetaWrapper <ResourceItem> >(It.Is <RestRequest>(s => s.Resource.EndsWith($"resources/{_danishLanguage.Id}")), It.IsAny <Action <HttpStatusCode> >())) .Returns(Task.FromResult(new DataMetaWrapper <ResourceItem> { Data = _danish })); _service = new NStackLocalizeService(_repository.Object); }
public void Test_PingUnknownhost() { // Setup ConfigurationManager Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.Sections.Clear(); config.SectionGroups.Clear(); DefaultSection section = new DefaultSection(); string rawXml = @"<Test.PingProbe> <add key=""HostName"" value=""UnknownHost""/> <add key=""TimeoutMs"" value=""1000""/> <add key=""SampleCount"" value=""3""/> <add key=""TTL"" value=""10""/> <add key=""MaxValue"" value=""10""/> <add key=""EventId"" value=""2""/> <add key=""EventType"" value=""Warning""/> <add key=""ProbeFrequency"" value=""1""/> </Test.PingProbe>"; section.SectionInformation.SetRawXml(rawXml); section.SectionInformation.Type = typeof(NameValueSectionHandler).FullName; config.Sections.Add("Test.PingProbe", section); config.Save(); ConfigurationManager.RefreshSection("Test.PingProbe"); PingProbe pingProbe = new PingProbe(); var traceSource = pingProbe.ConfigureProbe("Test.PingProbe"); traceSource.Switch = new SourceSwitch("Test.PingProbe") { Level = SourceLevels.All }; PingProbeTestListener probeListener = new PingProbeTestListener(); traceSource.Listeners.Clear(); traceSource.Listeners.Add(probeListener); pingProbe.ExecuteProbe(); Assert.AreEqual(TraceEventType.Critical, probeListener.TriggeredEvent, "Failed to hear from PingProbe"); }
protected override void CreateViews() { if (m_background == null) { m_background = new BackgroundSection(); m_background.Initialize(); } if (m_header == null) { m_header = new HeaderSection(); m_header.Initialize(); } if (m_characterList == null) { m_characterList = new CharacterListSection(); m_characterList.Initialize(); } if (m_createHolder == null) { m_createHolder = new CreateHolderSection(); m_createHolder.Initialize(); } if (m_characterCreation == null) { m_characterCreation = new CharacterCreationSection(); m_characterCreation.Initialize(); } if (m_defaultSection == null) { m_defaultSection = new DefaultSection(); m_defaultSection.Initialize(); } }
// .Net Framework handles IConfigurationSectionHandler sections only for default configurations (app/web.config), not for custom loaded. // This is because IConfigurationSectionHandler is deprecated, but still a lot of 3rd party libraries use it. (log4net, nlog etc.) // These sections returned as DefaultSection from Configuration.GetSection so we need to handle such sections by our self. private object HandleIConfigurationSectionHandlerSection(DefaultSection section) { string sectionTypeName = section.SectionInformation.Type; var sectionType = Type.GetType(sectionTypeName); if (typeof(IConfigurationSectionHandler).IsAssignableFrom(sectionType)) { var ctor = sectionType.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null); if (ctor == null) { throw new InvalidOperationException("Can't instantiate section handler without default ctor."); } // Create IConfigurationSectionHandler for this section. var handler = Activator.CreateInstance(sectionType, true) as IConfigurationSectionHandler; if (handler == null) { return(null); } var rawXml = section.SectionInformation.GetRawXml(); if (string.IsNullOrEmpty(rawXml)) { return(null); } var doc = new XmlDocument(); doc.LoadXml(rawXml); // Invoke IConfigurationSectionHandler.Create method with read rawXlm as parameter. // We pass DocumentElement because some 3rd party libs expects XmlElement passed, not XmlNode as declared in Create signature. return(handler.Create(null, null, doc.DocumentElement)); } return(null); }
public void Test_NextTriggerTime() { // Setup ConfigurationManager Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); DefaultSection section = new DefaultSection(); string rawXml = @"<HelloWorld> <add key=""NextTriggerTime"" value=""2""/> <add key=""DelayTriggerTime"" value=""0""/> </HelloWorld>"; section.SectionInformation.SetRawXml(rawXml); section.SectionInformation.Type = typeof(NameValueSectionHandler).FullName; config.Sections.Clear(); config.Sections.Add("HelloWorld", section); config.Save(); ConfigurationManager.RefreshSection("HelloWorld"); SnakeEyes.DelayStateFilter filter = new SnakeEyes.DelayStateFilter("HelloWorld"); Assert.AreEqual(filter.NextTriggerTime.TotalSeconds, 2); Assert.AreEqual(filter.DelayTriggerTime.TotalSeconds, 0); DelayStateFilterTestListener listener = new DelayStateFilterTestListener(); listener.Filter = filter; TraceSource source = new TraceSource("TestSource", SourceLevels.All); source.Listeners.Add(listener); // Check first error is reported at once source.TraceEvent(TraceEventType.Error, 0, "Damn"); Assert.IsTrue(listener.TriggeredEvent); // Check any similar errors are not reported at once listener.TriggeredEvent = false; source.TraceEvent(TraceEventType.Error, 0, "Damn"); Assert.IsTrue(!listener.TriggeredEvent); // Check any similar errors are not reported at once listener.TriggeredEvent = false; source.TraceEvent(TraceEventType.Error, 0, "Damn"); Assert.IsTrue(!listener.TriggeredEvent); // Check that after a "long" time then the same error is reported again listener.TriggeredEvent = false; System.Threading.Thread.Sleep((int)filter.NextTriggerTime.TotalMilliseconds + 1); source.TraceEvent(TraceEventType.Error, 0, "Damn"); Assert.IsTrue(listener.TriggeredEvent); // Check first ok is reported at once listener.TriggeredEvent = false; source.TraceEvent(TraceEventType.Information, 0, "Hurray"); Assert.IsTrue(listener.TriggeredEvent); // Check any following oks are not reported listener.TriggeredEvent = false; source.TraceEvent(TraceEventType.Information, 0, "Hurray"); Assert.IsTrue(!listener.TriggeredEvent); // Check that after a "long" time then the same ok is not reported again listener.TriggeredEvent = false; System.Threading.Thread.Sleep((int)filter.NextTriggerTime.TotalMilliseconds + 1); source.TraceEvent(TraceEventType.Information, 0, "Hurray"); Assert.IsTrue(!listener.TriggeredEvent); }
/// <summary> /// The actually processing happens in this method /// </summary> private void UpdateSolution() { AddToStatus("Adding AndroMDA support to solution..."); Project commonProject = null; Project coreProject = null; Project schemaExportProject = null; Project testProject = null; Project webProject = null; Project webCommonProject = null; m_srcPath = m_settings.SolutionWizardResourcesLocation + "\\"; m_dstPath = m_configuration["solution.path"] + "\\"; string versionControlType = m_configuration["application.versioncontrol"]; bool versionControl = versionControlType != "None"; string ignoreFile = string.Empty; switch (versionControlType) { case "CVS": ignoreFile = ".cvsignore"; break; } nvelocityContext = new VelocityContext(); foreach (string key in m_configuration.Keys) { object value = m_configuration[key]; if (m_configuration[key] == "true" || m_configuration[key] == "false") { value = GetConfigSettingBool(key); } nvelocityContext.Put("wizard." + key, value); nvelocityContext.Put("wizard_" + key.Replace('.', '_'), value); } AddToStatus("Creating AndroMDA configuration files..."); // Create mda directory CreateDirectory("mda"); // Create mda/conf directory CreateDirectory("mda/conf"); // Render /cvsignore if (versionControl) { WriteFile("cvsignore", ignoreFile); } if (m_configuration["application.andromda.bootstrap"] == "Apache Maven 2.x") { // Render /pom.xml WriteFile("pom.xml", WriteFileProperties.RenderTemplate | WriteFileProperties.ParseVariables); // Render /mda/pom.xml WriteFile("mda/pom.xml", WriteFileProperties.RenderTemplate | WriteFileProperties.ParseVariables); // Render /mda/conf/andromda.xml WriteFile("mda/conf/andromda.xml", WriteFileProperties.RenderTemplate | WriteFileProperties.ParseVariables); // Create mda/conf/mappings directory CreateDirectory("mda/conf/mappings"); // Render /mda/conf/mappings/MergeMappings.xml WriteFile("mda/conf/mappings/MergeMappings.xml"); // Render /mda/conf/mappings/NHibernateTypeMappings.xml (Required for NHibernate 1.2) WriteFile("mda/conf/mappings/NHibernateTypeMappings.xml"); // Create mda/resources CreateDirectory("mda/resources"); // Create mda/resources CreateDirectory("mda/resources/templates"); // Create mda/resources CreateDirectory("mda/resources/templates/cs"); // Create mda/resources CreateDirectory("mda/resources/templates/nspring"); // Create mda/resources CreateDirectory("mda/resources/templates/nhibernate"); } // Write mda/cvsignore if (versionControl) { WriteFile("mda/cvsignore", "mda/" + ignoreFile); } AddToStatus("Creating empty model file..."); // Create mda/src directory CreateDirectory("mda/src"); // Create mda/src/uml directory CreateDirectory("mda/src/uml"); { string modelPackageXML = "<UML:Model xmi.id='_9_5_1_874026a_1149883877463_480535_0' name='" + m_configuration["solution.name"] + "'><UML:Namespace.ownedElement>"; string xmiIdBase = "_9_5_1_874026a_" + DateTime.Now.Ticks.ToString(); modelPackageXML += GetXMI(m_configuration["solution.name"].Split('.'), xmiIdBase); modelPackageXML += "</UML:Namespace.ownedElement></UML:Model>"; string emptyModelFileData = ReadFile("mda/src/uml/empty-model.xmi"); emptyModelFileData = emptyModelFileData.Replace("${wizard.model.packagestructure.xml}", modelPackageXML); WriteFileProperties modelProperties = WriteFileProperties.SourceFileIsContent | WriteFileProperties.RenderTemplate | WriteFileProperties.ParseVariables; if (GetConfigSettingBool("application.model.zipped")) { modelProperties |= WriteFileProperties.Compressed; } WriteFile(emptyModelFileData, "mda/src/uml/" + m_configuration["application.model.filename"], modelProperties); } // Create the AndroMDA solution folder AddToStatus("Adding solution folder..."); Solution2 sol = m_applicationObject.Solution as Solution2; Project solutionFolder = null; try { solutionFolder = sol.AddSolutionFolder("AndroMDA"); if (m_configuration["application.andromda.bootstrap"] == "Apache Maven 2.x") { solutionFolder.ProjectItems.AddFromFile(m_dstPath + "mda\\pom.xml"); } solutionFolder.ProjectItems.AddFromFile(m_dstPath + "mda\\conf\\andromda.xml"); solutionFolder.ProjectItems.AddFromFile(m_dstPath + "mda\\conf\\mappings\\MergeMappings.xml"); solutionFolder.ProjectItems.AddFromFile(m_dstPath + "mda\\conf\\mappings\\NHibernateTypeMappings.xml"); //solutionFolder.ProjectItems.AddFromFile(m_dstPath + "mda\\src\\uml\\" + m_configuration["application.model.filename"]); } catch { } ////////////////////////////////// // Create/find the common project if (GetConfigSettingBool("projects.common.create")) { AddToStatus("Creating common project " + m_configuration["projects.common.name"] + "..."); commonProject = VSSolutionUtils.AddClassLibraryProjectToSolution(m_configuration["projects.common.name"], (Solution2)m_applicationObject.Solution); } else { AddToStatus("Using existing common project " + m_configuration["projects.common.name"] + "..."); commonProject = VSSolutionUtils.FindProjectByName(m_configuration["projects.common.name"], m_applicationObject.Solution); } try { commonProject.ProjectItems.AddFolder("src", Constants.vsProjectItemKindPhysicalFolder); } catch { } try { commonProject.ProjectItems.AddFolder("target", Constants.vsProjectItemKindPhysicalFolder); } catch { } // Write common/cvsignore if (versionControl) { WriteFile("Common/cvsignore", m_configuration["projects.common.dir"] + "/" + ignoreFile); } ////////////////////////////////// // Create/find the core project if (GetConfigSettingBool("projects.core.create")) { AddToStatus("Creating core project " + m_configuration["projects.core.name"] + "..."); coreProject = VSSolutionUtils.AddClassLibraryProjectToSolution(m_configuration["projects.core.name"], (Solution2)m_applicationObject.Solution); } else { AddToStatus("Using existing core project " + m_configuration["projects.core.name"] + "..."); coreProject = VSSolutionUtils.FindProjectByName(m_configuration["projects.core.name"], m_applicationObject.Solution); } try { coreProject.ProjectItems.AddFolder("src", Constants.vsProjectItemKindPhysicalFolder); } catch {} try { coreProject.ProjectItems.AddFolder("target", Constants.vsProjectItemKindPhysicalFolder); } catch { } // Write core/cvsignore if (versionControl) { WriteFile("Core/cvsignore", m_configuration["projects.core.dir"] + "/" + ignoreFile); } ////////////////////////////////// // Create the schema export project if (GetConfigSettingBool("projects.schemaexport.create")) { AddToStatus("Creating schema export project " + m_configuration["projects.schemaexport.name"] + "..."); schemaExportProject = VSSolutionUtils.AddConsoleAppProjectToSolution(m_configuration["projects.schemaexport.name"], (Solution2)m_applicationObject.Solution); WriteFile("SchemaExport/App.config", m_configuration["projects.schemaexport.dir"] + "/App.config"); WriteFile("SchemaExport/nhibernate.config", m_configuration["projects.schemaexport.dir"] + "/nhibernate.config"); WriteFile("SchemaExport/SchemaExport.cs", m_configuration["projects.schemaexport.dir"] + "/SchemaExport.cs"); WriteFile("SchemaExport/TestDataManager.cs", m_configuration["projects.schemaexport.dir"] + "/TestDataManager.cs"); ProjectItem appConfig = schemaExportProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.schemaexport.dir"] + "\\App.config"); ProjectItem nhibernateConfig = schemaExportProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.schemaexport.dir"] + "\\nhibernate.config"); // Set the config files 'Copy to Output Directory' property to 'Copy if Newer' appConfig.Properties.Item("CopyToOutputDirectory").Value = 2; appConfig.Properties.Item("BuildAction").Value = VSLangProj.prjBuildAction.prjBuildActionContent; nhibernateConfig.Properties.Item("CopyToOutputDirectory").Value = 2; nhibernateConfig.Properties.Item("BuildAction").Value = VSLangProj.prjBuildAction.prjBuildActionContent; schemaExportProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.schemaexport.dir"] + "\\SchemaExport.cs"); schemaExportProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.schemaexport.dir"] + "\\TestDataManager.cs"); // Write SchemaExport/cvsignore if (versionControl) { WriteFile("SchemaExport/cvsignore", m_configuration["projects.schemaexport.dir"] + "/" + ignoreFile); } } ////////////////////////////////// // Configure the web project if (GetConfigSettingBool("projects.web.configure")) { ////////////////////////////////// // Create/find the web project if (GetConfigSettingBool("projects.web.create")) { AddToStatus("Creating web project " + m_configuration["projects.web.name"] + "..."); webProject = VSSolutionUtils.AddWebProjectToSolution(m_configuration["projects.web.name"], (Solution2)m_applicationObject.Solution); } else { AddToStatus("Using existing web project " + m_configuration["projects.web.name"] + "..."); webProject = VSSolutionUtils.FindProjectByName(m_configuration["projects.web.dir"], m_applicationObject.Solution); } // Write the nhibernate.config if required if (GetConfigSettingBool("projects.web.usenhibernateconfig")) { WriteFile("Web/nhibernate.config", webProject.Name + "nhibernate.config", WriteFileProperties.DestinationPathAlreadyComplete | WriteFileProperties.ParseVariables); } string webConfigDstFile = webProject.Name + "Web.config"; if (!System.IO.File.Exists(webConfigDstFile)) { // Write out the web.config file WriteFile("Web/web.config", webConfigDstFile, WriteFileProperties.DestinationPathAlreadyComplete | WriteFileProperties.ParseVariables); webProject.ProjectItems.AddFromFile(webConfigDstFile); } // Open the web.config file System.Configuration.Configuration webconfig = OpenWebConfig(webConfigDstFile); // If the nhibernate settings are stored in nhibernate.config if (GetConfigSettingBool("projects.web.usenhibernateconfig")) { // Add that to the app settings if (webconfig.AppSettings.Settings["nhibernate.config"] == null) { webconfig.AppSettings.Settings.Add("nhibernate.config", "~/nhibernate.config"); } else { webconfig.AppSettings.Settings.Add("nhibernate.config", "~/nhibernate.config"); } // Remove the nhibernate section if it exists if (webconfig.Sections.Get("nhibernate") != null) { webconfig.Sections.Remove("nhibernate"); } } else { // Remove the nhibernate.config app setting if it exists if (webconfig.AppSettings.Settings["nhibernate.config"] != null) { webconfig.AppSettings.Settings.Remove("nhibernate.config"); } // Add the nhibernate config to the web.config DefaultSection nhibernateSection = new DefaultSection(); nhibernateSection.SectionInformation.Type = "System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"; nhibernateSection.SectionInformation.SetRawXml(ParseVariables(ReadFile("web/web.config.nhibernate"))); webconfig.Sections.Add("nhibernate", nhibernateSection); } // Write Web/cvsignore and Web\Bin\cvsignore if (versionControl) { WriteFile("web/cvsignore", webProject.Name + ignoreFile, WriteFileProperties.DestinationPathAlreadyComplete); CreateDirectory(webProject.Name + "Bin", false); WriteFile("web/bin/cvsignore", webProject.Name + "Bin\\" + ignoreFile, WriteFileProperties.DestinationPathAlreadyComplete); } if (GetConfigSettingBool("projects.web.common.configure")) { // Create/find the core project if (GetConfigSettingBool("projects.web.common.create")) { AddToStatus("Creating web common project " + m_configuration["projects.web.common.name"] + "..."); webCommonProject = VSSolutionUtils.AddClassLibraryProjectToSolution(m_configuration["projects.web.common.name"], (Solution2)m_applicationObject.Solution); } else { AddToStatus("Using existing web common project " + m_configuration["projects.web.common.name"] + "..."); webCommonProject = VSSolutionUtils.FindProjectByName(m_configuration["projects.web.common.name"], m_applicationObject.Solution); } } // Get the web site object VsWebSite.VSWebSite webSite = webProject.Object as VsWebSite.VSWebSite; // Refresh folder view webSite.Refresh(); // Add Membership support if (GetConfigSettingBool("projects.web.addmembership")) { AddToStatus("Adding membership support..."); string file; ProjectItem membershipFolder = VSSolutionUtils.FindProjectFolder(webCommonProject, "Membership"); if (membershipFolder == null) { membershipFolder = webCommonProject.ProjectItems.AddFolder("Membership", Constants.vsProjectItemKindPhysicalFolder); } // Render DomainMembershipProvider.cs WriteFile("Membership/DomainMembershipProvider.cs", m_configuration["projects.web.common.dir"] + "/Membership/DomainMembershipProvider.cs"); membershipFolder.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.web.common.dir"] + "\\Membership\\DomainMembershipProvider.cs"); // Render DomainRoleProvider.cs WriteFile("Membership/DomainRoleProvider.cs", m_configuration["projects.web.common.dir"] + "/Membership/DomainRoleProvider.cs"); membershipFolder.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.web.common.dir"] + "\\Membership\\DomainRoleProvider.cs"); // Render DomainMembershipUser.cs WriteFile("Membership/DomainMembershipUser.cs", m_configuration["projects.web.common.dir"] + "/Membership/DomainMembershipUser.cs"); membershipFolder.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.web.common.dir"] + "\\Membership\\DomainMembershipUser.cs"); // Create core/src/* folder tree from namespace string solutionName = m_configuration["solution.name"]; string[] namespaces = solutionName.Split('.'); file = m_configuration["projects.core.dir"] + "\\src\\"; foreach (string folder in namespaces) { file = file + folder; CreateDirectory(file); file = file + "\\"; } CreateDirectory(file + "Domain"); CreateDirectory(file + "Service"); // Render UserDao.cs WriteFile("Membership/UserDao.cs", file + "Domain/UserDao.cs"); coreProject.ProjectItems.AddFromFile(m_dstPath + file + "Domain\\UserDao.cs"); // Render MembershipService.cs WriteFile("Membership/MembershipService.cs", file + "Service/MembershipService.cs"); coreProject.ProjectItems.AddFromFile(m_dstPath + file + "Service\\MembershipService.cs"); ConfigurationSectionGroup systemweb = webconfig.SectionGroups["system.web"]; systemweb.Sections["membership"].SectionInformation.SetRawXml(ParseVariables(ReadFile("web/web.config.membershipsection"))); systemweb.Sections["roleManager"].SectionInformation.SetRawXml(ParseVariables(ReadFile("web/web.config.rolesection"))); systemweb.Sections["membership"].SectionInformation.ForceSave = true; systemweb.Sections["roleManager"].SectionInformation.ForceSave = true; // Turn on authentication systemweb.Sections["authentication"].SectionInformation.SetRawXml("<authentication mode=\"Forms\"> <forms name=\"FormsAuth\" timeout=\"30\" loginUrl=\"~/Public/Login.aspx\" defaultUrl=\"~/Default.aspx\" path=\"/\" protection=\"All\"/></authentication>"); } // Save the changes to the web.config webconfig.Save(); } // Create the lib directory CreateDirectory("Lib"); // Write the libraries out WriteBinaryFile("Lib/AndroMDA.NHibernateSupport.dll"); WriteBinaryFile("Lib/Bamboo.Prevalence.dll"); WriteBinaryFile("Lib/Castle.DynamicProxy.dll"); //WriteBinaryFile("Lib/HashCodeProvider.dll"); WriteBinaryFile("Lib/Iesi.Collections.dll"); WriteBinaryFile("Lib/log4net.dll"); WriteBinaryFile("Lib/NHibernate.Caches.Prevalence.dll"); WriteBinaryFile("Lib/NHibernate.Caches.SysCache.dll"); WriteBinaryFile("Lib/NHibernate.dll"); //WriteBinaryFile("Lib/NHibernate.Nullables2.dll"); WriteBinaryFile("Lib/Nullables.dll"); WriteBinaryFile("Lib/Nullables.NHibernate.dll"); ////////////////////////////////// // Configure the tests project if (GetConfigSettingBool("projects.tests.configure")) { // Create/find the core project if (GetConfigSettingBool("projects.tests.create")) { AddToStatus("Creating testing project " + m_configuration["projects.tests.name"] + "..."); testProject = VSSolutionUtils.AddClassLibraryProjectToSolution(m_configuration["projects.tests.name"], (Solution2)m_applicationObject.Solution); } else { AddToStatus("Using existing testing project " + m_configuration["projects.tests.name"] + "..."); testProject = VSSolutionUtils.FindProjectByName(m_configuration["projects.tests.name"], m_applicationObject.Solution); } WriteFile("Tests/App.config", m_configuration["projects.tests.dir"] + "/App.config", WriteFileProperties.RenderTemplate | WriteFileProperties.ParseVariables); WriteFile("Tests/nhibernate.config", m_configuration["projects.tests.dir"] + "/nhibernate.config"); ProjectItem appConfig = testProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.tests.dir"] + "\\App.config"); ProjectItem nhibernateConfig = testProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.tests.dir"] + "\\nhibernate.config"); // Set the config files 'Copy to Output Directory' property to 'Copy if Newer' appConfig.Properties.Item("CopyToOutputDirectory").Value = 2; appConfig.Properties.Item("BuildAction").Value = VSLangProj.prjBuildAction.prjBuildActionContent; nhibernateConfig.Properties.Item("CopyToOutputDirectory").Value = 2; nhibernateConfig.Properties.Item("BuildAction").Value = VSLangProj.prjBuildAction.prjBuildActionContent; AddToStatus("Writing NUnit assemblies..."); WriteBinaryFile("Lib/nunit.core.dll"); WriteBinaryFile("Lib/nunit.framework.dll"); AddToStatus("Adding NUnit references..."); VSProject vsTestProj = (VSProject)testProject.Object; vsTestProj.References.Add(m_dstPath + "Lib\\nunit.core.dll"); vsTestProj.References.Add(m_dstPath + "Lib\\nunit.framework.dll"); if (GetConfigSettingBool("projects.tests.scenariounit")) { AddToStatus("Writing ScenarioUnit assemblies..."); WriteBinaryFile("Lib/NXUnit.Framework.dll"); WriteBinaryFile("Lib/AndroMDA.ScenarioUnit.dll"); AddToStatus("Adding ScenarioUnit references..."); vsTestProj.References.Add(m_dstPath + "Lib\\NXUnit.Framework.dll"); vsTestProj.References.Add(m_dstPath + "Lib\\AndroMDA.ScenarioUnit.dll"); ProjectItem testDataFolder = testProject.ProjectItems.AddFolder("TestData", Constants.vsProjectItemKindPhysicalFolder); testDataFolder.ProjectItems.AddFolder("actual_output", Constants.vsProjectItemKindPhysicalFolder); testDataFolder.ProjectItems.AddFolder("expected_output", Constants.vsProjectItemKindPhysicalFolder); testDataFolder.ProjectItems.AddFolder("rules", Constants.vsProjectItemKindPhysicalFolder); testDataFolder.ProjectItems.AddFolder("input", Constants.vsProjectItemKindPhysicalFolder); } } // Add the references to all the DLLs we just put in /Lib AddToStatus("Adding project references to common project..."); AddBinaryReferences(commonProject); AddToStatus("Adding project references to core project..."); AddBinaryReferences(coreProject); // Add a reference from the core project to the common project AddProjectReference(coreProject, commonProject); // If we created the schema export project if (schemaExportProject != null) { VSProject proj = schemaExportProject.Object as VSProject; AddToStatus("Adding references to schema export project..."); // Add the references to the DLLs AddBinaryReferences(schemaExportProject); // Add references to the core and common projects AddProjectReference(schemaExportProject, commonProject); AddProjectReference(schemaExportProject, coreProject); AddToStatus("Adding System.Configuration reference to schema export project..."); try { proj.References.Add("System.Configuration"); } catch { } } // If we created the schema export project if (testProject != null) { AddToStatus("Adding references to testing project..."); // Add the references to the DLLs AddBinaryReferences(testProject); // Add references to the core and common projects AddProjectReference(testProject, commonProject); AddProjectReference(testProject, coreProject); } if (webProject != null) { AddToStatus("Adding project references to web project..."); VsWebSite.VSWebSite proj = webProject.Object as VsWebSite.VSWebSite; proj.References.AddFromFile(m_dstPath + "Lib\\AndroMDA.NHibernateSupport.dll"); try { proj.References.AddFromProject(commonProject); } catch {} try { proj.References.AddFromProject(coreProject); } catch {} if (webCommonProject != null) { try { proj.References.AddFromProject(webCommonProject); } catch { } } //m_applicationObject.Solution.Properties.Item("StartupProject").Value = webProject.Name; } if (webCommonProject != null) { VSProject proj = webCommonProject.Object as VSProject; AddToStatus("Adding common project reference to web common project..."); try { proj.References.AddProject(commonProject); } catch { } AddToStatus("Adding core project reference to web common project..."); try { proj.References.AddProject(coreProject); } catch { } AddToStatus("Adding System.Configuration reference to web common project..."); try { proj.References.Add("System.Configuration"); } catch { } AddToStatus("Adding System.Web reference to web common project..."); try { proj.References.Add("System.Web"); } catch { } } AddToStatus("Processing complete, cleaning up..."); }
public void Test_MaxFileSize() { var testDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test"); Directory.CreateDirectory(testDirectory); var testFile = Path.Combine(testDirectory, "Hello.txt"); if (File.Exists(testFile)) { File.Delete(testFile); } // Setup ConfigurationManager Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.Sections.Clear(); config.SectionGroups.Clear(); DefaultSection section = new DefaultSection(); string rawXml = @"<Test.FileProbe> <add key=""FileName"" value=""{0}""/> <add key=""MaxFileSize"" value=""0""/> <add key=""MaxFileAge"" value=""1""/> <add key=""EventId"" value=""30""/> <add key=""EventType"" value=""Warning""/> <add key=""ProbeFrequency"" value=""10""/> </Test.FileProbe>"; rawXml = string.Format(rawXml, testFile); section.SectionInformation.SetRawXml(rawXml); section.SectionInformation.Type = typeof(NameValueSectionHandler).FullName; config.Sections.Add("Test.FileProbe", section); config.Save(); ConfigurationManager.RefreshSection("Test.FileProbe"); FileProbe fileProbe = new FileProbe(); var traceSource = fileProbe.ConfigureProbe("Test.FileProbe"); traceSource.Switch = new SourceSwitch("Test.FileProbe") { Level = SourceLevels.All }; FileProbeTestListener probeListener = new FileProbeTestListener(); traceSource.Listeners.Clear(); traceSource.Listeners.Add(probeListener); fileProbe.ExecuteProbe(); Assert.AreEqual(TraceEventType.Critical, probeListener.TriggeredEvent, "Failed to detect missing file"); File.Create(testFile).Dispose(); fileProbe.ExecuteProbe(); Assert.AreEqual(TraceEventType.Information, probeListener.TriggeredEvent, "Failed to detect file"); System.Threading.Thread.Sleep(2000); fileProbe.ExecuteProbe(); Assert.AreEqual(TraceEventType.Warning, probeListener.TriggeredEvent, "Failed to detect old file"); File.WriteAllText(testFile, ""); fileProbe.ExecuteProbe(); Assert.AreEqual(TraceEventType.Information, probeListener.TriggeredEvent, "Failed to detect new file"); File.WriteAllText(testFile, "Error"); fileProbe.ExecuteProbe(); Assert.AreEqual(TraceEventType.Warning, probeListener.TriggeredEvent, "Failed to detect large file"); }
public AppConfig(DefaultSection defaultSection, FeaturesSection featuresSection) : this(defaultSection, featuresSection, new AppConfigSettings()) { }
private AppConfig(DefaultSection defaultSection, FeaturesSection featuresSection, AppConfigSettings settings) { _default = defaultSection; _features = featuresSection; _settings = settings; }
static void Main(string[] args) { string inputStr = String.Empty; string option = String.Empty; // Define a regular expression to allow only // alphanumeric inputs that are at most 20 character // long. For instance "/iii:". Regex rex = new Regex(@"[^\/w]{1,20}:"); // Parse the user's input. if (args.Length < 1) { // No option entered. Console.Write("Input parameter missing."); return; } else { // Get the user's option. inputStr = args[0].ToLower(); if (!(rex.Match(inputStr)).Success) { // Wrong option format used. Console.Write("Input parameter format not allowed."); return; } } // <Snippet1> // Get the Web application configuration. System.Configuration.Configuration configuration = WebConfigurationManager.OpenWebConfiguration( "/aspnetTest"); // Get the <system.web> group. SystemWebSectionGroup systemWeb = (SystemWebSectionGroup)configuration.GetSectionGroup("system.web"); // </Snippet1> try { switch (inputStr) { case "/anonymous:": // <Snippet2> // Get the anonymousIdentification section. AnonymousIdentificationSection anonymousIdentification = systemWeb.AnonymousIdentification; // Read section information. info = anonymousIdentification.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet2> Console.Write(msg); break; case "/authentication:": // <Snippet3> // Get the authentication section. AuthenticationSection authentication = systemWeb.Authentication; // Read section information. info = authentication.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet3> Console.Write(msg); break; case "/authorization:": // <Snippet4> // Get the authorization section. AuthorizationSection authorization = systemWeb.Authorization; // Read section information. info = authorization.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet4> Console.Write(msg); break; case "/compilation:": // <Snippet5> // Get the compilation section. CompilationSection compilation = systemWeb.Compilation; // Read section information. info = compilation.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet5> Console.Write(msg); break; case "/customerrors:": // <Snippet6> // Get the customerrors section. CustomErrorsSection customerrors = systemWeb.CustomErrors; // Read section information. info = customerrors.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet6> Console.Write(msg); break; case "/globalization:": // <Snippet7> // Get the globalization section. GlobalizationSection globalization = systemWeb.Globalization; // Read section information. info = globalization.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet7> Console.Write(msg); break; case "/httpcookies:": // <Snippet8> // Get the httpCookies section. HttpCookiesSection httpCookies = systemWeb.HttpCookies; // Read section information. info = httpCookies.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet8> Console.Write(msg); break; case "/httphandlers:": // <Snippet9> // Get the httpHandlers section. HttpHandlersSection httpHandlers = systemWeb.HttpHandlers; // Read section information. info = httpHandlers.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet9> Console.Write(msg); break; case "/httpmodules:": // <Snippet10> // Get the httpModules section. HttpModulesSection httpModules = systemWeb.HttpModules; // Read section information. info = httpModules.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet10> Console.Write(msg); break; case "/httpruntime:": // <Snippet11> // Get the httpRuntime section. HttpRuntimeSection httpRuntime = systemWeb.HttpRuntime; // Read section information. info = httpRuntime.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet11> Console.Write(msg); break; case "/identity:": // <Snippet12> // Get the identity section. IdentitySection identity = systemWeb.Identity; // Read section information. info = identity.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet12> Console.Write(msg); break; case "/machinekey:": // <Snippet13> // Get the machineKey section. MachineKeySection machineKey = systemWeb.MachineKey; // Read section information. info = machineKey.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet13> Console.Write(msg); break; case "/membership:": // <Snippet14> // Get the membership section. MembershipSection membership = systemWeb.Membership; // Read section information. info = membership.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet14> Console.Write(msg); break; case "/pages:": // <Snippet15> // Get the pages section. PagesSection pages = systemWeb.Pages; // Read section information. info = pages.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet15> Console.Write(msg); break; case "/processModel:": // <Snippet16> // Get the processModel section. ProcessModelSection processModel = systemWeb.ProcessModel; // Read section information. info = processModel.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet16> Console.Write(msg); break; case "/profile:": // <Snippet17> // Get the profile section. ProfileSection profile = systemWeb.Profile; // Read section information. info = profile.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet17> Console.Write(msg); break; case "/roleManager:": // <Snippet18> // Get the roleManager section. RoleManagerSection roleManager = systemWeb.RoleManager; // Read section information. info = roleManager.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet18> Console.Write(msg); break; case "/securityPolicy:": // <Snippet19> // Get the securityPolicy section. SecurityPolicySection securityPolicy = systemWeb.SecurityPolicy; // Read section information. info = securityPolicy.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet19> Console.Write(msg); break; case "/sessionState:": // <Snippet20> // Get the sessionState section. SessionStateSection sessionState = systemWeb.SessionState; // Read section information. info = sessionState.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet20> Console.Write(msg); break; case "/sitemap:": // <Snippet21> // Get the siteMap section. SiteMapSection siteMap = systemWeb.SiteMap; // Read section information. info = siteMap.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet21> Console.Write(msg); break; case "/trace:": // <Snippet22> // Get the trace section. TraceSection trace = systemWeb.Trace; // Read section information. info = trace.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet22> Console.Write(msg); break; case "/trust:": // <Snippet23> // Get the trust section. TrustSection trust = systemWeb.Trust; // Read section information. info = trust.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet23> Console.Write(msg); break; case "/browserCaps:": // <Snippet24> // Get the browserCaps section. DefaultSection browserCaps = systemWeb.BrowserCaps; // Read section information. info = browserCaps.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet24> Console.Write(msg); break; case "/clientTarget:": // <Snippet25> // Get the clientTarget section. ClientTargetSection clientTarget = systemWeb.ClientTarget; // Read section information. info = clientTarget.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet25> Console.Write(msg); break; case "/deployment:": // <Snippet26> // Get the deployment section. DeploymentSection deployment = systemWeb.Deployment; // Read section information. info = deployment.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet26> Console.Write(msg); break; case "/deviceFilters:": // <Snippet27> // Get the deviceFilters section. DefaultSection deviceFilters = systemWeb.DeviceFilters; // Read section information. info = deviceFilters.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet27> Console.Write(msg); break; case "/healthMonitoring:": // <Snippet28> // Get the healthMonitoring section. HealthMonitoringSection healthMonitoring = systemWeb.HealthMonitoring; // Read section information. info = healthMonitoring.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet28> Console.Write(msg); break; case "/hostingEnvironment:": // <Snippet29> // Get the hostingEnvironment section. HostingEnvironmentSection hostingEnvironment = systemWeb.HostingEnvironment; // Read section information. info = hostingEnvironment.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet29> Console.Write(msg); break; case "/mobileControls:": // <Snippet30> // Get the mobileControls section. ConfigurationSection mobileControls = systemWeb.MobileControls; // Read section information. info = mobileControls.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet30> Console.Write(msg); break; case "/protocols:": // <Snippet31> // Get the protocols section. DefaultSection protocols = systemWeb.Protocols; // Read section information. info = protocols.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet31> Console.Write(msg); break; case "/urlMappings:": // <Snippet32> // Get the urlMappings section. UrlMappingsSection urlMappings = systemWeb.UrlMappings; // Read section information. info = urlMappings.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet32> Console.Write(msg); break; case "/webControls:": // <Snippet33> // Get the webControls section. WebControlsSection webControls = systemWeb.WebControls; // Read section information. info = webControls.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet33> Console.Write(msg); break; case "/webParts:": // <Snippet34> // Get the webParts section. WebPartsSection webParts = systemWeb.WebParts; // Read section information. info = webParts.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet34> Console.Write(msg); break; case "/webServices:": // <Snippet35> // Get the webServices section. WebServicesSection webServices = systemWeb.WebServices; // Read section information. info = webServices.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet35> Console.Write(msg); break; case "/XhtmlConformance:": // <Snippet36> // Get the xhtmlConformance section. XhtmlConformanceSection xhtmlConformance = systemWeb.XhtmlConformance; // Read section information. info = xhtmlConformance.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet36> Console.Write(msg); break; case "/all:": StringBuilder allSections = new StringBuilder(); ConfigurationSectionGroup systemWebGroup = configuration.GetSectionGroup("system.web"); int i = 0; foreach (ConfigurationSection section in systemWebGroup.Sections) { i += 1; info = section.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); if (i < 10) { msg = String.Format( "{0})Name: {1}\nDeclared: {2}\nType: {3}\n", i.ToString(), name, declared, type); } else { msg = String.Format( "{0})Name: {1}\nDeclared: {2}\nType: {3}\n", i.ToString(), name, declared, type); } allSections.AppendLine(msg); } // Console.WriteLine(systemWebGroup.Name); // Console.WriteLine(systemWebGroup.SectionGroupName); Console.Write(allSections.ToString()); break; default: // Option is not allowed.. Console.Write("Input not allowed."); break; } } catch (ArgumentException e) { // Never display this. Use it for // debugging purposes. msg = e.ToString(); } }
public AppConfigDefault(DefaultSection defaultSection) { _defaultSection = defaultSection; }
// selects nodes by xpath from the Data (default section) public IEnumerable <XElement> SelectNodes(string xpath) { return(DefaultSection.Elements(xpath)); }