Пример #1
0
        /// <summary>
        /// Store the deployment location as a node in the given XML document
        /// </summary>
        /// <param name="config">The XML document</param>
        /// <param name="root">The node in which to store the element</param>
        /// <param name="id">The id of the element to create</param>
        /// <returns>Returns the node that was added or the one that
        /// already existed in the document.</returns>
        /// <remarks>The deployment location is stored in an element called
        /// <b>deploymentLocation</b> with two attributes (<b>id</b> matching
        /// the specified id and <b>location</b>) and nested
        /// <b>userCredentials</b> and <b>proxyCredentials</b> elements.  It
        /// is created if it does not already exist.</remarks>
        public XmlNode ToXml(XmlDocument config, XmlNode root, string id)
        {
            XmlNode      node;
            XmlAttribute attr;

            if (root == null)
            {
                throw new ArgumentNullException("root");
            }

            node = root.SelectSingleNode("deploymentLocation[@id='" +
                                         id + "']");

            if (node == null)
            {
                node = config.CreateNode(XmlNodeType.Element,
                                         "deploymentLocation", null);
                root.AppendChild(node);

                attr       = config.CreateAttribute("id");
                attr.Value = id;
                node.Attributes.Append(attr);
                attr = config.CreateAttribute("location");
                node.Attributes.Append(attr);
            }

            node.Attributes["location"].Value = (location == null) ?
                                                String.Empty : location.OriginalString;

            userCreds.ToXml(config, node);
            proxyCreds.ToXml(config, node);

            return(node);
        }
Пример #2
0
        /// <summary>
        /// Validate the configuration and save it
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            XmlAttribute attr;
            XmlNode root, node;
            UserCredentials userCreds;
            ProxyCredentials proxyCreds;
            bool isValid = true;
            Uri ajaxDoc = null, proxyServer = null;

            txtAjaxDocUrl.Text = txtAjaxDocUrl.Text.Trim();
            txtProjectName.Text = txtProjectName.Text.Trim();
            txtUserName.Text = txtUserName.Text.Trim();
            txtPassword.Text = txtPassword.Text.Trim();
            txtProxyServer.Text = txtProxyServer.Text.Trim();
            txtProxyUserName.Text = txtProxyUserName.Text.Trim();
            txtProxyPassword.Text = txtProxyPassword.Text.Trim();
            epErrors.Clear();

            if(txtAjaxDocUrl.Text.Length == 0)
            {
                epErrors.SetError(txtAjaxDocUrl, "An AjaxDoc URL is required");
                isValid = false;
            }
            else
                if(!Uri.TryCreate(txtAjaxDocUrl.Text, UriKind.RelativeOrAbsolute, out ajaxDoc))
                {
                    epErrors.SetError(txtAjaxDocUrl, "The AjaxDoc URL does not appear to be valid");
                    isValid = false;
                }

            if(txtProjectName.Text.Length == 0)
            {
                epErrors.SetError(txtProjectName, "A project filename is required");
                isValid = false;
            }

            if(!chkUseDefaultCredentials.Checked)
            {
                if(txtUserName.Text.Length == 0)
                {
                    epErrors.SetError(txtUserName, "A user name is required if not using default credentials");
                    isValid = false;
                }

                if(txtPassword.Text.Length == 0)
                {
                    epErrors.SetError(txtPassword, "A password is required if not using default credentials");
                    isValid = false;
                }
            }

            Uri.TryCreate(txtProxyServer.Text, UriKind.RelativeOrAbsolute, out proxyServer);

            if(chkUseProxyServer.Checked)
            {
                if(txtProxyServer.Text.Length == 0)
                {
                    epErrors.SetError(txtProxyServer, "A proxy server is required if one is used");
                    isValid = false;
                }
                else
                    if(proxyServer == null)
                    {
                        epErrors.SetError(txtProxyServer, "The proxy server name does not appear to be valid");
                        isValid = false;
                    }

                if(!chkUseProxyDefCreds.Checked)
                {
                    if(txtProxyUserName.Text.Length == 0)
                    {
                        epErrors.SetError(txtProxyUserName, "A user name is required if not using " +
                            "default credentials");
                        isValid = false;
                    }

                    if(txtProxyPassword.Text.Length == 0)
                    {
                        epErrors.SetError(txtProxyPassword, "A password is required if not using default " +
                            "credentials");
                        isValid = false;
                    }
                }
            }

            if(!isValid)
                return;

            if(txtAjaxDocUrl.Text[txtAjaxDocUrl.Text.Length - 1] != '/')
                txtAjaxDocUrl.Text += "/";

            // Store the changes
            root = config.SelectSingleNode("configuration");

            node = root.SelectSingleNode("ajaxDoc");

            if(node == null)
            {
                node = config.CreateNode(XmlNodeType.Element, "ajaxDoc", null);
                root.AppendChild(node);

                attr = config.CreateAttribute("url");
                node.Attributes.Append(attr);
                attr = config.CreateAttribute("project");
                node.Attributes.Append(attr);
                attr = config.CreateAttribute("regenerate");
                node.Attributes.Append(attr);
            }

            node.Attributes["url"].Value = txtAjaxDocUrl.Text;
            node.Attributes["project"].Value = txtProjectName.Text;
            node.Attributes["regenerate"].Value = chkRegenerateFiles.Checked.ToString().ToLowerInvariant();

            userCreds = new UserCredentials(chkUseDefaultCredentials.Checked, txtUserName.Text, txtPassword.Text);
            userCreds.ToXml(config, root);

            proxyCreds = new ProxyCredentials(chkUseProxyServer.Checked, proxyServer,
                new UserCredentials(chkUseProxyDefCreds.Checked, txtProxyUserName.Text, txtProxyPassword.Text));
            proxyCreds.ToXml(config, root);

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Пример #3
0
        /// <summary>
        /// Validate the configuration and save it
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            XmlAttribute     attr;
            XmlNode          root, node;
            UserCredentials  userCreds;
            ProxyCredentials proxyCreds;
            bool             isValid = true;
            Uri ajaxDoc = null, proxyServer = null;

            txtAjaxDocUrl.Text    = txtAjaxDocUrl.Text.Trim();
            txtProjectName.Text   = txtProjectName.Text.Trim();
            txtUserName.Text      = txtUserName.Text.Trim();
            txtPassword.Text      = txtPassword.Text.Trim();
            txtProxyServer.Text   = txtProxyServer.Text.Trim();
            txtProxyUserName.Text = txtProxyUserName.Text.Trim();
            txtProxyPassword.Text = txtProxyPassword.Text.Trim();
            epErrors.Clear();

            if (txtAjaxDocUrl.Text.Length == 0)
            {
                epErrors.SetError(txtAjaxDocUrl, "An AjaxDoc URL is required");
                isValid = false;
            }
            else
            if (!Uri.TryCreate(txtAjaxDocUrl.Text,
                               UriKind.RelativeOrAbsolute, out ajaxDoc))
            {
                epErrors.SetError(txtAjaxDocUrl, "The AjaxDoc URL does " +
                                  "not appear to be valid");
                isValid = false;
            }

            if (txtProjectName.Text.Length == 0)
            {
                epErrors.SetError(txtProjectName, "A project filename " +
                                  "is required");
                isValid = false;
            }

            if (!chkUseDefaultCredentials.Checked)
            {
                if (txtUserName.Text.Length == 0)
                {
                    epErrors.SetError(txtUserName, "A user name is " +
                                      "required if not using default credentials");
                    isValid = false;
                }

                if (txtPassword.Text.Length == 0)
                {
                    epErrors.SetError(txtPassword, "A password is " +
                                      "required if not using default credentials");
                    isValid = false;
                }
            }

            Uri.TryCreate(txtProxyServer.Text, UriKind.RelativeOrAbsolute,
                          out proxyServer);

            if (chkUseProxyServer.Checked)
            {
                if (txtProxyServer.Text.Length == 0)
                {
                    epErrors.SetError(txtProxyServer, "A proxy server is " +
                                      "required if one is used");
                    isValid = false;
                }
                else
                if (proxyServer == null)
                {
                    epErrors.SetError(txtProxyServer, "The proxy server " +
                                      "name does not appear to be valid");
                    isValid = false;
                }

                if (!chkUseProxyDefCreds.Checked)
                {
                    if (txtProxyUserName.Text.Length == 0)
                    {
                        epErrors.SetError(txtProxyUserName, "A user name is " +
                                          "required if not using default credentials");
                        isValid = false;
                    }

                    if (txtProxyPassword.Text.Length == 0)
                    {
                        epErrors.SetError(txtProxyPassword, "A password is " +
                                          "required if not using default credentials");
                        isValid = false;
                    }
                }
            }

            if (!isValid)
            {
                return;
            }

            if (txtAjaxDocUrl.Text[txtAjaxDocUrl.Text.Length - 1] != '/')
            {
                txtAjaxDocUrl.Text += "/";
            }

            // Store the changes
            root = config.SelectSingleNode("configuration");

            node = root.SelectSingleNode("ajaxDoc");
            if (node == null)
            {
                node = config.CreateNode(XmlNodeType.Element,
                                         "ajaxDoc", null);
                root.AppendChild(node);

                attr = config.CreateAttribute("url");
                node.Attributes.Append(attr);
                attr = config.CreateAttribute("project");
                node.Attributes.Append(attr);
                attr = config.CreateAttribute("regenerate");
                node.Attributes.Append(attr);
            }

            node.Attributes["url"].Value        = txtAjaxDocUrl.Text;
            node.Attributes["project"].Value    = txtProjectName.Text;
            node.Attributes["regenerate"].Value =
                chkRegenerateFiles.Checked.ToString().ToLower(
                    CultureInfo.InvariantCulture);

            userCreds = new UserCredentials(chkUseDefaultCredentials.Checked,
                                            txtUserName.Text, txtPassword.Text);
            userCreds.ToXml(config, root);

            proxyCreds = new ProxyCredentials(chkUseProxyServer.Checked,
                                              proxyServer, new UserCredentials(chkUseProxyDefCreds.Checked,
                                                                               txtProxyUserName.Text, txtProxyPassword.Text));
            proxyCreds.ToXml(config, root);

            this.DialogResult = DialogResult.OK;
            this.Close();
        }