public void ProgressDownloadHandler(HttpProgress progress) { //处理进度 包括了很多状态 如ConnectingToServer、WaitingForResponse等 string infoState = progress.Stage.ToString(); double totalByteToRecive = 0; if (progress.TotalBytesToSend.HasValue) { //要发送的数据 } if (progress.TotalBytesToReceive.HasValue) { //接收数据 获取总接收数据 totalByteToRecive = progress.TotalBytesToReceive.Value; } if (progress.Stage == HttpProgressStage.ReceivingContent) { progressUpload = progress.BytesReceived / totalByteToRecive; if (ProgressChangedEvent != null) { ProgressChangedEvent(progressUpload * 100); } } }
private void current_Progress(IHttpAsyncOperation asyncInfo, HttpProgress progressInfo) { if (asyncInfo != this.current) { return; } this.Progress?.Invoke(this, progressInfo); }
private static void ProgressHandler(HttpProgress progress) { Console.Write($"\r{progress.ToString("Download dotnet")} "); if (progress.IsDone) { Console.WriteLine(); } }
private void ProgressHandler(HttpProgress progress) { StageField.Text = progress.Stage.ToString(); RetriesField.Text = progress.Retries.ToString(CultureInfo.InvariantCulture); BytesSentField.Text = progress.BytesSent.ToString(CultureInfo.InvariantCulture); BytesReceivedField.Text = progress.BytesReceived.ToString(CultureInfo.InvariantCulture); ulong totalBytesToSend = 0; if (progress.TotalBytesToSend.HasValue) { totalBytesToSend = progress.TotalBytesToSend.Value; TotalBytesToSendField.Text = totalBytesToSend.ToString(CultureInfo.InvariantCulture); } else { TotalBytesToSendField.Text = "unknown"; } ulong totalBytesToReceive = 0; if (progress.TotalBytesToReceive.HasValue) { totalBytesToReceive = progress.TotalBytesToReceive.Value; TotalBytesToReceiveField.Text = totalBytesToReceive.ToString(CultureInfo.InvariantCulture); } else { TotalBytesToReceiveField.Text = "unknown"; } double requestProgress = 0; if (progress.Stage == HttpProgressStage.SendingContent && totalBytesToSend > 0) { requestProgress = progress.BytesSent * 50 / totalBytesToSend; } else if (progress.Stage == HttpProgressStage.ReceivingContent) { // Start with 50 percent, request content was already sent. requestProgress += 50; if (totalBytesToReceive > 0) { requestProgress += progress.BytesReceived * 50 / totalBytesToReceive; } } else { return; } RequestProgressBar.Value = requestProgress; }
private async void ProgressHandler(HttpProgress progressInfo) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (progressInfo.TotalBytesToReceive != null) { BytesTotal = (long)progressInfo.TotalBytesToReceive; } BytesDownloaded = (int)progressInfo.BytesReceived; }); }
/// <summary> /// Provides a JSON object for HttpProgress /// </summary> public static JsonObject ToJsonObject(this HttpProgress p) { var builder = new JsonBuilder("HttpProgress"); builder.AddString("Stage", p.Stage); builder.AddNumber("Retries", p.Retries); builder.AddNumber("BytesSent", p.BytesSent); builder.AddNumber("TotalBytesToSend", p.TotalBytesToSend); builder.AddNumber("BytesReceived", p.BytesReceived); builder.AddNumber("TotalBytesToReceive", p.TotalBytesToReceive); return(builder.GetJsonObject()); }
private async void ProgressHandler(HttpProgress progressInfo) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (progressInfo.TotalBytesToSend != null) { BytesTotal = (long)progressInfo.TotalBytesToSend; } BytesSend = (int)progressInfo.BytesSent; WaitingForServerResponse = BytesSend == BytesTotal; }); }
private void OnSendRequestProgress(HttpProgress obj) { if (_totalSize == 0 && obj.TotalBytesToReceive == null) { return; } if (obj.TotalBytesToReceive != null) { _totalSize = obj.TotalBytesToReceive.Value; } InstallProgress = (float)obj.BytesReceived / _totalSize * 100; Debug.WriteLine(obj.Stage + " " + obj.BytesReceived + " /" + obj.TotalBytesToReceive + " /" + InstallProgress); }
public static string Convert(HttpProgress progress) { var str = ""; switch (progress.Stage) { case HttpProgressStage.ConnectingToServer: str = "Connecting\n"; break; case HttpProgressStage.WaitingForResponse: str = "Waiting\n"; break; case HttpProgressStage.ReceivingHeaders: str = "Getting headers\n"; break; case HttpProgressStage.ReceivingContent: str = "Getting catalog\n"; break; } return(str); }
private void HttpProgress_ProgressChanged(object sender, Windows.Web.Http.HttpProgress e) { var key = (IProgress <Windows.Web.Http.HttpProgress>)sender; HttpProgress newProgress = new HttpProgress() { BytesReceived = e.BytesReceived, BytesSent = e.BytesSent, Retries = e.Retries, Stage = (HttpProgressStage)Enum.Parse(typeof(HttpProgressStage), e.Stage.ToString()), TotalBytesToReceive = e.TotalBytesToReceive, TotalBytesToSend = e.TotalBytesToSend }; var value = progresses[key]; value.Report(newProgress); }
private void ProgressHandler(HttpProgress progress) { string infoString = ""; infoString = progress.Stage.ToString(); //需要发送的数据 ulong totalBytesToSend = 0; if (progress.TotalBytesToSend.HasValue) { totalBytesToSend = progress.TotalBytesToSend.Value; infoString += "发送数据:" + totalBytesToSend.ToString(CultureInfo.InvariantCulture); } //已接收的数据 ulong totalBytesToReceive = 0; if (progress.TotalBytesToReceive.HasValue) { totalBytesToReceive = progress.TotalBytesToReceive.Value; infoString += "接收数据:" + totalBytesToReceive.ToString(CultureInfo.InvariantCulture); } //进度 double requestProgress = 0; //前面50%为发送进度,后50%为接收进度 if (progress.Stage == HttpProgressStage.SendingContent && totalBytesToSend > 0) { requestProgress = progress.BytesSent * 50 / totalBytesToSend; infoString += "发送进度:"; } else if (progress.Stage == HttpProgressStage.ReceivingContent) { requestProgress += 50; if (totalBytesToReceive > 0) { requestProgress += progress.BytesReceived * 50 / totalBytesToReceive; } infoString += "接收进度:"; } else { return; } infoString += requestProgress; information.Text = infoString; }
private void ProgressHandler(HttpProgress obj) { _transferspeed += obj.BytesReceived - _old_bytes_received; _old_bytes_received = obj.BytesReceived; if (_write && _transferspeed != 0) { _write = false; _transferspeed /= (ulong)(1024 * _times_count); _times_count = 0; _message = format_message(_stopwatch.Elapsed, "Transferspeed", _transferspeed.ToString(), " kB/s"); this.callback.on_transfer_speed_change(_message, this.results); this.main_view.text_to_logs(_message.Replace("\t", " ")); _transferspeed = 0; } }
private async void OnHttpProgressChanged(HttpProgress httpProgress) { if (Windows.ApplicationModel.Core.CoreApplication.Views.Count > 0) { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { ExecutionContext.Instance.TransferOperation = new TransferOperationInfo(httpProgress, null); if (httpProgress.Stage == HttpProgressStage.ReceivingContent) { ExecutionContext.Instance.Status = ExecutionStatus.Receiving; } if (httpProgress.Stage == HttpProgressStage.SendingContent) { ExecutionContext.Instance.Status = ExecutionStatus.Sending; } }); } }
private void UploadProgressHandler(HttpProgress progress) { ulong totalBytesToSend = 0; if (progress.TotalBytesToSend.HasValue) { //Total to send totalBytesToSend = progress.TotalBytesToSend.Value; } else { } ulong totalBytesToReceive = 0; if (progress.TotalBytesToReceive.HasValue) { totalBytesToReceive = progress.TotalBytesToReceive.Value; } double requestProgress = 0; if (progress.Stage == HttpProgressStage.SendingContent && totalBytesToSend > 0) { requestProgress = progress.BytesSent * 100 / totalBytesToSend; } else if (progress.Stage == HttpProgressStage.ReceivingContent) { // Start with 50 percent, request content was already sent. requestProgress += 50; if (totalBytesToReceive > 0) { requestProgress += progress.BytesReceived * 100 / totalBytesToReceive; } } else { return; } // var progress = requestProgress; }
private void _progressDownloadHandler(HttpProgress progress) { //处理进度 包括了很多状态 如ConnectingToServer、WaitingForResponse等 string infoState = progress.Stage.ToString(); double totalByteToRecive = 0; if (progress.TotalBytesToSend.HasValue) { //要发送的数据 } if (progress.TotalBytesToReceive.HasValue) { //接收数据 获取总接收数据 totalByteToRecive = progress.TotalBytesToReceive.Value; } if (progress.Stage == HttpProgressStage.ReceivingContent) { Process = progress.BytesReceived * 100 / totalByteToRecive; } }
private async void OnProgress(IAsyncOperationWithProgress <IBuffer, HttpProgress> info, HttpProgress progressInfo) { if (progressInfo.Stage != HttpProgressStage.ReceivingContent || !progressInfo.TotalBytesToReceive.HasValue || progressInfo.TotalBytesToReceive == 0) { return; } // Fire out an event only if we have made progress in downloading the image var progress = (int)(progressInfo.BytesReceived * 100 / progressInfo.TotalBytesToReceive); if (_progress == progress) { return; } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => SetProgress(progress)); }
private async void Session_MessageUploadProgress(IAsyncOperationWithProgress <HttpResponseMessage, HttpProgress> asyncInfo, HttpProgress progressInfo) { float dest = Convert.ToSingle((100 * (_fullBytesSentBuffer + progressInfo.BytesSent)) / _fullBytesSentBuffer); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { while (progressBar.Value < dest) { progressVal.Text = progressBar.Value + "%"; progressBar.Value++; await Task.Delay(10); } if (_lockWaitState || progressInfo.Stage == HttpProgressStage.WaitingForResponse || progressInfo.Stage == HttpProgressStage.ReceivingHeaders || progressInfo.Stage == HttpProgressStage.ReceivingContent) { _lockWaitState = true; progressVal.Visibility = Visibility.Collapsed; Waiting.Visibility = Visibility.Visible; } else { progressVal.Visibility = Visibility.Visible; Waiting.Visibility = Visibility.Collapsed; } }); }
private void ProgressHandler(HttpProgress obj) { _transferspeed += obj.BytesReceived - _old_bytes_received; _old_bytes_received = obj.BytesReceived; if (_write && _transferspeed != 0) { _write = false; _transferspeed /= (ulong) (1024 * _times_count); _times_count = 0; _message = format_message(_stopwatch.Elapsed, "Transferspeed", _transferspeed.ToString(), " kB/s"); this.callback.on_transfer_speed_change(_message, this.results); this.main_view.text_to_logs(_message.Replace("\t", " ")); _transferspeed = 0; } }
public TransferOperationInfo(HttpProgress httpProgress, CancellationTokenSource cancellationTokenSource) { HttpProgress = httpProgress; CancellationTokenSource = cancellationTokenSource; }
private void HandleProgress(HttpProgress progress) { TotalSize = progress.TotalBytesToSend; CurrentSize = progress.BytesSent; }
public void DownloadProgressCallback(IAsyncOperationWithProgress <HttpResponseMessage, HttpProgress> asyncInfo, HttpProgress progressInfo) { if (progressInfo.TotalBytesToReceive != null && progressInfo.TotalBytesToReceive > 0) { var progress = (int)((progressInfo.BytesReceived / (double)progressInfo.TotalBytesToReceive) * 100d); //Debug.WriteLine("received " + (int)progress); Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher. RunAsync(CoreDispatcherPriority.Normal, () => { Progressable.Progress = progress; }); } }
private async void ReportProgress(IAsyncOperationWithProgress <IBuffer, HttpProgress> asyncInfo, HttpProgress p) { await this.Dispatcher.Yield(); var c = this.currentDownloaded + (long)p.BytesReceived; this.pb.Value = 100d * c / this.totalDownloaded; this.pb.IsIndeterminate = false; this.tbCurrent.Text = Opportunity.Converters.XBind.ByteSize.ToBinaryString(c); this.tbTotal.Text = Opportunity.Converters.XBind.ByteSize.ToBinaryString(this.totalDownloaded); }
private void Progress_Handler(IAsyncOperationWithProgress <HttpResponseMessage, HttpProgress> asyncInfo, HttpProgress progressInfo) { Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { StatusProgress.Maximum = (double)progressInfo.TotalBytesToSend; StatusProgress.Value = progressInfo.BytesSent; }); }
private void ProgressHandler(HttpProgress progress) { /* For some reason, the progress is so messed up and I have no clue why. Theoretically this should work, but it doesn't. The progress bar doesn't even show up and the value doesn't get set */ // Debug.WriteLine("Stage: " + progress.Stage.ToString()); // Debug.WriteLine("Retires: " + progress.Retries.ToString()); // Debug.WriteLine("Bytes Sent: " + progress.BytesSent.ToString()); // Debug.WriteLine("Bytes Received: " + progress.BytesReceived.ToString()); ulong totalBytesToSend = 0; if (progress.TotalBytesToSend.HasValue) { totalBytesToSend = progress.TotalBytesToSend.Value; } ulong totalBytesToReceive = 0; if (progress.TotalBytesToReceive.HasValue) { totalBytesToReceive = progress.TotalBytesToReceive.Value; } double requestProgress = 0; if (progress.Stage == HttpProgressStage.SendingContent && totalBytesToSend > 0) { requestProgress = progress.BytesSent * 50 / totalBytesToSend; } else if (progress.Stage == HttpProgressStage.ReceivingContent) { requestProgress += 50; if (totalBytesToReceive > 0) { requestProgress += progress.BytesReceived * 50 / totalBytesToReceive; } } else { return; } Debug.WriteLine(requestProgress.ToString()); if (_progressBar != null) { Debug.WriteLine("not null"); if (requestProgress != 0) { Debug.WriteLine("progress not 0"); _progressBar.IsIndeterminate = false; _progressBar.Value = requestProgress; if (requestProgress == 100) { Debug.WriteLine("100% reset"); resetProgressBar(); } Debug.WriteLine("done"); } else { Debug.WriteLine("Else reset"); resetProgressBar(); } } }