2
0

ApiService.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.Serialization;
  5. using MediaBrowser.Controller;
  6. using MediaBrowser.Model.Entities;
  7. using MediaBrowser.Model.Users;
  8. namespace MediaBrowser.Api
  9. {
  10. /// <summary>
  11. /// Contains some helpers for the api
  12. /// </summary>
  13. public static class ApiService
  14. {
  15. public static BaseItem GetItemById(string id)
  16. {
  17. Guid guid = string.IsNullOrEmpty(id) ? Guid.Empty : new Guid(id);
  18. return Kernel.Instance.GetItemById(guid);
  19. }
  20. /// <summary>
  21. /// Takes a BaseItem and returns the actual object that will be serialized by the api
  22. /// </summary>
  23. public static ApiBaseItemWrapper<BaseItem> GetSerializationObject(BaseItem item, bool includeChildren, Guid userId)
  24. {
  25. ApiBaseItemWrapper<BaseItem> wrapper = new ApiBaseItemWrapper<BaseItem>()
  26. {
  27. Item = item,
  28. UserItemData = Kernel.Instance.GetUserItemData(userId, item.Id),
  29. Type = item.GetType().Name,
  30. IsFolder = (item is Folder)
  31. };
  32. if (includeChildren)
  33. {
  34. var folder = item as Folder;
  35. if (folder != null)
  36. {
  37. wrapper.Children = Kernel.Instance.GetParentalAllowedChildren(folder, userId).Select(c => GetSerializationObject(c, false, userId));
  38. }
  39. }
  40. return wrapper;
  41. }
  42. }
  43. }