LinkedChild.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. [IgnoreDataMember]
  12. public string Id { get; set; }
  13. /// <summary>
  14. /// Serves as a cache
  15. /// </summary>
  16. public Guid? ItemId { get; set; }
  17. public static LinkedChild Create(BaseItem item)
  18. {
  19. return new LinkedChild
  20. {
  21. Path = item.Path,
  22. Type = LinkedChildType.Manual
  23. };
  24. }
  25. public LinkedChild()
  26. {
  27. Id = Guid.NewGuid().ToString("N");
  28. }
  29. }
  30. public enum LinkedChildType
  31. {
  32. Manual = 0,
  33. Shortcut = 1
  34. }
  35. public class LinkedChildComparer : IEqualityComparer<LinkedChild>
  36. {
  37. private readonly IFileSystem _fileSystem;
  38. public LinkedChildComparer(IFileSystem fileSystem)
  39. {
  40. _fileSystem = fileSystem;
  41. }
  42. public bool Equals(LinkedChild x, LinkedChild y)
  43. {
  44. if (x.Type == y.Type)
  45. {
  46. return _fileSystem.AreEqual(x.Path, y.Path);
  47. }
  48. return false;
  49. }
  50. public int GetHashCode(LinkedChild obj)
  51. {
  52. return (obj.Path + obj.Type).GetHashCode();
  53. }
  54. }
  55. }