restore nuget targets for mono build

This commit is contained in:
Luke Pulverenti
2014-09-02 22:30:24 -04:00
parent a3d553a7fb
commit 60d1d5cdee
27 changed files with 396 additions and 251 deletions

View File

@@ -102,14 +102,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer
return result;
}
private bool SupportsCompression
{
get
{
return true;
}
}
/// <summary>
/// Gets the optimized result.
/// </summary>
@@ -127,7 +119,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
throw new ArgumentNullException("result");
}
var optimizedResult = SupportsCompression ? requestContext.ToOptimizedResult(result) : result;
var optimizedResult = requestContext.ToOptimizedResult(result);
if (responseHeaders != null)
{
@@ -471,7 +463,9 @@ namespace MediaBrowser.Server.Implementations.HttpServer
{
Throttle = options.Throttle,
ThrottleLimit = options.ThrottleLimit,
MinThrottlePosition = options.MinThrottlePosition
MinThrottlePosition = options.MinThrottlePosition,
ThrottleCallback = options.ThrottleCallback,
OnComplete = options.OnComplete
};
}
@@ -488,41 +482,22 @@ namespace MediaBrowser.Server.Implementations.HttpServer
{
Throttle = options.Throttle,
ThrottleLimit = options.ThrottleLimit,
MinThrottlePosition = options.MinThrottlePosition
MinThrottlePosition = options.MinThrottlePosition,
ThrottleCallback = options.ThrottleCallback,
OnComplete = options.OnComplete
};
}
string content;
long originalContentLength = 0;
using (var stream = await factoryFn().ConfigureAwait(false))
{
using (var memoryStream = new MemoryStream())
using (var reader = new StreamReader(stream))
{
await stream.CopyToAsync(memoryStream).ConfigureAwait(false);
memoryStream.Position = 0;
originalContentLength = memoryStream.Length;
using (var reader = new StreamReader(memoryStream))
{
content = await reader.ReadToEndAsync().ConfigureAwait(false);
}
content = await reader.ReadToEndAsync().ConfigureAwait(false);
}
}
if (!SupportsCompression)
{
responseHeaders["Content-Length"] = originalContentLength.ToString(UsCulture);
if (isHeadRequest)
{
return GetHttpResult(new byte[] { }, contentType);
}
return new HttpResult(content, contentType);
}
var contents = content.Compress(requestedCompressionType);
responseHeaders["Content-Length"] = contents.Length.ToString(UsCulture);

View File

@@ -27,6 +27,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer
public bool Throttle { get; set; }
public long ThrottleLimit { get; set; }
public long MinThrottlePosition;
public Func<long, long, long> ThrottleCallback { get; set; }
public Action OnComplete { get; set; }
/// <summary>
/// The _options
@@ -167,7 +169,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer
{
responseStream = new ThrottledStream(responseStream, ThrottleLimit)
{
MinThrottlePosition = MinThrottlePosition
MinThrottlePosition = MinThrottlePosition,
ThrottleCallback = ThrottleCallback
};
}
var task = WriteToAsync(responseStream);
@@ -182,22 +185,32 @@ namespace MediaBrowser.Server.Implementations.HttpServer
/// <returns>Task.</returns>
private async Task WriteToAsync(Stream responseStream)
{
// Headers only
if (IsHeadRequest)
try
{
return;
}
using (var source = SourceStream)
{
// If the requested range is "0-", we can optimize by just doing a stream copy
if (RangeEnd >= TotalContentLength - 1)
// Headers only
if (IsHeadRequest)
{
await source.CopyToAsync(responseStream).ConfigureAwait(false);
return;
}
else
using (var source = SourceStream)
{
await CopyToAsyncInternal(source, responseStream, Convert.ToInt32(RangeLength), CancellationToken.None).ConfigureAwait(false);
// If the requested range is "0-", we can optimize by just doing a stream copy
if (RangeEnd >= TotalContentLength - 1)
{
await source.CopyToAsync(responseStream).ConfigureAwait(false);
}
else
{
await CopyToAsyncInternal(source, responseStream, Convert.ToInt32(RangeLength), CancellationToken.None).ConfigureAwait(false);
}
}
}
finally
{
if (OnComplete != null)
{
OnComplete();
}
}
}

View File

@@ -39,6 +39,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer
public bool Throttle { get; set; }
public long ThrottleLimit { get; set; }
public long MinThrottlePosition;
public Func<long, long, long> ThrottleCallback { get; set; }
public Action OnComplete { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="StreamWriter" /> class.
@@ -85,7 +87,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer
{
responseStream = new ThrottledStream(responseStream, ThrottleLimit)
{
MinThrottlePosition = MinThrottlePosition
MinThrottlePosition = MinThrottlePosition,
ThrottleCallback = ThrottleCallback
};
}
var task = WriteToAsync(responseStream);
@@ -113,6 +116,13 @@ namespace MediaBrowser.Server.Implementations.HttpServer
throw;
}
finally
{
if (OnComplete != null)
{
OnComplete();
}
}
}
}
}

View File

@@ -15,6 +15,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer
/// </summary>
public const long Infinite = 0;
public Func<long, long, long> ThrottleCallback { get; set; }
#region Private members
/// <summary>
/// The base stream.
@@ -278,6 +280,32 @@ namespace MediaBrowser.Server.Implementations.HttpServer
}
#endregion
private bool ThrottleCheck(int bufferSizeInBytes)
{
if (_bytesWritten < MinThrottlePosition)
{
return false;
}
// Make sure the buffer isn't empty.
if (_maximumBytesPerSecond <= 0 || bufferSizeInBytes <= 0)
{
return false;
}
if (ThrottleCallback != null)
{
var val = ThrottleCallback(_maximumBytesPerSecond, _bytesWritten);
if (val == 0)
{
return false;
}
}
return true;
}
#region Protected methods
/// <summary>
/// Throttles for the specified buffer size in bytes.
@@ -285,15 +313,9 @@ namespace MediaBrowser.Server.Implementations.HttpServer
/// <param name="bufferSizeInBytes">The buffer size in bytes.</param>
protected void Throttle(int bufferSizeInBytes)
{
if (_bytesWritten < MinThrottlePosition)
if (!ThrottleCheck(bufferSizeInBytes))
{
return;
}
// Make sure the buffer isn't empty.
if (_maximumBytesPerSecond <= 0 || bufferSizeInBytes <= 0)
{
return;
return ;
}
_byteCount += bufferSizeInBytes;
@@ -332,13 +354,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
protected async Task ThrottleAsync(int bufferSizeInBytes, CancellationToken cancellationToken)
{
if (_bytesWritten < MinThrottlePosition)
{
return;
}
// Make sure the buffer isn't empty.
if (_maximumBytesPerSecond <= 0 || bufferSizeInBytes <= 0)
if (!ThrottleCheck(bufferSizeInBytes))
{
return;
}