LinkedChild.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using MediaBrowser.Model.IO;
  4. using MediaBrowser.Model.Serialization;
  5. namespace MediaBrowser.Controller.Entities
  6. {
  7. public class LinkedChild
  8. {
  9. public string Path { get; set; }
  10. public LinkedChildType Type { get; set; }
  11. public string LibraryItemId { get; set; }
  12. [IgnoreDataMember]
  13. public string Id { get; set; }
  14. /// <summary>
  15. /// Serves as a cache
  16. /// </summary>
  17. public Guid? ItemId { get; set; }
  18. public static LinkedChild Create(BaseItem item)
  19. {
  20. var child = new LinkedChild
  21. {
  22. Path = item.Path,
  23. Type = LinkedChildType.Manual
  24. };
  25. if (string.IsNullOrEmpty(child.Path))
  26. {
  27. child.LibraryItemId = item.Id.ToString("N");
  28. }
  29. return child;
  30. }
  31. public LinkedChild()
  32. {
  33. Id = Guid.NewGuid().ToString("N");
  34. }
  35. }
  36. public enum LinkedChildType
  37. {
  38. Manual = 0,
  39. Shortcut = 1
  40. }
  41. public class LinkedChildComparer : IEqualityComparer<LinkedChild>
  42. {
  43. private readonly IFileSystem _fileSystem;
  44. public LinkedChildComparer(IFileSystem fileSystem)
  45. {
  46. _fileSystem = fileSystem;
  47. }
  48. public bool Equals(LinkedChild x, LinkedChild y)
  49. {
  50. if (x.Type == y.Type)
  51. {
  52. return _fileSystem.AreEqual(x.Path, y.Path);
  53. }
  54. return false;
  55. }
  56. public int GetHashCode(LinkedChild obj)
  57. {
  58. return ((obj.Path ?? string.Empty) + (obj.LibraryItemId ?? string.Empty) + obj.Type).GetHashCode();
  59. }
  60. }
  61. }