Beispiel #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);
        }
Beispiel #2
0
        /// <summary>
        /// Adds the specified endpoint to the "system.serviceModel/domainServices" endpoint collection.
        /// </summary>
        /// <param name="endpointName">The name of the new endpoint to add.</param>
        /// <param name="endpointFactoryTypeName">The fully qualified type name of the endpoint factory type.</param>
        public void AddEndpointDeclaration(string endpointName, string endpointFactoryTypeName)
        {
            Debug.Assert(!string.IsNullOrEmpty(endpointName), "endpointName cannot be empty");
            Debug.Assert(!string.IsNullOrEmpty(endpointFactoryTypeName), "endpointFactoryTypeName cannot be empty");

            if (!string.IsNullOrEmpty(endpointName) && !string.IsNullOrEmpty(endpointFactoryTypeName))
            {
                bool createdDomainServicesSection           = false;
                DomainServicesSection domainServicesSection = this.GetOrCreateDomainServicesSection(out createdDomainServicesSection);
                if (domainServicesSection != null)
                {
                    // If the DomainServicesSection existed, just add the new endpoint
                    if (!createdDomainServicesSection)
                    {
                        domainServicesSection.Endpoints.Add(new ProviderSettings(endpointName, endpointFactoryTypeName));
                    }
                    else
                    {
                        // However, if we created it manually, we need to insert the new endpoint manually,
                        // otherwise the configuration logic believes we are overriding the defaults
                        // and emits extra <remove> elements.
                        string rawXml = domainServicesSection.SectionInformation.GetRawXml();
                        if (string.IsNullOrEmpty(rawXml))
                        {
                            rawXml = "<domainServices><endpoints /></domainServices>";
                        }
                        XDocument xdoc = WebConfigUtil.CreateXDoc(rawXml);

                        XElement xelem         = xdoc.Element("domainServices");
                        XElement endpointsElem = xelem == null ? null : xelem.Element("endpoints");
                        if (endpointsElem != null)
                        {
                            // Add a new <add name="xxx" type="yyy" /> element to the endpoints collection
                            XElement newEndpointElem = new XElement("add");
                            newEndpointElem.Add(new XAttribute("name", endpointName));
                            newEndpointElem.Add(new XAttribute("type", endpointFactoryTypeName));
                            endpointsElem.Add(newEndpointElem);
                            rawXml = WebConfigUtil.CreateRawXml(xdoc);
                            domainServicesSection.SectionInformation.SetRawXml(rawXml);
                        }
                    }
                }
            }
        }
Beispiel #3
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);
            }
        }
Beispiel #4
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);
            }
        }
Beispiel #5
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);
        }