using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Controller.Entities
{
///
/// Specialized folder that can have items added to it's children by external entities.
/// Used for our RootFolder so plug-ins can add items.
///
public class AggregateFolder : Folder
{
///
/// We don't support manual shortcuts
///
protected override bool SupportsShortcutChildren
{
get
{
return false;
}
}
///
/// The _virtual children
///
private readonly ConcurrentBag _virtualChildren = new ConcurrentBag();
///
/// Gets the virtual children.
///
/// The virtual children.
public ConcurrentBag VirtualChildren
{
get { return _virtualChildren; }
}
///
/// Adds the virtual child.
///
/// The child.
///
public void AddVirtualChild(BaseItem child)
{
if (child == null)
{
throw new ArgumentNullException();
}
_virtualChildren.Add(child);
}
///
/// Get the children of this folder from the actual file system
///
/// IEnumerable{BaseItem}.
protected override IEnumerable GetNonCachedChildren()
{
return base.GetNonCachedChildren().Concat(_virtualChildren);
}
///
/// Finds the virtual child.
///
/// The id.
/// BaseItem.
/// id
public BaseItem FindVirtualChild(Guid id)
{
if (id == Guid.Empty)
{
throw new ArgumentNullException("id");
}
return _virtualChildren.FirstOrDefault(i => i.Id == id);
}
}
}