From 7bca933af0f1b85e289306ae482db8846f94026c Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Fri, 1 Mar 2013 21:44:46 -0500 Subject: [PATCH] added the beginning of a service stack abstraction --- .../UserLibrary/UserLibraryService.cs | 4 +-- .../HttpServer/BaseRestService.cs | 12 ++++++- .../HttpServer/HttpServer.cs | 5 +++ .../MediaBrowser.Common.csproj | 1 + MediaBrowser.Common/Net/IRestfulService.cs | 8 ++++- MediaBrowser.Common/Net/RouteInfo.cs | 28 +++++++++++++++ MediaBrowser.Controller/Kernel.cs | 8 ----- .../{Playback => Library}/IIntroProvider.cs | 2 +- .../Library/ILibraryManager.cs | 21 ++++++++---- .../MediaBrowser.Controller.csproj | 2 +- MediaBrowser.Model/Connectivity/ClientType.cs | 1 + .../Library/LibraryManager.cs | 34 +++++++++++++++---- .../ApplicationHost.cs | 2 +- 13 files changed, 99 insertions(+), 29 deletions(-) create mode 100644 MediaBrowser.Common/Net/RouteInfo.cs rename MediaBrowser.Controller/{Playback => Library}/IIntroProvider.cs (92%) diff --git a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs index 920532609c..78e9ad63e6 100644 --- a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs +++ b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs @@ -409,13 +409,11 @@ namespace MediaBrowser.Api.UserLibrary /// System.Object. public object Get(GetIntros request) { - var kernel = (Kernel)Kernel; - var user = _userManager.GetUserById(request.UserId); var item = DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id); - var result = kernel.IntroProviders.SelectMany(i => i.GetIntros(item, user)); + var result = _libraryManager.GetIntros(item, user); return ToOptimizedResult(result); } diff --git a/MediaBrowser.Common.Implementations/HttpServer/BaseRestService.cs b/MediaBrowser.Common.Implementations/HttpServer/BaseRestService.cs index 1c64194a62..bf487b7603 100644 --- a/MediaBrowser.Common.Implementations/HttpServer/BaseRestService.cs +++ b/MediaBrowser.Common.Implementations/HttpServer/BaseRestService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Extensions; +using System.Collections.Generic; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Common.Kernel; using MediaBrowser.Common.Net; @@ -451,5 +452,14 @@ namespace MediaBrowser.Common.Implementations.HttpServer Response.AddHeader("Age", Convert.ToInt64((DateTime.UtcNow - lastDateModified.Value).TotalSeconds).ToString(CultureInfo.InvariantCulture)); } } + + /// + /// Gets the routes. + /// + /// IEnumerable{RouteInfo}. + public IEnumerable GetRoutes() + { + return new RouteInfo[] {}; + } } } diff --git a/MediaBrowser.Common.Implementations/HttpServer/HttpServer.cs b/MediaBrowser.Common.Implementations/HttpServer/HttpServer.cs index c0f075c5ae..785ca56c66 100644 --- a/MediaBrowser.Common.Implementations/HttpServer/HttpServer.cs +++ b/MediaBrowser.Common.Implementations/HttpServer/HttpServer.cs @@ -511,6 +511,11 @@ namespace MediaBrowser.Common.Implementations.HttpServer EndpointHost.ConfigureHost(this, ServerName, CreateServiceManager()); ContentTypeFilters.Register(ContentType.ProtoBuf, (reqCtx, res, stream) => ProtobufSerializer.SerializeToStream(res, stream), (type, stream) => ProtobufSerializer.DeserializeFromStream(stream, type)); + foreach (var route in services.SelectMany(i => i.GetRoutes())) + { + Routes.Add(route.RequestType, route.Path, route.Verbs); + } + Init(); } } diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index c8543168f5..d2bfcc38f3 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -75,6 +75,7 @@ + diff --git a/MediaBrowser.Common/Net/IRestfulService.cs b/MediaBrowser.Common/Net/IRestfulService.cs index d62be4987e..9f37676450 100644 --- a/MediaBrowser.Common/Net/IRestfulService.cs +++ b/MediaBrowser.Common/Net/IRestfulService.cs @@ -1,4 +1,5 @@ - +using System.Collections.Generic; + namespace MediaBrowser.Common.Net { /// @@ -6,5 +7,10 @@ namespace MediaBrowser.Common.Net /// public interface IRestfulService { + /// + /// Gets the routes. + /// + /// IEnumerable{RouteInfo}. + IEnumerable GetRoutes(); } } diff --git a/MediaBrowser.Common/Net/RouteInfo.cs b/MediaBrowser.Common/Net/RouteInfo.cs new file mode 100644 index 0000000000..379aff9c5e --- /dev/null +++ b/MediaBrowser.Common/Net/RouteInfo.cs @@ -0,0 +1,28 @@ +using System; + +namespace MediaBrowser.Common.Net +{ + /// + /// Class RouteInfo + /// + public class RouteInfo + { + /// + /// Gets or sets the path. + /// + /// The path. + public string Path { get; set; } + + /// + /// Gets or sets the verbs. + /// + /// The verbs. + public string Verbs { get; set; } + + /// + /// Gets or sets the type of the request. + /// + /// The type of the request. + public Type RequestType { get; set; } + } +} diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 275b7868b1..145171fd83 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -7,7 +7,6 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Localization; using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Persistence; -using MediaBrowser.Controller.Playback; using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Updates; @@ -86,12 +85,6 @@ namespace MediaBrowser.Controller /// The configuration pages. public IEnumerable PluginConfigurationPages { get; private set; } - /// - /// Gets the intro providers. - /// - /// The intro providers. - public IEnumerable IntroProviders { get; private set; } - /// /// Gets the list of currently registered weather prvoiders /// @@ -210,7 +203,6 @@ namespace MediaBrowser.Controller DisplayPreferencesRepositories = ApplicationHost.GetExports(); ItemRepositories = ApplicationHost.GetExports(); WeatherProviders = ApplicationHost.GetExports(); - IntroProviders = ApplicationHost.GetExports(); PluginConfigurationPages = ApplicationHost.GetExports(); ImageEnhancers = ApplicationHost.GetExports().OrderBy(e => e.Priority).ToArray(); StringFiles = ApplicationHost.GetExports(); diff --git a/MediaBrowser.Controller/Playback/IIntroProvider.cs b/MediaBrowser.Controller/Library/IIntroProvider.cs similarity index 92% rename from MediaBrowser.Controller/Playback/IIntroProvider.cs rename to MediaBrowser.Controller/Library/IIntroProvider.cs index 1f7d12fee9..f54c3a3299 100644 --- a/MediaBrowser.Controller/Playback/IIntroProvider.cs +++ b/MediaBrowser.Controller/Library/IIntroProvider.cs @@ -1,7 +1,7 @@ using MediaBrowser.Controller.Entities; using System.Collections.Generic; -namespace MediaBrowser.Controller.Playback +namespace MediaBrowser.Controller.Library { /// /// Class BaseIntroProvider diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 721b5c216e..64070cb834 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -1,11 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Entities; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; namespace MediaBrowser.Controller.Library { @@ -143,13 +143,22 @@ namespace MediaBrowser.Controller.Library /// BaseItem. BaseItem GetItemById(Guid id, Guid userId); + /// + /// Gets the intros. + /// + /// The item. + /// The user. + /// IEnumerable{System.String}. + IEnumerable GetIntros(BaseItem item, User user); + /// /// Adds the parts. /// /// The rules. /// The plugin folders. /// The resolvers. + /// The intro providers. void AddParts(IEnumerable rules, IEnumerable pluginFolders, - IEnumerable resolvers); + IEnumerable resolvers, IEnumerable introProviders); } } \ No newline at end of file diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 3806defe79..1e55ae78eb 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -132,7 +132,7 @@ - + diff --git a/MediaBrowser.Model/Connectivity/ClientType.cs b/MediaBrowser.Model/Connectivity/ClientType.cs index 409dc96374..7e837ed0e9 100644 --- a/MediaBrowser.Model/Connectivity/ClientType.cs +++ b/MediaBrowser.Model/Connectivity/ClientType.cs @@ -17,6 +17,7 @@ /// The dashboard /// Dashboard, + Dlna, /// /// The ios /// diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index f25f7b2bba..18108842f9 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Events; +using System.Collections; +using MediaBrowser.Common.Events; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Controller; @@ -26,23 +27,29 @@ namespace MediaBrowser.Server.Implementations.Library /// public class LibraryManager : ILibraryManager { + /// + /// Gets the intro providers. + /// + /// The intro providers. + private IEnumerable IntroProviders { get; set; } + /// /// Gets the list of entity resolution ignore rules /// /// The entity resolution ignore rules. - public IEnumerable EntityResolutionIgnoreRules { get; private set; } + private IEnumerable EntityResolutionIgnoreRules { get; set; } /// /// Gets the list of BasePluginFolders added by plugins /// /// The plugin folders. - public IEnumerable PluginFolderCreators { get; set; } + private IEnumerable PluginFolderCreators { get; set; } /// /// Gets the list of currently registered entity resolvers /// /// The entity resolvers enumerable. - public IEnumerable EntityResolvers { get; private set; } + private IEnumerable EntityResolvers { get; set; } #region LibraryChanged Event /// @@ -105,11 +112,13 @@ namespace MediaBrowser.Server.Implementations.Library /// The rules. /// The plugin folders. /// The resolvers. - public void AddParts(IEnumerable rules, IEnumerable pluginFolders, IEnumerable resolvers) + /// The intro providers. + public void AddParts(IEnumerable rules, IEnumerable pluginFolders, IEnumerable resolvers, IEnumerable introProviders) { EntityResolutionIgnoreRules = rules; PluginFolderCreators = pluginFolders; EntityResolvers = resolvers.OrderBy(i => i.Priority).ToArray(); + IntroProviders = introProviders; } /// @@ -655,8 +664,19 @@ namespace MediaBrowser.Server.Implementations.Library { throw new ArgumentNullException("id"); } - return null; - //return RootFolder.FindItemById(id, null); + + return RootFolder.FindItemById(id, null); + } + + /// + /// Gets the intros. + /// + /// The item. + /// The user. + /// IEnumerable{System.String}. + public IEnumerable GetIntros(BaseItem item, User user) + { + return IntroProviders.SelectMany(i => i.GetIntros(item, user)); } } } diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 654fce42ec..ce4aa5ebd5 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -146,7 +146,7 @@ namespace MediaBrowser.ServerApplication { base.FindParts(); - Resolve().AddParts(GetExports(), GetExports(), GetExports()); + Resolve().AddParts(GetExports(), GetExports(), GetExports(), GetExports()); Kernel.InstallationManager = (InstallationManager)CreateInstance(typeof(InstallationManager));