CollectionFolder.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using MediaBrowser.Controller.Library;
  2. using System;
  3. using System.Collections.Concurrent;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Runtime.Serialization;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. namespace MediaBrowser.Controller.Entities
  11. {
  12. /// <summary>
  13. /// Specialized Folder class that points to a subset of the physical folders in the system.
  14. /// It is created from the user-specific folders within the system root
  15. /// </summary>
  16. public class CollectionFolder : Folder, ICollectionFolder
  17. {
  18. /// <summary>
  19. /// Gets a value indicating whether this instance is virtual folder.
  20. /// </summary>
  21. /// <value><c>true</c> if this instance is virtual folder; otherwise, <c>false</c>.</value>
  22. [IgnoreDataMember]
  23. public override bool IsVirtualFolder
  24. {
  25. get
  26. {
  27. return true;
  28. }
  29. }
  30. public string CollectionType { get; set; }
  31. /// <summary>
  32. /// Allow different display preferences for each collection folder
  33. /// </summary>
  34. /// <value>The display prefs id.</value>
  35. public override Guid DisplayPreferencesId
  36. {
  37. get
  38. {
  39. return Id;
  40. }
  41. }
  42. // Cache this since it will be used a lot
  43. /// <summary>
  44. /// The null task result
  45. /// </summary>
  46. private static readonly Task NullTaskResult = Task.FromResult<object>(null);
  47. /// <summary>
  48. /// Compare our current children (presumably just read from the repo) with the current state of the file system and adjust for any changes
  49. /// ***Currently does not contain logic to maintain items that are unavailable in the file system***
  50. /// </summary>
  51. /// <param name="progress">The progress.</param>
  52. /// <param name="cancellationToken">The cancellation token.</param>
  53. /// <param name="recursive">if set to <c>true</c> [recursive].</param>
  54. /// <param name="forceRefreshMetadata">if set to <c>true</c> [force refresh metadata].</param>
  55. /// <returns>Task.</returns>
  56. protected override Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool? recursive = null, bool forceRefreshMetadata = false)
  57. {
  58. //we don't directly validate our children
  59. //but we do need to clear out the index cache...
  60. IndexCache = new ConcurrentDictionary<string, List<BaseItem>>(StringComparer.OrdinalIgnoreCase);
  61. return NullTaskResult;
  62. }
  63. /// <summary>
  64. /// Our children are actually just references to the ones in the physical root...
  65. /// </summary>
  66. /// <value>The linked children.</value>
  67. public override List<LinkedChild> LinkedChildren
  68. {
  69. get
  70. {
  71. ItemResolveArgs resolveArgs;
  72. try
  73. {
  74. resolveArgs = ResolveArgs;
  75. }
  76. catch (IOException ex)
  77. {
  78. Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
  79. return new List<LinkedChild>();
  80. }
  81. return LibraryManager.RootFolder.RecursiveChildren
  82. .OfType<Folder>()
  83. .Where(i => i.Path != null && resolveArgs.PhysicalLocations.Contains(i.Path, StringComparer.OrdinalIgnoreCase))
  84. .SelectMany(c => c.LinkedChildren).ToList();
  85. }
  86. set
  87. {
  88. base.LinkedChildren = value;
  89. }
  90. }
  91. /// <summary>
  92. /// Our children are actually just references to the ones in the physical root...
  93. /// </summary>
  94. /// <value>The actual children.</value>
  95. protected override ConcurrentDictionary<Guid, BaseItem> ActualChildren
  96. {
  97. get
  98. {
  99. ItemResolveArgs resolveArgs;
  100. try
  101. {
  102. resolveArgs = ResolveArgs;
  103. }
  104. catch (IOException ex)
  105. {
  106. Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
  107. return new ConcurrentDictionary<Guid, BaseItem>();
  108. }
  109. var ourChildren =
  110. LibraryManager.RootFolder.RecursiveChildren
  111. .OfType<Folder>()
  112. .Where(i => i.Path != null && resolveArgs.PhysicalLocations.Contains(i.Path, StringComparer.OrdinalIgnoreCase))
  113. .SelectMany(c => c.Children);
  114. return new ConcurrentDictionary<Guid, BaseItem>(ourChildren.ToDictionary(i => i.Id));
  115. }
  116. }
  117. }
  118. }