Provides a couple of functions for external services like FileHippo.
예제 #1
0
        /// <summary>
        /// Executes the actual download (determines the URL to download from). Does not handle exceptions,
        /// but takes care of proper cleanup.
        /// </summary>
        /// <param name="job">The job to process</param>
        /// <param name="requestedUrl">The URL from which has been downloaded</param>
        /// <returns>true, if a new update has been found and downloaded, false otherwise</returns>
        protected Status DoDownload(ApplicationJob job, out string requestedUrl)
        {
            string downloadUrl;

            if (job.DownloadSourceType == ApplicationJob.SourceType.FileHippo)
            {
                downloadUrl = ExternalServices.FileHippoDownloadUrl(job.FileHippoId, job.AvoidDownloadBeta);
            }
            else
            {
                downloadUrl = job.FixedDownloadUrl;
                // Now replace variables
                downloadUrl = job.Variables.ReplaceAllInString(downloadUrl);
            }

            requestedUrl = downloadUrl;

            if (string.IsNullOrEmpty(downloadUrl))
            {
                // No download URL specified, only check if update is required
                if (job.RequiresDownload(null, null))
                {
                    return(Status.UpdateAvailable);
                }

                return(Status.NoUpdate);
            }

            Uri url = new Uri(downloadUrl);

            return(this.DoDownload(job, url));
        }
예제 #2
0
        /// <summary>
        /// Executes the actual download (determines the URL to download from). Does not handle exceptions,
        /// but takes care of proper cleanup.
        /// </summary>
        /// <param name="job">The job to process</param>
        /// <param name="requestedUrl">The URL from which has been downloaded</param>
        /// <returns>true, if a new update has been found and downloaded, false otherwise</returns>
        protected Status DoDownload(ApplicationJob job, out string requestedUrl)
        {
            // Lower security policies
            try
            {
                ServicePointManager.CheckCertificateRevocationList = false;
            }
            catch (PlatformNotSupportedException)
            {
                // .NET bug under special circumstances
            }

            ServicePointManager.ServerCertificateValidationCallback = delegate {
                return(true);
            };

            ServicePointManager.SecurityProtocol = DefaultHttpProtocols;

            // If we want to download multiple files simultaneously
            // from the same server, we need to "remove" the connection limit.
            ServicePointManager.DefaultConnectionLimit = 50;

            string downloadUrl;

            if (job.DownloadSourceType == ApplicationJob.SourceType.FileHippo)
            {
                downloadUrl = ExternalServices.FileHippoDownloadUrl(job.FileHippoId, job.AvoidDownloadBeta);
            }
            else
            {
                downloadUrl = job.FixedDownloadUrl;
                // Now replace variables
                downloadUrl = job.Variables.ReplaceAllInString(downloadUrl);
            }

            requestedUrl = downloadUrl;

            if (string.IsNullOrEmpty(downloadUrl))
            {
                // No download URL specified, only check if update is required
                if (job.RequiresDownload(null, null))
                {
                    return(Status.UpdateAvailable);
                }

                return(Status.NoUpdate);
            }

            Uri url = new Uri(downloadUrl);

            return(this.DoDownload(job, url));
        }