Dev2.CustomControls.Progress.ProgressFileDownloader.Download C# (CSharp) Method

Download() public method

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.
public Download ( Uri address, string tmpFileName, bool dontStartUpdate, string fileName, string checkSum ) : void
address System.Uri
tmpFileName string
dontStartUpdate bool
fileName string
checkSum string
return void
        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;
        }

Usage Example

// ReSharper disable InconsistentNaming
        public void ProgressFileDownloader_UnitTest_Download_AsyncDownloadStartedAndProgressDialogShown()
// ReSharper restore InconsistentNaming
        {
            //init
            var mockWebClient = new Mock<IDev2WebClient>();
            mockWebClient.Setup(c => c.DownloadFileAsync(It.IsAny<Uri>(), It.IsAny<string>(), It.IsAny<string>())).Verifiable();
            var mockProgressDialog = new Mock<IProgressDialog>();
            mockProgressDialog.Setup(c => c.Show()).Verifiable();
            ProgressFileDownloader.GetProgressDialogViewModel = (x, y) => mockProgressDialog.Object;
            var testProgressFileDownloader = new ProgressFileDownloader(mockWebClient.Object, new Mock<IFile>().Object,new Mock<ICryptoProvider>().Object);
            //exe
            testProgressFileDownloader.Download(It.IsAny<Uri>(), It.IsAny<string>(), false,It.IsAny<string>(), "");

            //assert
            mockWebClient.Verify(c => c.DownloadFileAsync(It.IsAny<Uri>(), It.IsAny<string>(), It.IsAny<string>()));

        }
All Usage Examples Of Dev2.CustomControls.Progress.ProgressFileDownloader::Download