CollectionFolder.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using MediaBrowser.Common.Extensions;
  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. /// <summary>
  31. /// Allow different display preferences for each collection folder
  32. /// </summary>
  33. /// <value>The display prefs id.</value>
  34. protected 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. IndexCache = new ConcurrentDictionary<string, List<BaseItem>>(StringComparer.OrdinalIgnoreCase);
  60. return NullTaskResult;
  61. }
  62. /// <summary>
  63. /// Our children are actually just references to the ones in the physical root...
  64. /// </summary>
  65. /// <value>The actual children.</value>
  66. protected override ConcurrentDictionary<Guid,BaseItem> ActualChildren
  67. {
  68. get
  69. {
  70. var ourChildren =
  71. LibraryManager.RootFolder.RecursiveChildren
  72. .Where(i => i is Folder && i.Path != null && ResolveArgs.PhysicalLocations.Contains(i.Path, StringComparer.OrdinalIgnoreCase))
  73. .Cast<Folder>().SelectMany(c => c.Children);
  74. return new ConcurrentDictionary<Guid,BaseItem>(ourChildren.ToDictionary(i => i.Id));
  75. }
  76. }
  77. }
  78. }