|  | @@ -2,7 +2,12 @@
 | 
	
		
			
				|  |  |  using MediaBrowser.Controller.Entities;
 | 
	
		
			
				|  |  |  using MediaBrowser.Controller.Library;
 | 
	
		
			
				|  |  |  using MediaBrowser.Controller.Persistence;
 | 
	
		
			
				|  |  | +using MediaBrowser.Model.Dto;
 | 
	
		
			
				|  |  |  using ServiceStack.ServiceHost;
 | 
	
		
			
				|  |  | +using System;
 | 
	
		
			
				|  |  | +using System.Collections.Generic;
 | 
	
		
			
				|  |  | +using System.IO;
 | 
	
		
			
				|  |  | +using System.Linq;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  namespace MediaBrowser.Api
 | 
	
		
			
				|  |  |  {
 | 
	
	
		
			
				|  | @@ -15,6 +20,21 @@ namespace MediaBrowser.Api
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /// <summary>
 | 
	
		
			
				|  |  | +    /// Class GetGameSystemSummaries
 | 
	
		
			
				|  |  | +    /// </summary>
 | 
	
		
			
				|  |  | +    [Route("/Games/SystemSummaries", "GET")]
 | 
	
		
			
				|  |  | +    [Api(Description = "Finds games similar to a given game.")]
 | 
	
		
			
				|  |  | +    public class GetGameSystemSummaries : IReturn<List<GameSystemSummary>>
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        /// <summary>
 | 
	
		
			
				|  |  | +        /// Gets or sets the user id.
 | 
	
		
			
				|  |  | +        /// </summary>
 | 
	
		
			
				|  |  | +        /// <value>The user id.</value>
 | 
	
		
			
				|  |  | +        [ApiMember(Name = "UserId", Description = "Optional. Filter by user id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
 | 
	
		
			
				|  |  | +        public Guid? UserId { get; set; }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /// <summary>
 | 
	
		
			
				|  |  |      /// Class GamesService
 | 
	
		
			
				|  |  |      /// </summary>
 | 
	
	
		
			
				|  | @@ -34,7 +54,13 @@ namespace MediaBrowser.Api
 | 
	
		
			
				|  |  |          /// </summary>
 | 
	
		
			
				|  |  |          private readonly ILibraryManager _libraryManager;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        /// <summary>
 | 
	
		
			
				|  |  | +        /// The _item repo
 | 
	
		
			
				|  |  | +        /// </summary>
 | 
	
		
			
				|  |  |          private readonly IItemRepository _itemRepo;
 | 
	
		
			
				|  |  | +        /// <summary>
 | 
	
		
			
				|  |  | +        /// The _dto service
 | 
	
		
			
				|  |  | +        /// </summary>
 | 
	
		
			
				|  |  |          private readonly IDtoService _dtoService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          /// <summary>
 | 
	
	
		
			
				|  | @@ -44,6 +70,7 @@ namespace MediaBrowser.Api
 | 
	
		
			
				|  |  |          /// <param name="userDataRepository">The user data repository.</param>
 | 
	
		
			
				|  |  |          /// <param name="libraryManager">The library manager.</param>
 | 
	
		
			
				|  |  |          /// <param name="itemRepo">The item repo.</param>
 | 
	
		
			
				|  |  | +        /// <param name="dtoService">The dto service.</param>
 | 
	
		
			
				|  |  |          public GamesService(IUserManager userManager, IUserDataRepository userDataRepository, ILibraryManager libraryManager, IItemRepository itemRepo, IDtoService dtoService)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              _userManager = userManager;
 | 
	
	
		
			
				|  | @@ -53,6 +80,52 @@ namespace MediaBrowser.Api
 | 
	
		
			
				|  |  |              _dtoService = dtoService;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        /// <summary>
 | 
	
		
			
				|  |  | +        /// Gets the specified request.
 | 
	
		
			
				|  |  | +        /// </summary>
 | 
	
		
			
				|  |  | +        /// <param name="request">The request.</param>
 | 
	
		
			
				|  |  | +        /// <returns>System.Object.</returns>
 | 
	
		
			
				|  |  | +        public object Get(GetGameSystemSummaries request)
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            var gameSystems = GetAllLibraryItems(request.UserId, _userManager, _libraryManager)
 | 
	
		
			
				|  |  | +                .OfType<GameSystem>()
 | 
	
		
			
				|  |  | +                .ToList();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var user = request.UserId == null ? null : _userManager.GetUserById(request.UserId.Value);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var result = gameSystems
 | 
	
		
			
				|  |  | +                .Select(i => GetSummary(i, user))
 | 
	
		
			
				|  |  | +                .ToList();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            return ToOptimizedResult(result);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        /// <summary>
 | 
	
		
			
				|  |  | +        /// Gets the summary.
 | 
	
		
			
				|  |  | +        /// </summary>
 | 
	
		
			
				|  |  | +        /// <param name="system">The system.</param>
 | 
	
		
			
				|  |  | +        /// <param name="user">The user.</param>
 | 
	
		
			
				|  |  | +        /// <returns>GameSystemSummary.</returns>
 | 
	
		
			
				|  |  | +        private GameSystemSummary GetSummary(GameSystem system, User user)
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            var summary = new GameSystemSummary
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                Name = system.Name
 | 
	
		
			
				|  |  | +            };
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var items = user == null ? system.RecursiveChildren : system.GetRecursiveChildren(user);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var games = items.OfType<Game>().ToList();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            summary.GameCount = games.Count;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            summary.GameFileExtensions = games.Select(i => Path.GetExtension(i.Path))
 | 
	
		
			
				|  |  | +                .Distinct(StringComparer.OrdinalIgnoreCase)
 | 
	
		
			
				|  |  | +                .ToList();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            return summary;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          /// <summary>
 | 
	
		
			
				|  |  |          /// Gets the specified request.
 | 
	
		
			
				|  |  |          /// </summary>
 |