CollectionFolder.cs 4.6 KB

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