Beispiel #1
0
        /// <summary>
        /// Downloads the resource at the URI specified by in the address parameter.
        /// When the download completes successfully, the downloaded file is named fileName on the local computer.
        /// </summary>
        /// <param name="address"></param>
        /// <param name="tmpFileName"></param>
        /// <param name="dontStartUpdate"></param>
        /// <param name="fileName"></param>
        /// <param name="checkSum"></param>
        public void Download(Uri address, string tmpFileName, bool dontStartUpdate, string fileName, string checkSum)
        {
            _tmpFileName = tmpFileName;
            if (_file.Exists(_tmpFileName))
            {
                _file.Delete(_tmpFileName);
            }

            _dontStartUpdate = dontStartUpdate;
            _webClient.DownloadFileAsync(address, tmpFileName, tmpFileName);
            _webClient.DownloadFileCompleted += (o, args) =>
            {
                if (!args.Cancelled && null == args.Error && PerformCheckSum(tmpFileName, checkSum))
                {
                    _file.Move(tmpFileName, fileName);
                    OnDownloadFileCompleted(args, fileName);
                }
                else
                {
                    _file.Delete(tmpFileName);
                    ProgressDialog.Close();
                }
            };

            ProgressDialog.Show();
            IsBusyDownloading = true;
        }
Beispiel #2
0
 public void Cancel()
 {
     _webClient.CancelAsync();
     ProgressDialog.Close();
     IsBusyDownloading = false;
     if (_file.Exists(_tmpFileName))
     {
         _file.Delete(_tmpFileName);
     }
 }