Пример #1
0
        private void ReportDownloadProgress()
        {
            var temp = 0L;

            while (DownloadState == DownloadStateEnum.Downloading)
            {
                Thread.Sleep(1000);
                if (temp == 0)
                {
                    temp = Info.CompletedLength;
                }
                else
                {
                    if (DownloadState == DownloadStateEnum.Downloading)
                    {
                        DownloadSpeed      = Info.CompletedLength - temp;
                        DownloadPercentage = Info.CompletedLength;
                        DownloadProgressChangedEvent?.Invoke(this,
                                                             new DownloadPercentageChangedEventArgs(
                                                                 new DataSize(DownloadPercentage),
                                                                 new DataSize(DownloadSpeed)));

                        temp = Info.CompletedLength;
                    }
                }
            }
        }
Пример #2
0
        void ProgressChanged(long value, long max)
        {
            var percentage = (float)value / max * 100;

            var e = new ProgressChangedEventArgs((int)percentage, null);

            DownloadProgressChangedEvent?.Invoke(this, e);
        }
Пример #3
0
        // Note that this event is invoked on a background thread, so we cannot access the UI directly.
        private void DownloadProgress(DownloadOperation download)
        {
            // DownloadOperation.Progress is updated in real-time while the operation is ongoing. Therefore,
            // we must make a local copy so that we can have a consistent view of that ever-changing state
            // throughout this method's lifetime.
            BackgroundDownloadProgress currentProgress = download.Progress;

            double percent = 100;

            if (currentProgress.TotalBytesToReceive > 0)
            {
                percent = currentProgress.BytesReceived * 100 / currentProgress.TotalBytesToReceive;
            }

            var payload = new DownloadProgressChangedEvent();

            payload.Identifier = download.Guid;
            payload.Percent    = percent;

            var transfer = this.TransferHistory.Where(f => f.Identifier == download.Guid).FirstOrDefault();

            if (transfer != null)
            {
                transfer.PercentComplete = percent;
            }

            Messenger.Default.Send <DownloadProgressChangedEvent>(payload);

            if (currentProgress.HasRestarted)
            {
            }

            if (currentProgress.HasResponseChanged)
            {
                // We have received new response headers from the server.
                // Be aware that GetResponseInformation() returns null for non-HTTP transfers (e.g., FTP).
                ResponseInformation response = download.GetResponseInformation();
                int headersCount             = response != null ? response.Headers.Count : 0;
            }
        }
Пример #4
0
 private static void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
 {
     DownloadProgressChangedEvent?.Invoke(sender, e);
 }
Пример #5
0
 public static void ResetDownloadProgressChanged()
 {
     DownloadProgressChangedEvent?.Invoke(null, null);
 }
 private void _onDownloadProgressChanged(object sender,
                                         DownloadProgressChangedEventArgs downloadProgressChangedEventArgs)
 {
     DownloadProgressChangedEvent?.Invoke(sender, new RedditImageDownloaderEvents.DownloadChangedEventArgs(downloadProgressChangedEventArgs, _currentFileName, _currentUri, _currentFileNumber));
 }
Пример #7
0
 private static void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
 {
     WiiuClient.ReportProgress(0, (int)e.TotalBytesToReceive, (int)e.BytesReceived);
     DownloadProgressChangedEvent?.Invoke(sender, e);
 }