From 2e91d69d20e49f971d9890674d3016351ee87ccd Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 15 Jul 2016 13:13:55 -0400 Subject: update async stream writing --- .../HttpServer/AsyncStreamWriterFunc.cs | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 MediaBrowser.Server.Implementations/HttpServer/AsyncStreamWriterFunc.cs (limited to 'MediaBrowser.Server.Implementations/HttpServer/AsyncStreamWriterFunc.cs') diff --git a/MediaBrowser.Server.Implementations/HttpServer/AsyncStreamWriterFunc.cs b/MediaBrowser.Server.Implementations/HttpServer/AsyncStreamWriterFunc.cs new file mode 100644 index 000000000..4f8b18319 --- /dev/null +++ b/MediaBrowser.Server.Implementations/HttpServer/AsyncStreamWriterFunc.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using ServiceStack; +using ServiceStack.Web; + +namespace MediaBrowser.Server.Implementations.HttpServer +{ + public class AsyncStreamWriterFunc : IStreamWriter, IAsyncStreamWriter, IHasOptions + { + /// + /// Gets or sets the source stream. + /// + /// The source stream. + private Func Writer { get; set; } + + /// + /// Gets the options. + /// + /// The options. + public IDictionary Options { get; } + + public Action OnComplete { get; set; } + public Action OnError { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public AsyncStreamWriterFunc(Func writer, IDictionary headers) + { + Writer = writer; + + if (headers == null) + { + headers = new Dictionary(StringComparer.OrdinalIgnoreCase); + } + Options = headers; + } + + /// + /// Writes to. + /// + /// The response stream. + public void WriteTo(Stream responseStream) + { + var task = Writer(responseStream); + Task.WaitAll(task); + } + + public async Task WriteToAsync(Stream responseStream) + { + await Writer(responseStream).ConfigureAwait(false); + } + } +} -- cgit v1.2.3 From b51c614980a6cac56d132dd504b5b26282e8ed2b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 15 Jul 2016 13:18:01 -0400 Subject: update async stream writer --- MediaBrowser.Server.Implementations/HttpServer/AsyncStreamWriterFunc.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'MediaBrowser.Server.Implementations/HttpServer/AsyncStreamWriterFunc.cs') diff --git a/MediaBrowser.Server.Implementations/HttpServer/AsyncStreamWriterFunc.cs b/MediaBrowser.Server.Implementations/HttpServer/AsyncStreamWriterFunc.cs index 4f8b18319..5aa01c706 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/AsyncStreamWriterFunc.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/AsyncStreamWriterFunc.cs @@ -19,7 +19,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer /// Gets the options. /// /// The options. - public IDictionary Options { get; } + public IDictionary Options { get; private set; } public Action OnComplete { get; set; } public Action OnError { get; set; } -- cgit v1.2.3