/// <summary>takes our copy of the stream, and puts it into the request stream</summary> protected void CopyRequestData() { if (this.requestCopy != null) { // Since we don't use write buffering on the WebRequest object, // we need to ensure the Content-Length field is correctly set // to the length we want to set. EnsureWebRequest(); this.Request.ContentLength = this.requestCopy.Length; // stream it into the real request stream Stream req = base.GetRequestStream(); try { const int size = 4096; byte[] bytes = new byte[size]; int numBytes; double oneLoop = 100; if (requestCopy.Length > size) { oneLoop = (100 / ((double)this.requestCopy.Length / size)); } // 3 lines of debug code // this.requestCopy.Seek(0, SeekOrigin.Begin); // StreamReader reader = new StreamReader( this.requestCopy ); // string text = reader.ReadToEnd(); this.requestCopy.Seek(0, SeekOrigin.Begin); long bytesWritten = 0; double current = 0; while ((numBytes = this.requestCopy.Read(bytes, 0, size)) > 0) { req.Write(bytes, 0, numBytes); bytesWritten += numBytes; if (this.asyncData != null && this.asyncData.Delegate != null && this.asyncData.DataHandler != null) { AsyncOperationProgressEventArgs args; args = new AsyncOperationProgressEventArgs(this.requestCopy.Length, bytesWritten, (int)current, this.Request.RequestUri, this.Request.Method, this.asyncData.UserData); current += oneLoop; if (!this.asyncData.DataHandler.SendProgressData(asyncData, args)) { break; } } } } finally { req.Close(); } } }
// This method is invoked via the AsyncOperation object, // so it is guaranteed to be executed on the correct thread. private void OnAsyncReportProgress(object state) { AsyncOperationProgressEventArgs e = state as AsyncOperationProgressEventArgs; if (this.AsyncOperationProgress != null) { this.AsyncOperationProgress(this, e); } }
internal bool SendProgressData(AsyncData data, AsyncOperationProgressEventArgs args) { // In this case, don't allow cancellation, as the method // is about to raise the completed event. bool ret = !CheckIfOperationIsCancelled(data.UserData); if (ret) { data.Operation.Post(data.Delegate, args); } return(ret); }
private MemoryStream CopyResponseToMemory(AsyncData data, Stream responseStream, long contentLength) { if (responseStream == null) { return(null); } // read the stream into memory. That's the only way to satisfy the "main work // on the other thread requirement MemoryStream memStream = new MemoryStream(); const int size = 4096; var bytes = new byte[size]; int numBytes; double current = 0; long bytesWritten = 0; while ((numBytes = responseStream.Read(bytes, 0, size)) > 0) { memStream.Write(bytes, 0, numBytes); if (data == null || data.Delegate == null) { continue; } bytesWritten += numBytes; if (contentLength > size) { current = bytesWritten * 100d / contentLength; } // see if we are still in the list... // Multiple threads will access the task dictionary, // so it must be locked to serialize access. if (CheckIfOperationIsCancelled(data.UserData)) { throw new ArgumentException("Operation was cancelled"); } var args = new AsyncOperationProgressEventArgs(contentLength, bytesWritten, (int)current, data.UriToUse, data.HttpVerb, data.UserData); data.Operation.Post(data.Delegate, args); } memStream.Seek(0, SeekOrigin.Begin); return(memStream); }
protected void OnResumableUploaderAsyncOperationProgress(object sender, AsyncOperationProgressEventArgs e) { var message = string.Format("Upload Progress: {0} ({1}/{2} - {3}%) {4} {5}", DateTime.Now, e.Position, e.CompleteSize, e.ProgressPercentage, e.HttpVerb, e.Uri); var executePicasaUploaderWorkflowMessage = (IExecutePicasaUploaderWorkflowMessage)e.UserState; var picasaUploaderProgressMessage = new PicasaUploaderProgressMessage { CorrelationId = executePicasaUploaderWorkflowMessage.CorrelationId, InputFilePath = executePicasaUploaderWorkflowMessage.InputFilePath, Output = message }; var bus = BusDriver.Instance.GetBus(PicasaUploaderService.BusName); bus.Publish(picasaUploaderProgressMessage); }
private static void OnSpreadsheetUploadProgress(object in_sender, AsyncOperationProgressEventArgs in_e) { Instance.InstanceData.WorkbookUploadProgress = in_e.ProgressPercentage; }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>takes our copy of the stream, and puts it into the request stream</summary> ////////////////////////////////////////////////////////////////////// protected void CopyRequestData() { if (this.requestCopy != null) { // Since we don't use write buffering on the WebRequest object, // we need to ensure the Content-Length field is correctly set // to the length we want to set. EnsureWebRequest(); this.Request.ContentLength = this.requestCopy.Length; // stream it into the real request stream Stream req = base.GetRequestStream(); try { const int size = 4096; byte[] bytes = new byte[size]; int numBytes; double oneLoop = 100; if (requestCopy.Length > size) { oneLoop = (100 / ((double)this.requestCopy.Length / size)); } this.requestCopy.Seek(0, SeekOrigin.Begin); #if WindowsCE || PocketPC #else long bytesWritten = 0; double current = 0; #endif while ((numBytes = this.requestCopy.Read(bytes, 0, size)) > 0) { req.Write(bytes, 0, numBytes); #if WindowsCE || PocketPC #else bytesWritten += numBytes; if (this.asyncData != null && this.asyncData.Delegate != null && this.asyncData.Service != null) { AsyncOperationProgressEventArgs args; args = new AsyncOperationProgressEventArgs(this.requestCopy.Length, bytesWritten, (int)current, this.asyncData.UserData); if (this.asyncData.Service.SendProgressData(asyncData, args) == false) break; current += oneLoop; } #endif } } finally { req.Close(); } } }
private void OnProgress(object sender, AsyncOperationProgressEventArgs e) { this.CancelAsync.Enabled = true; this.CancelAsync.Visible = true; if (this.states.Contains(e.UserState as UserState) == true) { this.progressBar.Value = e.ProgressPercentage ; } }
internal bool SendProgressData(AsyncData data, AsyncOperationProgressEventArgs args) { // In this case, don't allow cancellation, as the method // is about to raise the completed event. bool ret = !CheckIfOperationIsCancelled(data.UserData); if (ret) { data.Operation.Post(data.Delegate, args); } return ret; }
private MemoryStream CopyResponseToMemory(AsyncData data, Stream responseStream, long contentLength) { if (responseStream == null) { return null; } // read the stream into memory. That's the only way to satisfy the "main work // on the other thread requirement MemoryStream memStream = new MemoryStream(); const int size = 4096; var bytes = new byte[size]; int numBytes; double current = 0; long bytesWritten = 0; while ((numBytes = responseStream.Read(bytes, 0, size)) > 0) { memStream.Write(bytes, 0, numBytes); if (data == null || data.Delegate == null) { continue; } bytesWritten += numBytes; if (contentLength > size) { current = bytesWritten * 100d / contentLength; } // see if we are still in the list... // Multiple threads will access the task dictionary, // so it must be locked to serialize access. if (CheckIfOperationIsCancelled(data.UserData)) { throw new ArgumentException("Operation was cancelled"); } var args = new AsyncOperationProgressEventArgs(contentLength, bytesWritten, (int)current, data.UriToUse, data.HttpVerb, data.UserData); data.Operation.Post(data.Delegate, args); } memStream.Seek(0, SeekOrigin.Begin); return memStream; }
// when we get a progress notification we remember a bunch of state info send // that info is needed to retry later private void OnProgress(object sender, AsyncOperationProgressEventArgs e) { UserState u = e.UserState as UserState; if (u != null && u.Row != null) { string status = ""; if (u.RetryCounter > 1) { status = "Retrying (" + (u.RetryCounter - 1).ToString() + "), uploading: " + e.ProgressPercentage + "% done"; } else { status = "Uploading: " + e.ProgressPercentage + "% done"; } Trace.TraceInformation("OnProgress: " + status); Trace.Indent(); Trace.TraceInformation("Verb: " + e.HttpVerb); Trace.TraceInformation("Uri: " + e.Uri); Trace.TraceInformation("Current position: " + e.Position); Trace.Unindent(); u.CurrentPosition = e.Position; u.ResumeUri = e.Uri; u.HttpVerb = e.HttpVerb; u.Row.Cells[COLUMNINDEX_STATUS].Value = status; } }
private void Service_AsyncOperationProgress(object sender, AsyncOperationProgressEventArgs e) { // Being lazy and reusing their event args AsyncOperationProgress(sender, e); }
void Upload_AsyncOperationProgress(object sender, AsyncOperationProgressEventArgs e) { progressBar1.Value = e.ProgressPercentage; }
/// <summary>takes our copy of the stream, and puts it into the request stream</summary> protected void CopyRequestData() { if (this.requestCopy != null) { // Since we don't use write buffering on the WebRequest object, // we need to ensure the Content-Length field is correctly set // to the length we want to set. EnsureWebRequest(); this.Request.ContentLength = this.requestCopy.Length; // stream it into the real request stream Stream req = base.GetRequestStream(); try { const int size = 4096; byte[] bytes = new byte[size]; int numBytes; double oneLoop = 100; if (requestCopy.Length > size) { oneLoop = (100 / ((double)this.requestCopy.Length / size)); } // 3 lines of debug code // this.requestCopy.Seek(0, SeekOrigin.Begin); // StreamReader reader = new StreamReader( this.requestCopy ); // string text = reader.ReadToEnd(); this.requestCopy.Seek(0, SeekOrigin.Begin); long bytesWritten = 0; double current = 0; while ((numBytes = this.requestCopy.Read(bytes, 0, size)) > 0) { req.Write(bytes, 0, numBytes); bytesWritten += numBytes; if (this.asyncData != null && this.asyncData.Delegate != null && this.asyncData.DataHandler != null) { AsyncOperationProgressEventArgs args; args = new AsyncOperationProgressEventArgs(this.requestCopy.Length, bytesWritten, (int)current, this.Request.RequestUri, this.Request.Method, this.asyncData.UserData); current += oneLoop; if (!this.asyncData.DataHandler.SendProgressData(asyncData, args)) break; } } } finally { req.Close(); } } }
void Service_AsyncOperationProgress(object sender, AsyncOperationProgressEventArgs e) { //Console.WriteLine(e.ProgressPercentage); progressBar1.Value = e.ProgressPercentage; debugBox.Text = e.ProgressPercentage.ToString(); }