Пример #1
0
        //
        public async System.Threading.Tasks.Task DownloadAsync(string remoteUri, IDownloadObserver observer)
        {
            this.url = remoteUri;
            // Set the Notiifcation Observer..
            this.DownloadObserver = observer;
            //
            String fileName = Path.GetFileName(remoteUri);
            string filePath = Directory.GetCurrentDirectory() + "\\" + fileName;

            this.downloadLocation = filePath;

            mHttpClientWithProgress = new HttpClientWithProgress(remoteUri, filePath, this);
            {
                this.downloadStatus = "Continue";
                //
                mHttpClientWithProgress.ProgressChanged += (totalFileSize, totalBytesDownloaded, progressPercentage) => {
                    //Console.WriteLine($"{progressPercentage}% ({totalBytesDownloaded}/{totalFileSize})");
                    this.uodateStatus($"{progressPercentage}% ({totalBytesDownloaded}/{totalFileSize})");
                    if (progressPercentage == 100)
                    {
                        this.onComplete(this, new AsyncCompletedEventArgs(null, false, null));
                    }
                };



                await mHttpClientWithProgress.StartDownload();
            }
        }
Пример #2
0
        public void cancel()
        {
            AsyncCompletedEventArgs ag = new AsyncCompletedEventArgs(null, true, null);

            if (mHttpClientWithProgress != null)
            {
                onComplete(this, ag);

                mHttpClientWithProgress.cancel();
                mHttpClientWithProgress = null;
            }
        }