예제 #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="useProxy">True to use default the proxy server, false
        /// to not use it.</param>
        /// <param name="server">The server name to use.</param>
        /// <param name="proxyUser">The user credentials to use for the proxy
        /// server.</param>
        public ProxyCredentials(bool useProxy, Uri server,
          UserCredentials proxyUser)
        {
            useProxyServer = useProxy;
            proxyServer = server;

            if(proxyUser == null)
                credentials = new UserCredentials();
            else
                credentials = proxyUser;
        }
예제 #2
0
        /// <summary>
        /// This method is used to initialize the plug-in at the start of the
        /// build process.
        /// </summary>
        /// <param name="buildProcess">A reference to the current build
        /// process.</param>
        /// <param name="configuration">The configuration data that the plug-in
        /// should use to initialize itself.</param>
        /// <exception cref="BuilderException">This is thrown if the plug-in
        /// configuration is not valid.</exception>
        public void Initialize(BuildProcess buildProcess,
          XPathNavigator configuration)
        {
            XPathNavigator root, node;

            builder = buildProcess;
            ajaxDocUrl = projectName = String.Empty;
            userCreds = new UserCredentials();
            proxyCreds = new ProxyCredentials();

            builder.ReportProgress("{0} Version {1}\r\n{2}",
                this.Name, this.Version, this.Copyright);

            root = configuration.SelectSingleNode("configuration");

            if(root.IsEmptyElement)
                throw new BuilderException("ADP0001", "The AjaxDoc plug-in " +
                    "has not been configured yet");

            node = root.SelectSingleNode("ajaxDoc");
            if(node != null)
            {
                ajaxDocUrl = node.GetAttribute("url", String.Empty).Trim();
                projectName = node.GetAttribute("project", String.Empty).Trim();
                regenerateFiles = Convert.ToBoolean(node.GetAttribute(
                    "regenerate", String.Empty), CultureInfo.InvariantCulture);
            }

            userCreds = UserCredentials.FromXPathNavigator(root);
            proxyCreds = ProxyCredentials.FromXPathNavigator(root);

            if(ajaxDocUrl.Length == 0 || projectName.Length == 0 ||
              (!userCreds.UseDefaultCredentials &&
              (userCreds.UserName.Length == 0 ||
              userCreds.Password.Length == 0)) ||
              (proxyCreds.UseProxyServer &&
              (proxyCreds.ProxyServer == null ||
              (!proxyCreds.Credentials.UseDefaultCredentials &&
              (proxyCreds.Credentials.UserName.Length == 0 ||
              proxyCreds.Credentials.Password.Length == 0)))))
                throw new BuilderException("ADP0002", "The AjaxDoc plug-in " +
                    "has an invalid configuration");
        }
예제 #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="deployTo">The deployment location</param>
 /// <param name="user">The user credentials, if any</param>
 /// <param name="proxy">The proxy credentials, if any</param>
 public DeploymentLocation(Uri deployTo, UserCredentials user,
     ProxyCredentials proxy)
 {
     location = deployTo;
     userCreds = user ?? new UserCredentials();
     proxyCreds = proxy ?? new ProxyCredentials();
 }
예제 #4
0
        //=====================================================================
        // Methods, etc.

        /// <summary>
        /// Constructor
        /// </summary>
        /// <overloads>There are two overloads for the constructor</overloads>
        public DeploymentLocation()
        {
            userCreds = new UserCredentials();
            proxyCreds = new ProxyCredentials();
        }
        /// <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 credentials;
            bool isValid = true;

            txtSmtpServer.Text = txtSmtpServer.Text.Trim();
            txtUserName.Text = txtUserName.Text.Trim();
            txtPassword.Text = txtPassword.Text.Trim();
            txtSuccessEMailAddress.Text = txtSuccessEMailAddress.Text.Trim();
            txtFailureEMailAddress.Text = txtFailureEMailAddress.Text.Trim();
            txtXSLTransform.Text = txtXSLTransform.Text.Trim();
            epErrors.Clear();

            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;
                }
            }

            if(txtFailureEMailAddress.Text.Length == 0)
            {
                epErrors.SetError(txtFailureEMailAddress, "A failure " +
                    "e-mail address is required");
                isValid = false;
            }

            if(!isValid)
                return;

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

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

                attr = config.CreateAttribute("host");
                node.Attributes.Append(attr);
                attr = config.CreateAttribute("port");
                node.Attributes.Append(attr);
            }

            node.Attributes["host"].Value = txtSmtpServer.Text;
            node.Attributes["port"].Value = udcSmtpPort.Value.ToString(
                CultureInfo.InvariantCulture);

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

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

                attr = config.CreateAttribute("address");
                node.Attributes.Append(attr);
            }

            node.Attributes["address"].Value = txtFromEMail.Text;

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

                attr = config.CreateAttribute("address");
                node.Attributes.Append(attr);
                attr = config.CreateAttribute("attachLog");
                node.Attributes.Append(attr);
            }

            node.Attributes["address"].Value = txtSuccessEMailAddress.Text;
            node.Attributes["attachLog"].Value =
                chkAttachLogFileOnSuccess.Checked.ToString().ToLower(
                    CultureInfo.InvariantCulture);

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

                attr = config.CreateAttribute("address");
                node.Attributes.Append(attr);
                attr = config.CreateAttribute("attachLog");
                node.Attributes.Append(attr);
            }

            node.Attributes["address"].Value = txtFailureEMailAddress.Text;
            node.Attributes["attachLog"].Value =
                chkAttachLogFileOnFailure.Checked.ToString().ToLower(
                    CultureInfo.InvariantCulture);

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

                attr = config.CreateAttribute("filename");
                node.Attributes.Append(attr);
            }

            node.Attributes["filename"].Value = txtXSLTransform.Text;

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
        /// <summary>
        /// This method is used to initialize the plug-in at the start of the build process
        /// </summary>
        /// <param name="buildProcess">A reference to the current build process</param>
        /// <param name="configuration">The configuration data that the plug-in should use to initialize itself</param>
        /// <exception cref="BuilderException">This is thrown if the plug-in configuration is not valid</exception>
        public void Initialize(BuildProcess buildProcess, XPathNavigator configuration)
        {
            XPathNavigator root, node;
            string value;

            builder = buildProcess;
            attachLogOnSuccess = false;
            attachLogOnFailure = true;
            smtpServer = successEMailAddress = failureEMailAddress = xslTransformFile = String.Empty;
            credentials = new UserCredentials();
            smtpPort = 25;

            var metadata = (HelpFileBuilderPlugInExportAttribute)this.GetType().GetCustomAttributes(
                typeof(HelpFileBuilderPlugInExportAttribute), false).First();

            builder.ReportProgress("{0} Version {1}\r\n{2}", metadata.Id, metadata.Version, metadata.Copyright);

            root = configuration.SelectSingleNode("configuration");

            if(root.IsEmptyElement)
                throw new BuilderException("CNP0001", "The Completion Notification plug-in has not been " +
                    "configured yet");

            node = root.SelectSingleNode("smtpServer");

            if(node != null)
            {
                smtpServer = node.GetAttribute("host", String.Empty).Trim();
                value = node.GetAttribute("port", String.Empty);

                if(!Int32.TryParse(value, out smtpPort))
                    smtpPort = 25;
            }

            credentials = UserCredentials.FromXPathNavigator(root);

            node = root.SelectSingleNode("fromEMail");

            if(node != null)
                fromEMailAddress = node.GetAttribute("address", String.Empty).Trim();

            node = root.SelectSingleNode("successEMail");

            if(node != null)
            {
                successEMailAddress = node.GetAttribute("address", String.Empty).Trim();
                attachLogOnSuccess = Convert.ToBoolean(node.GetAttribute("attachLog", String.Empty),
                    CultureInfo.InvariantCulture);
            }

            node = root.SelectSingleNode("failureEMail");

            if(node != null)
            {
                failureEMailAddress = node.GetAttribute("address", String.Empty).Trim();
                attachLogOnFailure = Convert.ToBoolean(node.GetAttribute("attachLog", String.Empty),
                    CultureInfo.InvariantCulture);
            }

            node = root.SelectSingleNode("xslTransform");

            if(node != null)
                xslTransformFile = builder.TransformText(node.GetAttribute("filename", String.Empty).Trim());

            if((!credentials.UseDefaultCredentials && (credentials.UserName.Length == 0 ||
              credentials.Password.Length == 0)) || failureEMailAddress.Length == 0)
                throw new BuilderException("CNP0002", "The Completion Notification plug-in has an invalid " +
                    "configuration");
        }
        /// <summary>
        /// Validate the control values and, if valid, create and return a new
        /// deployment location settings object.
        /// </summary>
        /// <returns>The deployment location settings if they are valid or
        /// null if they are not valid.</returns>
        public DeploymentLocation CreateDeploymentLocation()
        {
            DeploymentLocation location = null;
            UserCredentials userCreds;
            ProxyCredentials proxyCreds;
            Uri targetUri = null, proxyUri = null;
            bool isValid = true;

            epErrors.Clear();

            txtTargetLocation.Text = txtTargetLocation.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();

            if(txtTargetLocation.Text.Length != 0 && !Uri.TryCreate(
              txtTargetLocation.Text, UriKind.RelativeOrAbsolute, out targetUri))
            {
                epErrors.SetError(txtTargetLocation, "The target location " +
                    "does not appear to be valid");
                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;
                }
            }

            if(chkUseProxyServer.Checked)
            {
                if(txtProxyServer.Text.Length == 0)
                {
                    epErrors.SetError(txtProxyServer, "A proxy server is " +
                        "required if one is used");
                    isValid = false;
                }
                else
                {
                    Uri.TryCreate(txtProxyServer.Text, UriKind.RelativeOrAbsolute,
                        out proxyUri);

                    if(proxyUri == 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)
            {
                userCreds = new UserCredentials(chkUseDefaultCredentials.Checked,
                    txtUserName.Text, txtPassword.Text);
                proxyCreds = new ProxyCredentials(chkUseProxyServer.Checked,
                    proxyUri, new UserCredentials(chkUseProxyDefCreds.Checked,
                    txtProxyUserName.Text, txtProxyPassword.Text));
                location = new DeploymentLocation(targetUri, userCreds,
                    proxyCreds);
            }

            return location;
        }
예제 #8
0
        /// <summary>
        /// Create a user credentials instance from an XPath navigator containing the settings
        /// </summary>
        /// <param name="navigator">The XPath navigator from which to obtain the settings</param>
        /// <returns>A <see cref="UserCredentials"/> object containing the settings from the XPath navigator</returns>
        /// <remarks>It should contain an element called <c>userCredentials</c> with three attributes:
        /// <c>useDefault</c>, <c>userName</c>, and <c>password</c>.</remarks>
        public static UserCredentials FromXPathNavigator(XPathNavigator navigator)
        {
            UserCredentials credentials = new UserCredentials();

            if(navigator != null)
            {
                navigator = navigator.SelectSingleNode("userCredentials");

                if(navigator != null)
                {
                    credentials.UseDefaultCredentials = Convert.ToBoolean(navigator.GetAttribute("useDefault",
                        String.Empty), CultureInfo.InvariantCulture);
                    credentials.UserName = navigator.GetAttribute("userName", String.Empty).Trim();
                    credentials.Password = navigator.GetAttribute("password", String.Empty).Trim();
                }
            }

            return credentials;
        }
예제 #9
0
 //=====================================================================
 // Methods, etc.
 /// <summary>
 /// Constructor
 /// </summary>
 /// <overloads>There are two overloads for the constructor.</overloads>
 public ProxyCredentials()
 {
     credentials = new UserCredentials();
 }
예제 #10
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();
        }