private static void CheckSessionState(string pathToConfig, IISServer server)
        {
            if (string.IsNullOrEmpty(pathToConfig))
            {
                return;
            }

            XmlDocument doc = new XmlDocument();
            try
            {
                doc.Load(pathToConfig);
                var xmlNodeList =
                    doc.SelectNodes(
                        "//*[local-name()='sessionState']");
                foreach (XmlNode node in xmlNodeList)
                {
                    foreach (XmlAttribute attrib in node.Attributes)
                    {
                        if (attrib.Name.Equals("mode") && !attrib.Value.Equals("InProc") && !attrib.Value.Equals("Off"))
                        {
                            string message = "";
                            if (attrib.Value.Equals("StateServer"))
                            {
                                message = string.Format("Session StateServer is not supported on Azure Web Apps");

                            }
                            else if (attrib.Value.Equals("SQLServer"))
                            {
                                message = string.Format("SQL Server session state needs to be configured separately");

                            }
                            else
                            {
                                message = string.Format("Custom session provider may or may not work on Azure Web Apps");

                            }
                            server.SchemaCheckErrors.Add(message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // dont throw. Its ok if we dont get default document list. Let migration continue
                MessageBox.Show(ex.ToString());
                TraceHelper.Tracer.WriteTrace(ex.ToString());
            }
        }
Пример #2
0
        private static void CheckSessionState(string pathToConfig, IISServer server)
        {
            if (string.IsNullOrEmpty(pathToConfig))
            {
                return;
            }

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(pathToConfig);
                var xmlNodeList =
                    doc.SelectNodes(
                        "//*[local-name()='sessionState']");
                foreach (XmlNode node in xmlNodeList)
                {
                    foreach (XmlAttribute attrib in node.Attributes)
                    {
                        if (attrib.Name.Equals("mode") && !attrib.Value.Equals("InProc") && !attrib.Value.Equals("Off"))
                        {
                            string message = "";
                            if (attrib.Value.Equals("StateServer"))
                            {
                                message = string.Format("Session StateServer is not supported on Azure Web Apps");
                            }
                            else if (attrib.Value.Equals("SQLServer"))
                            {
                                message = string.Format("SQL Server session state needs to be configured separately");
                            }
                            else
                            {
                                message = string.Format("Custom session provider may or may not work on Azure Web Apps");
                            }
                            server.SchemaCheckErrors.Add(message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // dont throw. Its ok if we dont get default document list. Let migration continue
                MessageBox.Show(ex.ToString());
                TraceHelper.Tracer.WriteTrace(ex.ToString());
            }
        }
 protected IISInfoReader(string migrationID, double iisVersion, string osVersion, string name)
 {
     _server = new IISServer(migrationID, iisVersion, osVersion, name);
 }
        private void CheckElements(string sectionPath, XmlDocument antaresDoc, XmlNode node, IISServer server)
        {
            var map = new ElementCountMap();

            foreach (XmlNode childNode in node.ChildNodes)
            {
                map.Add(childNode.Name);
            }

            foreach (XmlNode childNode in node.ChildNodes)
            {
                var  formatStrCollection = string.Empty;
                var  formatStr           = string.Empty;
                bool isCollection        = map[childNode.Name] > 1;
                if (sectionPath.StartsWith("configSchema/"))
                {
                    formatStr = ElementFormat;
                    if (childNode.Name.Equals("clear"))
                    {
                        formatStrCollection = ElementCollectionClearFormat;
                    }
                    else if (childNode.Name.Equals("remove"))
                    {
                        formatStrCollection = ElementCollectionRemoveFormat;
                    }
                    else
                    {
                        formatStrCollection = ElementCollectionFormat;
                    }
                }
                else
                {
                    if (childNode.Name.Equals("clear"))
                    {
                        formatStrCollection = RootedElementCollectionClearFormat;
                    }
                    else if (childNode.Name.Equals("remove"))
                    {
                        formatStrCollection = RootedElementCollectionRemoveFormat;
                    }
                    else
                    {
                        formatStrCollection = RootedElementCollectionFormat;
                    }
                    formatStr = RootedElementFormat;
                }

                var childSectionPath       = string.Empty;
                var childSectionPathSingle = string.Format(formatStr, sectionPath, childNode.Name);
                var childSectionPathColl   = string.Format(formatStrCollection, sectionPath, childNode.Name);
                var sectionFound           = false;
                if (antaresDoc.SelectNodes(childSectionPathSingle).Count > 0)
                {
                    sectionFound     = true;
                    childSectionPath = childSectionPathSingle;
                }
                else if (antaresDoc.SelectNodes(childSectionPathColl).Count > 0)
                {
                    sectionFound     = true;
                    childSectionPath = childSectionPathColl;
                }

                if (sectionFound)
                {
                    CheckAttributes(childSectionPath, antaresDoc, childNode, server);
                    CheckElements(childSectionPath, antaresDoc, childNode, server);
                }
                else
                {
                    var message = string.Format("Missing element {0} for path {1}", childNode.Name, childSectionPath);
                    server.SchemaCheckErrors.Add(message);
                }
            }
        }
        private void CheckAttributes(string sectionPath, XmlDocument antaresDoc, XmlNode node, IISServer server)
        {
            foreach (XmlAttribute attribute in node.Attributes)
            {
                var formatStr = string.Empty;
                if (sectionPath.StartsWith("configSchema/"))
                {
                    formatStr = AttributeFormat;
                }
                else
                {
                    formatStr = RootedAttributeFormat;
                }

                string attributeSectionPath = string.Format(formatStr, sectionPath, attribute.Name);
                if (antaresDoc.SelectNodes(attributeSectionPath).Count < 1 && !attribute.Name.Equals("lockAttributes"))
                {
                    string message = string.Format("Attribute {0} not supported for {1}", attribute.Name, sectionPath);
                    server.SchemaCheckErrors.Add(message);
                }
            }
        }
        private void CheckConfig(IISServer server, RemoteSystemInfo remoteSystemInfo)
        {
            string configSectionName = "configSections";
            string ftpServerSection  = "system.ftpServer";
            string NameAttribute     = "name";
            string xpathFormat       = "configuration/";

            var antaresSchema = new XmlDocument();

            antaresSchema.Load(Assembly.GetExecutingAssembly()
                               .GetManifestResourceStream("CompatCheckAndMigrate.Resources.IIS_MergedSchema.xml"));
            var customerAppHost = new XmlDocument();

            var userApphostConfig = Path.Combine(Environment.SystemDirectory,
                                                 @"inetsrv\config\applicationhost.config");

            if (remoteSystemInfo != null)
            {
                userApphostConfig = remoteSystemInfo.RemoteAppHostConfigPath;
            }
            customerAppHost.Load(userApphostConfig);

            var antaresConfigSections = new HashSet <string>(StringComparer.Ordinal);

            XmlNodeList nodes = antaresSchema.SelectNodes("configSchema/sectionSchema");

            foreach (XmlNode node in nodes)
            {
                antaresConfigSections.Add(node.Attributes[NameAttribute].Value);
            }

            var customerConfigSections = new List <string>();

            nodes = customerAppHost.SelectNodes("//section");
            foreach (XmlNode node in nodes)
            {
                XmlNode tempNode    = node;
                string  sectionPath = tempNode.Attributes[NameAttribute].Value;
                while (!string.Equals(tempNode.ParentNode.Name, configSectionName, StringComparison.OrdinalIgnoreCase))
                {
                    tempNode    = tempNode.ParentNode;
                    sectionPath = tempNode.Attributes[NameAttribute].Value + "/" + sectionPath;
                }

                if (!sectionPath.StartsWith(ftpServerSection, StringComparison.OrdinalIgnoreCase))
                {
                    customerConfigSections.Add(sectionPath);
                }
            }

            foreach (string customerSection in customerConfigSections)
            {
                if (!antaresConfigSections.Contains(customerSection))
                {
                    string message = string.Format("Section definition not supported for {0}", customerSection);
                    server.SchemaCheckErrors.Add(message);
                }

                var nodeList = customerAppHost.SelectNodes(string.Concat(xpathFormat, customerSection));
                foreach (XmlNode node in nodeList)
                {
                    CheckAttributes(customerSection, antaresSchema, node, server);
                    CheckElements(customerSection, antaresSchema, node, server);
                }
            }
        }
        private void CheckElements(string sectionPath, XmlDocument antaresDoc, XmlNode node, IISServer server)
        {
            var map = new ElementCountMap();
            foreach (XmlNode childNode in node.ChildNodes)
            {
                map.Add(childNode.Name);
            }

            foreach (XmlNode childNode in node.ChildNodes)
            {
                var formatStrCollection = string.Empty;
                var formatStr = string.Empty;
                bool isCollection = map[childNode.Name] > 1;
                if (sectionPath.StartsWith("configSchema/"))
                {
                    formatStr = ElementFormat;
                    if (childNode.Name.Equals("clear"))
                    {
                        formatStrCollection = ElementCollectionClearFormat;
                    }
                    else if (childNode.Name.Equals("remove"))
                    {
                        formatStrCollection = ElementCollectionRemoveFormat;
                    }
                    else
                    {
                        formatStrCollection = ElementCollectionFormat;
                    }
                }
                else
                {
                    if (childNode.Name.Equals("clear"))
                    {
                        formatStrCollection = RootedElementCollectionClearFormat;
                    }
                    else if (childNode.Name.Equals("remove"))
                    {
                        formatStrCollection = RootedElementCollectionRemoveFormat;
                    }
                    else
                    {
                        formatStrCollection = RootedElementCollectionFormat;
                    }
                    formatStr = RootedElementFormat;
                }

                var childSectionPath = string.Empty;
                var childSectionPathSingle = string.Format(formatStr, sectionPath, childNode.Name);
                var childSectionPathColl = string.Format(formatStrCollection, sectionPath, childNode.Name);
                var sectionFound = false;
                if (antaresDoc.SelectNodes(childSectionPathSingle).Count > 0)
                {
                    sectionFound = true;
                    childSectionPath = childSectionPathSingle;
                }
                else if (antaresDoc.SelectNodes(childSectionPathColl).Count > 0)
                {
                    sectionFound = true;
                    childSectionPath = childSectionPathColl;
                }

                if (sectionFound)
                {
                    CheckAttributes(childSectionPath, antaresDoc, childNode, server);
                    CheckElements(childSectionPath, antaresDoc, childNode, server);
                }
                else
                {
                    var message = string.Format("Missing element {0} for path {1}", childNode.Name, childSectionPath);
                    server.SchemaCheckErrors.Add(message);
                }
            }
        }
        private void CheckConfig(IISServer server, RemoteSystemInfo remoteSystemInfo)
        {
            string configSectionName = "configSections";
            string ftpServerSection = "system.ftpServer";
            string NameAttribute = "name";
            string xpathFormat = "configuration/";

            var antaresSchema = new XmlDocument();
            antaresSchema.Load(Assembly.GetExecutingAssembly()
                            .GetManifestResourceStream("CompatCheckAndMigrate.Resources.IIS_MergedSchema.xml"));
            var customerAppHost = new XmlDocument();

            var userApphostConfig = Path.Combine(Environment.SystemDirectory,
                            @"inetsrv\config\applicationhost.config");
            if (remoteSystemInfo != null)
            {
                userApphostConfig = remoteSystemInfo.RemoteAppHostConfigPath;
            }
            customerAppHost.Load(userApphostConfig);

            var antaresConfigSections = new HashSet<string>(StringComparer.Ordinal);

            XmlNodeList nodes = antaresSchema.SelectNodes("configSchema/sectionSchema");
            foreach (XmlNode node in nodes)
            {
                antaresConfigSections.Add(node.Attributes[NameAttribute].Value);
            }

            var customerConfigSections = new List<string>();
            nodes = customerAppHost.SelectNodes("//section");
            foreach (XmlNode node in nodes)
            {
                XmlNode tempNode = node;
                string sectionPath = tempNode.Attributes[NameAttribute].Value;
                while (!string.Equals(tempNode.ParentNode.Name, configSectionName, StringComparison.OrdinalIgnoreCase))
                {
                    tempNode = tempNode.ParentNode;
                    sectionPath = tempNode.Attributes[NameAttribute].Value + "/" + sectionPath;
                }

                if (!sectionPath.StartsWith(ftpServerSection, StringComparison.OrdinalIgnoreCase))
                {
                    customerConfigSections.Add(sectionPath);
                }
            }

            foreach (string customerSection in customerConfigSections)
            {
                if (!antaresConfigSections.Contains(customerSection))
                {
                    string message = string.Format("Section definition not supported for {0}", customerSection);
                    server.SchemaCheckErrors.Add(message);
                }

                var nodeList = customerAppHost.SelectNodes(string.Concat(xpathFormat, customerSection));
                foreach (XmlNode node in nodeList)
                {
                    CheckAttributes(customerSection, antaresSchema, node, server);
                    CheckElements(customerSection, antaresSchema, node, server);
                }
            }
        }
        private void CheckAttributes(string sectionPath, XmlDocument antaresDoc, XmlNode node, IISServer server)
        {
            foreach (XmlAttribute attribute in node.Attributes)
            {
                var formatStr = string.Empty;
                if (sectionPath.StartsWith("configSchema/"))
                {
                    formatStr = AttributeFormat;
                }
                else
                {
                    formatStr = RootedAttributeFormat;
                }

                string attributeSectionPath = string.Format(formatStr, sectionPath, attribute.Name);
                if (antaresDoc.SelectNodes(attributeSectionPath).Count < 1 && !attribute.Name.Equals("lockAttributes"))
                {
                    string message = string.Format("Attribute {0} not supported for {1}", attribute.Name, sectionPath);
                    server.SchemaCheckErrors.Add(message);
                }
            }
        }
 protected IISInfoReader(string migrationID, double iisVersion, string osVersion, string name)
 {
     _server = new IISServer(migrationID, iisVersion, osVersion, name);
 }