private IEnumerator <IAsyncResult> FlushToInnerStreamImpl(TimeSpan timeout, AsyncIteratorContext <NoResults> context) { this.CheckDisposed(); Duration startingNow = Duration.StartingNow; bool flag = true; List <BufferWrapper> .Enumerator enumerator = this.buffers.GetEnumerator(); try { while (enumerator.MoveNext()) { byte[] numArray = enumerator.Current.Buffer; if (this.bytesAccumulated == 0) { goto Label0; } int num = Math.Min((int)numArray.Length, this.bytesAccumulated); int timeoutInMS = AsyncStreamCopy.TimeSpanToTimeoutInMS(startingNow.Remaining(timeout)); if (timeoutInMS == 0) { throw new TimeoutException("timed out while flushing"); } if (flag) { try { this.innerStream.WriteTimeout = timeoutInMS; } catch (InvalidOperationException invalidOperationException) { flag = false; } } IAsyncResult asyncResult = this.innerStream.BeginWrite(numArray, 0, num, context.GetResumeCallback(), context.GetResumeState("this.innerStream.Write")); yield return(asyncResult); this.innerStream.EndWrite(asyncResult); IStringDataEventStream verbose = Logger <IRestProtocolHeadLogger> .Instance.Verbose; verbose.Log("Finished flushing one block of data into underlying stream. Data bytes: {0}", new object[] { num }); this.bytesAccumulated -= num; } goto Label0; throw new TimeoutException("timed out while flushing"); } finally { ((IDisposable)enumerator).Dispose(); } Label0: this.ResetBuffers(); }
private IEnumerator <IAsyncResult> PerformOperationImpl(IAccountIdentifier identifier, string accountName, TableProtocolHead tableProtocolHead, RequestStartedCallback requestStartedCallback, CheckPermissionDelegate checkPermissionCallback, QueryRowCommandPropertiesAvailableCallback queryRowCommandPropertiesAvailableCallback, Dictionary <string, string> continuationToken, ContinuationTokenAvailableCallback continuationTokenAvailableCallback, bool operationIsConditional, RequestContext requestContext, AsyncIteratorContext <NoResults> context) { TimeSpan maxValue = TimeSpan.MaxValue; if (VersioningHelper.CompareVersions(tableProtocolHead.RequestRestVersion, "2016-05-31") >= 0) { maxValue = tableProtocolHead.operationContext.RemainingTimeout(); } IAsyncResult workerThread = this.authorizationManager.BeginCheckAccess(identifier, accountName, null, null, PermissionLevel.Owner, maxValue, context.GetResumeCallback(), context.GetResumeState("AuthorizationManager.BeginCheckAccess")); yield return(workerThread); this.authorizationManager.EndCheckAccess(workerThread); using (Stream bufferPoolMemoryStream = new BufferPoolMemoryStream(65536)) { bool flag = false; if (tableProtocolHead.ShouldReadRequestBody) { long requestContentLength = tableProtocolHead.RequestContentLength; if (requestContentLength > (long)4194304) { IStringDataEventStream verbose = Logger <IRestProtocolHeadLogger> .Instance.Verbose; object[] objArray = new object[] { requestContentLength, 4194304 }; verbose.Log("Content-Length is out of range. Content-Length={0} MaxRequestBodySize={1}", objArray); if (!tableProtocolHead.IsBatchRequest()) { if (VersioningHelper.CompareVersions(tableProtocolHead.RequestRestVersion, "2013-08-15") < 0) { throw new RequestTooLargeException(); } throw new RequestEntityTooLargeException(new long?((long)4194304)); } flag = true; requestContentLength = (long)102400; } else if (requestContentLength == (long)-1) { requestContentLength = (long)4194305; } Logger <IRestProtocolHeadLogger> .Instance.Verbose.Log("Started asynchronously reading from input stream"); if (VersioningHelper.CompareVersions(tableProtocolHead.RequestRestVersion, "2016-05-31") >= 0) { maxValue = tableProtocolHead.operationContext.RemainingTimeout(); } workerThread = AsyncStreamCopy.BeginAsyncStreamCopy(tableProtocolHead.RequestStream, bufferPoolMemoryStream, requestContentLength, 65536, maxValue, context.GetResumeCallback(), context.GetResumeState("BeginAsyncStreamCopy")); yield return(workerThread); long num = AsyncStreamCopy.EndAsyncStreamCopy(workerThread); bufferPoolMemoryStream.Seek((long)0, SeekOrigin.Begin); tableProtocolHead.RequestStream = bufferPoolMemoryStream; Logger <IRestProtocolHeadLogger> .Instance.Verbose.Log("Finished reading from input stream"); workerThread = AsyncHelpers.BeginSwitchToWorkerThread(context.GetResumeCallback(), context.GetResumeState("PerformOperationImpl")); yield return(workerThread); AsyncHelpers.EndSwitchToWorkerThread(workerThread); Logger <IRestProtocolHeadLogger> .Instance.Verbose.Log("Switched to a WorkerThread"); if (num > (long)4194304) { IStringDataEventStream stringDataEventStream = Logger <IRestProtocolHeadLogger> .Instance.Verbose; object[] requestContentLength1 = new object[] { tableProtocolHead.RequestContentLength, 4194304, num }; stringDataEventStream.Log("Request body is too long. Content-Length={0} MaxRequestBodySize={1} BytesRead={2}", requestContentLength1); if (!tableProtocolHead.IsBatchRequest()) { if (VersioningHelper.CompareVersions(tableProtocolHead.RequestRestVersion, "2013-08-15") < 0) { throw new RequestTooLargeException(); } throw new RequestEntityTooLargeException(new long?((long)4194304)); } flag = true; } } if (!flag) { this.DispatchRequestToAstoria(identifier, tableProtocolHead, requestStartedCallback, checkPermissionCallback, queryRowCommandPropertiesAvailableCallback, continuationToken, continuationTokenAvailableCallback, operationIsConditional); } else { Logger <IRestProtocolHeadLogger> .Instance.Error.Log("Batch request body is too long. Sending error batch response now."); if (VersioningHelper.CompareVersions(tableProtocolHead.RequestRestVersion, "2013-08-15") >= 0) { throw new RequestEntityTooLargeException(new long?((long)4194304)); } string str = tableProtocolHead.ReadContentIdFromRequest(100, 102400); TableProtocolHead tableProtocolHead1 = tableProtocolHead; string str1 = str; if (str1 == null) { str1 = "1"; } tableProtocolHead1.SendBatchRequestTooLargeResponse(str1); } } }