static void progress(object sender, StreamTransferProgressArgs args) { if (args.PercentDone != currentPercentage) { currentPercentage = args.PercentDone; Console.WriteLine("Downloaded {0}%", args.PercentDone); } }
private void uploadPartProgressEventCallback(object sender, Amazon.Runtime.StreamTransferProgressArgs e) { lock (this.COUNTER_LOCK) { this._totalTransferredBytes += e.IncrementTransferred; } this._fileTransporterRequest.OnRaiseProgressEvent(e.IncrementTransferred, this._totalTransferredBytes, this._contentLength); }
public void OnUploadProgress(object sender, StreamTransferProgressArgs args) { if (args.PercentDone >= 0 && args.PercentDone <= 100) { UploadProgress.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UploadProgress.Value = args.PercentDone; })); } }
void ProgressCallback(object sender, Runtime.StreamTransferProgressArgs args) { lock (currentUploadProgressArgsLock) { this.currentUploadProgressArgs = new StreamTransferProgressArgs(args.IncrementTransferred, this.currentUploadProgressArgs.TransferredBytes + args.IncrementTransferred, this.currentUploadProgressArgs.TotalBytes); } AWSSDKUtils.InvokeInBackground(this.options.StreamTransferProgress, this.currentUploadProgressArgs, this); }
public void OnTransferProgress(object sender, StreamTransferProgressArgs e) { var compensationForRetry = 0L; if (_lastProgressArgs != null) { if (_lastProgressArgs.TransferredBytes >= e.TransferredBytes) { // The request was retried compensationForRetry = _lastProgressArgs.TransferredBytes; } } var progressArgs = new UploadProgressArgs(e.IncrementTransferred, e.TransferredBytes, e.TotalBytes, compensationForRetry, null); _callback(this, progressArgs); _lastProgressArgs = e; }
internal override void Execute() { FileInfo fileInfo = new FileInfo(filePath); FileStream fileStream = File.OpenRead(filePath); string uploadId = null; try { this.currentUploadProgressArgs = new StreamTransferProgressArgs(0, 0, fileInfo.Length); long partSize = CalculatePartSize(fileInfo.Length); InitiateMultipartUploadRequest initiateRequest = new InitiateMultipartUploadRequest { AccountId = this.options.AccountId, ArchiveDescription = archiveDescription, VaultName = vaultName, PartSize = partSize }; initiateRequest.BeforeRequestEvent += new UserAgentPostFix("MultiUpload").UserAgentRequestEventHandlerSync; InitiateMultipartUploadResult initiateResult = this.manager.GlacierClient.InitiateMultipartUpload(initiateRequest).InitiateMultipartUploadResult; uploadId = initiateResult.UploadId; List<string> partTreeHashs = new List<string>(); long currentPosition = 0; while (currentPosition < fileInfo.Length) { long length = partSize; if (currentPosition + partSize > fileInfo.Length) { length = fileInfo.Length - currentPosition; } PartStreamWrapper partStream = new PartStreamWrapper(fileStream, length); string checksum = TreeHashGenerator.CalculateTreeHash(partStream); partTreeHashs.Add(checksum); UploadMultipartPartRequest uploadRequest = new UploadMultipartPartRequest { AccountId=this.options.AccountId, Checksum=checksum, Body=partStream, Range = ("bytes " + currentPosition + "-" + (currentPosition + length - 1) + "/*"), UploadId=uploadId, VaultName=vaultName }; uploadRequest.StreamTransferProgress += this.ProgressCallback; uploadRequest.BeforeRequestEvent += new UserAgentPostFix("MultiUpload").UserAgentRequestEventHandlerSync; this.manager.GlacierClient.UploadMultipartPart(uploadRequest); currentPosition += partSize; } string totalFileChecksum = TreeHashGenerator.CalculateTreeHash(partTreeHashs); string archiveSize = fileInfo.Length.ToString(); CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest { AccountId=this.options.AccountId, ArchiveSize=archiveSize, VaultName=vaultName, Checksum=totalFileChecksum, UploadId=uploadId }; compRequest.BeforeRequestEvent += new UserAgentPostFix("MultiUpload").UserAgentRequestEventHandlerSync; CompleteMultipartUploadResult completeMultipartUploadResult = this.manager.GlacierClient.CompleteMultipartUpload(compRequest).CompleteMultipartUploadResult; string archiveId = completeMultipartUploadResult.ArchiveId; this.UploadResult = new UploadResult(archiveId, totalFileChecksum); } catch (Exception) { // If we got an unrecoverable then abort the upload. if (!string.IsNullOrEmpty(uploadId)) { AbortMultipartUploadRequest abortRequest = new AbortMultipartUploadRequest() { AccountId = this.options.AccountId, VaultName = this.vaultName, UploadId = uploadId }; abortRequest.BeforeRequestEvent += new UserAgentPostFix("MultiUpload").UserAgentRequestEventHandlerSync; this.manager.GlacierClient.AbortMultipartUpload(abortRequest); } throw; } finally { try { fileStream.Close(); } catch (Exception) { } } }
/// <summary> /// Perform signing, setup WWWRequestData with headers, binary data(for POST request) /// and enqueues to the RequestQueue for Main thread /// </summary> /// <param name="asyncResult"></param> private void ProcessHttpRequest(AsyncResult asyncResult) { try { // prepare request IRequest wrappedRequest = asyncResult.Request; WWWRequestData requestData = new WWWRequestData(); if (HttpOverrideSupportedServices.Contains(asyncResult.Request.ServiceName)) { asyncResult.Request.Headers.Add("X-HTTP-Method-Override", asyncResult.Request.HttpMethod); if (asyncResult.Request.HttpMethod == "GET") { string emptyString = "{}"; asyncResult.Request.ContentStream = new MemoryStream(Encoding.UTF8.GetBytes(emptyString)); requestData.Data = Encoding.Default.GetBytes(emptyString); } } #if UNITY_WEBPLAYER wrappedRequest.Headers.Remove("User-Agent"); wrappedRequest.Headers.Remove("Host"); #endif SignRequest(asyncResult); if (asyncResult.RetriesAttempt > 0) { HandleRetry(asyncResult); } requestData.Url = ComposeUrl(wrappedRequest, wrappedRequest.Endpoint).ToString(); if (!wrappedRequest.UseQueryString && !(wrappedRequest.HttpMethod.Equals("GET", StringComparison.OrdinalIgnoreCase))) { if (wrappedRequest.ContentStream != null) { if (wrappedRequest.OriginalRequest.IncludeSHA256Header && !wrappedRequest.Headers.ContainsKey(HeaderKeys.XAmzContentSha256Header)) { requestData.Headers.Add(HeaderKeys.XAmzContentSha256Header, wrappedRequest.ComputeContentStreamHash()); } } } AddHeaders2(requestData, wrappedRequest.Headers); if (asyncResult.Unmarshaller is JsonResponseUnmarshaller) { requestData.Headers.Add(HeaderKeys.AcceptHeader, "application/json"); } if (!asyncResult.Request.HttpMethod.Equals("GET", StringComparison.OrdinalIgnoreCase)) { if (asyncResult.Request.Content != null && asyncResult.Request.Content.Length > 0) { requestData.Data = asyncResult.Request.Content; } else if (asyncResult.Request.ContentStream != null && asyncResult.Request.ContentStream.Length > 0) { using (asyncResult.Request.ContentStream) { requestData.Data = StreamToByteArray.Convert(asyncResult.Request.ContentStream, this.Config.BufferSize); StreamTransferProgressArgs args = new StreamTransferProgressArgs(asyncResult.Request.ContentStream.Length, asyncResult.Request.ContentStream.Length, asyncResult.Request.ContentStream.Length); if (asyncResult.Request.OriginalRequest.StreamUploadProgressCallback != null) { asyncResult.Request.OriginalRequest.StreamUploadProgressCallback(this, args); } if (args.PercentDone >= 100) { asyncResult.Request.OriginalRequest.StreamUploadProgressCallback = null; } } } else if (asyncResult.Request.Parameters != null && asyncResult.Request.Parameters.Count > 0) { requestData.Data = GetRequestData(asyncResult.Request); } } asyncResult.RequestData = requestData; // setting up callback for response handling asyncResult.WaitCallback = this.ProcessHttpResponse; // switching to main thread to make the network call AmazonMainThreadDispatcher.QueueAWSRequest(asyncResult); } catch (Exception e) { AmazonLogging.LogException(AmazonLogging.AmazonLoggingLevel.Errors, asyncResult.Request.ServiceName, e); asyncResult.IsCompleted = true; asyncResult.HandleException(e); return; } }
private void putObjectProgressEventCallback(object sender, Amazon.Runtime.StreamTransferProgressArgs e) { this._fileTransporterRequest.OnRaiseProgressEvent(e.IncrementTransferred, e.TransferredBytes, e.TotalBytes); }
public void Update(object sender, StreamTransferProgressArgs e) { /* TODO: add bitrate indicator (use timer with interval of 1-10 * seconds, which compares bytes transferred before and after) * also, use this for the ETA calculation (with longer interval) */ float percent; if (e.TotalBytes != 0) percent = 100f * ((float)e.TransferredBytes / (float)e.TotalBytes); else percent = 0f; TimeSpan eta; if (e.TransferredBytes != 0) { long bytesLeft = e.TotalBytes - e.TransferredBytes; float rate = (float)watch.Elapsed.Ticks / (float)e.TransferredBytes; eta = new TimeSpan((long)((float)bytesLeft * rate)); } else eta = new TimeSpan(0); try { /* return to first column */ Console.CursorTop = Console.BufferHeight - 1; Console.CursorLeft = 0; } catch(ArgumentOutOfRangeException) { /* Terminal resize can cause an ArgumentOutOfRangeException * because of Mono bug 874 where the dimenisions of * the console aren't updated until after a write * https://bugzilla.xamarin.com/show_bug.cgi?id=874 */ Console.Write(""); return; } /* BUG: the hack used below will roll over if either time is over * 24 hours, which is likely for large archives * * in the future: use __d __:__:__ (right-aligned space-padded * two-digit days, only displayed if >24 hrs) */ /* Mono can't handle custom TimeSpan formatting, so we convert the * TimeSpans to DateTimes before printing them */ Console.Write(String.Format("{0,6:f1}%{1,7:d} MiB{2,9:d} MiB" + "{3,11:HH:mm:ss}{4,12:HH:mm:ss}", percent, (e.TransferredBytes / 1024 / 1024), (e.TotalBytes / 1024 / 1024), new DateTime(watch.Elapsed.Ticks), new DateTime(eta.Ticks))); }
void progress(object sender, StreamTransferProgressArgs args) { progressBar1.Value = args.PercentDone; }
void ProgressCallback(object sender, Runtime.StreamTransferProgressArgs args) { this.currentUploadProgressArgs = new StreamTransferProgressArgs(args.IncrementTransferred, this.currentUploadProgressArgs.TransferredBytes + args.IncrementTransferred, this.currentUploadProgressArgs.TotalBytes); if(this.options.StreamTransferProgress != null) this.options.StreamTransferProgress(this.manager, this.currentUploadProgressArgs); }