Ejemplo n.º 1
0
        /// <summary>
        /// Determines whether we need to add the "validateIntegratedModeConfiguration=false" attribute to the system.webServer section
        /// </summary>
        /// <remarks>This section is used by IIS in integrated mode and is necessary to deploy this domain service.</remarks>
        /// <returns><c>true</c> if we need to add validateIntegratedModeConfiguration to the system.webServer section.</returns>
        public bool DoWeNeedToValidateIntegratedModeToWebServer()
        {
            IgnoreSection webServerSection = this._configuration.GetSection(SystemWebServerSectionName) as IgnoreSection;

            if (webServerSection != null)
            {
                SectionInformation sectionInformation = webServerSection.SectionInformation;
                string             rawXml             = sectionInformation == null ? null : sectionInformation.GetRawXml();
                if (string.IsNullOrEmpty(rawXml))
                {
                    return(true);
                }

                XDocument xdoc = WebConfigUtil.CreateXDoc(rawXml);

                XElement xelem = xdoc.Element(SystemWebServerSectionName);
                if (xelem != null)
                {
                    xelem = xelem.Element(WebConfigUtil.ValidationSectionName);
                    XAttribute attr = xelem == null ? null : xelem.Attribute(WebConfigUtil.ValidateIntegratedModeConfigurationAttributeName);
                    return(attr == null ? true : !string.Equals(attr.Value, WebConfigUtil.FalseAttributeValue, StringComparison.OrdinalIgnoreCase));
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        // 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");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get runtime object.
        /// </summary>
        /// <returns>Runtime object.</returns>
        protected internal virtual object GetRuntimeObject()
        {
            if (SectionHandler != null)
            {
                try
                {
                    XmlReader reader = new XmlTextReader(new StringReader(RawXml));

                    DoDeserializeSection(reader);

                    if (!String.IsNullOrEmpty(SectionInformation.Source))
                    {
                        RawXml = File.ReadAllText(SectionInformation.Source);
                        SectionInformation.SetRawXml(RawXml);
                    }
                }
                catch
                {
                }

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(RawXml);
                return(SectionHandler.Create(GenContext, doc.DocumentElement));
            }

            return(this);
        }
Ejemplo n.º 4
0
        // </Snippet110>

        // <Snippet111>
        static public void GetSectionType()
        {
            SectionInformation sInfo =
                GetSectionInformation();

            string sectionType = sInfo.Type;

            Console.WriteLine("Section type: {0}", sectionType);
        }
Ejemplo n.º 5
0
        // <Snippet107>
        static public void GetSectionNameProperty()
        {
            SectionInformation sInfo =
                GetSectionInformation();

            string sectionNameProperty = sInfo.Name;

            Console.WriteLine("Section name: {0}",
                              sectionNameProperty);
        }
Ejemplo n.º 6
0
        // </Snippet91>

        // <Snippet92>
        static public void GetParentSection()
        {
            SectionInformation sInfo =
                GetSectionInformation();

            ConfigurationSection parentSection =
                sInfo.GetParentSection();

            Console.WriteLine("Parent section : {0}",
                              parentSection.SectionInformation.Name);
        }
Ejemplo n.º 7
0
        // </Snippet108>

        // <Snippet109>
        static public void RestartOnExternalChanges()
        {
            SectionInformation sInfo =
                GetSectionInformation();

            bool restartOnChange =
                sInfo.RestartOnExternalChanges;

            Console.WriteLine("Section type: {0}",
                              restartOnChange.ToString());
        }
Ejemplo n.º 8
0
        // </Snippet92>

        // <Snippet93>
        static public void GetSectionXml()
        {
            SectionInformation sInfo =
                GetSectionInformation();

            string sectionXml =
                sInfo.GetRawXml();

            Console.WriteLine("Section xml:");
            Console.WriteLine(sectionXml);
        }
Ejemplo n.º 9
0
        // <Snippet100>
        static public void GetInheritInChildApps()
        {
            SectionInformation sInfo =
                GetSectionInformation();

            bool inheritInChildApps =
                sInfo.InheritInChildApplications;

            Console.WriteLine("Inherit in child apps: {0}",
                              inheritInChildApps.ToString());
        }
Ejemplo n.º 10
0
        private static TReturn LoadSection <TReturn>(SectionInformation information) where TReturn : class
        {
            string[] strs    = information.Type.Split(",".ToCharArray(), 2);
            var      handler = (IConfigurationSectionHandler)Assembly.Load(strs[1]).CreateInstance(strs[0]);
            var      doc     = new XmlDocument();

            doc.LoadXml(information.GetRawXml());
            if (handler != null)
            {
                return((TReturn)handler.Create(null, null, doc.ChildNodes[0]));
            }
            return(null);
        }
Ejemplo n.º 11
0
 /// <summary>
 ///     Removes the protected configuration encryption from the associated configuration section.
 /// </summary>
 public void UnprotectSection()
 {
     if (_section == null)
     {
         throw new ConfigurationException();
     }
     if (_section.SectionInformation.IsProtected)
     {
         SectionInformation sectionInformation = _section.SectionInformation;
         sectionInformation.UnprotectSection();
         Save(Resources.ConfigurationSectionHelper_UnprotectSection);
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 ///     Marks a configuration section for protection.
 /// </summary>
 /// <exception cref="T:System.InvalidOperationException">
 ///     The
 ///     <see cref="P:System.Configuration.SectionInformation.AllowLocation" /> property is set to false.
 /// </exception>
 public void ProtectSection()
 {
     if (_section == null)
     {
         throw new ConfigurationException();
     }
     if (!_section.SectionInformation.IsProtected)
     {
         string             protectionProvider = _protectionProvider.GetDescription();
         SectionInformation sectionInformation = _section.SectionInformation;
         sectionInformation.ProtectSection(protectionProvider);
         Save(Resources.ConfigurationSectionHelper_ProtectSection);
     }
 }
Ejemplo n.º 13
0
        // </Snippet94>

        static public void GetAllowProperties()
        {
            // <Snippet95>
            // Get the current configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None);

            // Get the section.
            UrlsSection section =
                (UrlsSection)config.GetSection("MyUrls");


            SectionInformation sInfo =
                section.SectionInformation;
            // </Snippet95>

            // <Snippet96>
            ConfigurationAllowDefinition allowDefinition =
                sInfo.AllowDefinition;

            Console.WriteLine("Allow definition: {0}",
                              allowDefinition.ToString());
            // </Snippet96>

            // <Snippet97>
            ConfigurationAllowExeDefinition allowExeDefinition =
                sInfo.AllowExeDefinition;

            Console.WriteLine("Allow exe definition: {0}",
                              allowExeDefinition.ToString());
            // </Snippet97>

            // <Snippet98>
            bool allowLocation =
                sInfo.AllowLocation;

            Console.WriteLine("Allow location: {0}",
                              allowLocation.ToString());
            // </Snippet98>

            // <Snippet99>
            bool allowOverride =
                sInfo.AllowOverride;

            Console.WriteLine("Allow override: {0}",
                              allowOverride.ToString());
            // </Snippet99>
        }
Ejemplo n.º 14
0
        // </Snippet100>

        static public void GetIsProperties()
        {
            // <Snippet102>
            // Get the current configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None);

            // Get the section.
            UrlsSection section =
                (UrlsSection)config.GetSection("MyUrls");


            SectionInformation sInfo =
                section.SectionInformation;
            // </Snippet102>

            // <Snippet103>
            bool declRequired =
                sInfo.IsDeclarationRequired;

            Console.WriteLine("Declaration required?: {0}",
                              declRequired.ToString());
            // </Snippet103>

            // <Snippet104>
            bool declared =
                sInfo.IsDeclared;

            Console.WriteLine("Section declared?: {0}",
                              declared.ToString());
            // </Snippet104>

            // <Snippet105>
            bool locked =
                sInfo.IsLocked;

            Console.WriteLine("Section locked?: {0}",
                              locked.ToString());
            // </Snippet105>

            // <Snippet106>
            bool protect =
                sInfo.IsProtected;

            Console.WriteLine("Section protected?: {0}",
                              protect.ToString());
            // </Snippet106>
        }
Ejemplo n.º 15
0
            public OverlaySymbols(Overlay parent, IEnumerable <Symbol> symbols, SectionInformation textSection)
            {
                symbols = symbols.ToList();

                _symbols = new SortedDictionary <uint, Symbol>(
                    symbols
                    .GroupBy(s => s.Address)
                    .Select(g => g
                            .OrderByDescending(s => s.TypeHint == TypeHint.Function)
                            .First())
                    .ToDictionary(s => s.Address, s => s)
                    );

                _pairLookup = parent.Relocations
                              .Where(r => r.Type == RelocationType.R_MIPS_HI16 || r.Type == RelocationType.R_MIPS_LO16)
                              .Select(r => new { Pc = r.AbsoluteLocation, SymbolAddress = r.Address })
                              .ToDictionary(p => p.Pc, p => p.SymbolAddress);

                // Find strange symbols in .text section that are not 4-byte aligned
                var malignedTextSymbols = symbols
                                          .Where(s => s.Address >= textSection.StartAddress && s.Address < textSection.EndAddress)
                                          .Where(s => s.Address % 4 != 0)
                                          .Select(s => new {
                    New = new Symbol((uint)(s.Address & ~3), string.Format("data_{0:X8} + {1}", s.Address & ~3, s.Address - (s.Address & ~3)), s.TypeHint),
                    Old = s
                })
                                          .ToArray();

                foreach (var x in malignedTextSymbols)
                {
                    _symbols.Remove(x.Old.Address);
                    _symbols.Add(x.New.Address, x.New);

                    var pcToRemove = _pairLookup
                                     .Where(p => p.Value == x.Old.Address)
                                     .Select(p => p.Key)
                                     .ToArray();

                    foreach (var pc in pcToRemove)
                    {
                        _pairLookup[pc] = x.New.Address;
                    }
                }

                parent._oddities.AddRange(
                    malignedTextSymbols.Select(s => $"{s.Old.Name} in .text section but not 4-byte aligned")
                    );
            }
Ejemplo n.º 16
0
        GetSectionInformation()
        {
            // Get the current configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None);

            // Get the section.
            UrlsSection section =
                (UrlsSection)config.GetSection("MyUrls");

            SectionInformation sInfo =
                section.SectionInformation;

            return(sInfo);
        }
Ejemplo n.º 17
0
        // </Snippet107>

        // <Snippet108>
        static public void GetProtectionProvider()
        {
            SectionInformation sInfo =
                GetSectionInformation();

            ProtectedConfigurationProvider pp =
                sInfo.ProtectionProvider;

            if (pp == null)
            {
                Console.WriteLine("Protection provider is null");
            }
            else
            {
                Console.WriteLine("Protection provider: {0}",
                                  pp.ToString());
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Saves the provided connectionString to the program's configurations file using the default name, and Rsa encryption.
 /// </summary>
 /// <param name="connectionString">The connection string to save.</param>
 public void SaveConnectionString()
 {
     if (!ConnectionString.Equals(string.Empty) && !ConnectionString.Equals(DEFAULT_CONSTR))
     {
         ConnectionStringsSection section     = _config.ConnectionStrings;
         SectionInformation       sectionInfo = section.SectionInformation;
         if (!sectionInfo.IsProtected)
         {
             sectionInfo.ProtectSection("RsaProtectedConfigurationProvider");
         }
         ConnectionStringSettings existingSection = section.ConnectionStrings[DEFAULT_CONSTR_NAME];
         if (null != existingSection)
         {
             section.ConnectionStrings.Remove(existingSection);
         }
         section.ConnectionStrings.Add(new ConnectionStringSettings(DEFAULT_CONSTR_NAME, _conStrBuilder.ConnectionString));
         _config.Save(ConfigurationSaveMode.Modified);
         ConfigurationManager.RefreshSection("connectionStrings");
     }
 }
Ejemplo n.º 19
0
        public static void DecryptAppConfigSections(string exePath, string commaSeparatedSections)
        {
            List <string>      sectionNames       = new List <string>(commaSeparatedSections.Split(",".ToCharArray()));
            Configuration      config             = ConfigurationManager.OpenExeConfiguration(exePath);
            SectionInformation sectionInformation = null;

            foreach (string sectionName in sectionNames)
            {
                sectionInformation = config.GetSection(sectionName.Trim()).SectionInformation;
                if (sectionInformation == null)
                {
                    continue;
                }
                if (sectionInformation.IsProtected)
                {
                    sectionInformation.UnprotectSection();
                    sectionInformation.ForceSave = true;
                }
            }
            config.Save(ConfigurationSaveMode.Full);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Adds a module to the system.webServer section to point to our domain service module
        /// </summary>
        /// <param name="domainServiceModuleTypeName">Full type name of the domain service module</param>
        public void AddModuleToWebServer(string domainServiceModuleTypeName)
        {
            IgnoreSection      webServerSection   = this.GetOrCreateSystemWebServerSection();
            SectionInformation sectionInformation = webServerSection.SectionInformation;
            string             rawXml             = sectionInformation.GetRawXml();

            if (!string.IsNullOrEmpty(rawXml))
            {
                XDocument xdoc = WebConfigUtil.CreateXDoc(rawXml);

                XElement webSvrElement = xdoc.Element(SystemWebServerSectionName);
                XElement xelem         = webSvrElement.Element("modules");

                if (xelem == null)
                {
                    xelem = new XElement("modules");
                    webSvrElement.Add(xelem);
                }

                // Ensure we have the runAllManagedModulesForAllRequests attribute.
                // If it is present, we do not alter it
                XAttribute runAllManagedAttr = xelem.Attribute("runAllManagedModulesForAllRequests");
                if (runAllManagedAttr == null)
                {
                    runAllManagedAttr = new XAttribute("runAllManagedModulesForAllRequests", "true");
                    xelem.Add(runAllManagedAttr);
                }

                XElement newElem = new XElement("add",
                                                new XAttribute("name", BusinessLogicClassConstants.DomainServiceModuleName),
                                                new XAttribute("preCondition", BusinessLogicClassConstants.ManagedHandler),
                                                new XAttribute("type", domainServiceModuleTypeName));
                xelem.Add(newElem);

                rawXml = WebConfigUtil.CreateRawXml(xdoc);

                sectionInformation.SetRawXml(rawXml);
            }
        }
Ejemplo n.º 21
0
 static void EncryptConfigs()
 {
     if (!EyediaCoreConfigurationSection.CurrentConfig.Debug)
     {
         try
         {
             Configuration      config     = ConfigurationManager.OpenExeConfiguration(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "idpe.exe"));
             SectionInformation sreSection = config.GetSection("idpeConfigurationSection").SectionInformation;
             if (sreSection == null)
             {
                 return;
             }
             string srecmdFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "idpec.exe");
             if ((!sreSection.IsProtected) &&
                 (File.Exists(srecmdFile)))
             {
                 Process.Start(srecmdFile, "e");
             }
         }
         catch { }
     }
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Retrieves or creates the system.webServer section
        /// </summary>
        /// <remarks>
        /// This section self initializes to empty xml, so if we detect that condition,
        /// we initialize it to empty but valid xml so that it can be manipulated.
        /// </remarks>
        /// <returns>The existing or new system.webServer section.</returns>
        public IgnoreSection GetOrCreateSystemWebServerSection()
        {
            // This section has no strongly typed equivalent, so we treat it only as an IgnoreSection
            IgnoreSection webServerSection = this._configuration.GetSection(SystemWebServerSectionName) as IgnoreSection;

            if (webServerSection == null)
            {
                webServerSection = new IgnoreSection();
                this._configuration.Sections.Add(SystemWebServerSectionName, webServerSection);
            }

            // Detect empty xml and initialize it to legal empty state if found.
            // We do this to simplify the logic of parsing it and adding new sections.
            SectionInformation sectionInformation = webServerSection.SectionInformation;
            string             rawXml             = sectionInformation.GetRawXml();

            if (string.IsNullOrEmpty(rawXml))
            {
                rawXml = "<" + SystemWebServerSectionName + "/>";
                sectionInformation.SetRawXml(rawXml);
            }
            return(webServerSection);
        }
Ejemplo n.º 23
0
        // 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");
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Determines whether we need to add a module to the system.webServer section
        /// </summary>
        /// <remarks>This module section is used by IIS in integrated mode and is necessary to deploy this domain service.</remarks>
        /// <returns><c>true</c> if we need to add a module to the system.webServer section.</returns>
        public bool DoWeNeedToAddModuleToWebServer()
        {
            IgnoreSection webServerSection = this._configuration.GetSection(SystemWebServerSectionName) as IgnoreSection;

            if (webServerSection != null)
            {
                SectionInformation sectionInformation = webServerSection.SectionInformation;
                string             rawXml             = sectionInformation == null ? null : sectionInformation.GetRawXml();
                if (string.IsNullOrEmpty(rawXml))
                {
                    return(true);
                }

                XDocument xdoc = WebConfigUtil.CreateXDoc(rawXml);

                // The logic is actually the following, but we null check to protect against malformed xml
                // xdoc.Element("system.webServer")
                //                    .Element("modules")
                //                    .Elements("add")
                //                    .Any(e => (string)e.Attribute("name") == BusinessLogicClassConstants.DomainServiceModuleName);
                XElement xelem = xdoc.Element(SystemWebServerSectionName);
                if (xelem != null)
                {
                    xelem = xelem.Element("modules");

                    if (xelem == null)
                    {
                        return(true);
                    }

                    IEnumerable <XElement> xelems = xelem.Elements("add");
                    return(xelems == null ? false : !xelems.Any(e => (string)e.Attribute("name") == BusinessLogicClassConstants.DomainServiceModuleName));
                }
            }
            return(true);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Adds the validateIntegratedModeConfiguration to the system.webServer/validation section
        /// </summary>
        public void AddValidateIntegratedModeToWebServer()
        {
            IgnoreSection webServerSection = this.GetOrCreateSystemWebServerSection();

            SectionInformation sectionInformation = webServerSection.SectionInformation;
            string             rawXml             = sectionInformation.GetRawXml();

            if (!string.IsNullOrEmpty(rawXml))
            {
                XDocument xdoc = WebConfigUtil.CreateXDoc(rawXml);

                XElement webSvrElement = xdoc.Element(SystemWebServerSectionName);
                XElement xelem         = webSvrElement.Element(WebConfigUtil.ValidationSectionName);

                if (xelem == null)
                {
                    xelem = new XElement(WebConfigUtil.ValidationSectionName);
                    webSvrElement.Add(xelem);
                }

                XAttribute attr = xelem.Attribute(WebConfigUtil.ValidateIntegratedModeConfigurationAttributeName);
                if (attr != null)
                {
                    attr.SetValue(WebConfigUtil.FalseAttributeValue);
                }
                else
                {
                    attr = new XAttribute(WebConfigUtil.ValidateIntegratedModeConfigurationAttributeName, WebConfigUtil.FalseAttributeValue);
                    xelem.Add(attr);
                }

                rawXml = WebConfigUtil.CreateRawXml(xdoc);

                sectionInformation.SetRawXml(rawXml);
            }
        }
        private static IDictionary<SectionInformation, IList<Item>> GetSectionsWithFields(Database database, string fieldIds)
        {
            Assert.ArgumentNotNull(database, "database");
            Assert.ArgumentNotNull(fieldIds, "fieldIds");
            IDictionary<SectionInformation, IList<Item>> sectionsWithFields = new Dictionary<SectionInformation, IList<Item>>();

            foreach (TemplateFieldItem field in GetFields(database, fieldIds))
            {
                SectionInformation sectionInformation = new SectionInformation(field.Section.InnerItem);
                if (sectionsWithFields.ContainsKey(sectionInformation))
                {
                    sectionsWithFields[sectionInformation].Add(field.InnerItem);
                }
                else
                {
                    sectionsWithFields.Add(sectionInformation, new List<Item>(new[] { field.InnerItem }));
                }
            }

            return sectionsWithFields;
        }
        private static void MoveFieldsToAppropriateSection(Item baseTemplate, SectionInformation sectionInformation, IEnumerable<Item> fields)
        {
            TemplateItem templateItem = baseTemplate;
            TemplateSectionItem templateSectionItem = templateItem.GetSection(sectionInformation.Section.Name);

            if (templateSectionItem != null)
            {
                MoveFields(templateSectionItem, fields);
            }
            else
            {
                Item sectionItemCopy = sectionInformation.Section.CopyTo(baseTemplate, sectionInformation.Section.Name, ID.NewID, false);
                MoveFields(sectionItemCopy, fields);
            }

            if (!sectionInformation.Section.GetChildren().Any())
            {
                sectionInformation.Section.Delete();
            }
        }
Ejemplo n.º 28
0
        private void Run()
        {
            //<snippet1>
            Configuration machine = ConfigurationManager.OpenMachineConfiguration();
            //<snippet5>
            // Register our validator configuration element.
            ExtensionsSection extensions
                = machine.GetSection(@"system.serviceModel/extensions") as ExtensionsSection;

            if (extensions == null)
            {
                throw new Exception("not extensions section.");
            }
            ExtensionElement validator
                = new ExtensionElement(
                      "internetClientValidator",
                      "Microsoft.ServiceModel.Samples.InternetClientValidatorElement, InternetClientValidator, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
                      );

            validator.LockItem = true;
            if (extensions.BehaviorExtensions.IndexOf(validator) < 0)
            {
                extensions.BehaviorExtensions.Add(validator);
            }
            //</snippet5>

            //<snippet6>
            // Add a new section for our validator and lock it down.
            // Behaviors for client applications must be endpoint behaviors.
            // Behaviors for service applications must be service behaviors.
            CommonBehaviorsSection commonBehaviors
                = machine.GetSection(@"system.serviceModel/commonBehaviors") as CommonBehaviorsSection;
            InternetClientValidatorElement internetValidator = new InternetClientValidatorElement();

            internetValidator.LockItem = true;
            commonBehaviors.EndpointBehaviors.Add(internetValidator);
            //</snippet6>
            //<snippet7>
            // Write to disk.
            machine.SaveAs("newMachine.config");

            // Write our new information.
            SectionInformation cBInfo = commonBehaviors.SectionInformation;

            Console.WriteLine(cBInfo.GetRawXml());
            Console.WriteLine(extensions.SectionInformation.GetRawXml());
            Console.Read();
            //</snippet7>
            //</snippet1>

            /*
             * //<snippet4>
             * <extensions>
             * <behaviorExtensions>
             * <add
             *  name="internetClientValidator"
             *  type="Microsoft.ServiceModel.Samples.InternetClientValidatorElement, InternetClientValidator, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
             *  lockItem="true" />
             * </behaviorExtensions>
             * </extensions>
             * <commonBehaviors>
             * <endpointBehaviors>
             * <internetClientValidator lockItem="true" />
             * </endpointBehaviors>
             * </commonBehaviors>
             * //</snippet4>
             *
             */
        }
Ejemplo n.º 29
0
        public Overlay(UInt32 entryPoint, IReadOnlyList <byte> overlayData, Options options = null, IEnumerable <KeyValuePair <UInt32, string> > extraSymbols = null)
        {
            options = options ?? new Options();

            EntryPoint    = entryPoint;
            _extraSymbols = extraSymbols ?? new KeyValuePair <UInt32, string> [0];

            var headerOffset = HeaderOffset = Utilities.ReadU32(overlayData, overlayData.Count - sizeof(UInt32));
            var headerStart  = overlayData.Count - (int)headerOffset;
            var sectionPtr   = 0u;

            var sections = Enumerable.Range(0, SectionCount)
                           .Select((i, idx) =>
            {
                var size = Utilities.ReadU32(overlayData, headerStart + i * 4);
                var rval = new SectionInformation(
                    i,
                    SectionNames[i],
                    new ListSegment <byte>(overlayData, (int)sectionPtr, (int)size),
                    entryPoint + sectionPtr +
                    // The BSS section appears to be offset by the size of the header / relocations
                    // section. Here, we add the size of the header to the start of the bss.
                    (uint)(idx == 3 ? headerOffset : 0),
                    size
                    );

                sectionPtr += size;

                return(rval);
            })
                           .ToList();

            var relocationCount = Utilities.ReadU32(overlayData, headerStart + SectionCount * 4);

            var relocations = Enumerable.Range(0, (int)relocationCount)
                              .Select((i, _) => new Relocation(Utilities.ReadU32(overlayData, headerStart + HeaderSize + i * 4), this, 0))
                              .OrderBy(r => r.SectionId)
                              .ToList();

            Sections    = sections;
            Relocations = new OverlayRelocations(relocations);



            var hiLoRelocs = relocations
                             .Where(r => r.Type == RelocationType.R_MIPS_HI16 || r.Type == RelocationType.R_MIPS_LO16)
                             .ToArray();

            Relocation lastHi16 = null;

            foreach (var r in hiLoRelocs)
            {
                if (r.Type == RelocationType.R_MIPS_HI16)
                {
                    lastHi16 = r;
                }
                else
                {
                    if (lastHi16 == null)
                    {
                        throw new RelocationException(
                                  $"Relocation `{r.ToShortString()}` has no preceding R_MIPS_HI16.",
                                  relocations,
                                  r.Location
                                  );
                    }


                    var address = ((IInternalRelocation)r).Address =
                        (UInt32)((new Instruction(lastHi16.Data).Immediate << 16) + new Instruction(r.Data).ImmediateSigned);

                    if (((IInternalRelocation)lastHi16).Sibling == null)
                    {
                        ((IInternalRelocation)lastHi16).Sibling = r;
                        ((IInternalRelocation)lastHi16).Address = address;
                    }

                    ((IInternalRelocation)r).Sibling = lastHi16;
                }
            }

            var textInsns = Sections[0].Data
                            .ToInstructions()
                            .ToArray();

            var fns = textInsns
                      .DiscoverFunctions(EntryPoint)
                      .ToArray();

            IEnumerable <Symbol> GenerateSymbols() =>
            Relocations
            .OrderBy(r => r.Address)
            .GroupBy(r => r.Address)
            .Select((g, i) => {
                var typeHint = g
                               .Select(t => t.TypeHint)
                               .Aggregate((t1, t2) => t1 | t2);

                return(options.NumberSymbols
                            ? new Symbol(g.Key, $"{Symbol.HintToName(typeHint)}_{i}", typeHint)
                            : new Symbol(g.Key, typeHint));
            })
            .Concat(
                textInsns
                .DiscoverBranchTargets(EntryPoint)
                .GroupBy(t => fns.First(f => t >= f.StartAddress && t < f.EndAddress).StartAddress)
                .SelectMany((g, outerI) => g.Select((b, i) => new Symbol(b, $"$L{outerI}_{i}", TypeHint.BranchTarget)))
                )
            .Concat(
                textInsns
                .DiscoverFunctionCalls(EntryPoint)
                .Where(f => f < EntryPoint)
                .Select(f =>
                        f < EntryPoint
                                ? new Symbol(f, string.Format("external_func_{0:X8}", f), TypeHint.Function, SymbolType.External)
                                : new Symbol(f, string.Format("func_{0:X8}", f), TypeHint.Function, SymbolType.External))
                )
            .Concat(
                _extraSymbols
                .Select(s => new Symbol(s.Key, s.Value, 0, SymbolType.External))
                );

            Symbols =
                new OverlaySymbols(
                    this,
                    GenerateSymbols(),
                    Sections[0]
                    );

            var extra = GenerateExtraSymbols(this, Symbols);

            Symbols = new OverlaySymbols(
                this,
                GenerateSymbols()
                .Select(x =>
            {
                if (extra.offsetSymbols.ContainsKey(x.Name))
                {
                    return(new Symbol(x.Address, extra.offsetSymbols[x.Name], x.TypeHint));
                }

                return(x);
            }),
                Sections[0]
                );

            try
            {
                for (var i = Relocations.Count - 1; i >= 0; i--)
                {
                    try
                    {
                        var o = Relocations[i].Address;
                    }
                    catch (Exception e)
                    {
                        throw new RelocationException(
                                  $"Error evaluating address for relocation {i} ({Relocations[i].ToShortString()})",
                                  e,
                                  relocations,
                                  Relocations[i].Location
                                  );
                    }
                }

                LinkerScript = string.Join(
                    Environment.NewLine,
                    new[]
                {
                    string.Format("ADDRESS_START = 0x{0:X8};", EntryPoint),
                    "ENTRY_POINT = ADDRESS_START;"
                }.Concat(
                        extra.list
                        )
                    );
            }
            catch (RelocationException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new RelocationException("Error while evaluating relocation addresses and generating linker script", e, relocations);
            }
        }
Ejemplo n.º 30
0
 protected T LoadSection(SectionInformation information)
 {
     return(LoadSection <T>(information));
 }
Ejemplo n.º 31
0
 private void DoDeserializeSection(XmlReader reader)
 {
     reader.MoveToContent();
     SectionInformation.SetRawXml(RawXml);
     DeserializeElement(reader, false);
 }
Ejemplo n.º 32
0
        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();
            }
        }