Exemple #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);
        }
Exemple #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);
                        }
                    }
                }
            }
        }
Exemple #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);
            }
        }
Exemple #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);
            }
        }
Exemple #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);
        }
        /// <summary>
        /// Updates the web.config as necessary to permit the generated domain service to be found.
        /// </summary>
        private void UpdateConfiguration()
        {
            // There is no work to do unless the user has selected some context
            // and chosen to expose the DomainService via [EnableClientAccess] or
            // to expose an OData endpoint.
            if (!this._isClientAccessEnabled && !this._isODataEndpointEnabled)
            {
                return;
            }

            // Get active project.  Throws if not available.
            Project project = this.ActiveProject;

            // Get hierarchy.  Throws if not available.
            IVsHierarchy vsHierarchy = this.GetVsHierarchy(project);

            IVsApplicationConfigurationManager cfgMgr = this.GetService(typeof(IVsApplicationConfigurationManager)) as IVsApplicationConfigurationManager;
            if (cfgMgr == null)
            {
                this.TerminateWizard(Resources.BusinessLogicClass_Error_No_ConfigurationManager);
            }

            // Return the current application's configuration file by using 
            // the IVsApplicationConfiguration APIs. Make sure that the 
            // instance that is returned is disposed of correctly in order 
            // to clean up any event hooks or docdatas.
            // Note that this interface is aware of source control and text buffers, so it
            // works even if the file is currently open and modified.
            using (IVsApplicationConfiguration appCfg = cfgMgr.GetApplicationConfiguration(vsHierarchy, Microsoft.VisualStudio.VSConstants.VSITEMID_ROOT))
            {
                // Do not do anything unless the file already exists, else we will create an empty one
                if (appCfg != null && appCfg.FileExists())
                {
                    System.Configuration.Configuration cfg = appCfg.LoadConfiguration();
                    if (cfg != null)
                    {
                        WebConfigUtil webConfigUtil = new WebConfigUtil(cfg);

                        // First check whether any work needs to done
                        bool addHttpModule = webConfigUtil.DoWeNeedToAddHttpModule();
                        bool addModuleToWebServer = webConfigUtil.DoWeNeedToAddModuleToWebServer();
                        bool setAspNetCompatiblity = !webConfigUtil.IsAspNetCompatibilityEnabled();
                        bool setMultipleSiteBindingsEnabled = !webConfigUtil.IsMultipleSiteBindingsEnabled();
                        bool addValidationSection = webConfigUtil.DoWeNeedToValidateIntegratedModeToWebServer();
                        bool addODataEndpoint = this._isODataEndpointEnabled && !webConfigUtil.IsEndpointDeclared(BusinessLogicClassConstants.ODataEndpointName);

                        // Modify the file only if we decided work is required
                        if (addHttpModule || addModuleToWebServer || setAspNetCompatiblity || setMultipleSiteBindingsEnabled || addValidationSection || addODataEndpoint)
                        {
                            string domainServiceFactoryName = WebConfigUtil.GetDomainServiceModuleTypeName();

                            // Check the file out from Source Code Control if it exists.
                            appCfg.QueryEditConfiguration();

                            if (addHttpModule)
                            {
                                webConfigUtil.AddHttpModule(domainServiceFactoryName);
                            }

                            if (addModuleToWebServer)
                            {
                                webConfigUtil.AddModuleToWebServer(domainServiceFactoryName);
                            }

                            if (setAspNetCompatiblity)
                            {
                                webConfigUtil.SetAspNetCompatibilityEnabled(true);
                            }

                            if (setMultipleSiteBindingsEnabled)
                            {
                                webConfigUtil.SetMultipleSiteBindingsEnabled(true);
                            }

                            if (addValidationSection)
                            {
                                webConfigUtil.AddValidateIntegratedModeToWebServer();
                            }

                            if (addODataEndpoint)
                            {
                                string odataEndpointFactoryName = WebConfigUtil.GetODataEndpointFactoryTypeName();
                                webConfigUtil.AddEndpointDeclaration(BusinessLogicClassConstants.ODataEndpointName, odataEndpointFactoryName);
                            }
                            cfg.Save();
                        }
                    }
                }
            }
        }
        public void RunFinished()
        {
            IOleServiceProvider oleServiceProvider = this.Dte2 as IOleServiceProvider;
            IVsApplicationConfigurationManager cfgMgr = null;
            IVsHierarchy vsHierarchy = null;

            using (ServiceProvider sp = new ServiceProvider(oleServiceProvider))
            {
                // Get the solution 
                IVsSolution sln = sp.GetService(typeof(IVsSolution)) as IVsSolution;
                if (sln == null)
                {
                    return;
                }

                cfgMgr = sp.GetService(typeof(IVsApplicationConfigurationManager)) as IVsApplicationConfigurationManager;
                if (cfgMgr == null)
                {
                    return;
                }

                int result = sln.GetProjectOfUniqueName(this._project.UniqueName, out vsHierarchy);
                if (result != 0 || vsHierarchy == null)
                {
                    return;
                }
            }

            // Return the current application's configuration file by using 
            // the IVsApplicationConfiguration APIs. Make sure that the 
            // instance that is returned is disposed of correctly in order 
            // to clean up any event hooks or docdatas.
            // Note that this interface is aware of source control and text buffers, so it
            // works even if the file is currently open and modified.
            using (IVsApplicationConfiguration appCfg = cfgMgr.GetApplicationConfiguration(vsHierarchy, Microsoft.VisualStudio.VSConstants.VSITEMID_ROOT))
            {
                // Do not do anything unless the file already exists, else we will create an empty one
                if (appCfg != null && appCfg.FileExists())
                {
                    System.Configuration.Configuration cfg = appCfg.LoadConfiguration();
                    if (cfg != null)
                    {
                        WebConfigUtil webConfigUtil = new WebConfigUtil(cfg);

                        // First check whether any work needs to done
                        bool addHttpModule = webConfigUtil.DoWeNeedToAddHttpModule();
                        bool addModuleToWebServer = webConfigUtil.DoWeNeedToAddModuleToWebServer();
                        bool setAspNetCompatiblity = !webConfigUtil.IsAspNetCompatibilityEnabled();
                        bool setMultipleSiteBindingsEnabled = !webConfigUtil.IsMultipleSiteBindingsEnabled();
                        bool addValidationSection = webConfigUtil.DoWeNeedToValidateIntegratedModeToWebServer();

                        // Modify the file only if we decided work is required
                        if (addHttpModule || addModuleToWebServer || setAspNetCompatiblity || setMultipleSiteBindingsEnabled || addValidationSection)
                        {
                            string domainServiceModuleName = WebConfigUtil.GetDomainServiceModuleTypeName();

                            // Check the file out from Source Code Control if it exists.
                            appCfg.QueryEditConfiguration();

                            if (addHttpModule)
                            {
                                webConfigUtil.AddHttpModule(domainServiceModuleName);
                            }

                            if (addModuleToWebServer)
                            {
                                webConfigUtil.AddModuleToWebServer(domainServiceModuleName);
                            }

                            if (setAspNetCompatiblity)
                            {
                                webConfigUtil.SetAspNetCompatibilityEnabled(true);
                            }

                            if (setMultipleSiteBindingsEnabled)
                            {
                                webConfigUtil.SetMultipleSiteBindingsEnabled(true);
                            }

                            if (addValidationSection)
                            {
                                webConfigUtil.AddValidateIntegratedModeToWebServer();
                            }

                            cfg.Save();
                        }
                    }
                }
            }
        }
Exemple #8
0
        /// <summary>
        /// Updates the web.config as necessary to permit the generated domain service to be found.
        /// </summary>
        private void UpdateConfiguration()
        {
            // There is no work to do unless the user has selected some context
            // and chosen to expose the DomainService via [EnableClientAccess] or
            // to expose an OData endpoint.
            if (!this._isClientAccessEnabled && !this._isODataEndpointEnabled)
            {
                return;
            }

            // Get active project.  Throws if not available.
            Project project = this.ActiveProject;

            // Get hierarchy.  Throws if not available.
            IVsHierarchy vsHierarchy = this.GetVsHierarchy(project);

            IVsApplicationConfigurationManager cfgMgr = this.GetService(typeof(IVsApplicationConfigurationManager)) as IVsApplicationConfigurationManager;

            if (cfgMgr == null)
            {
                this.TerminateWizard(Resources.BusinessLogicClass_Error_No_ConfigurationManager);
            }

            // Return the current application's configuration file by using
            // the IVsApplicationConfiguration APIs. Make sure that the
            // instance that is returned is disposed of correctly in order
            // to clean up any event hooks or docdatas.
            // Note that this interface is aware of source control and text buffers, so it
            // works even if the file is currently open and modified.
            using (IVsApplicationConfiguration appCfg = cfgMgr.GetApplicationConfiguration(vsHierarchy, Microsoft.VisualStudio.VSConstants.VSITEMID_ROOT))
            {
                // Do not do anything unless the file already exists, else we will create an empty one
                if (appCfg != null && appCfg.FileExists())
                {
                    System.Configuration.Configuration cfg = appCfg.LoadConfiguration();
                    if (cfg != null)
                    {
                        WebConfigUtil webConfigUtil = new WebConfigUtil(cfg);

                        // First check whether any work needs to done
                        bool addHttpModule                  = webConfigUtil.DoWeNeedToAddHttpModule();
                        bool addModuleToWebServer           = webConfigUtil.DoWeNeedToAddModuleToWebServer();
                        bool setAspNetCompatiblity          = !webConfigUtil.IsAspNetCompatibilityEnabled();
                        bool setMultipleSiteBindingsEnabled = !webConfigUtil.IsMultipleSiteBindingsEnabled();
                        bool addValidationSection           = webConfigUtil.DoWeNeedToValidateIntegratedModeToWebServer();
                        bool addODataEndpoint               = this._isODataEndpointEnabled && !webConfigUtil.IsEndpointDeclared(BusinessLogicClassConstants.ODataEndpointName);

                        // Modify the file only if we decided work is required
                        if (addHttpModule || addModuleToWebServer || setAspNetCompatiblity || setMultipleSiteBindingsEnabled || addValidationSection || addODataEndpoint)
                        {
                            string domainServiceFactoryName = WebConfigUtil.GetDomainServiceModuleTypeName();

                            // Check the file out from Source Code Control if it exists.
                            appCfg.QueryEditConfiguration();

                            if (addHttpModule)
                            {
                                webConfigUtil.AddHttpModule(domainServiceFactoryName);
                            }

                            if (addModuleToWebServer)
                            {
                                webConfigUtil.AddModuleToWebServer(domainServiceFactoryName);
                            }

                            if (setAspNetCompatiblity)
                            {
                                webConfigUtil.SetAspNetCompatibilityEnabled(true);
                            }

                            if (setMultipleSiteBindingsEnabled)
                            {
                                webConfigUtil.SetMultipleSiteBindingsEnabled(true);
                            }

                            if (addValidationSection)
                            {
                                webConfigUtil.AddValidateIntegratedModeToWebServer();
                            }

                            if (addODataEndpoint)
                            {
                                string odataEndpointFactoryName = WebConfigUtil.GetODataEndpointFactoryTypeName();
                                webConfigUtil.AddEndpointDeclaration(BusinessLogicClassConstants.ODataEndpointName, odataEndpointFactoryName);
                            }
                            cfg.Save();
                        }
                    }
                }
            }
        }
        public void RunFinished()
        {
            IOleServiceProvider oleServiceProvider    = this.Dte2 as IOleServiceProvider;
            IVsApplicationConfigurationManager cfgMgr = null;
            IVsHierarchy vsHierarchy = null;

            using (ServiceProvider sp = new ServiceProvider(oleServiceProvider))
            {
                // Get the solution
                IVsSolution sln = sp.GetService(typeof(IVsSolution)) as IVsSolution;
                if (sln == null)
                {
                    return;
                }

                cfgMgr = sp.GetService(typeof(IVsApplicationConfigurationManager)) as IVsApplicationConfigurationManager;
                if (cfgMgr == null)
                {
                    return;
                }

                int result = sln.GetProjectOfUniqueName(this._project.UniqueName, out vsHierarchy);
                if (result != 0 || vsHierarchy == null)
                {
                    return;
                }
            }

            // Return the current application's configuration file by using
            // the IVsApplicationConfiguration APIs. Make sure that the
            // instance that is returned is disposed of correctly in order
            // to clean up any event hooks or docdatas.
            // Note that this interface is aware of source control and text buffers, so it
            // works even if the file is currently open and modified.
            using (IVsApplicationConfiguration appCfg = cfgMgr.GetApplicationConfiguration(vsHierarchy, Microsoft.VisualStudio.VSConstants.VSITEMID_ROOT))
            {
                // Do not do anything unless the file already exists, else we will create an empty one
                if (appCfg != null && appCfg.FileExists())
                {
                    System.Configuration.Configuration cfg = appCfg.LoadConfiguration();
                    if (cfg != null)
                    {
                        WebConfigUtil webConfigUtil = new WebConfigUtil(cfg);

                        // First check whether any work needs to done
                        bool addHttpModule                  = webConfigUtil.DoWeNeedToAddHttpModule();
                        bool addModuleToWebServer           = webConfigUtil.DoWeNeedToAddModuleToWebServer();
                        bool setAspNetCompatiblity          = !webConfigUtil.IsAspNetCompatibilityEnabled();
                        bool setMultipleSiteBindingsEnabled = !webConfigUtil.IsMultipleSiteBindingsEnabled();
                        bool addValidationSection           = webConfigUtil.DoWeNeedToValidateIntegratedModeToWebServer();

                        // Modify the file only if we decided work is required
                        if (addHttpModule || addModuleToWebServer || setAspNetCompatiblity || setMultipleSiteBindingsEnabled || addValidationSection)
                        {
                            string domainServiceModuleName = WebConfigUtil.GetDomainServiceModuleTypeName();

                            // Check the file out from Source Code Control if it exists.
                            appCfg.QueryEditConfiguration();

                            if (addHttpModule)
                            {
                                webConfigUtil.AddHttpModule(domainServiceModuleName);
                            }

                            if (addModuleToWebServer)
                            {
                                webConfigUtil.AddModuleToWebServer(domainServiceModuleName);
                            }

                            if (setAspNetCompatiblity)
                            {
                                webConfigUtil.SetAspNetCompatibilityEnabled(true);
                            }

                            if (setMultipleSiteBindingsEnabled)
                            {
                                webConfigUtil.SetMultipleSiteBindingsEnabled(true);
                            }

                            if (addValidationSection)
                            {
                                webConfigUtil.AddValidateIntegratedModeToWebServer();
                            }

                            cfg.Save();
                        }
                    }
                }
            }
        }