LinkedChild.cs 1.8 KB

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