diff options
13 files changed, 79 insertions, 88 deletions
diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index 56b4efd2f..cba268813 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -252,30 +252,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager _logger.Info("HttpClientManager.GetTempFile url: {0}, temp file: {1}", options.Url, tempFile); - FileStream tempFileStream; - - if (resumeCount > 0 && File.Exists(tempFile)) - { - tempFileStream = new FileStream(tempFile, FileMode.Open, FileAccess.Write, FileShare.Read, - StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous); - - var startPosition = tempFileStream.Length; - tempFileStream.Seek(startPosition, SeekOrigin.Current); - - message.Headers.Range = new RangeHeaderValue(startPosition, null); - - _logger.Info("Resuming from position {1} for {0}", options.Url, startPosition); - } - else - { - tempFileStream = new FileStream(tempFile, FileMode.Create, FileAccess.Write, FileShare.Read, - StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous); - } - - var serverSupportsRangeRequests = false; - - Exception downloadException = null; - try { options.CancellationToken.ThrowIfCancellationRequested(); @@ -286,15 +262,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager options.CancellationToken.ThrowIfCancellationRequested(); - var rangeValue = string.Join(" ", response.Headers.AcceptRanges.ToArray()); - serverSupportsRangeRequests = rangeValue.IndexOf("bytes", StringComparison.OrdinalIgnoreCase) != -1 || rangeValue.IndexOf("*", StringComparison.OrdinalIgnoreCase) != -1; - - if (!serverSupportsRangeRequests && resumeCount > 0) - { - _logger.Info("Server does not support range requests for {0}", options.Url); - tempFileStream.Position = 0; - } - IEnumerable<string> lengthValues; if (!response.Headers.TryGetValues("content-length", out lengthValues) && @@ -303,7 +270,10 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager // We're not able to track progress using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false)) { - await stream.CopyToAsync(tempFileStream, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false); + using (var fs = new FileStream(tempFile, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous)) + { + await stream.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false); + } } } else @@ -312,7 +282,10 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager using (var stream = ProgressStream.CreateReadProgressStream(await response.Content.ReadAsStreamAsync().ConfigureAwait(false), options.Progress.Report, length)) { - await stream.CopyToAsync(tempFileStream, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false); + using (var fs = new FileStream(tempFile, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous)) + { + await stream.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false); + } } } @@ -323,23 +296,16 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager } catch (Exception ex) { - downloadException = ex; + HandleTempFileException(ex, options, tempFile); } finally { - tempFileStream.Dispose(); - if (options.ResourcePool != null) { options.ResourcePool.Release(); } } - if (downloadException != null) - { - await HandleTempFileException(downloadException, options, tempFile, serverSupportsRangeRequests, resumeCount).ConfigureAwait(false); - } - return tempFile; } @@ -349,11 +315,9 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager /// <param name="ex">The ex.</param> /// <param name="options">The options.</param> /// <param name="tempFile">The temp file.</param> - /// <param name="serverSupportsRangeRequests">if set to <c>true</c> [server supports range requests].</param> - /// <param name="resumeCount">The resume count.</param> /// <returns>Task.</returns> /// <exception cref="HttpException"></exception> - private Task HandleTempFileException(Exception ex, HttpRequestOptions options, string tempFile, bool serverSupportsRangeRequests, int resumeCount) + private void HandleTempFileException(Exception ex, HttpRequestOptions options, string tempFile) { var operationCanceledException = ex as OperationCanceledException; @@ -375,14 +339,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager // Cleanup if (File.Exists(tempFile)) { - // Try to resume - if (httpRequestException != null && serverSupportsRangeRequests && resumeCount < options.MaxResumeCount && new FileInfo(tempFile).Length > 0) - { - _logger.Info("Attempting to resume download from {0}", options.Url); - - return GetTempFile(options, tempFile, resumeCount + 1); - } - File.Delete(tempFile); } diff --git a/MediaBrowser.Common.Implementations/Updates/PackageManager.cs b/MediaBrowser.Common.Implementations/Updates/PackageManager.cs index 594027bcb..f3ab27293 100644 --- a/MediaBrowser.Common.Implementations/Updates/PackageManager.cs +++ b/MediaBrowser.Common.Implementations/Updates/PackageManager.cs @@ -75,8 +75,7 @@ namespace MediaBrowser.Common.Implementations.Updates { Url = package.sourceUrl, CancellationToken = cancellationToken, - Progress = progress, - MaxResumeCount = 3 + Progress = progress }).ConfigureAwait(false); diff --git a/MediaBrowser.Common/Net/HttpRequestOptions.cs b/MediaBrowser.Common/Net/HttpRequestOptions.cs index a45acb206..98d02a9f9 100644 --- a/MediaBrowser.Common/Net/HttpRequestOptions.cs +++ b/MediaBrowser.Common/Net/HttpRequestOptions.cs @@ -33,12 +33,6 @@ namespace MediaBrowser.Common.Net public string UserAgent { get; set; } /// <summary> - /// Gets or sets the max resume count. - /// </summary> - /// <value>The max resume count.</value> - public int MaxResumeCount { get; set; } - - /// <summary> /// Gets or sets the progress. /// </summary> /// <value>The progress.</value> diff --git a/MediaBrowser.Controller/Drawing/ImageExtensions.cs b/MediaBrowser.Controller/Drawing/ImageExtensions.cs index cecbfe74a..32268011f 100644 --- a/MediaBrowser.Controller/Drawing/ImageExtensions.cs +++ b/MediaBrowser.Controller/Drawing/ImageExtensions.cs @@ -65,6 +65,39 @@ namespace MediaBrowser.Controller.Drawing } /// <summary> + /// Determines whether [is pixel format supported by graphics object] [the specified format]. + /// </summary> + /// <param name="format">The format.</param> + /// <returns><c>true</c> if [is pixel format supported by graphics object] [the specified format]; otherwise, <c>false</c>.</returns> + public static bool IsPixelFormatSupportedByGraphicsObject(PixelFormat format) + { + // http://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromimage.aspx + + if (format.HasFlag(PixelFormat.Indexed)) + { + return false; + } + if (format.HasFlag(PixelFormat.Undefined)) + { + return false; + } + if (format.HasFlag(PixelFormat.DontCare)) + { + return false; + } + if (format.HasFlag(PixelFormat.Format16bppArgb1555)) + { + return false; + } + if (format.HasFlag(PixelFormat.Format16bppGrayScale)) + { + return false; + } + + return true; + } + + /// <summary> /// Crops an image by removing whitespace and transparency from the edges /// </summary> /// <param name="bmp">The BMP.</param> diff --git a/MediaBrowser.Controller/Drawing/ImageManager.cs b/MediaBrowser.Controller/Drawing/ImageManager.cs index 3c6f845e5..6bae3510a 100644 --- a/MediaBrowser.Controller/Drawing/ImageManager.cs +++ b/MediaBrowser.Controller/Drawing/ImageManager.cs @@ -179,7 +179,7 @@ namespace MediaBrowser.Controller.Drawing var newHeight = Convert.ToInt32(newSize.Height); // Graphics.FromImage will throw an exception if the PixelFormat is Indexed, so we need to handle that here - var thumbnail = originalImage.PixelFormat.HasFlag(PixelFormat.Indexed) ? new Bitmap(originalImage, newWidth, newHeight) : new Bitmap(newWidth, newHeight, originalImage.PixelFormat); + var thumbnail = !ImageExtensions.IsPixelFormatSupportedByGraphicsObject(originalImage.PixelFormat) ? new Bitmap(originalImage, newWidth, newHeight) : new Bitmap(newWidth, newHeight, originalImage.PixelFormat); // Preserve the original resolution thumbnail.SetResolution(originalImage.HorizontalResolution, originalImage.VerticalResolution); diff --git a/MediaBrowser.Controller/Library/IUserManager.cs b/MediaBrowser.Controller/Library/IUserManager.cs index f1cef1d66..910ba13b2 100644 --- a/MediaBrowser.Controller/Library/IUserManager.cs +++ b/MediaBrowser.Controller/Library/IUserManager.cs @@ -20,7 +20,7 @@ namespace MediaBrowser.Controller.Library /// Gets the active connections. /// </summary> /// <value>The active connections.</value> - IEnumerable<ClientConnectionInfo> ConnectedUsers { get; } + IEnumerable<ClientConnectionInfo> RecentConnections { get; } /// <summary> /// Occurs when [playback start]. diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs index 01a745e95..1ebf99b6a 100644 --- a/MediaBrowser.Server.Implementations/Library/UserManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs @@ -25,8 +25,8 @@ namespace MediaBrowser.Server.Implementations.Library /// <summary> /// The _active connections /// </summary> - private readonly ConcurrentBag<ClientConnectionInfo> _activeConnections = - new ConcurrentBag<ClientConnectionInfo>(); + private readonly List<ClientConnectionInfo> _activeConnections = + new List<ClientConnectionInfo>(); /// <summary> /// The _users @@ -67,7 +67,7 @@ namespace MediaBrowser.Server.Implementations.Library /// Gets all connections. /// </summary> /// <value>All connections.</value> - private IEnumerable<ClientConnectionInfo> AllConnections + public IEnumerable<ClientConnectionInfo> AllConnections { get { return _activeConnections.Where(c => GetUserById(c.UserId) != null).OrderByDescending(c => c.LastActivityDate); } } @@ -76,7 +76,7 @@ namespace MediaBrowser.Server.Implementations.Library /// Gets the active connections. /// </summary> /// <value>The active connections.</value> - public IEnumerable<ClientConnectionInfo> ConnectedUsers + public IEnumerable<ClientConnectionInfo> RecentConnections { get { return AllConnections.Where(c => (DateTime.UtcNow - c.LastActivityDate).TotalMinutes <= 10); } } @@ -303,22 +303,29 @@ namespace MediaBrowser.Server.Implementations.Library /// <returns>ClientConnectionInfo.</returns> private ClientConnectionInfo GetConnection(Guid userId, ClientType clientType, string deviceId, string deviceName) { - var conn = _activeConnections.FirstOrDefault(c => c.UserId == userId && c.ClientType == clientType && string.Equals(deviceId, c.DeviceId)); - - if (conn == null) + lock (_activeConnections) { - conn = new ClientConnectionInfo + var conn = _activeConnections.FirstOrDefault(c => c.ClientType == clientType && string.Equals(deviceId, c.DeviceId)); + + if (conn == null) { - UserId = userId, - ClientType = clientType, - DeviceName = deviceName, - DeviceId = deviceId - }; + conn = new ClientConnectionInfo + { + UserId = userId, + ClientType = clientType, + DeviceName = deviceName, + DeviceId = deviceId + }; - _activeConnections.Add(conn); - } + _activeConnections.Add(conn); + } + else + { + conn.UserId = userId; + } - return conn; + return conn; + } } /// <summary> diff --git a/MediaBrowser.Server.Implementations/Updates/InstallationManager.cs b/MediaBrowser.Server.Implementations/Updates/InstallationManager.cs index bdbf3896f..271d3d877 100644 --- a/MediaBrowser.Server.Implementations/Updates/InstallationManager.cs +++ b/MediaBrowser.Server.Implementations/Updates/InstallationManager.cs @@ -375,8 +375,10 @@ namespace MediaBrowser.Server.Implementations.Updates throw; } - catch + catch (Exception ex) { + _logger.ErrorException("Package installation failed", ex); + lock (CurrentInstallations) { CurrentInstallations.Remove(tuple); diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs index 3f4c84a87..7428b4389 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardService.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs @@ -125,7 +125,7 @@ namespace MediaBrowser.WebDashboard.Api /// <returns>DashboardInfo.</returns> public static async Task<DashboardInfo> GetDashboardInfo(IServerApplicationHost appHost, ILogger logger, ITaskManager taskManager, IUserManager userManager, ILibraryManager libraryManager) { - var connections = userManager.ConnectedUsers.ToArray(); + var connections = userManager.RecentConnections.ToArray(); var dtoBuilder = new DtoBuilder(logger, libraryManager); diff --git a/MediaBrowser.WebDashboard/ApiClient.js b/MediaBrowser.WebDashboard/ApiClient.js index e7025c890..af26e4614 100644 --- a/MediaBrowser.WebDashboard/ApiClient.js +++ b/MediaBrowser.WebDashboard/ApiClient.js @@ -1387,7 +1387,7 @@ $(document).ajaxSend(function (event, jqXHR) { if (ApiClient.currentUserId) { - var auth = 'MediaBrowser UserId="' + ApiClient.currentUserId + '", Client="Dashboard", Device="' + ApiClient.getDeviceName() + '", DeviceId="' + ApiClient.getDeviceName() + '"'; + var auth = 'MediaBrowser UserId="' + ApiClient.currentUserId + '", Client="Dashboard", Device="' + ApiClient.getDeviceName() + '", DeviceId="' + ApiClient.getDeviceId() + '"'; jqXHR.setRequestHeader("Authorization", auth); } });
\ No newline at end of file diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index a2a4f8871..7be51fb1a 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> <metadata> <id>MediaBrowser.Common.Internal</id> - <version>3.0.48</version> + <version>3.0.49</version> <title>MediaBrowser.Common.Internal</title> <authors>Luke</authors> <owners>ebr,Luke,scottisafool</owners> @@ -12,7 +12,7 @@ <description>Contains common components shared by Media Browser Theatre and Media Browser Server. Not intended for plugin developer consumption.</description> <copyright>Copyright © Media Browser 2013</copyright> <dependencies> - <dependency id="MediaBrowser.Common" version="3.0.48" /> + <dependency id="MediaBrowser.Common" version="3.0.49" /> <dependency id="NLog" version="2.0.0.2000" /> <dependency id="ServiceStack.Text" version="3.9.38" /> <dependency id="protobuf-net" version="2.0.0.621" /> diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index c3ef3537b..26737dc73 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <metadata> <id>MediaBrowser.Common</id> - <version>3.0.48</version> + <version>3.0.49</version> <title>MediaBrowser.Common</title> <authors>Media Browser Team</authors> <owners>ebr,Luke,scottisafool</owners> diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 7e59d6dab..a5738419e 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <metadata> <id>MediaBrowser.Server.Core</id> - <version>3.0.48</version> + <version>3.0.49</version> <title>Media Browser.Server.Core</title> <authors>Media Browser Team</authors> <owners>ebr,Luke,scottisafool</owners> @@ -12,7 +12,7 @@ <description>Contains core components required to build plugins for Media Browser Server.</description> <copyright>Copyright © Media Browser 2013</copyright> <dependencies> - <dependency id="MediaBrowser.Common" version="3.0.48" /> + <dependency id="MediaBrowser.Common" version="3.0.49" /> </dependencies> </metadata> <files> |
