/// <summary>
        /// Create a deployment location instance from an XML element containing the settings
        /// </summary>
        /// <param name="configuration">The XML element from which to obtain the settings</param>
        /// <param name="id">The id of the element to load</param>
        /// <returns>A <see cref="DeploymentLocation"/> object containing the settings from the XPath navigator.</returns>
        /// <remarks>It should contain an element called <b>deploymentLocation</b> with two attributes (<b>id</b>
        /// with the specified ID value and <b>location</b>) and nested <b>userCredentials</b> and
        /// <b>proxyCredentials</b> elements.</remarks>
        public static DeploymentLocation FromXml(XElement configuration, string id)
        {
            DeploymentLocation depLoc = new DeploymentLocation();

            configuration = configuration?.XPathSelectElement("deploymentLocation[@id='" + id + "']");

            if (configuration != null)
            {
                string location = configuration.Attribute("location").Value;

                if (!String.IsNullOrWhiteSpace(location))
                {
                    depLoc.Location = new Uri(location, UriKind.RelativeOrAbsolute);
                }

                UserCredentials user = UserCredentials.FromXml(configuration);

                depLoc.UserCredentials.UseDefaultCredentials = user.UseDefaultCredentials;
                depLoc.UserCredentials.UserName = user.UserName;
                depLoc.UserCredentials.Password = user.Password;

                ProxyCredentials proxy = ProxyCredentials.FromXml(configuration);

                depLoc.ProxyCredentials.UseProxyServer = proxy.UseProxyServer;
                depLoc.ProxyCredentials.ProxyServer    = proxy.ProxyServer;
                depLoc.ProxyCredentials.Credentials.UseDefaultCredentials = proxy.Credentials.UseDefaultCredentials;
                depLoc.ProxyCredentials.Credentials.UserName = proxy.Credentials.UserName;
                depLoc.ProxyCredentials.Credentials.Password = proxy.Credentials.Password;
            }

            return(depLoc);
        }
Exemple #2
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="currentConfig">The current XML configuration XML fragment</param>
        public DeploymentConfigDlg(string currentConfig)
        {
            XPathNavigator navigator, root, msHelpViewer;
            string         value;
            bool           renameMSHA;

            InitializeComponent();

            lnkProjectSite.Links[0].LinkData = "https://GitHub.com/EWSoftware/SHFB";

            // Load the current settings
            config = new XmlDocument();
            config.LoadXml(currentConfig);
            navigator = config.CreateNavigator();

            root = navigator.SelectSingleNode("configuration");

            if (root.IsEmptyElement)
            {
                return;
            }

            value = root.GetAttribute("deleteAfterDeploy", String.Empty);

            if (!String.IsNullOrEmpty(value))
            {
                chkDeleteAfterDeploy.Checked = Convert.ToBoolean(value, CultureInfo.InvariantCulture);
            }

            // Get HTML Help 1 deployment information
            ucHtmlHelp1.LoadFromSettings(DeploymentLocation.FromXPathNavigator(root, "help1x"));

            // Get MS Help 2 deployment information
            ucMSHelp2.LoadFromSettings(DeploymentLocation.FromXPathNavigator(root, "help2x"));

            // Get MS Help Viewer deployment information
            msHelpViewer = root.SelectSingleNode("deploymentLocation[@id='helpViewer']");

            if (msHelpViewer != null)
            {
                if (!Boolean.TryParse(msHelpViewer.GetAttribute("renameMSHA", String.Empty).Trim(), out renameMSHA))
                {
                    renameMSHA = false;
                }

                chkRenameMSHA.Checked = renameMSHA;
            }

            ucMSHelpViewer.LoadFromSettings(DeploymentLocation.FromXPathNavigator(root, "helpViewer"));

            // Get website deployment information
            ucWebsite.LoadFromSettings(DeploymentLocation.FromXPathNavigator(root, "website"));

            // Get Open XML deployment information
            ucOpenXml.LoadFromSettings(DeploymentLocation.FromXPathNavigator(root, "openXml"));
        }
Exemple #3
0
        /// <summary>
        /// Create a deployment location instance from an XPath navigator
        /// containing the settings.
        /// </summary>
        /// <param name="navigator">The XPath navigator from which to
        /// obtain the settings.</param>
        /// <param name="id">The id of the element to load</param>
        /// <returns>A <see cref="DeploymentLocation"/> object containing the
        /// settings from the XPath navigator.</returns>
        /// <remarks>It should contain an element called <b>deploymentLocation</b>
        /// with two attributes (<b>id</b> with the specified ID value and
        /// <b>location</b>) and nested <b>userCredentials</b> and
        /// <b>proxyCredentials</b> elements.</remarks>
        public static DeploymentLocation FromXPathNavigator(
            XPathNavigator navigator, string id)
        {
            DeploymentLocation depLoc = new DeploymentLocation();
            UserCredentials    user;
            ProxyCredentials   proxy;
            string             location;

            if (navigator != null)
            {
                navigator = navigator.SelectSingleNode(
                    "deploymentLocation[@id='" + id + "']");

                if (navigator != null)
                {
                    location = navigator.GetAttribute("location",
                                                      String.Empty).Trim();

                    if (location.Length != 0)
                    {
                        depLoc.Location = new Uri(location,
                                                  UriKind.RelativeOrAbsolute);
                    }

                    user = UserCredentials.FromXPathNavigator(navigator);

                    depLoc.UserCredentials.UseDefaultCredentials =
                        user.UseDefaultCredentials;
                    depLoc.UserCredentials.UserName = user.UserName;
                    depLoc.UserCredentials.Password = user.Password;

                    proxy = ProxyCredentials.FromXPathNavigator(navigator);

                    depLoc.ProxyCredentials.UseProxyServer =
                        proxy.UseProxyServer;
                    depLoc.ProxyCredentials.ProxyServer = proxy.ProxyServer;
                    depLoc.ProxyCredentials.Credentials.UseDefaultCredentials =
                        proxy.Credentials.UseDefaultCredentials;
                    depLoc.ProxyCredentials.Credentials.UserName =
                        proxy.Credentials.UserName;
                    depLoc.ProxyCredentials.Credentials.Password =
                        proxy.Credentials.Password;
                }
            }

            return(depLoc);
        }
Exemple #4
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="currentConfig">The current XML configuration
        /// XML fragment</param>
        public DeploymentConfigDlg(string currentConfig)
        {
            XPathNavigator navigator, root;
            string         value;

            InitializeComponent();

            lnkCodePlexSHFB.Links[0].LinkData = "http://SHFB.CodePlex.com";

            // Load the current settings
            config = new XmlDocument();
            config.LoadXml(currentConfig);
            navigator = config.CreateNavigator();

            root = navigator.SelectSingleNode("configuration");

            if (root.IsEmptyElement)
            {
                return;
            }

            value = root.GetAttribute("deleteAfterDeploy", String.Empty);

            if (!String.IsNullOrEmpty(value))
            {
                chkDeleteAfterDeploy.Checked = Convert.ToBoolean(value,
                                                                 CultureInfo.InvariantCulture);
            }

            // Get HTML Help 1 deployment information
            ucHtmlHelp1.LoadFromSettings(DeploymentLocation.FromXPathNavigator(
                                             root, "help1x"));

            // Get MS Help 2 deployment information
            ucMSHelp2.LoadFromSettings(DeploymentLocation.FromXPathNavigator(
                                           root, "help2x"));

            // Get MS Help Viewer deployment information
            ucMSHelpViewer.LoadFromSettings(DeploymentLocation.FromXPathNavigator(
                                                root, "helpViewer"));

            // Get website deployment information
            ucWebsite.LoadFromSettings(DeploymentLocation.FromXPathNavigator(
                                           root, "website"));
        }
        //=====================================================================

        /// <summary>
        /// Load the control values from the specified deployment location
        /// settings object.
        /// </summary>
        /// <param name="location">The location settings</param>
        public void LoadFromSettings(DeploymentLocation location)
        {
            txtTargetLocation.Text = (location.Location != null) ?
                                     location.Location.OriginalString : null;
            chkUseDefaultCredentials.Checked =
                location.UserCredentials.UseDefaultCredentials;
            txtUserName.Text = location.UserCredentials.UserName;
            txtPassword.Text = location.UserCredentials.Password;

            chkUseProxyServer.Checked =
                location.ProxyCredentials.UseProxyServer;
            txtProxyServer.Text =
                (location.ProxyCredentials.ProxyServer == null) ? null :
                location.ProxyCredentials.ProxyServer.OriginalString;
            chkUseProxyDefCreds.Checked =
                location.ProxyCredentials.Credentials.UseDefaultCredentials;
            txtProxyUserName.Text =
                location.ProxyCredentials.Credentials.UserName;
            txtProxyPassword.Text =
                location.ProxyCredentials.Credentials.Password;
        }
        //=====================================================================

        /// <summary>
        /// Load the control values from the specified deployment location
        /// settings object.
        /// </summary>
        /// <param name="location">The location settings</param>
        public void LoadFromSettings(DeploymentLocation location)
        {
            txtTargetLocation.Text = (location.Location != null) ?
                location.Location.OriginalString : null;
            chkUseDefaultCredentials.Checked =
                location.UserCredentials.UseDefaultCredentials;
            txtUserName.Text = location.UserCredentials.UserName;
            txtPassword.Text = location.UserCredentials.Password;

            chkUseProxyServer.Checked =
                location.ProxyCredentials.UseProxyServer;
            txtProxyServer.Text =
                (location.ProxyCredentials.ProxyServer == null) ? null :
                location.ProxyCredentials.ProxyServer.OriginalString;
            chkUseProxyDefCreds.Checked =
                location.ProxyCredentials.Credentials.UseDefaultCredentials;
            txtProxyUserName.Text =
                location.ProxyCredentials.Credentials.UserName;
            txtProxyPassword.Text =
                location.ProxyCredentials.Credentials.Password;
        }
        /// <summary>
        /// Create a deployment location instance from an XPath navigator
        /// containing the settings.
        /// </summary>
        /// <param name="navigator">The XPath navigator from which to
        /// obtain the settings.</param>
        /// <param name="id">The id of the element to load</param>
        /// <returns>A <see cref="DeploymentLocation"/> object containing the
        /// settings from the XPath navigator.</returns>
        /// <remarks>It should contain an element called <b>deploymentLocation</b>
        /// with two attributes (<b>id</b> with the specified ID value and
        /// <b>location</b>) and nested <b>userCredentials</b> and
        /// <b>proxyCredentials</b> elements.</remarks>
        public static DeploymentLocation FromXPathNavigator(
          XPathNavigator navigator, string id)
        {
            DeploymentLocation depLoc = new DeploymentLocation();
            UserCredentials user;
            ProxyCredentials proxy;
            string location;

            if(navigator != null)
            {
                navigator = navigator.SelectSingleNode(
                    "deploymentLocation[@id='" + id + "']");

                if(navigator != null)
                {
                    location = navigator.GetAttribute("location",
                        String.Empty).Trim();

                    if(location.Length != 0)
                        depLoc.Location = new Uri(location,
                            UriKind.RelativeOrAbsolute);

                    user = UserCredentials.FromXPathNavigator(navigator);

                    depLoc.UserCredentials.UseDefaultCredentials =
                        user.UseDefaultCredentials;
                    depLoc.UserCredentials.UserName = user.UserName;
                    depLoc.UserCredentials.Password = user.Password;

                    proxy = ProxyCredentials.FromXPathNavigator(navigator);

                    depLoc.ProxyCredentials.UseProxyServer =
                        proxy.UseProxyServer;
                    depLoc.ProxyCredentials.ProxyServer = proxy.ProxyServer;
                    depLoc.ProxyCredentials.Credentials.UseDefaultCredentials =
                        proxy.Credentials.UseDefaultCredentials;
                    depLoc.ProxyCredentials.Credentials.UserName =
                        proxy.Credentials.UserName;
                    depLoc.ProxyCredentials.Credentials.Password =
                        proxy.Credentials.Password;
                }
            }

            return depLoc;
        }
        //=====================================================================

        /// <summary>
        /// Deploy the given list of files to the specified location
        /// </summary>
        /// <param name="files">The list of files to deploy</param>
        /// <param name="location">The deployment location</param>
        private void DeployOutput(Collection<string> files, DeploymentLocation location)
        {
            WebClient webClient = null;
            Uri destUri, target = location.Location;
            string rootPath, destFile, destPath;
            int basePathLength = builder.OutputFolder.Length;

            if(target == null)
            {
                builder.ReportProgress("No deployment location defined for this help format");
                return;
            }

            if(files.Count == 0)
            {
                builder.ReportProgress("No files found to deploy");
                return;
            }

            try
            {
                // Determine the path type
                if(!target.IsAbsoluteUri)
                    rootPath = Path.GetFullPath(target.OriginalString);
                else
                    if(target.IsFile || target.IsUnc)
                        rootPath = target.LocalPath;
                    else
                    {
                        // FTP, HTTP, etc.
                        rootPath = target.ToString();
                        webClient = new WebClient();

                        // Initialize the web client
                        if(!location.UserCredentials.UseDefaultCredentials)
                            webClient.Credentials = new NetworkCredential(location.UserCredentials.UserName,
                                location.UserCredentials.Password);

                        webClient.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);

                        if(location.ProxyCredentials.UseProxyServer)
                        {
                            webClient.Proxy = new WebProxy(location.ProxyCredentials.ProxyServer, true);

                            if(!location.ProxyCredentials.Credentials.UseDefaultCredentials)
                                webClient.Proxy.Credentials = new NetworkCredential(
                                    location.ProxyCredentials.Credentials.UserName,
                                    location.ProxyCredentials.Credentials.Password);
                        }
                    }

                foreach(string sourceFile in files)
                {
                    destFile = Path.Combine(rootPath, sourceFile.Substring(basePathLength));

                    // Rename MSHA file?  Note that if renamed and there is more than one, the last one
                    // copied wins.  This really only applies to MS Help Viewer output but it's the only
                    // unique option so we'll do it in all cases for now.
                    if(Path.GetExtension(destFile).Equals(".msha", StringComparison.OrdinalIgnoreCase) && renameMSHA)
                        destFile = Path.Combine(Path.GetDirectoryName(destFile), "HelpContentSetup.msha");

                    if(webClient == null)
                    {
                        builder.ReportProgress("    Deploying {0} to {1}", sourceFile, destFile);

                        destPath = Path.GetDirectoryName(destFile);

                        if(!Directory.Exists(destPath))
                            Directory.CreateDirectory(destPath);

                        File.Copy(sourceFile, destFile, true);
                    }
                    else
                    {
                        destUri = new Uri(destFile);
                        builder.ReportProgress("    Deploying {0} to {1}", sourceFile, destUri);

                        webClient.UploadFile(destUri, sourceFile);
                    }

                    // If not wanted, remove the source file after deployment
                    if(deleteAfterDeploy)
                        File.Delete(sourceFile);
                }
            }
            finally
            {
                if(webClient != null)
                    webClient.Dispose();
            }
        }
        /// <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, msHelpViewer;
            string value;

            builder = buildProcess;

            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");
            value = root.GetAttribute("deleteAfterDeploy", String.Empty);

            if(!String.IsNullOrEmpty(value))
                deleteAfterDeploy = Convert.ToBoolean(value, CultureInfo.InvariantCulture);

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

            deployHelp1 = DeploymentLocation.FromXPathNavigator(root, "help1x");
            deployHelp2 = DeploymentLocation.FromXPathNavigator(root, "help2x");
            deployHelpViewer = DeploymentLocation.FromXPathNavigator(root, "helpViewer");
            deployWebsite = DeploymentLocation.FromXPathNavigator(root, "website");
            deployOpenXml = DeploymentLocation.FromXPathNavigator(root, "openXml");

            msHelpViewer = root.SelectSingleNode("deploymentLocation[@id='helpViewer']");

            if(msHelpViewer == null || !Boolean.TryParse(msHelpViewer.GetAttribute("renameMSHA",
              String.Empty).Trim(), out renameMSHA))
                renameMSHA = false;

            // At least one deployment location must be defined
            if(deployHelp1.Location == null && deployHelp2.Location == null &&
              deployHelpViewer.Location == null && deployWebsite.Location == null && deployOpenXml.Location == null)
                throw new BuilderException("ODP0002", "The output deployment plug-in must have at least " +
                    "one configured deployment location");

            // Issue a warning if the deployment location is null and the associated help file format is active
            if(deployHelp1.Location == null &&
              (builder.CurrentProject.HelpFileFormat & HelpFileFormats.HtmlHelp1) != 0)
                builder.ReportWarning("ODP0003", "HTML Help 1 will be generated but not deployed due to " +
                    "missing deployment location information");

            if(deployHelp2.Location == null &&
              (builder.CurrentProject.HelpFileFormat & HelpFileFormats.MSHelp2) != 0)
                builder.ReportWarning("ODP0003", "MS Help 2 will be generated but not deployed due to " +
                    "missing deployment location information");

            if(deployHelpViewer.Location == null &&
              (builder.CurrentProject.HelpFileFormat & HelpFileFormats.MSHelpViewer) != 0)
                builder.ReportWarning("ODP0003", "MS Help Viewer will be generated but not deployed due " +
                    "to missing deployment location information");

            if(deployWebsite.Location == null &&
              (builder.CurrentProject.HelpFileFormat & HelpFileFormats.Website) != 0)
                builder.ReportWarning("ODP0003", "Website will be generated but not deployed due to " +
                    "missing deployment location information");

            if(deployOpenXml.Location == null &&
              (builder.CurrentProject.HelpFileFormat & HelpFileFormats.OpenXml) != 0)
                builder.ReportWarning("ODP0003", "Open XML will be generated but not deployed due to " +
                    "missing deployment location information");
        }
        /// <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;
        }
        /// <summary>
        /// Deploy the given list of files to the specified location
        /// </summary>
        /// <param name="files">The list of files to deploy</param>
        /// <param name="location">The deployment location</param>
        private void DeployOutput(Collection<string> files,
          DeploymentLocation location)
        {
            WebClient webClient = null;
            Uri destUri, target = location.Location;
            string rootPath, destFile, destPath;
            int basePathLength = builder.OutputFolder.Length;

            if(files.Count == 0)
            {
                builder.ReportProgress("No files found to deploy");
                return;
            }

            try
            {
                // Determine the path type
                if(!target.IsAbsoluteUri)
                    rootPath = Path.GetFullPath(target.OriginalString);
                else
                    if(target.IsFile || target.IsUnc)
                        rootPath = target.LocalPath;
                    else
                    {
                        // FTP, HTTP, etc.
                        rootPath = target.ToString();
                        webClient = new WebClient();

                        // Initialize the web client
                        if(!location.UserCredentials.UseDefaultCredentials)
                            webClient.Credentials = new NetworkCredential(
                                location.UserCredentials.UserName,
                                location.UserCredentials.Password);

                        webClient.CachePolicy = new RequestCachePolicy(
                            RequestCacheLevel.NoCacheNoStore);

                        if(location.ProxyCredentials.UseProxyServer)
                        {
                            webClient.Proxy = new WebProxy(
                                location.ProxyCredentials.ProxyServer, true);

                            if(!location.ProxyCredentials.Credentials.UseDefaultCredentials)
                                webClient.Proxy.Credentials =
                                    new NetworkCredential(
                                        location.ProxyCredentials.Credentials.UserName,
                                        location.ProxyCredentials.Credentials.Password);
                        }
                    }

                foreach(string sourceFile in files)
                {
                    destFile = Path.Combine(rootPath,
                        sourceFile.Substring(basePathLength));

                    if(webClient == null)
                    {
                        builder.ReportProgress("    Deploying {0} to {1}",
                            sourceFile, destFile);

                        destPath = Path.GetDirectoryName(destFile);

                        if(!Directory.Exists(destPath))
                            Directory.CreateDirectory(destPath);

                        File.Copy(sourceFile, destFile, true);
                    }
                    else
                    {
                        destUri = new Uri(destFile);
                        builder.ReportProgress("    Deploying {0} to {1}",
                            sourceFile, destUri);

                        webClient.UploadFile(destUri, sourceFile);
                    }

                    // If not wanted, remove the source file after deployment
                    if(deleteAfterDeploy)
                        File.Delete(sourceFile);
                }
            }
            finally
            {
                if(webClient != null)
                    webClient.Dispose();
            }
        }
        /// <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 valud 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);
        }
Exemple #13
0
        /// <summary>
        /// Deploy the given list of files to the specified location
        /// </summary>
        /// <param name="files">The list of files to deploy</param>
        /// <param name="location">The deployment location</param>
        private void DeployOutput(Collection <string> files,
                                  DeploymentLocation location)
        {
            WebClient webClient = null;
            Uri       destUri, target = location.Location;
            string    rootPath, destFile, destPath;
            int       basePathLength = builder.OutputFolder.Length;

            if (files.Count == 0)
            {
                builder.ReportProgress("No files found to deploy");
                return;
            }

            try
            {
                // Determine the path type
                if (!target.IsAbsoluteUri)
                {
                    rootPath = Path.GetFullPath(target.OriginalString);
                }
                else
                if (target.IsFile || target.IsUnc)
                {
                    rootPath = target.LocalPath;
                }
                else
                {
                    // FTP, HTTP, etc.
                    rootPath  = target.ToString();
                    webClient = new WebClient();

                    // Initialize the web client
                    if (!location.UserCredentials.UseDefaultCredentials)
                    {
                        webClient.Credentials = new NetworkCredential(
                            location.UserCredentials.UserName,
                            location.UserCredentials.Password);
                    }

                    webClient.CachePolicy = new RequestCachePolicy(
                        RequestCacheLevel.NoCacheNoStore);

                    if (location.ProxyCredentials.UseProxyServer)
                    {
                        webClient.Proxy = new WebProxy(
                            location.ProxyCredentials.ProxyServer, true);

                        if (!location.ProxyCredentials.Credentials.UseDefaultCredentials)
                        {
                            webClient.Proxy.Credentials =
                                new NetworkCredential(
                                    location.ProxyCredentials.Credentials.UserName,
                                    location.ProxyCredentials.Credentials.Password);
                        }
                    }
                }

                foreach (string sourceFile in files)
                {
                    destFile = Path.Combine(rootPath,
                                            sourceFile.Substring(basePathLength));

                    if (webClient == null)
                    {
                        builder.ReportProgress("    Deploying {0} to {1}",
                                               sourceFile, destFile);

                        destPath = Path.GetDirectoryName(destFile);

                        if (!Directory.Exists(destPath))
                        {
                            Directory.CreateDirectory(destPath);
                        }

                        File.Copy(sourceFile, destFile, true);
                    }
                    else
                    {
                        destUri = new Uri(destFile);
                        builder.ReportProgress("    Deploying {0} to {1}",
                                               sourceFile, destUri);

                        webClient.UploadFile(destUri, sourceFile);
                    }

                    // If not wanted, remove the source file after deployment
                    if (deleteAfterDeploy)
                    {
                        File.Delete(sourceFile);
                    }
                }
            }
            finally
            {
                if (webClient != null)
                {
                    webClient.Dispose();
                }
            }
        }
Exemple #14
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;
            string         value;

            builder = buildProcess;

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

            root  = configuration.SelectSingleNode("configuration");
            value = root.GetAttribute("deleteAfterDeploy", String.Empty);

            if (!String.IsNullOrEmpty(value))
            {
                deleteAfterDeploy = Convert.ToBoolean(value,
                                                      CultureInfo.InvariantCulture);
            }

            if (root.IsEmptyElement)
            {
                throw new BuilderException("ODP0001", "The Output Deployment " +
                                           "plug-in has not been configured yet");
            }

            deployHelp1      = DeploymentLocation.FromXPathNavigator(root, "help1x");
            deployHelp2      = DeploymentLocation.FromXPathNavigator(root, "help2x");
            deployHelpViewer = DeploymentLocation.FromXPathNavigator(root, "helpViewer");
            deployWebsite    = DeploymentLocation.FromXPathNavigator(root, "website");

            // At least one deployment location must be defined
            if (deployHelp1.Location == null && deployHelp2.Location == null &&
                deployHelpViewer.Location == null && deployWebsite.Location == null)
            {
                throw new BuilderException("ODP0002", "The output deployment " +
                                           "plug-in must have at least one configured deployment " +
                                           "location");
            }

            // Issue a warning if the deployment location is null and the
            // associated help file format is active.
            if (deployHelp1.Location == null &&
                (builder.CurrentProject.HelpFileFormat & HelpFileFormat.HtmlHelp1) != 0)
            {
                builder.ReportWarning("ODP0003", "HTML Help 1 will be generated " +
                                      "but not deployed due to missing deployment location " +
                                      "information");
            }

            if (deployHelp2.Location == null &&
                (builder.CurrentProject.HelpFileFormat & HelpFileFormat.MSHelp2) != 0)
            {
                builder.ReportWarning("ODP0003", "MS Help 2 will be generated " +
                                      "but not deployed due to missing deployment location " +
                                      "information");
            }

            if (deployHelpViewer.Location == null &&
                (builder.CurrentProject.HelpFileFormat & HelpFileFormat.MSHelpViewer) != 0)
            {
                builder.ReportWarning("ODP0003", "MS Help Viewer will be generated " +
                                      "but not deployed due to missing deployment location " +
                                      "information");
            }

            if (deployWebsite.Location == null &&
                (builder.CurrentProject.HelpFileFormat & HelpFileFormat.Website) != 0)
            {
                builder.ReportWarning("ODP0003", "Website will be generated " +
                                      "but not deployed due to missing deployment location " +
                                      "information");
            }
        }
Exemple #15
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, XElement configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            builder = buildProcess;

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

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

            if (configuration.IsEmpty)
            {
                throw new BuilderException("ODP0001", "The Output Deployment plug-in has not been configured yet");
            }

            deleteAfterDeploy = (bool)configuration.Attribute("deleteAfterDeploy");
            verboseLogging    = (bool?)configuration.Attribute("verboseLogging") ?? false;

            deployHelp1      = DeploymentLocation.FromXml(configuration, "help1x");
            deployHelpViewer = DeploymentLocation.FromXml(configuration, "helpViewer");
            deployWebsite    = DeploymentLocation.FromXml(configuration, "website");
            deployOpenXml    = DeploymentLocation.FromXml(configuration, "openXml");
            deployMarkdown   = DeploymentLocation.FromXml(configuration, "markdown");

            var msHelpViewer = configuration.XPathSelectElement("deploymentLocation[@id='helpViewer']");

            if (msHelpViewer == null || !Boolean.TryParse(msHelpViewer.Attribute("renameMSHA").Value, out renameMSHA))
            {
                renameMSHA = false;
            }

            // At least one deployment location must be defined
            if (deployHelp1.Location == null && deployHelpViewer.Location == null && deployWebsite.Location == null &&
                deployOpenXml.Location == null && deployMarkdown.Location == null)
            {
                throw new BuilderException("ODP0002", "The output deployment plug-in must have at least " +
                                           "one configured deployment location");
            }

            // Issue a warning if the deployment location is null and the associated help file format is active
            if (deployHelp1.Location == null &&
                (builder.CurrentProject.HelpFileFormat & HelpFileFormats.HtmlHelp1) != 0)
            {
                builder.ReportWarning("ODP0003", "HTML Help 1 will be generated but not deployed due to " +
                                      "missing deployment location information");
            }

            if (deployHelpViewer.Location == null &&
                (builder.CurrentProject.HelpFileFormat & HelpFileFormats.MSHelpViewer) != 0)
            {
                builder.ReportWarning("ODP0003", "MS Help Viewer will be generated but not deployed due " +
                                      "to missing deployment location information");
            }

            if (deployWebsite.Location == null &&
                (builder.CurrentProject.HelpFileFormat & HelpFileFormats.Website) != 0)
            {
                builder.ReportWarning("ODP0003", "Website will be generated but not deployed due to " +
                                      "missing deployment location information");
            }

            if (deployOpenXml.Location == null &&
                (builder.CurrentProject.HelpFileFormat & HelpFileFormats.OpenXml) != 0)
            {
                builder.ReportWarning("ODP0003", "Open XML will be generated but not deployed due to " +
                                      "missing deployment location information");
            }

            if (deployMarkdown.Location == null &&
                (builder.CurrentProject.HelpFileFormat & HelpFileFormats.Markdown) != 0)
            {
                builder.ReportWarning("ODP0003", "Markdown content will be generated but not deployed due to " +
                                      "missing deployment location information");
            }
        }
Exemple #16
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, msHelpViewer;
            string         value;

            builder = buildProcess;

            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");
            value = root.GetAttribute("deleteAfterDeploy", String.Empty);

            if (!String.IsNullOrEmpty(value))
            {
                deleteAfterDeploy = Convert.ToBoolean(value, CultureInfo.InvariantCulture);
            }

            value = root.GetAttribute("verboseLogging", String.Empty);

            if (!String.IsNullOrEmpty(value))
            {
                verboseLogging = Convert.ToBoolean(value, CultureInfo.InvariantCulture);
            }

            if (root.IsEmptyElement)
            {
                throw new BuilderException("ODP0001", "The Output Deployment plug-in has not been " +
                                           "configured yet");
            }

            deployHelp1      = DeploymentLocation.FromXPathNavigator(root, "help1x");
            deployHelpViewer = DeploymentLocation.FromXPathNavigator(root, "helpViewer");
            deployWebsite    = DeploymentLocation.FromXPathNavigator(root, "website");
            deployOpenXml    = DeploymentLocation.FromXPathNavigator(root, "openXml");
            deployMarkdown   = DeploymentLocation.FromXPathNavigator(root, "markdown");

            msHelpViewer = root.SelectSingleNode("deploymentLocation[@id='helpViewer']");

            if (msHelpViewer == null || !Boolean.TryParse(msHelpViewer.GetAttribute("renameMSHA",
                                                                                    String.Empty).Trim(), out renameMSHA))
            {
                renameMSHA = false;
            }

            // At least one deployment location must be defined
            if (deployHelp1.Location == null && deployHelpViewer.Location == null && deployWebsite.Location == null &&
                deployOpenXml.Location == null && deployMarkdown.Location == null)
            {
                throw new BuilderException("ODP0002", "The output deployment plug-in must have at least " +
                                           "one configured deployment location");
            }

            // Issue a warning if the deployment location is null and the associated help file format is active
            if (deployHelp1.Location == null &&
                (builder.CurrentProject.HelpFileFormat & HelpFileFormats.HtmlHelp1) != 0)
            {
                builder.ReportWarning("ODP0003", "HTML Help 1 will be generated but not deployed due to " +
                                      "missing deployment location information");
            }

            if (deployHelpViewer.Location == null &&
                (builder.CurrentProject.HelpFileFormat & HelpFileFormats.MSHelpViewer) != 0)
            {
                builder.ReportWarning("ODP0003", "MS Help Viewer will be generated but not deployed due " +
                                      "to missing deployment location information");
            }

            if (deployWebsite.Location == null &&
                (builder.CurrentProject.HelpFileFormat & HelpFileFormats.Website) != 0)
            {
                builder.ReportWarning("ODP0003", "Website will be generated but not deployed due to " +
                                      "missing deployment location information");
            }

            if (deployOpenXml.Location == null &&
                (builder.CurrentProject.HelpFileFormat & HelpFileFormats.OpenXml) != 0)
            {
                builder.ReportWarning("ODP0003", "Open XML will be generated but not deployed due to " +
                                      "missing deployment location information");
            }

            if (deployMarkdown.Location == null &&
                (builder.CurrentProject.HelpFileFormat & HelpFileFormats.Markdown) != 0)
            {
                builder.ReportWarning("ODP0003", "Markdown content will be generated but not deployed due to " +
                                      "missing deployment location information");
            }
        }
Exemple #17
0
        //=====================================================================

        /// <summary>
        /// Deploy the given list of files to the specified location
        /// </summary>
        /// <param name="files">The list of files to deploy</param>
        /// <param name="location">The deployment location</param>
        private void DeployOutput(Collection <string> files, DeploymentLocation location)
        {
            WebClient webClient = null;
            Uri       destUri, target = location.Location;
            string    rootPath, destFile, destPath;
            int       fileCount = 0, basePathLength = builder.OutputFolder.Length;

            if (target == null)
            {
                builder.ReportProgress("No deployment location defined for this help format");
                return;
            }

            if (files.Count == 0)
            {
                builder.ReportProgress("No files found to deploy");
                return;
            }

            try
            {
                // Determine the path type
                if (!target.IsAbsoluteUri)
                {
                    rootPath = Path.GetFullPath(target.OriginalString);
                }
                else
                if (target.IsFile || target.IsUnc)
                {
                    rootPath = target.LocalPath;
                }
                else
                {
                    // .NET 4.5 doesn't use TLS 1.2 by default so we have to manually tell it to use it or the
                    // web client connections will fail.  This can be removed once we upgrade to .NET 4.6.2 or
                    // later.
                    if ((ServicePointManager.SecurityProtocol & SecurityProtocolType.Tls12) != SecurityProtocolType.Tls12)
                    {
                        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                    }

                    // FTP, HTTP, etc.
                    rootPath  = target.ToString();
                    webClient = new WebClient();

                    // Initialize the web client
                    if (!location.UserCredentials.UseDefaultCredentials)
                    {
                        webClient.Credentials = new NetworkCredential(location.UserCredentials.UserName,
                                                                      location.UserCredentials.Password);
                    }

                    webClient.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);

                    if (location.ProxyCredentials.UseProxyServer)
                    {
                        webClient.Proxy = new WebProxy(location.ProxyCredentials.ProxyServer, true);

                        if (!location.ProxyCredentials.Credentials.UseDefaultCredentials)
                        {
                            webClient.Proxy.Credentials = new NetworkCredential(
                                location.ProxyCredentials.Credentials.UserName,
                                location.ProxyCredentials.Credentials.Password);
                        }
                    }
                }

                foreach (string sourceFile in files)
                {
                    destFile = Path.Combine(rootPath, sourceFile.Substring(basePathLength));

                    // Rename MSHA file?  Note that if renamed and there is more than one, the last one
                    // copied wins.  This really only applies to MS Help Viewer output but it's the only
                    // unique option so we'll do it in all cases for now.
                    if (Path.GetExtension(destFile).Equals(".msha", StringComparison.OrdinalIgnoreCase) && renameMSHA)
                    {
                        destFile = Path.Combine(Path.GetDirectoryName(destFile), "HelpContentSetup.msha");
                    }

                    if (webClient == null)
                    {
                        if (verboseLogging)
                        {
                            builder.ReportProgress("    Deploying {0} to {1}", sourceFile, destFile);
                        }

                        destPath = Path.GetDirectoryName(destFile);

                        if (!Directory.Exists(destPath))
                        {
                            Directory.CreateDirectory(destPath);
                        }

                        File.Copy(sourceFile, destFile, true);
                    }
                    else
                    {
                        destUri = new Uri(destFile);

                        if (verboseLogging)
                        {
                            builder.ReportProgress("    Deploying {0} to {1}", sourceFile, destUri);
                        }

                        webClient.UploadFile(destUri, sourceFile);
                    }

                    // If not wanted, remove the source file after deployment
                    if (deleteAfterDeploy)
                    {
                        File.Delete(sourceFile);
                    }

                    if (!verboseLogging)
                    {
                        fileCount++;

                        if ((fileCount % 500) == 0)
                        {
                            builder.ReportProgress("    Deployed {0} files", fileCount);
                        }
                    }
                }

                if (!verboseLogging)
                {
                    builder.ReportProgress("    Finished deploying {0} files", fileCount);
                }
            }
            finally
            {
                if (webClient != null)
                {
                    webClient.Dispose();
                }
            }
        }
        /// <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;
            string value;

            builder = buildProcess;

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

            root = configuration.SelectSingleNode("configuration");
            value = root.GetAttribute("deleteAfterDeploy", String.Empty);

            if(!String.IsNullOrEmpty(value))
                deleteAfterDeploy = Convert.ToBoolean(value,
                    CultureInfo.InvariantCulture);

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

            deployHelp1 = DeploymentLocation.FromXPathNavigator(root, "help1x");
            deployHelp2 = DeploymentLocation.FromXPathNavigator(root, "help2x");
            deployHelpViewer = DeploymentLocation.FromXPathNavigator(root, "helpViewer");
            deployWebsite = DeploymentLocation.FromXPathNavigator(root, "website");

            // At least one deployment location must be defined
            if(deployHelp1.Location == null && deployHelp2.Location == null &&
              deployHelpViewer.Location == null && deployWebsite.Location == null)
                throw new BuilderException("ODP0002", "The output deployment " +
                    "plug-in must have at least one configured deployment " +
                    "location");

            // Issue a warning if the deployment location is null and the
            // associated help file format is active.
            if(deployHelp1.Location == null &&
              (builder.CurrentProject.HelpFileFormat & HelpFileFormat.HtmlHelp1) != 0)
                builder.ReportWarning("ODP0003", "HTML Help 1 will be generated " +
                    "but not deployed due to missing deployment location " +
                    "information");

            if(deployHelp2.Location == null &&
              (builder.CurrentProject.HelpFileFormat & HelpFileFormat.MSHelp2) != 0)
                builder.ReportWarning("ODP0003", "MS Help 2 will be generated " +
                    "but not deployed due to missing deployment location " +
                    "information");

            if(deployHelpViewer.Location == null &&
              (builder.CurrentProject.HelpFileFormat & HelpFileFormat.MSHelpViewer) != 0)
                builder.ReportWarning("ODP0003", "MS Help Viewer will be generated " +
                    "but not deployed due to missing deployment location " +
                    "information");

            if(deployWebsite.Location == null &&
              (builder.CurrentProject.HelpFileFormat & HelpFileFormat.Website) != 0)
                builder.ReportWarning("ODP0003", "Website will be generated " +
                    "but not deployed due to missing deployment location " +
                    "information");
        }