Microsoft.WindowsAzure.MediaServices.Client.BlobUploader.BeginUploadStream C# (CSharp) Method

BeginUploadStream() private method

private BeginUploadStream ( Microsoft.WindowsAzure.MediaServices.Client.BlobTransferContext transferContext, int>.KeyValuePair startAndLength, MemoryStream memoryStream, byte streamBuffer ) : void
transferContext Microsoft.WindowsAzure.MediaServices.Client.BlobTransferContext
startAndLength int>.KeyValuePair
memoryStream System.IO.MemoryStream
streamBuffer byte
return void
        private void BeginUploadStream(
            BlobTransferContext transferContext,
            KeyValuePair<long, int> startAndLength,
            MemoryStream memoryStream,
            byte[] streamBuffer)
        {
            if (transferContext.CancellationToken.IsCancellationRequested)
            {
                return;
            }

            memoryStream.Seek(0, SeekOrigin.Begin);

            OperationContext operationContext = new OperationContext();
            operationContext.ClientRequestID = transferContext.ClientRequestId;

            Interlocked.Increment(ref transferContext.NumInProgressUploadDownloads);

            string blockId =
                Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format(CultureInfo.InvariantCulture, "BlockId{0:d7}", (startAndLength.Key / transferContext.BlockSize))));

            memoryStream.SetLength(startAndLength.Value);

            transferContext.Blob.BeginPutBlock(
                blockId,
                memoryStream,
                null,
                AccessCondition.GenerateEmptyCondition(),
                transferContext.BlobRequestOptions,
                operationContext,
                ar =>
                {
                    SuccessfulOrRetryableResult wasWriteSuccessful = EndPutBlock(transferContext, ar);
                    Interlocked.Decrement(ref transferContext.NumInProgressUploadDownloads);

                    if (wasWriteSuccessful.IsRetryable)
                    {
                        BeginUploadStream(transferContext, startAndLength, memoryStream, streamBuffer);
                        return;
                    }

                    transferContext.MemoryManager.ReleaseBuffer(streamBuffer);

                    if (!wasWriteSuccessful.IsSuccessful)
                    {
                        return;
                    }

                    Interlocked.Add(ref transferContext.BytesBlobIOCompleted, startAndLength.Value);

                    InvokeProgressCallback(transferContext, transferContext.BytesBlobIOCompleted, startAndLength.Value);

                    if (transferContext.BytesBlobIOCompleted >= transferContext.Length)
                    {
                        BeginPutBlockList(transferContext);
                    }

                },
                state: null);
        }