예제 #1
0
        private static bool ParseData(ParserContext context)
        {
            if (context.InputLength <= 0)
            {
                return(false);
            }

            var ctxMessage = context.Message;

            var dataLen = ctxMessage.Header.DataSize;

            if (dataLen < 0)
            {
                throw new Exception(RpcErrors.InvalidMessage);
            }

            if (dataLen == 0)
            {
                context.Completed = true;
                return(true);
            }

            if (context.InputLength >= dataLen)
            {
                var dataStream = new ChunkedStream();
                try
                {
                    var readLen = dataStream.ReadFrom(context.Input, dataLen);
                    if (readLen < dataLen)
                    {
                        dataStream.Dispose();
                        return(false);
                    }

                    context.InputLength  -= dataLen;
                    context.StreamOffset += dataLen;

                    ctxMessage.Data = dataStream;

                    context.Completed = true;
                    return(true);
                }
                catch (Exception)
                {
                    dataStream.Dispose();
                }
            }
            return(false);
        }
 private async Task AppendBlockAsync(
     ChunkedStream block,
     long offset,
     string leaseId,
     IProgress <long> progressHandler,
     CancellationToken cancellationToken)
 {
     try
     {
         await _client.AppendAsync(
             new MemoryStream(block.Bytes, 0, block.Length, writable : false),
             offset : offset,
             leaseId : leaseId,
             progressHandler : progressHandler,
             cancellationToken : cancellationToken)
         .ConfigureAwait(false);
     }
     finally
     {
         // Return the memory used by the block to our ArrayPool as soon
         // as we've staged it
         block.Dispose();
     }
 }
 private async Task StageBlockAsync(
     ChunkedStream block,
     string blockId,
     BlobRequestConditions conditions,
     IProgress <long> progressHandler,
     CancellationToken cancellationToken)
 {
     try
     {
         await _client.StageBlockAsync(
             blockId,
             new MemoryStream(block.Bytes, 0, block.Length, writable : false),
             conditions : conditions,
             progressHandler : progressHandler,
             cancellationToken : cancellationToken)
         .ConfigureAwait(false);
     }
     finally
     {
         // Return the memory used by the block to our ArrayPool as soon
         // as we've staged it
         block.Dispose();
     }
 }