protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            // First write out content to local file asynchronously
            string fileName = Guid.NewGuid().ToString("D");
            string filePath = Path.Combine(_outputPath, fileName);

            using (FileStream fStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, BufferSize, useAsync: true))
            {
                await InnerContent.CopyToAsync(fStream);
            }

            // Now write out content to actual output stream
            await InnerContent.CopyToAsync(stream);

            // Invoke content processor so that it can process the content asynchonously
            try
            {
                await _contentProcessor(filePath);
            }
            finally
            {
                // We are done with the local file and can delete it.
                File.Delete(filePath);
            }
        }
Exemplo n.º 2
0
 protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
 {
     if (SerializeToStreamAsyncCallback != null)
     {
         return(SerializeToStreamAsyncCallback(stream, context));
     }
     else if (InnerContent != null)
     {
         return(InnerContent.CopyToAsync(stream, context));
     }
     else
     {
         throw new InvalidOperationException("Construct with inner HttpContent or set SerializeToStreamCallback first.");
     }
 }