|
@@ -4,38 +4,41 @@ using System.IO;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
using ServiceStack;
|
|
using ServiceStack;
|
|
using ServiceStack.Web;
|
|
using ServiceStack.Web;
|
|
|
|
+using MediaBrowser.Controller.Net;
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.HttpServer
|
|
namespace MediaBrowser.Server.Implementations.HttpServer
|
|
{
|
|
{
|
|
- public class AsyncStreamWriterFunc : IStreamWriter, IAsyncStreamWriter, IHasOptions
|
|
|
|
|
|
+ public class AsyncStreamWriter : IStreamWriter, IAsyncStreamWriter, IHasOptions
|
|
{
|
|
{
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets or sets the source stream.
|
|
/// Gets or sets the source stream.
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <value>The source stream.</value>
|
|
/// <value>The source stream.</value>
|
|
- private Func<Stream, Task> Writer { get; set; }
|
|
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// Gets the options.
|
|
|
|
- /// </summary>
|
|
|
|
- /// <value>The options.</value>
|
|
|
|
- public IDictionary<string, string> Options { get; private set; }
|
|
|
|
|
|
+ private IAsyncStreamSource _source;
|
|
|
|
|
|
public Action OnComplete { get; set; }
|
|
public Action OnComplete { get; set; }
|
|
public Action OnError { get; set; }
|
|
public Action OnError { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// Initializes a new instance of the <see cref="StreamWriter" /> class.
|
|
|
|
|
|
+ /// Initializes a new instance of the <see cref="AsyncStreamWriter" /> class.
|
|
/// </summary>
|
|
/// </summary>
|
|
- public AsyncStreamWriterFunc(Func<Stream, Task> writer, IDictionary<string, string> headers)
|
|
|
|
|
|
+ public AsyncStreamWriter(IAsyncStreamSource source)
|
|
{
|
|
{
|
|
- Writer = writer;
|
|
|
|
|
|
+ _source = source;
|
|
|
|
+ }
|
|
|
|
|
|
- if (headers == null)
|
|
|
|
|
|
+ public IDictionary<string, string> Options
|
|
|
|
+ {
|
|
|
|
+ get
|
|
{
|
|
{
|
|
- headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
+ var hasOptions = _source as IHasOptions;
|
|
|
|
+ if (hasOptions != null)
|
|
|
|
+ {
|
|
|
|
+ return hasOptions.Options;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|
}
|
|
}
|
|
- Options = headers;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -44,13 +47,13 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
|
/// <param name="responseStream">The response stream.</param>
|
|
/// <param name="responseStream">The response stream.</param>
|
|
public void WriteTo(Stream responseStream)
|
|
public void WriteTo(Stream responseStream)
|
|
{
|
|
{
|
|
- var task = Writer(responseStream);
|
|
|
|
|
|
+ var task = _source.WriteToAsync(responseStream);
|
|
Task.WaitAll(task);
|
|
Task.WaitAll(task);
|
|
}
|
|
}
|
|
|
|
|
|
public async Task WriteToAsync(Stream responseStream)
|
|
public async Task WriteToAsync(Stream responseStream)
|
|
{
|
|
{
|
|
- await Writer(responseStream).ConfigureAwait(false);
|
|
|
|
|
|
+ await _source.WriteToAsync(responseStream).ConfigureAwait(false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|