AggregateFolder.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace MediaBrowser.Controller.Entities
  6. {
  7. /// <summary>
  8. /// Specialized folder that can have items added to it's children by external entities.
  9. /// Used for our RootFolder so plug-ins can add items.
  10. /// </summary>
  11. public class AggregateFolder : Folder
  12. {
  13. /// <summary>
  14. /// We don't support manual shortcuts
  15. /// </summary>
  16. protected override bool SupportsShortcutChildren
  17. {
  18. get
  19. {
  20. return false;
  21. }
  22. }
  23. /// <summary>
  24. /// The _virtual children
  25. /// </summary>
  26. private readonly ConcurrentBag<BaseItem> _virtualChildren = new ConcurrentBag<BaseItem>();
  27. /// <summary>
  28. /// Gets the virtual children.
  29. /// </summary>
  30. /// <value>The virtual children.</value>
  31. public ConcurrentBag<BaseItem> VirtualChildren
  32. {
  33. get { return _virtualChildren; }
  34. }
  35. /// <summary>
  36. /// Adds the virtual child.
  37. /// </summary>
  38. /// <param name="child">The child.</param>
  39. /// <exception cref="System.ArgumentNullException"></exception>
  40. public void AddVirtualChild(BaseItem child)
  41. {
  42. if (child == null)
  43. {
  44. throw new ArgumentNullException();
  45. }
  46. _virtualChildren.Add(child);
  47. }
  48. /// <summary>
  49. /// Get the children of this folder from the actual file system
  50. /// </summary>
  51. /// <returns>IEnumerable{BaseItem}.</returns>
  52. protected override IEnumerable<BaseItem> GetNonCachedChildren()
  53. {
  54. return base.GetNonCachedChildren().Concat(_virtualChildren);
  55. }
  56. /// <summary>
  57. /// Finds the virtual child.
  58. /// </summary>
  59. /// <param name="id">The id.</param>
  60. /// <returns>BaseItem.</returns>
  61. /// <exception cref="System.ArgumentNullException">id</exception>
  62. public BaseItem FindVirtualChild(Guid id)
  63. {
  64. if (id == Guid.Empty)
  65. {
  66. throw new ArgumentNullException("id");
  67. }
  68. return _virtualChildren.FirstOrDefault(i => i.Id == id);
  69. }
  70. }
  71. }