Exemplo n.º 1
0
        /// <summary>
        /// Determines the content for request body and uses the HTTP request
        /// to write the content to the HTTP request body.
        /// </summary>
        /// <param name="requestContent">Content to be written.</param>
        /// <param name="httpRequest">The HTTP request.</param>
        /// <param name="requestContext">The request context.</param>
        private void WriteContentToRequestBody(TRequestContent requestContent,
                                               IHttpRequest <TRequestContent> httpRequest,
                                               IRequestContext requestContext)
        {
            IRequest wrappedRequest = requestContext.Request;

            if (wrappedRequest.ContentStream == null)
            {
                byte[] requestData = wrappedRequest.Content;
                requestContext.Metrics.AddProperty(Metric.RequestSize, requestData.Length);
                httpRequest.WriteToRequestBody(requestContent, requestData, requestContext.Request.Headers);
            }
            else
            {
                var originalStream = wrappedRequest.ContentStream;
                var callback       = ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)wrappedRequest.OriginalRequest).StreamUploadProgressCallback;
                if (callback != null)
                {
                    var eventStream = new EventStream(originalStream, true);
                    var tracker     = new StreamReadTracker(this.CallbackSender, callback, originalStream.Length,
                                                            requestContext.ClientConfig.ProgressUpdateInterval);
                    eventStream.OnRead += tracker.ReadProgress;
                    originalStream      = eventStream;
                }

                var inputStream = wrappedRequest.UseChunkEncoding && wrappedRequest.AWS4SignerResult != null
                    ? new ChunkedUploadWrapperStream(originalStream,
                                                     requestContext.ClientConfig.BufferSize,
                                                     wrappedRequest.AWS4SignerResult)
                    : originalStream;

                httpRequest.WriteToRequestBody(requestContent, inputStream,
                                               requestContext.Request.Headers, requestContext);
            }
        }
        /// <summary>
        /// Sets up the progress listeners
        /// </summary>
        /// <param name="originalStream">The content stream</param>
        /// <param name="progressUpdateInterval">The interval at which progress needs to be published</param>
        /// <param name="sender">The objects which is trigerring the progress changes</param>
        /// <param name="callback">The callback which will be invoked when the progress changed event is trigerred</param>
        /// <returns>an <see cref="EventStream"/> object, incase the progress is setup, else returns the original stream</returns>
        public Stream SetupProgressListeners(Stream originalStream, long progressUpdateInterval, object sender, EventHandler <StreamTransferProgressArgs> callback)
        {
            this.Tracker = new StreamReadTracker(sender, callback, originalStream.Length,
                                                 progressUpdateInterval);

            return(originalStream);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sets up the progress listeners
        /// </summary>
        /// <param name="originalStream">The content stream</param>
        /// <param name="progressUpdateInterval">The interval at which progress needs to be published</param>
        /// <param name="sender">The objects which is trigerring the progress changes</param>
        /// <param name="callback">The callback which will be invoked when the progress changed event is trigerred</param>
        /// <returns>an <see cref="EventStream"/> object, incase the progress is setup, else returns the original stream</returns>
        public Stream SetupProgressListeners(Stream originalStream, long progressUpdateInterval, object sender, EventHandler <StreamTransferProgressArgs> callback)
        {
            var eventStream = new EventStream(originalStream, true);
            var tracker     = new StreamReadTracker(sender, callback, originalStream.Length,
                                                    progressUpdateInterval);

            eventStream.OnRead += tracker.ReadProgress;
            return(eventStream);
        }