Exemplo n.º 1
0
        internal void Load(XPathNavigator nav)
        {
            Debug.Assert(nav != null, "nav should not be null");
            bool   foundPublishSettings = false;
            string name  = string.Empty;
            string value = string.Empty;

            nav.MoveToFirstChild();

            if (nav.Name != ProfileRootNode)
            {
                throw new XmlException(string.Format("Expected root node to be '{0}'", ProfileRootNode));
            }

            bool fContinue = nav.MoveToFirstChild();

            if (nav.Name != ProfileNode)
            {
                throw new XmlException(string.Format("Expected first child node to be '{0}'", ProfileNode));
            }

            while (fContinue)
            {
                string publishMethod = nav.GetAttribute(PublishMethod, string.Empty);

                if (string.Equals(publishMethod, "MSDeploy", StringComparison.OrdinalIgnoreCase))
                {
                    bool hasMoreAttributes = nav.MoveToFirstAttribute();

                    while (hasMoreAttributes)
                    {
                        if (string.Equals(nav.Name, "publishUrl", StringComparison.OrdinalIgnoreCase))
                        {
                            _publishUrlRaw = nav.Value;
                        }
                        else if (string.Equals(nav.Name, "msdeploySite", StringComparison.OrdinalIgnoreCase))
                        {
                            _siteName = nav.Value;
                        }
                        else if (string.Equals(nav.Name, "userName", StringComparison.OrdinalIgnoreCase))
                        {
                            _userName = nav.Value;
                        }
                        else if (string.Equals(nav.Name, "userPWD", StringComparison.OrdinalIgnoreCase))
                        {
                            _password = nav.Value;
                        }
                        else if (string.Equals(nav.Name, "destinationAppUrl", StringComparison.OrdinalIgnoreCase))
                        {
                            _destinationAppUrl = nav.Value;
                        }
                        else if (string.Equals(nav.Name, "agentType", StringComparison.OrdinalIgnoreCase))
                        {
                            string agentType = nav.Value;
                            try
                            {
                                _agentType = (PublishSettingsRemoteAgent)Enum.Parse(typeof(PublishSettingsRemoteAgent), agentType, true);
                            }
                            catch (ArgumentException ex)
                            {
                                throw new XmlException(
                                          string.Format("Invalid agent type.  Valid options are '{0}'",
                                                        string.Join(", ", Enum.GetNames(typeof(PublishSettingsRemoteAgent)))),
                                          ex);
                            }
                        }
                        else if (string.Equals(nav.Name, "SQLServerDBConnectionString", StringComparison.OrdinalIgnoreCase))
                        {
                            _sqlDbConnectionString = nav.Value;
                        }
                        else if (string.Equals(nav.Name, "mySQLDBConnectionString", StringComparison.OrdinalIgnoreCase))
                        {
                            _mysqlDbConnectionString = nav.Value;
                        }
                        else if (string.Equals(nav.Name, "msdeployAllowUntrustedCertificate", StringComparison.OrdinalIgnoreCase))
                        {
                            string allowUntrustedValue = nav.Value;
                            _allowUntrusted = string.Equals(allowUntrustedValue, "true", StringComparison.OrdinalIgnoreCase) ? true : false;
                        }
                        else if (string.Equals(nav.Name, "useNTLM", StringComparison.OrdinalIgnoreCase))
                        {
                            string useNTLM = nav.Value;
                            if (!string.IsNullOrEmpty(useNTLM))
                            {
                                _useNTLM = Convert.ToBoolean(useNTLM);
                            }

                            // User didn't specify a value so we'll automatically figure it out a little later based on agent type.
                        }
                        else if (!string.Equals(nav.Name, PublishMethod, StringComparison.OrdinalIgnoreCase))
                        {
                            OtherAttributes.Add(nav.Name, nav.Value);
                        }

                        hasMoreAttributes = nav.MoveToNextAttribute();
                    }

                    // Move to the publishProfile node
                    nav.MoveToParent();
                    if (nav.MoveToFirstChild())
                    {
                        do
                        {
                            if (string.Equals(nav.Name, "databases", StringComparison.OrdinalIgnoreCase))
                            {
                                AddDatabases(Databases, nav);
                            }
                        } while (nav.MoveToNext());

                        // Move to publishProfile node
                        nav.MoveToParent();
                    }

                    foundPublishSettings = true;
                    break;
                }

                //move to next publishprofile node
                fContinue = nav.MoveToNext();
            }

            if (!foundPublishSettings)
            {
                throw new XmlException("Could not find MSDeploy publish settings");
            }
        }
        internal void Load(XPathNavigator nav)
        {
            Debug.Assert(nav != null, "nav should not be null");
            bool foundPublishSettings = false;
            string name = string.Empty;
            string value = string.Empty;

            nav.MoveToFirstChild();

            if (nav.Name != ProfileRootNode)
            {
                throw new XmlException(string.Format("Expected root node to be '{0}'", ProfileRootNode));
            }

            bool fContinue = nav.MoveToFirstChild();

            if (nav.Name != ProfileNode)
            {
                throw new XmlException(string.Format("Expected first child node to be '{0}'", ProfileNode));
            }

            while (fContinue)
            {
                string publishMethod = nav.GetAttribute(PublishMethod, string.Empty);

                if (string.Equals(publishMethod, "MSDeploy", StringComparison.OrdinalIgnoreCase))
                {
                    bool hasMoreAttributes = nav.MoveToFirstAttribute();

                    while (hasMoreAttributes)
                    {
                        if (string.Equals(nav.Name, "publishUrl", StringComparison.OrdinalIgnoreCase))
                        {
                            _publishUrlRaw = nav.Value;
                        }
                        else if (string.Equals(nav.Name, "msdeploySite", StringComparison.OrdinalIgnoreCase))
                        {
                            _siteName = nav.Value;
                        }
                        else if (string.Equals(nav.Name, "userName", StringComparison.OrdinalIgnoreCase))
                        {
                            _userName = nav.Value;
                        }
                        else if (string.Equals(nav.Name, "userPWD", StringComparison.OrdinalIgnoreCase))
                        {
                            _password = nav.Value;
                        }
                        else if (string.Equals(nav.Name, "destinationAppUrl", StringComparison.OrdinalIgnoreCase))
                        {
                            _destinationAppUrl = nav.Value;
                        }
                        else if (string.Equals(nav.Name, "agentType", StringComparison.OrdinalIgnoreCase))
                        {
                            string agentType = nav.Value;
                            try
                            {
                                _agentType = (PublishSettingsRemoteAgent)Enum.Parse(typeof(PublishSettingsRemoteAgent), agentType, true);
                            }
                            catch (ArgumentException ex)
                            {
                                throw new XmlException(
                                    string.Format("Invalid agent type.  Valid options are '{0}'",
                                                  string.Join(", ", Enum.GetNames(typeof(PublishSettingsRemoteAgent)))),
                                    ex);
                            }
                        }
                        else if (string.Equals(nav.Name, "SQLServerDBConnectionString", StringComparison.OrdinalIgnoreCase))
                        {
                            _sqlDbConnectionString = nav.Value;
                        }
                        else if (string.Equals(nav.Name, "mySQLDBConnectionString", StringComparison.OrdinalIgnoreCase))
                        {
                            _mysqlDbConnectionString = nav.Value;
                        }
                        else if (string.Equals(nav.Name, "msdeployAllowUntrustedCertificate", StringComparison.OrdinalIgnoreCase))
                        {
                            string allowUntrustedValue = nav.Value;
                            _allowUntrusted = string.Equals(allowUntrustedValue, "true", StringComparison.OrdinalIgnoreCase) ? true : false;
                        }
                        else if (string.Equals(nav.Name, "useNTLM", StringComparison.OrdinalIgnoreCase))
                        {
                            string useNTLM = nav.Value;
                            if (!string.IsNullOrEmpty(useNTLM))
                            {
                                _useNTLM = Convert.ToBoolean(useNTLM);
                            }

                            // User didn't specify a value so we'll automatically figure it out a little later based on agent type.
                        }
                        else if (!string.Equals(nav.Name, PublishMethod, StringComparison.OrdinalIgnoreCase))
                        {
                            OtherAttributes.Add(nav.Name, nav.Value);
                        }

                        hasMoreAttributes = nav.MoveToNextAttribute();
                    }

                    // Move to the publishProfile node
                    nav.MoveToParent();
                    if (nav.MoveToFirstChild())
                    {
                        do
                        {
                            if (string.Equals(nav.Name, "databases", StringComparison.OrdinalIgnoreCase))
                            {
                                AddDatabases(Databases, nav);
                            }
                        } while (nav.MoveToNext());

                        // Move to publishProfile node
                        nav.MoveToParent();
                    }

                    foundPublishSettings = true;
                    break;
                }

                //move to next publishprofile node
                fContinue = nav.MoveToNext();
            }

            if (!foundPublishSettings)
            {
                throw new XmlException("Could not find MSDeploy publish settings");
            }
        }