AggregateFolder.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. /// The _virtual children
  15. /// </summary>
  16. private readonly ConcurrentBag<BaseItem> _virtualChildren = new ConcurrentBag<BaseItem>();
  17. /// <summary>
  18. /// Gets the virtual children.
  19. /// </summary>
  20. /// <value>The virtual children.</value>
  21. public ConcurrentBag<BaseItem> VirtualChildren
  22. {
  23. get { return _virtualChildren; }
  24. }
  25. /// <summary>
  26. /// Adds the virtual child.
  27. /// </summary>
  28. /// <param name="child">The child.</param>
  29. /// <exception cref="System.ArgumentNullException"></exception>
  30. public void AddVirtualChild(BaseItem child)
  31. {
  32. if (child == null)
  33. {
  34. throw new ArgumentNullException();
  35. }
  36. _virtualChildren.Add(child);
  37. }
  38. /// <summary>
  39. /// Get the children of this folder from the actual file system
  40. /// </summary>
  41. /// <returns>IEnumerable{BaseItem}.</returns>
  42. protected override IEnumerable<BaseItem> GetNonCachedChildren()
  43. {
  44. return base.GetNonCachedChildren().Concat(_virtualChildren);
  45. }
  46. /// <summary>
  47. /// Finds the virtual child.
  48. /// </summary>
  49. /// <param name="id">The id.</param>
  50. /// <returns>BaseItem.</returns>
  51. /// <exception cref="System.ArgumentNullException">id</exception>
  52. public BaseItem FindVirtualChild(Guid id)
  53. {
  54. if (id == Guid.Empty)
  55. {
  56. throw new ArgumentNullException("id");
  57. }
  58. return _virtualChildren.FirstOrDefault(i => i.Id == id);
  59. }
  60. }
  61. }