using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Entities
{
///
/// Specialized Folder class that points to a subset of the physical folders in the system.
/// It is created from the user-specific folders within the system root
///
public class CollectionFolder : Folder, ICollectionFolder
{
public CollectionFolder()
{
PhysicalLocationsList = new List();
}
///
/// Gets a value indicating whether this instance is virtual folder.
///
/// true if this instance is virtual folder; otherwise, false.
[IgnoreDataMember]
public override bool IsVirtualFolder
{
get
{
return true;
}
}
public string CollectionType { get; set; }
///
/// Allow different display preferences for each collection folder
///
/// The display prefs id.
[IgnoreDataMember]
public override Guid DisplayPreferencesId
{
get
{
return Id;
}
}
[IgnoreDataMember]
public override IEnumerable PhysicalLocations
{
get
{
return PhysicalLocationsList;
}
}
public List PhysicalLocationsList { get; set; }
protected override IEnumerable GetFileSystemChildren(IDirectoryService directoryService)
{
return CreateResolveArgs(directoryService).FileSystemChildren;
}
private ItemResolveArgs CreateResolveArgs(IDirectoryService directoryService)
{
var path = ContainingFolderPath;
var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths, LibraryManager, directoryService)
{
FileInfo = new DirectoryInfo(path),
Path = path,
Parent = Parent
};
// Gather child folder and files
if (args.IsDirectory)
{
var isPhysicalRoot = args.IsPhysicalRoot;
// When resolving the root, we need it's grandchildren (children of user views)
var flattenFolderDepth = isPhysicalRoot ? 2 : 0;
var fileSystemDictionary = FileData.GetFilteredFileSystemEntries(directoryService, args.Path, FileSystem, Logger, args, flattenFolderDepth: flattenFolderDepth, resolveShortcuts: isPhysicalRoot || args.IsVf);
// Need to remove subpaths that may have been resolved from shortcuts
// Example: if \\server\movies exists, then strip out \\server\movies\action
if (isPhysicalRoot)
{
var paths = LibraryManager.NormalizeRootPathList(fileSystemDictionary.Keys);
fileSystemDictionary = paths.Select(i => (FileSystemInfo)new DirectoryInfo(i)).ToDictionary(i => i.FullName);
}
args.FileSystemDictionary = fileSystemDictionary;
}
PhysicalLocationsList = args.PhysicalLocations.ToList();
return args;
}
// Cache this since it will be used a lot
///
/// The null task result
///
private static readonly Task NullTaskResult = Task.FromResult