public override Task Start() { String fileName = Path.GetFileName(SourceUri.LocalPath); String destinationPathAndFileName = Path.Combine(DestinationUri.LocalPath, fileName); this.StartTime = DateTimeOffset.Now; this.EndTime = DateTimeOffset.MaxValue; this.IsComplete = false; this.IsRunning = true; this.PercentComplete = 0; this.StatusMessage = "Download initializing..."; this.TimeElapsed = DateTimeOffset.Now.Subtract(this.StartTime); this.TimeRemaining = TimeSpan.MaxValue; this.BytesReceived = 0; this.BytesTotal = 0; using (WebClient client = new WebClient()) { _webClient = client; client.DownloadProgressChanged += (sender, e) => { InstrumentationProgressChangedEventArgs eventArgs = new InstrumentationProgressChangedEventArgs(this); this.BytesTotal = e.TotalBytesToReceive; this.BytesReceived = e.BytesReceived; this.PercentComplete = e.ProgressPercentage; OnInstrumentationProgressChanged(eventArgs); }; client.DownloadFileCompleted += (sender, e) => { InstrumentationCompleteEventArgs eventArgs = new InstrumentationCompleteEventArgs(this); OnInstrumentationComplete(eventArgs); }; return client.DownloadFileTaskAsync(SourceUri, destinationPathAndFileName); } }
public override void OnInstrumentationProgressChanged(InstrumentationProgressChangedEventArgs eventArgs) { RecalculateStatistics(); base.OnInstrumentationProgressChanged(eventArgs); }