/// <summary> /// Raises the <see cref="HttpReceiveProgress"/> event. /// </summary> /// <param name="request">The request.</param> /// <param name="e">The <see cref="HttpProgressEventArgs"/> instance containing the event data.</param> protected internal virtual void OnHttpResponseProgress(HttpRequestMessage request, HttpProgressEventArgs e) { if (HttpReceiveProgress != null) { HttpReceiveProgress(request, e); } }
private void UpdateProgress(object sender, HttpProgressEventArgs e) { Dispatcher.Invoke(() => { if (e.TotalBytes.HasValue) { progressBar.Value = (100 * e.BytesTransferred) / e.TotalBytes.Value; } }); }
/// <summary> /// Raises the <see cref="HttpReceiveProgress"/> event. /// </summary> /// <param name="request">The request.</param> /// <param name="e">The <see cref="HttpProgressEventArgs"/> instance containing the event data.</param> protected internal virtual void OnHttpResponseProgress( HttpRequestMessage request, HttpProgressEventArgs e ) { if (HttpReceiveProgress != null) { HttpReceiveProgress(request, e); } }
public void Constructor_Initializes() { // Arrange int progressPercentage = 10; object userState = new object(); long bytesTransferred = 10L * 1024 * 1024 * 1024; long? totalBytes = 10L * 1024 * 1024 * 1024; // Act HttpProgressEventArgs args = new HttpProgressEventArgs(progressPercentage, userState, bytesTransferred, totalBytes); // Assert Assert.Equal(progressPercentage, args.ProgressPercentage); Assert.Equal(userState, args.UserState); Assert.Equal(bytesTransferred, args.BytesTransferred); Assert.Equal(totalBytes, args.TotalBytes); }
public void Constructor_Initializes() { // Arrange int progressPercentage = 10; object userState = new object(); int bytesTransferred = 1024; long? totalBytes = 1024 * 1024; // Act HttpProgressEventArgs args = new HttpProgressEventArgs(progressPercentage, userState, bytesTransferred, totalBytes); // Assert Assert.Equal(progressPercentage, args.ProgressPercentage); Assert.Equal(userState, args.UserState); Assert.Equal(bytesTransferred, args.BytesTransferred); Assert.Equal(totalBytes, args.TotalBytes); }
private void ReportProgress(object sender, HttpProgressEventArgs e) { if (System.Windows.Threading.Dispatcher.CurrentDispatcher.CheckAccess()) { double x, y; x = e.BytesTransferred; y = e.TotalBytes.GetValueOrDefault(1); double percentage = x / y * 100; this.UploadPercentage = percentage; //Math.Round(percentage,0); } NotifyOfPropertyChange(() => this.UploadPercentage); }
public static void ProgressHandler(object sender, HttpProgressEventArgs e) { LogToConsole("#", false); }
private void HttpSendProgress(object sender, HttpProgressEventArgs e) { HttpRequestMessage request = sender as HttpRequestMessage; ProgressBar.Dispatcher.BeginInvoke( DispatcherPriority.Normal, new DispatcherOperationCallback(delegate { ProgressBar.Value = e.ProgressPercentage; return null; }), null); }
static void ProgressEventHandler(object sender, HttpProgressEventArgs eventArgs) { // The sender is the originating HTTP request HttpRequestMessage request = sender as HttpRequestMessage; // Write different message depending on whether we have a total length or not string message; if (eventArgs.TotalBytes != null) { message = String.Format(" Request {0} uploaded {1} of {2} bytes ({3}%)", request.RequestUri, eventArgs.BytesTransferred, eventArgs.TotalBytes, eventArgs.ProgressPercentage); } else { message = String.Format(" Request {0} uploaded {1} bytes", request.RequestUri, eventArgs.BytesTransferred, eventArgs.TotalBytes, eventArgs.ProgressPercentage); } // Write progress message to console Console.WriteLine(message); }