private void NotifyProgressChanged(int fileSize, long contentLength) { var @continue = HasEnoughTimeElapsed || _lastFileSize == 0 || fileSize >= contentLength; if (!@continue) { return; } var fileSizeDelta = (fileSize - _lastFileSize); var timeSpan = (DateTime.Now - _lastTick); var bytesPerSecond = fileSizeDelta / timeSpan.TotalSeconds; if (timeSpan.TotalSeconds == 0) { Logger.Error("Not enough time between notifications to generate meaningful data"); return; } var progress = new FileDownloadProgress(State, fileSize, contentLength, bytesPerSecond * 8); Console.WriteLine(progress); if (ProgressChanged != null) { var thread = CallbackThread ?? (SynchronizationContext.Current != null ? TaskScheduler.FromCurrentSynchronizationContext() : TaskScheduler.Default); Task.Factory.StartNew(() => ProgressChanged(progress), CancellationToken.None, TaskCreationOptions.None, thread); ProgressChanged(progress); } }
public void OnUpdateDownloadProgressChanged(Update update, FileDownloadProgress progress) { _menuItem.Text = string.Format( "Downloading Update: {0:P}...", progress.PercentComplete / 100.0); }
private void DownloaderOnProgressChanged(FileDownloadProgress fileDownloadProgress) { if (DownloadProgressChanged != null) DownloadProgressChanged(fileDownloadProgress); }
private void ProgressChanged(FileDownloadProgress progress) { var message = string.Format( "Downloading version {0}: {1} of {2} @ {3} ({4:P})", _updater.LatestUpdate.Version, FileUtils.HumanFriendlyFileSize(progress.BytesDownloaded), FileUtils.HumanFriendlyFileSize(progress.ContentLength), progress.HumanSpeed, progress.PercentComplete / 100.0); Logger.Debug(message); Notify(observer => observer.OnUpdateDownloadProgressChanged(_updater.LatestUpdate, progress)); }
private void NotifyProgressChanged(int fileSize, long contentLength) { var @continue = HasEnoughTimeElapsed || _lastFileSize == 0 || fileSize >= contentLength; if (!@continue) return; var fileSizeDelta = (fileSize - _lastFileSize); var timeSpan = (DateTime.Now - _lastTick); var bytesPerSecond = fileSizeDelta / timeSpan.TotalSeconds; if (timeSpan.TotalSeconds == 0) { Logger.Error("Not enough time between notifications to generate meaningful data"); return; } var progress = new FileDownloadProgress(State, fileSize, contentLength, bytesPerSecond * 8); Console.WriteLine(progress); if (ProgressChanged != null) { var thread = CallbackThread ?? (SynchronizationContext.Current != null ? TaskScheduler.FromCurrentSynchronizationContext() : TaskScheduler.Default); Task.Factory.StartNew(() => ProgressChanged(progress), CancellationToken.None, TaskCreationOptions.None, thread); ProgressChanged(progress); } }