Ejemplo n.º 1
0
            /// <summary>
            /// Begins the download.
            /// </summary>
            private void BeginDownload()
            {
                Uri    url = new Uri($"{m_datafile.Address}/{m_datafile.Name}");
                string urlValidationError;

                if (!HttpWebClientService.IsValidURL(url, out urlValidationError))
                {
                    return;
                }

                if (File.Exists(m_tempFilename))
                {
                    FileHelper.DeleteFile(m_tempFilename);
                }

                try
                {
                    using (WebClient)
                    {
                        WebClient.DownloadFileCompleted   += DownloadCompleted;
                        WebClient.DownloadProgressChanged += ProgressChanged;

                        try
                        {
                            WebClient.DownloadFileAsync(url, m_tempFilename);
                        }
                        catch (WebException ex)
                        {
                            throw HttpWebClientServiceException.HttpWebClientException(url, ex);
                        }
                        catch (Exception ex)
                        {
                            throw HttpWebClientServiceException.Exception(url, ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ExceptionHandler.LogRethrowException(ex);
                    throw;
                }
            }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the Shown event of the UpdateDownloadForm control.
        /// </summary>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            string urlValidationError;

            if (!HttpWebClientService.IsValidURL(m_url, out urlValidationError))
            {
                throw new ArgumentException(urlValidationError);
            }

            try
            {
                using (m_client = HttpWebClientService.GetWebClient())
                {
                    m_client.DownloadFileCompleted   += DownloadCompleted;
                    m_client.DownloadProgressChanged += ProgressChanged;

                    try
                    {
                        m_client.DownloadFileAsync(m_url, m_fileName);
                    }
                    catch (WebException ex)
                    {
                        throw HttpWebClientServiceException.HttpWebClientException(m_url, ex);
                    }
                    catch (Exception ex)
                    {
                        throw HttpWebClientServiceException.Exception(m_url, ex);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.LogRethrowException(ex);
                throw;
            }
        }