Exemplo n.º 1
0
        public override async Task ExecuteResultAsync(ActionContext context)
        {
            var response = context.HttpContext.Response;

            response.ContentType = ContentType;
            var targetStream = response.Body;

            if (CopyStream is not null)
            {
                await Task.Factory.StartNew(() =>
                {
                    CopyStream(targetStream);
                });
            }
            else if (Content is not null)
            {
                await targetStream.WriteAsync(Content, 0, Content.Length);
            }
            else
            {
                using (SourceStream)
                {
                    if (SourceStream.CanSeek)
                    {
                        SourceStream.Seek(0, SeekOrigin.Begin);
                    }
                    await SourceStream.CopyToAsync(targetStream);
                }
            }
        }
Exemplo n.º 2
0
            public override async Task SaveToAsync(Stream stream, MediaFile mediaFile)
            {
                if (stream.CanSeek)
                {
                    stream.SetLength(0);
                }

                await SourceStream.CopyToAsync(stream);

                if (stream.CanSeek)
                {
                    stream.Position = 0;
                }

                mediaFile.Size = (int)stream.Length;
            }