2
0

LinkedChild.cs 1.8 KB

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