Exemplo n.º 1
0
        protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            PrepareContent();

            return(Task.Run(() =>
            {
                var buffer = new Byte[bufferSize];
                var size = content.Length;
                var uploaded = 0;

                Uploader.ChangeState(DownloadState.PendingUpload);

                using (content)
                    while (true)
                    {
                        var length = content.Read(buffer, 0, buffer.Length);
                        if (length <= 0)
                        {
                            break;
                        }

                        uploaded += length;

                        Uploader.PercentComplete = (double)uploaded / (double)size;

                        stream.Write(buffer, 0, length);

                        Uploader.ChangeState(DownloadState.Uploading);
                    }

                Uploader.ChangeState(DownloadState.PendingResponse);
            }));
        }