diff options
| author | Eric Reed <ebr@mediabrowser3.com> | 2013-05-28 13:37:17 -0400 |
|---|---|---|
| committer | Eric Reed <ebr@mediabrowser3.com> | 2013-05-28 13:37:17 -0400 |
| commit | 316b2b80a36ee5a7032a0f9076818c2df4be60fa (patch) | |
| tree | aa67dc2fe78ebe5d5785da5065ed02a228e93016 | |
| parent | 4268800589653e57f6130c66bf92a5a406e9cbf1 (diff) | |
| parent | 9274f9f35f1269c147c6815bb85e196e3128374a (diff) | |
Merge branch 'master' of https://github.com/MediaBrowser/MediaBrowser
9 files changed, 153 insertions, 39 deletions
diff --git a/MediaBrowser.Api/SessionsService.cs b/MediaBrowser.Api/SessionsService.cs index bdf01f568..1ab18a022 100644 --- a/MediaBrowser.Api/SessionsService.cs +++ b/MediaBrowser.Api/SessionsService.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Controller.Dto; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Session; using MediaBrowser.Model.Net; using MediaBrowser.Model.Session; @@ -8,6 +9,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading; +using System.Threading.Tasks; namespace MediaBrowser.Api { @@ -44,7 +46,7 @@ namespace MediaBrowser.Api /// Artist, Genre, Studio, Person, or any kind of BaseItem /// </summary> /// <value>The type of the item.</value> - [ApiMember(Name = "ItemType", Description = "Only required if the item is an Artist, Genre, Studio, or Person.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] + [ApiMember(Name = "ItemType", Description = "The type of item to browse to.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] public string ItemType { get; set; } /// <summary> @@ -60,7 +62,7 @@ namespace MediaBrowser.Api /// <value>The name of the item.</value> [ApiMember(Name = "ItemName", Description = "The name of the item.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] public string ItemName { get; set; } - + /// <summary> /// Gets or sets the context (Movies, Music, TvShows, etc) /// Applicable to genres, studios and persons only because the context of items and artists can be inferred. @@ -71,6 +73,39 @@ namespace MediaBrowser.Api public string Context { get; set; } } + [Route("/Sessions/{Id}/Playing", "POST")] + [Api(("Instructs a session to play an item"))] + public class Play : IReturnVoid + { + /// <summary> + /// Gets or sets the id. + /// </summary> + /// <value>The id.</value> + [ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] + public Guid Id { get; set; } + + /// <summary> + /// Artist, Genre, Studio, Person, or any kind of BaseItem + /// </summary> + /// <value>The type of the item.</value> + [ApiMember(Name = "ItemIds", Description = "The ids of the items to play, comma delimited", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST", AllowMultiple = true)] + public string ItemIds { get; set; } + + /// <summary> + /// Gets or sets the start position ticks that the first item should be played at + /// </summary> + /// <value>The start position ticks.</value> + [ApiMember(Name = "StartPositionTicks", Description = "The starting position of the first item.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] + public long? StartPositionTicks { get; set; } + + /// <summary> + /// Gets or sets the play command. + /// </summary> + /// <value>The play command.</value> + [ApiMember(Name = "PlayCommand", Description = "The type of play command to issue (PlayNow, PlayNext, PlayLast). Clients who have not yet implemented play next and play last may play now.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] + public PlayCommand PlayCommand { get; set; } + } + /// <summary> /// Class SessionsService /// </summary> @@ -111,8 +146,22 @@ namespace MediaBrowser.Api /// Posts the specified request. /// </summary> /// <param name="request">The request.</param> + public void Post(BrowseTo request) + { + var task = BrowseTo(request); + + Task.WaitAll(task); + } + + /// <summary> + /// Browses to. + /// </summary> + /// <param name="request">The request.</param> + /// <returns>Task.</returns> /// <exception cref="ResourceNotFoundException"></exception> - public async void Post(BrowseTo request) + /// <exception cref="System.ArgumentException"></exception> + /// <exception cref="System.InvalidOperationException">The requested session does not have an open web socket.</exception> + private async Task BrowseTo(BrowseTo request) { var session = _sessionManager.Sessions.FirstOrDefault(i => i.Id == request.Id); @@ -149,5 +198,69 @@ namespace MediaBrowser.Api throw new InvalidOperationException("The requested session does not have an open web socket."); } } + + /// <summary> + /// Posts the specified request. + /// </summary> + /// <param name="request">The request.</param> + public void Post(Play request) + { + var task = Play(request); + + Task.WaitAll(task); + } + + /// <summary> + /// Plays the specified request. + /// </summary> + /// <param name="request">The request.</param> + /// <returns>Task.</returns> + /// <exception cref="ResourceNotFoundException"></exception> + /// <exception cref="System.ArgumentException"></exception> + /// <exception cref="System.InvalidOperationException">The requested session does not have an open web socket.</exception> + private async Task Play(Play request) + { + var session = _sessionManager.Sessions.FirstOrDefault(i => i.Id == request.Id); + + if (session == null) + { + throw new ResourceNotFoundException(string.Format("Session {0} not found.", request.Id)); + } + + if (!session.SupportsRemoteControl) + { + throw new ArgumentException(string.Format("Session {0} does not support remote control.", session.Id)); + } + + var socket = session.WebSockets.OrderByDescending(i => i.LastActivityDate).FirstOrDefault(i => i.State == WebSocketState.Open); + + if (socket != null) + { + try + { + await socket.SendAsync(new WebSocketMessage<PlayRequest> + { + MessageType = "Play", + + Data = new PlayRequest + { + ItemIds = request.ItemIds.Split(',').ToArray(), + + PlayCommand = request.PlayCommand, + StartPositionTicks = request.StartPositionTicks + } + + }, CancellationToken.None).ConfigureAwait(false); + } + catch (Exception ex) + { + Logger.ErrorException("Error sending web socket message", ex); + } + } + else + { + throw new InvalidOperationException("The requested session does not have an open web socket."); + } + } } } diff --git a/MediaBrowser.Controller/Providers/Music/LastfmHelper.cs b/MediaBrowser.Controller/Providers/Music/LastfmHelper.cs index d8bbfb00d..ca9f8bc71 100644 --- a/MediaBrowser.Controller/Providers/Music/LastfmHelper.cs +++ b/MediaBrowser.Controller/Providers/Music/LastfmHelper.cs @@ -42,6 +42,7 @@ namespace MediaBrowser.Controller.Providers.Music target.Tags = source.Tags.ToList(); target.Overview = source.Overview; target.ProductionLocations = source.ProductionLocations.ToList(); + target.Genres = source.Genres.ToList(); } public static void ProcessAlbumData(BaseItem item, LastfmAlbum data) diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs index 8e715e47c..115114e3a 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -381,6 +381,14 @@ namespace MediaBrowser.Server.Implementations.HttpServer } if (contentType.StartsWith("application/", StringComparison.OrdinalIgnoreCase)) { + if (string.Equals(contentType, "application/x-javascript", StringComparison.OrdinalIgnoreCase)) + { + return true; + } + if (string.Equals(contentType, "application/xml", StringComparison.OrdinalIgnoreCase)) + { + return true; + } return false; } diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteDisplayPreferencesRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteDisplayPreferencesRepository.cs index 2df377cbc..60c3c1fe0 100644 --- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteDisplayPreferencesRepository.cs +++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteDisplayPreferencesRepository.cs @@ -148,6 +148,8 @@ namespace MediaBrowser.Server.Implementations.Sqlite { transaction.Rollback(); } + + throw; } catch (Exception e) { @@ -157,6 +159,8 @@ namespace MediaBrowser.Server.Implementations.Sqlite { transaction.Rollback(); } + + throw; } finally { diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteItemRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteItemRepository.cs index 33e9c7fe3..a0acd523e 100644 --- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteItemRepository.cs @@ -236,15 +236,19 @@ namespace MediaBrowser.Server.Implementations.Sqlite { transaction.Rollback(); } + + throw; } catch (Exception e) { - Logger.ErrorException("Failed to save item:", e); + Logger.ErrorException("Failed to save items:", e); if (transaction != null) { transaction.Rollback(); } + + throw; } finally { @@ -439,15 +443,19 @@ namespace MediaBrowser.Server.Implementations.Sqlite { transaction.Rollback(); } + + throw; } catch (Exception e) { - Logger.ErrorException("Failed to save item:", e); + Logger.ErrorException("Failed to save children:", e); if (transaction != null) { transaction.Rollback(); } + + throw; } finally { diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs index ee2fcc10c..7547212c5 100644 --- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs +++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs @@ -152,38 +152,6 @@ namespace MediaBrowser.Server.Implementations.Sqlite } /// <summary> - /// Executes the command. - /// </summary> - /// <param name="cmd">The CMD.</param> - /// <returns>Task.</returns> - /// <exception cref="System.ArgumentNullException">cmd</exception> - public async Task ExecuteCommand(DbCommand cmd) - { - if (cmd == null) - { - throw new ArgumentNullException("cmd"); - } - - using (var tran = Connection.BeginTransaction()) - { - try - { - cmd.Connection = Connection; - cmd.Transaction = tran; - - await cmd.ExecuteNonQueryAsync().ConfigureAwait(false); - - tran.Commit(); - } - catch (Exception e) - { - Logger.ErrorException("Failed to commit transaction.", e); - tran.Rollback(); - } - } - } - - /// <summary> /// Gets a stream from a DataReader at a given ordinal /// </summary> /// <param name="reader">The reader.</param> diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserDataRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserDataRepository.cs index 284ef10fb..d378809ff 100644 --- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserDataRepository.cs +++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserDataRepository.cs @@ -203,6 +203,8 @@ namespace MediaBrowser.Server.Implementations.Sqlite { transaction.Rollback(); } + + throw; } catch (Exception e) { @@ -212,6 +214,8 @@ namespace MediaBrowser.Server.Implementations.Sqlite { transaction.Rollback(); } + + throw; } finally { diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs index df0d13b62..335841549 100644 --- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs +++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs @@ -145,6 +145,8 @@ namespace MediaBrowser.Server.Implementations.Sqlite { transaction.Rollback(); } + + throw; } catch (Exception e) { @@ -154,6 +156,8 @@ namespace MediaBrowser.Server.Implementations.Sqlite { transaction.Rollback(); } + + throw; } finally { @@ -228,7 +232,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite cmd.Transaction = transaction; - await ExecuteCommand(cmd).ConfigureAwait(false); + await cmd.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false); } transaction.Commit(); @@ -239,6 +243,8 @@ namespace MediaBrowser.Server.Implementations.Sqlite { transaction.Rollback(); } + + throw; } catch (Exception e) { @@ -248,6 +254,8 @@ namespace MediaBrowser.Server.Implementations.Sqlite { transaction.Rollback(); } + + throw; } finally { diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs index 20c612be2..7061f8c7f 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardService.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs @@ -409,7 +409,7 @@ namespace MediaBrowser.WebDashboard.Api var files = new[] { "http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css", - "thirdparty/jqm-icon-pack-3.0/font-awesome/jqm-icon-pack-3.0.0-fa.css", + "thirdparty/jqm-icon-pack-3.0/font-awesome/jqm-icon-pack-3.0.0-fa.css" + versionString, "css/all.css" + versionString }; |
