2014-12-01 18:42:07 +00:00
|
|
|
|
using MediaBrowser.Common.Progress;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-01-28 18:37:01 +00:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-07-04 02:22:57 +00:00
|
|
|
|
using MediaBrowser.Model.Dto;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2014-09-01 20:10:54 +00:00
|
|
|
|
using MediaBrowser.Model.Querying;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-05-26 06:48:54 +00:00
|
|
|
|
|
2016-06-19 06:18:29 +00:00
|
|
|
|
using MediaBrowser.Controller.Channels;
|
2017-05-21 07:25:49 +00:00
|
|
|
|
using MediaBrowser.Controller.Dto;
|
2016-08-16 17:08:37 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2017-04-18 19:22:17 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
2016-08-08 18:14:05 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2016-10-25 19:02:04 +00:00
|
|
|
|
using MediaBrowser.Controller.IO;
|
2016-03-19 05:04:38 +00:00
|
|
|
|
using MediaBrowser.Model.Channels;
|
2016-10-25 19:02:04 +00:00
|
|
|
|
using MediaBrowser.Model.IO;
|
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2017-08-09 19:56:38 +00:00
|
|
|
|
using MediaBrowser.Model.Extensions;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class Folder
|
|
|
|
|
/// </summary>
|
2016-10-09 07:18:43 +00:00
|
|
|
|
public class Folder : BaseItem
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-10-06 01:04:41 +00:00
|
|
|
|
public static IUserManager UserManager { get; set; }
|
2014-09-01 20:10:54 +00:00
|
|
|
|
public static IUserViewManager UserViewManager { get; set; }
|
2013-10-06 01:04:41 +00:00
|
|
|
|
|
2016-10-09 07:18:43 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets a value indicating whether this instance is root.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if this instance is root; otherwise, <c>false</c>.</value>
|
|
|
|
|
public bool IsRoot { get; set; }
|
|
|
|
|
|
2017-08-10 18:01:31 +00:00
|
|
|
|
public LinkedChild[] LinkedChildren { get; set; }
|
2014-02-06 04:39:16 +00:00
|
|
|
|
|
2016-05-09 03:13:38 +00:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public DateTime? DateLastMediaAdded { get; set; }
|
|
|
|
|
|
2013-07-05 13:47:10 +00:00
|
|
|
|
public Folder()
|
|
|
|
|
{
|
2017-08-10 18:01:31 +00:00
|
|
|
|
LinkedChildren = EmptyLinkedChildArray;
|
2016-10-09 07:18:43 +00:00
|
|
|
|
}
|
2013-12-05 16:50:21 +00:00
|
|
|
|
|
2016-10-09 07:18:43 +00:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override bool SupportsThemeMedia
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
2013-07-05 13:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-03 02:16:37 +00:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public virtual bool IsPreSorted
|
|
|
|
|
{
|
2015-09-03 04:16:31 +00:00
|
|
|
|
get { return false; }
|
2014-08-03 02:16:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-09 07:18:43 +00:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public virtual bool IsPhysicalRoot
|
|
|
|
|
{
|
|
|
|
|
get { return false; }
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-29 19:10:58 +00:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override bool SupportsInheritedParentImages
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 06:46:59 +00:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override bool SupportsPlayedStatus
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether this instance is folder.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if this instance is folder; otherwise, <c>false</c>.</value>
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override bool IsFolder
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-06 04:38:03 +00:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override bool IsDisplayedAsFolder
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-09 03:13:38 +00:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public virtual bool SupportsCumulativeRunTimeTicks
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public virtual bool SupportsDateLastMediaAdded
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-17 20:52:05 +00:00
|
|
|
|
public override bool CanDelete()
|
|
|
|
|
{
|
|
|
|
|
if (IsRoot)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.CanDelete();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-09 03:13:38 +00:00
|
|
|
|
public override bool RequiresRefresh()
|
|
|
|
|
{
|
|
|
|
|
var baseResult = base.RequiresRefresh();
|
|
|
|
|
|
|
|
|
|
if (SupportsCumulativeRunTimeTicks && !RunTimeTicks.HasValue)
|
|
|
|
|
{
|
|
|
|
|
baseResult = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return baseResult;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-09 04:57:18 +00:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override string FileNameWithoutExtension
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (LocationType == LocationType.FileSystem)
|
|
|
|
|
{
|
|
|
|
|
return System.IO.Path.GetFileName(Path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-09 06:56:45 +00:00
|
|
|
|
protected override bool IsAllowTagFilterEnforced()
|
2015-02-09 06:17:11 +00:00
|
|
|
|
{
|
|
|
|
|
if (this is ICollectionFolder)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (this is UserView)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-28 21:29:02 +00:00
|
|
|
|
[IgnoreDataMember]
|
2013-07-06 00:19:44 +00:00
|
|
|
|
protected virtual bool SupportsShortcutChildren
|
2013-07-05 13:47:10 +00:00
|
|
|
|
{
|
2016-04-02 21:08:35 +00:00
|
|
|
|
get { return false; }
|
2013-07-05 13:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-03 17:46:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds the child.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
|
|
|
|
/// <exception cref="System.InvalidOperationException">Unable to add + item.Name</exception>
|
2017-08-27 00:32:33 +00:00
|
|
|
|
public void AddChild(BaseItem item, CancellationToken cancellationToken)
|
2013-05-03 17:46:35 +00:00
|
|
|
|
{
|
2015-07-09 05:52:25 +00:00
|
|
|
|
item.SetParent(this);
|
2013-05-12 13:13:57 +00:00
|
|
|
|
|
|
|
|
|
if (item.Id == Guid.Empty)
|
|
|
|
|
{
|
2014-11-30 19:01:33 +00:00
|
|
|
|
item.Id = LibraryManager.GetNewItemId(item.Path, item.GetType());
|
2013-05-12 13:13:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-03 07:36:32 +00:00
|
|
|
|
if (Children.Any(i => i.Id == item.Id))
|
2013-10-06 01:04:41 +00:00
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException(string.Format("A child with the Id {0} already exists.", item.Id));
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-12 13:13:57 +00:00
|
|
|
|
if (item.DateCreated == DateTime.MinValue)
|
|
|
|
|
{
|
2013-07-17 15:19:28 +00:00
|
|
|
|
item.DateCreated = DateTime.UtcNow;
|
2013-05-12 13:13:57 +00:00
|
|
|
|
}
|
|
|
|
|
if (item.DateModified == DateTime.MinValue)
|
|
|
|
|
{
|
2013-07-17 15:19:28 +00:00
|
|
|
|
item.DateModified = DateTime.UtcNow;
|
2013-05-12 13:13:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-27 00:32:33 +00:00
|
|
|
|
LibraryManager.CreateItem(item, cancellationToken);
|
2013-09-19 21:23:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-03 17:46:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes the child.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
2016-03-21 20:15:18 +00:00
|
|
|
|
public void RemoveChild(BaseItem item)
|
2013-05-03 17:46:35 +00:00
|
|
|
|
{
|
2015-07-09 05:52:25 +00:00
|
|
|
|
item.SetParent(null);
|
2013-05-03 17:46:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-20 21:32:26 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the actual children.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The actual children.</value>
|
2016-05-19 19:06:58 +00:00
|
|
|
|
[IgnoreDataMember]
|
2017-06-03 07:36:32 +00:00
|
|
|
|
public virtual IEnumerable<BaseItem> Children
|
2016-03-20 21:32:26 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-06-17 13:06:13 +00:00
|
|
|
|
return LoadChildren();
|
2016-03-20 21:32:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// thread-safe access to all recursive children of this folder - without regard to user
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The recursive children.</value>
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public IEnumerable<BaseItem> RecursiveChildren
|
|
|
|
|
{
|
2013-09-27 12:24:28 +00:00
|
|
|
|
get { return GetRecursiveChildren(); }
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-21 05:04:11 +00:00
|
|
|
|
public override bool IsVisible(User user)
|
|
|
|
|
{
|
2015-01-22 16:41:34 +00:00
|
|
|
|
if (this is ICollectionFolder && !(this is BasePluginFolder))
|
2014-02-21 05:04:11 +00:00
|
|
|
|
{
|
2015-04-15 03:41:29 +00:00
|
|
|
|
if (user.Policy.BlockedMediaFolders != null)
|
2014-02-21 05:04:11 +00:00
|
|
|
|
{
|
2015-04-15 03:41:29 +00:00
|
|
|
|
if (user.Policy.BlockedMediaFolders.Contains(Id.ToString("N"), StringComparer.OrdinalIgnoreCase) ||
|
|
|
|
|
|
|
|
|
|
// Backwards compatibility
|
|
|
|
|
user.Policy.BlockedMediaFolders.Contains(Name, StringComparer.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!user.Policy.EnableAllFolders && !user.Policy.EnabledFolders.Contains(Id.ToString("N"), StringComparer.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-02-21 05:04:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.IsVisible(user);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loads our children. Validation will occur externally.
|
|
|
|
|
/// We want this sychronous.
|
|
|
|
|
/// </summary>
|
2017-06-03 07:36:32 +00:00
|
|
|
|
protected virtual List<BaseItem> LoadChildren()
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2016-08-13 19:53:20 +00:00
|
|
|
|
//Logger.Debug("Loading children from {0} {1} {2}", GetType().Name, Id, Path);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
//just load our children from the repo - the library will be validated and maintained in other processes
|
2013-09-18 23:33:21 +00:00
|
|
|
|
return GetCachedChildren();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-23 16:04:45 +00:00
|
|
|
|
public override double? GetRefreshProgress()
|
|
|
|
|
{
|
|
|
|
|
return ProviderManager.GetRefreshProgress(Id);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-09 07:27:44 +00:00
|
|
|
|
public Task ValidateChildren(IProgress<double> progress, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2016-08-06 04:48:00 +00:00
|
|
|
|
return ValidateChildren(progress, cancellationToken, new MetadataRefreshOptions(new DirectoryService(Logger, FileSystem)));
|
2014-02-09 07:27:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Validates that the children of the folder still exist
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="progress">The progress.</param>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
2014-02-09 07:27:44 +00:00
|
|
|
|
/// <param name="metadataRefreshOptions">The metadata refresh options.</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
2014-02-09 07:27:44 +00:00
|
|
|
|
public Task ValidateChildren(IProgress<double> progress, CancellationToken cancellationToken, MetadataRefreshOptions metadataRefreshOptions, bool recursive = true)
|
2014-02-06 22:22:03 +00:00
|
|
|
|
{
|
2015-01-27 06:50:40 +00:00
|
|
|
|
return ValidateChildrenInternal(progress, cancellationToken, recursive, true, metadataRefreshOptions, metadataRefreshOptions.DirectoryService);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-23 20:35:58 +00:00
|
|
|
|
private Dictionary<Guid, BaseItem> GetActualChildrenDictionary()
|
|
|
|
|
{
|
|
|
|
|
var dictionary = new Dictionary<Guid, BaseItem>();
|
|
|
|
|
|
2017-06-03 07:36:32 +00:00
|
|
|
|
var childrenList = Children.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var child in childrenList)
|
2014-02-23 20:35:58 +00:00
|
|
|
|
{
|
|
|
|
|
var id = child.Id;
|
|
|
|
|
if (dictionary.ContainsKey(id))
|
|
|
|
|
{
|
2014-02-26 04:38:21 +00:00
|
|
|
|
Logger.Error("Found folder containing items with duplicate id. Path: {0}, Child Name: {1}",
|
2014-02-23 20:35:58 +00:00
|
|
|
|
Path ?? Name,
|
|
|
|
|
child.Path ?? child.Name);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dictionary[id] = child;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dictionary;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-03 05:11:03 +00:00
|
|
|
|
private bool IsValidFromResolver(BaseItem current, BaseItem newItem)
|
|
|
|
|
{
|
2014-12-03 03:13:03 +00:00
|
|
|
|
return current.IsValidFromResolver(newItem);
|
2014-03-03 05:11:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-23 16:04:45 +00:00
|
|
|
|
protected override void TriggerOnRefreshStart()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void TriggerOnRefreshComplete()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
2014-02-06 22:22:03 +00:00
|
|
|
|
/// Validates the children internal.
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="progress">The progress.</param>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
|
2014-02-06 22:22:03 +00:00
|
|
|
|
/// <param name="refreshChildMetadata">if set to <c>true</c> [refresh child metadata].</param>
|
|
|
|
|
/// <param name="refreshOptions">The refresh options.</param>
|
2014-02-08 22:38:02 +00:00
|
|
|
|
/// <param name="directoryService">The directory service.</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <returns>Task.</returns>
|
2017-06-23 16:04:45 +00:00
|
|
|
|
protected virtual async Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService)
|
|
|
|
|
{
|
|
|
|
|
if (recursive)
|
|
|
|
|
{
|
|
|
|
|
ProviderManager.OnRefreshStart(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await ValidateChildrenInternal2(progress, cancellationToken, recursive, refreshChildMetadata, refreshOptions, directoryService).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (recursive)
|
|
|
|
|
{
|
|
|
|
|
ProviderManager.OnRefreshComplete(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task ValidateChildrenInternal2(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-07-05 16:17:32 +00:00
|
|
|
|
var locationType = LocationType;
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
2014-02-06 16:46:26 +00:00
|
|
|
|
var validChildren = new List<BaseItem>();
|
2013-07-07 15:53:38 +00:00
|
|
|
|
|
2017-01-10 20:44:02 +00:00
|
|
|
|
var allLibraryPaths = LibraryManager
|
|
|
|
|
.GetVirtualFolders()
|
|
|
|
|
.SelectMany(i => i.Locations)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
2013-12-27 00:52:36 +00:00
|
|
|
|
if (locationType != LocationType.Remote && locationType != LocationType.Virtual)
|
2013-07-07 15:53:38 +00:00
|
|
|
|
{
|
2013-12-27 00:52:36 +00:00
|
|
|
|
IEnumerable<BaseItem> nonCachedChildren;
|
2013-07-07 15:53:38 +00:00
|
|
|
|
|
2013-12-27 00:52:36 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2014-02-08 22:38:02 +00:00
|
|
|
|
nonCachedChildren = GetNonCachedChildren(directoryService);
|
2013-12-27 00:52:36 +00:00
|
|
|
|
}
|
|
|
|
|
catch (IOException ex)
|
|
|
|
|
{
|
2014-02-06 04:39:16 +00:00
|
|
|
|
nonCachedChildren = new BaseItem[] { };
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-12-27 00:52:36 +00:00
|
|
|
|
Logger.ErrorException("Error getting file system entries for {0}", ex, Path);
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-12-27 00:52:36 +00:00
|
|
|
|
if (nonCachedChildren == null) return; //nothing to validate
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-12-27 00:52:36 +00:00
|
|
|
|
progress.Report(5);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2017-06-23 16:04:45 +00:00
|
|
|
|
if (recursive)
|
|
|
|
|
{
|
|
|
|
|
ProviderManager.OnRefreshProgress(this, 5);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-27 00:52:36 +00:00
|
|
|
|
//build a dictionary of the current children we have now by Id so we can compare quickly and easily
|
2014-02-23 20:35:58 +00:00
|
|
|
|
var currentChildren = GetActualChildrenDictionary();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-12-27 00:52:36 +00:00
|
|
|
|
//create a list for our validated children
|
|
|
|
|
var newItems = new List<BaseItem>();
|
2013-04-12 18:22:40 +00:00
|
|
|
|
|
2013-12-27 00:52:36 +00:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-12-27 00:52:36 +00:00
|
|
|
|
foreach (var child in nonCachedChildren)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-12-27 00:52:36 +00:00
|
|
|
|
BaseItem currentChild;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2015-11-23 16:04:57 +00:00
|
|
|
|
if (currentChildren.TryGetValue(child.Id, out currentChild) && IsValidFromResolver(currentChild, child))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2015-11-23 16:04:57 +00:00
|
|
|
|
validChildren.Add(currentChild);
|
|
|
|
|
|
|
|
|
|
continue;
|
2015-11-23 16:01:42 +00:00
|
|
|
|
}
|
2015-11-23 16:04:57 +00:00
|
|
|
|
|
|
|
|
|
// Brand new item - needs to be added
|
|
|
|
|
child.SetParent(this);
|
|
|
|
|
newItems.Add(child);
|
|
|
|
|
validChildren.Add(child);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2013-12-27 00:52:36 +00:00
|
|
|
|
|
|
|
|
|
// If any items were added or removed....
|
|
|
|
|
if (newItems.Count > 0 || currentChildren.Count != validChildren.Count)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-12-27 00:52:36 +00:00
|
|
|
|
// That's all the new and changed ones - now see if there are any that are missing
|
2014-02-06 16:46:26 +00:00
|
|
|
|
var itemsRemoved = currentChildren.Values.Except(validChildren).ToList();
|
2013-12-27 00:52:36 +00:00
|
|
|
|
var actualRemovals = new List<BaseItem>();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-12-27 00:52:36 +00:00
|
|
|
|
foreach (var item in itemsRemoved)
|
|
|
|
|
{
|
2016-05-25 02:06:56 +00:00
|
|
|
|
var itemLocationType = item.LocationType;
|
|
|
|
|
if (itemLocationType == LocationType.Virtual ||
|
|
|
|
|
itemLocationType == LocationType.Remote)
|
2013-12-27 00:52:36 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2017-01-10 20:44:02 +00:00
|
|
|
|
else if (!string.IsNullOrEmpty(item.Path) && IsPathOffline(item.Path, allLibraryPaths))
|
2013-12-27 00:52:36 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
actualRemovals.Add(item);
|
|
|
|
|
}
|
2013-10-16 23:35:11 +00:00
|
|
|
|
}
|
2013-07-05 18:23:41 +00:00
|
|
|
|
|
2013-12-27 00:52:36 +00:00
|
|
|
|
if (actualRemovals.Count > 0)
|
2013-10-06 01:04:41 +00:00
|
|
|
|
{
|
2013-12-27 00:52:36 +00:00
|
|
|
|
foreach (var item in actualRemovals)
|
|
|
|
|
{
|
2015-11-23 16:04:57 +00:00
|
|
|
|
Logger.Debug("Removed item: " + item.Path);
|
|
|
|
|
|
|
|
|
|
item.SetParent(null);
|
|
|
|
|
await LibraryManager.DeleteItem(item, new DeleteOptions { DeleteFileLocation = false }).ConfigureAwait(false);
|
2013-12-27 00:52:36 +00:00
|
|
|
|
LibraryManager.ReportItemRemoved(item);
|
|
|
|
|
}
|
2013-09-23 18:28:07 +00:00
|
|
|
|
}
|
2013-09-19 00:37:01 +00:00
|
|
|
|
|
2017-08-27 00:32:33 +00:00
|
|
|
|
LibraryManager.CreateItems(newItems, cancellationToken);
|
2013-12-27 00:52:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-23 16:04:45 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (recursive || refreshChildMetadata)
|
|
|
|
|
{
|
|
|
|
|
// used below
|
|
|
|
|
validChildren = Children.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-03-28 19:25:36 +00:00
|
|
|
|
progress.Report(10);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2014-02-06 22:22:03 +00:00
|
|
|
|
if (recursive)
|
|
|
|
|
{
|
2017-06-23 16:04:45 +00:00
|
|
|
|
ProviderManager.OnRefreshProgress(this, 10);
|
2014-02-06 22:22:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-23 16:04:45 +00:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
2014-02-06 22:22:03 +00:00
|
|
|
|
|
2017-06-23 16:04:45 +00:00
|
|
|
|
if (recursive)
|
2014-02-06 22:22:03 +00:00
|
|
|
|
{
|
2017-06-23 16:04:45 +00:00
|
|
|
|
using (var innerProgress = new ActionableProgress<double>())
|
|
|
|
|
{
|
|
|
|
|
var folder = this;
|
|
|
|
|
innerProgress.RegisterAction(p =>
|
|
|
|
|
{
|
2017-06-24 18:33:19 +00:00
|
|
|
|
double newPct = .80 * p + 10;
|
2017-06-23 16:04:45 +00:00
|
|
|
|
progress.Report(newPct);
|
|
|
|
|
ProviderManager.OnRefreshProgress(folder, newPct);
|
|
|
|
|
});
|
2014-02-06 22:22:03 +00:00
|
|
|
|
|
2017-06-23 16:04:45 +00:00
|
|
|
|
await ValidateSubFolders(validChildren.OfType<Folder>().ToList(), directoryService, innerProgress, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-06 22:22:03 +00:00
|
|
|
|
|
2017-06-23 16:04:45 +00:00
|
|
|
|
if (refreshChildMetadata)
|
|
|
|
|
{
|
2017-06-24 18:33:19 +00:00
|
|
|
|
progress.Report(90);
|
2014-02-06 22:22:03 +00:00
|
|
|
|
|
2017-06-23 16:04:45 +00:00
|
|
|
|
if (recursive)
|
2014-02-06 22:22:03 +00:00
|
|
|
|
{
|
2017-06-24 18:33:19 +00:00
|
|
|
|
ProviderManager.OnRefreshProgress(this, 90);
|
2014-02-06 22:22:03 +00:00
|
|
|
|
}
|
2017-06-23 16:04:45 +00:00
|
|
|
|
|
|
|
|
|
var container = this as IMetadataContainer;
|
|
|
|
|
|
|
|
|
|
using (var innerProgress = new ActionableProgress<double>())
|
2014-02-06 22:22:03 +00:00
|
|
|
|
{
|
2017-06-23 16:04:45 +00:00
|
|
|
|
var folder = this;
|
|
|
|
|
innerProgress.RegisterAction(p =>
|
|
|
|
|
{
|
2017-06-24 18:33:19 +00:00
|
|
|
|
double newPct = .10 * p + 90;
|
2017-06-23 16:04:45 +00:00
|
|
|
|
progress.Report(newPct);
|
|
|
|
|
if (recursive)
|
|
|
|
|
{
|
|
|
|
|
ProviderManager.OnRefreshProgress(folder, newPct);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (container != null)
|
|
|
|
|
{
|
|
|
|
|
await container.RefreshAllMetadata(refreshOptions, innerProgress, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await RefreshMetadataRecursive(validChildren, refreshOptions, recursive, innerProgress, cancellationToken);
|
|
|
|
|
}
|
2014-02-06 22:22:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-23 16:04:45 +00:00
|
|
|
|
private async Task RefreshMetadataRecursive(List<BaseItem> children, MetadataRefreshOptions refreshOptions, bool recursive, IProgress<double> progress, CancellationToken cancellationToken)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2015-01-29 03:58:39 +00:00
|
|
|
|
var numComplete = 0;
|
|
|
|
|
var count = children.Count;
|
2017-06-23 16:04:45 +00:00
|
|
|
|
double currentPercent = 0;
|
2013-04-15 15:10:12 +00:00
|
|
|
|
|
2014-02-06 22:22:03 +00:00
|
|
|
|
foreach (var child in children)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2014-02-06 22:22:03 +00:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
2014-02-09 07:27:44 +00:00
|
|
|
|
|
2017-06-23 16:04:45 +00:00
|
|
|
|
using (var innerProgress = new ActionableProgress<double>())
|
2014-02-06 22:22:03 +00:00
|
|
|
|
{
|
2015-01-29 03:58:39 +00:00
|
|
|
|
// Avoid implicitly captured closure
|
2017-06-23 16:04:45 +00:00
|
|
|
|
var currentInnerPercent = currentPercent;
|
|
|
|
|
|
2015-01-29 03:58:39 +00:00
|
|
|
|
innerProgress.RegisterAction(p =>
|
2014-02-06 22:22:03 +00:00
|
|
|
|
{
|
2017-06-23 16:04:45 +00:00
|
|
|
|
double innerPercent = currentInnerPercent;
|
|
|
|
|
innerPercent += p / (count);
|
|
|
|
|
progress.Report(innerPercent);
|
2015-01-29 03:58:39 +00:00
|
|
|
|
});
|
2014-02-06 22:22:03 +00:00
|
|
|
|
|
2017-06-23 16:04:45 +00:00
|
|
|
|
await RefreshChildMetadata(child, refreshOptions, recursive && child.IsFolder, innerProgress, cancellationToken)
|
2015-01-29 03:58:39 +00:00
|
|
|
|
.ConfigureAwait(false);
|
2014-02-06 22:22:03 +00:00
|
|
|
|
}
|
2015-01-29 03:58:39 +00:00
|
|
|
|
|
|
|
|
|
numComplete++;
|
|
|
|
|
double percent = numComplete;
|
|
|
|
|
percent /= count;
|
|
|
|
|
percent *= 100;
|
2017-06-23 16:04:45 +00:00
|
|
|
|
currentPercent = percent;
|
2015-01-29 03:58:39 +00:00
|
|
|
|
|
|
|
|
|
progress.Report(percent);
|
2014-02-06 22:22:03 +00:00
|
|
|
|
}
|
2014-01-01 18:26:31 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2014-02-06 22:22:03 +00:00
|
|
|
|
private async Task RefreshChildMetadata(BaseItem child, MetadataRefreshOptions refreshOptions, bool recursive, IProgress<double> progress, CancellationToken cancellationToken)
|
2014-01-01 18:26:31 +00:00
|
|
|
|
{
|
2014-02-06 22:22:03 +00:00
|
|
|
|
var container = child as IMetadataContainer;
|
2013-04-15 15:10:12 +00:00
|
|
|
|
|
2014-02-06 22:22:03 +00:00
|
|
|
|
if (container != null)
|
2014-01-01 18:26:31 +00:00
|
|
|
|
{
|
2014-02-06 22:22:03 +00:00
|
|
|
|
await container.RefreshAllMetadata(refreshOptions, progress, cancellationToken).ConfigureAwait(false);
|
2014-01-01 18:26:31 +00:00
|
|
|
|
}
|
2014-02-06 22:22:03 +00:00
|
|
|
|
else
|
2014-01-01 18:26:31 +00:00
|
|
|
|
{
|
2014-02-06 22:22:03 +00:00
|
|
|
|
await child.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
if (recursive)
|
|
|
|
|
{
|
|
|
|
|
var folder = child as Folder;
|
|
|
|
|
|
|
|
|
|
if (folder != null)
|
|
|
|
|
{
|
2017-06-23 16:04:45 +00:00
|
|
|
|
await folder.RefreshMetadataRecursive(folder.Children.ToList(), refreshOptions, true, progress, cancellationToken);
|
2014-02-06 22:22:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-01 18:26:31 +00:00
|
|
|
|
}
|
2014-02-06 22:22:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Refreshes the children.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="children">The children.</param>
|
2014-02-08 22:38:02 +00:00
|
|
|
|
/// <param name="directoryService">The directory service.</param>
|
2014-02-06 22:22:03 +00:00
|
|
|
|
/// <param name="progress">The progress.</param>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
2014-02-10 18:39:41 +00:00
|
|
|
|
private async Task ValidateSubFolders(IList<Folder> children, IDirectoryService directoryService, IProgress<double> progress, CancellationToken cancellationToken)
|
2014-02-06 22:22:03 +00:00
|
|
|
|
{
|
2017-06-23 16:04:45 +00:00
|
|
|
|
var numComplete = 0;
|
|
|
|
|
var count = children.Count;
|
|
|
|
|
double currentPercent = 0;
|
2014-02-06 22:22:03 +00:00
|
|
|
|
|
2017-06-23 16:04:45 +00:00
|
|
|
|
foreach (var child in children)
|
2014-01-01 18:26:31 +00:00
|
|
|
|
{
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
2013-04-15 15:10:12 +00:00
|
|
|
|
|
2017-06-23 16:04:45 +00:00
|
|
|
|
using (var innerProgress = new ActionableProgress<double>())
|
2014-01-01 18:26:31 +00:00
|
|
|
|
{
|
2017-06-23 16:04:45 +00:00
|
|
|
|
// Avoid implicitly captured closure
|
|
|
|
|
var currentInnerPercent = currentPercent;
|
|
|
|
|
|
|
|
|
|
innerProgress.RegisterAction(p =>
|
2013-03-28 19:25:36 +00:00
|
|
|
|
{
|
2017-06-23 16:04:45 +00:00
|
|
|
|
double innerPercent = currentInnerPercent;
|
|
|
|
|
innerPercent += p / (count);
|
|
|
|
|
progress.Report(innerPercent);
|
|
|
|
|
});
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2017-06-23 16:04:45 +00:00
|
|
|
|
await child.ValidateChildrenInternal(innerProgress, cancellationToken, true, false, null, directoryService)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
}
|
2013-03-28 19:25:36 +00:00
|
|
|
|
|
2017-06-23 16:04:45 +00:00
|
|
|
|
numComplete++;
|
|
|
|
|
double percent = numComplete;
|
|
|
|
|
percent /= count;
|
|
|
|
|
percent *= 100;
|
|
|
|
|
currentPercent = percent;
|
2014-01-01 18:26:31 +00:00
|
|
|
|
|
2017-06-23 16:04:45 +00:00
|
|
|
|
progress.Report(percent);
|
2013-04-15 15:10:12 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-10 20:44:02 +00:00
|
|
|
|
public static bool IsPathOffline(string path, List<string> allLibraryPaths)
|
2013-07-05 14:54:14 +00:00
|
|
|
|
{
|
2017-08-23 18:00:42 +00:00
|
|
|
|
//if (FileSystem.FileExists(path))
|
|
|
|
|
//{
|
|
|
|
|
// return false;
|
|
|
|
|
//}
|
2013-07-07 15:53:38 +00:00
|
|
|
|
|
2013-10-06 01:04:41 +00:00
|
|
|
|
var originalPath = path;
|
|
|
|
|
|
2013-07-06 00:19:44 +00:00
|
|
|
|
// Depending on whether the path is local or unc, it may return either null or '\' at the top
|
2017-08-23 18:00:42 +00:00
|
|
|
|
while (!string.IsNullOrWhiteSpace(path) && path.Length > 1)
|
2013-07-05 14:54:14 +00:00
|
|
|
|
{
|
2015-09-17 01:33:46 +00:00
|
|
|
|
if (FileSystem.DirectoryExists(path))
|
2013-07-05 14:54:14 +00:00
|
|
|
|
{
|
2013-10-06 01:04:41 +00:00
|
|
|
|
return false;
|
2013-07-05 14:54:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-10 20:44:02 +00:00
|
|
|
|
if (allLibraryPaths.Contains(path, StringComparer.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-07-05 14:54:14 +00:00
|
|
|
|
|
2017-05-04 18:14:45 +00:00
|
|
|
|
path = FileSystem.GetDirectoryName(path);
|
2013-10-06 01:04:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-10 20:44:02 +00:00
|
|
|
|
return allLibraryPaths.Any(i => ContainsPath(i, originalPath));
|
2013-10-06 01:04:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 15:43:10 +00:00
|
|
|
|
private static bool ContainsPath(string parent, string path)
|
2013-10-06 01:04:41 +00:00
|
|
|
|
{
|
2017-01-11 17:56:26 +00:00
|
|
|
|
return FileSystem.AreEqual(parent, path) || FileSystem.ContainsSubPath(parent, path);
|
2013-07-05 14:54:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get the children of this folder from the actual file system
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>IEnumerable{BaseItem}.</returns>
|
2014-02-10 18:39:41 +00:00
|
|
|
|
protected virtual IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2014-12-21 18:58:17 +00:00
|
|
|
|
var collectionType = LibraryManager.GetContentType(this);
|
2016-08-13 05:49:00 +00:00
|
|
|
|
var libraryOptions = LibraryManager.GetLibraryOptions(this);
|
2014-10-23 04:26:01 +00:00
|
|
|
|
|
2016-08-13 05:49:00 +00:00
|
|
|
|
return LibraryManager.ResolvePaths(GetFileSystemChildren(directoryService), directoryService, this, libraryOptions, collectionType);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get our children from the repo - stubbed for now
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>IEnumerable{BaseItem}.</returns>
|
2017-06-03 07:36:32 +00:00
|
|
|
|
protected List<BaseItem> GetCachedChildren()
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2016-06-17 13:06:13 +00:00
|
|
|
|
return ItemRepository.GetItemList(new InternalItemsQuery
|
2015-09-24 02:31:40 +00:00
|
|
|
|
{
|
2017-05-23 16:43:24 +00:00
|
|
|
|
Parent = this,
|
2017-05-21 07:25:49 +00:00
|
|
|
|
GroupByPresentationUniqueKey = false,
|
|
|
|
|
DtoOptions = new DtoOptions(true)
|
2016-03-21 20:15:18 +00:00
|
|
|
|
});
|
2014-10-23 04:26:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-16 13:24:12 +00:00
|
|
|
|
public virtual int GetChildCount(User user)
|
|
|
|
|
{
|
2017-08-10 18:01:31 +00:00
|
|
|
|
if (LinkedChildren.Length > 0)
|
2016-06-16 13:24:12 +00:00
|
|
|
|
{
|
|
|
|
|
if (!(this is ICollectionFolder))
|
|
|
|
|
{
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return GetChildren(user, true).Count;
|
2016-06-16 13:24:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = GetItems(new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
Recursive = false,
|
|
|
|
|
Limit = 0,
|
2017-05-23 16:43:24 +00:00
|
|
|
|
Parent = this,
|
2017-05-21 07:25:49 +00:00
|
|
|
|
DtoOptions = new DtoOptions(false)
|
|
|
|
|
{
|
|
|
|
|
EnableImages = false
|
|
|
|
|
}
|
2016-06-16 13:24:12 +00:00
|
|
|
|
|
2017-05-26 06:48:54 +00:00
|
|
|
|
});
|
2016-06-16 13:24:12 +00:00
|
|
|
|
|
|
|
|
|
return result.TotalRecordCount;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-25 17:36:00 +00:00
|
|
|
|
public virtual int GetRecursiveChildCount(User user)
|
|
|
|
|
{
|
|
|
|
|
return GetItems(new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
Recursive = true,
|
|
|
|
|
IsFolder = false,
|
|
|
|
|
IsVirtualItem = false,
|
|
|
|
|
EnableTotalRecordCount = true,
|
2017-05-21 07:25:49 +00:00
|
|
|
|
Limit = 0,
|
|
|
|
|
DtoOptions = new DtoOptions(false)
|
|
|
|
|
{
|
|
|
|
|
EnableImages = false
|
|
|
|
|
}
|
2016-11-25 17:36:00 +00:00
|
|
|
|
|
2017-05-26 06:48:54 +00:00
|
|
|
|
}).TotalRecordCount;
|
2016-11-25 17:36:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-20 06:46:51 +00:00
|
|
|
|
public QueryResult<BaseItem> QueryRecursive(InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
var user = query.User;
|
|
|
|
|
|
2016-05-18 05:34:10 +00:00
|
|
|
|
if (!query.ForceDirect && RequiresPostFiltering(query))
|
2016-03-20 06:46:51 +00:00
|
|
|
|
{
|
|
|
|
|
IEnumerable<BaseItem> items;
|
|
|
|
|
Func<BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager);
|
|
|
|
|
|
|
|
|
|
if (query.User == null)
|
|
|
|
|
{
|
|
|
|
|
items = GetRecursiveChildren(filter);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-05-18 05:34:10 +00:00
|
|
|
|
items = GetRecursiveChildren(user, query);
|
2016-03-20 06:46:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-17 20:52:16 +00:00
|
|
|
|
return PostFilterAndSort(items, query, true, true);
|
2016-03-20 06:46:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(this is UserRootFolder) && !(this is AggregateFolder))
|
|
|
|
|
{
|
2017-05-23 16:43:24 +00:00
|
|
|
|
if (!query.ParentId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
query.Parent = this;
|
|
|
|
|
}
|
2016-03-20 06:46:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-18 19:22:17 +00:00
|
|
|
|
if (RequiresPostFiltering2(query))
|
|
|
|
|
{
|
|
|
|
|
return QueryWithPostFiltering2(query);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-20 06:46:51 +00:00
|
|
|
|
return LibraryManager.GetItemsResult(query);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-18 19:22:17 +00:00
|
|
|
|
private QueryResult<BaseItem> QueryWithPostFiltering2(InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
var startIndex = query.StartIndex;
|
|
|
|
|
var limit = query.Limit;
|
|
|
|
|
|
|
|
|
|
query.StartIndex = null;
|
|
|
|
|
query.Limit = null;
|
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
var itemsList = LibraryManager.GetItemList(query);
|
2017-04-18 19:22:17 +00:00
|
|
|
|
var user = query.User;
|
|
|
|
|
|
|
|
|
|
if (user != null)
|
|
|
|
|
{
|
|
|
|
|
// needed for boxsets
|
2017-08-19 19:43:35 +00:00
|
|
|
|
itemsList = itemsList.Where(i => i.IsVisibleStandalone(query.User)).ToList();
|
2017-04-18 19:22:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
BaseItem[] returnItems;
|
2017-04-18 20:11:42 +00:00
|
|
|
|
int totalCount = 0;
|
|
|
|
|
|
|
|
|
|
if (query.EnableTotalRecordCount)
|
|
|
|
|
{
|
|
|
|
|
var itemsArray = itemsList.ToArray();
|
|
|
|
|
totalCount = itemsArray.Length;
|
|
|
|
|
returnItems = itemsArray;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-08-19 19:43:35 +00:00
|
|
|
|
returnItems = itemsList.ToArray();
|
2017-04-18 20:11:42 +00:00
|
|
|
|
}
|
2017-04-18 19:22:17 +00:00
|
|
|
|
|
|
|
|
|
if (limit.HasValue)
|
|
|
|
|
{
|
2017-08-19 19:43:35 +00:00
|
|
|
|
returnItems = returnItems.Skip(startIndex ?? 0).Take(limit.Value).ToArray();
|
2017-04-18 19:22:17 +00:00
|
|
|
|
}
|
|
|
|
|
else if (startIndex.HasValue)
|
|
|
|
|
{
|
2017-08-19 19:43:35 +00:00
|
|
|
|
returnItems = returnItems.Skip(startIndex.Value).ToArray();
|
2017-04-18 19:22:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new QueryResult<BaseItem>
|
|
|
|
|
{
|
|
|
|
|
TotalRecordCount = totalCount,
|
2017-04-18 20:11:42 +00:00
|
|
|
|
Items = returnItems.ToArray()
|
2017-04-18 19:22:17 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool RequiresPostFiltering2(InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
if (query.IncludeItemTypes.Length == 1 && string.Equals(query.IncludeItemTypes[0], typeof(BoxSet).Name, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Query requires post-filtering due to BoxSet query");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-20 06:46:51 +00:00
|
|
|
|
private bool RequiresPostFiltering(InternalItemsQuery query)
|
|
|
|
|
{
|
2017-08-10 18:01:31 +00:00
|
|
|
|
if (LinkedChildren.Length > 0)
|
2016-03-20 06:46:51 +00:00
|
|
|
|
{
|
2016-03-20 18:39:20 +00:00
|
|
|
|
if (!(this is ICollectionFolder))
|
|
|
|
|
{
|
2016-06-04 00:15:14 +00:00
|
|
|
|
Logger.Debug("Query requires post-filtering due to LinkedChildren. Type: " + GetType().Name);
|
2016-03-20 18:39:20 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-03-20 06:46:51 +00:00
|
|
|
|
}
|
2016-05-20 21:18:48 +00:00
|
|
|
|
|
2016-03-20 06:46:51 +00:00
|
|
|
|
if (query.IsInBoxSet.HasValue)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Query requires post-filtering due to IsInBoxSet");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter by Video3DFormat
|
|
|
|
|
if (query.Is3D.HasValue)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Query requires post-filtering due to Is3D");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.HasOfficialRating.HasValue)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Query requires post-filtering due to HasOfficialRating");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.IsPlaceHolder.HasValue)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Query requires post-filtering due to IsPlaceHolder");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.HasSpecialFeature.HasValue)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Query requires post-filtering due to HasSpecialFeature");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.HasSubtitles.HasValue)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Query requires post-filtering due to HasSubtitles");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.HasTrailer.HasValue)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Query requires post-filtering due to HasTrailer");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter by VideoType
|
|
|
|
|
if (query.VideoTypes.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Query requires post-filtering due to VideoTypes");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply person filter
|
|
|
|
|
if (query.ItemIdsFromPersonFilters != null)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Query requires post-filtering due to ItemIdsFromPersonFilters");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-05 19:44:55 +00:00
|
|
|
|
if (UserViewBuilder.CollapseBoxSetItems(query, this, query.User, ConfigurationManager))
|
2016-03-20 06:46:51 +00:00
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Query requires post-filtering due to CollapseBoxSetItems");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(query.AdjacentTo))
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Query requires post-filtering due to AdjacentTo");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-20 19:53:22 +00:00
|
|
|
|
if (query.SeriesStatuses.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Query requires post-filtering due to SeriesStatuses");
|
|
|
|
|
return true;
|
2016-03-20 20:04:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.AiredDuringSeason.HasValue)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Query requires post-filtering due to AiredDuringSeason");
|
|
|
|
|
return true;
|
2016-03-21 00:15:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-08 18:14:05 +00:00
|
|
|
|
if (query.IsPlayed.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if (query.IncludeItemTypes.Length == 1 && query.IncludeItemTypes.Contains(typeof(Series).Name))
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Query requires post-filtering due to IsPlayed");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-20 06:46:51 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 06:48:54 +00:00
|
|
|
|
public QueryResult<BaseItem> GetItems(InternalItemsQuery query)
|
2016-04-02 21:08:35 +00:00
|
|
|
|
{
|
|
|
|
|
if (query.ItemIds.Length > 0)
|
|
|
|
|
{
|
2016-08-25 16:55:57 +00:00
|
|
|
|
var result = LibraryManager.GetItemsResult(query);
|
2016-08-18 15:13:18 +00:00
|
|
|
|
|
2017-09-04 19:28:22 +00:00
|
|
|
|
if (query.OrderBy.Length == 0)
|
2016-08-18 15:13:18 +00:00
|
|
|
|
{
|
|
|
|
|
var ids = query.ItemIds.ToList();
|
|
|
|
|
|
|
|
|
|
// Try to preserve order
|
2016-08-25 16:55:57 +00:00
|
|
|
|
result.Items = result.Items.OrderBy(i => ids.IndexOf(i.Id.ToString("N"))).ToArray();
|
2016-08-18 15:13:18 +00:00
|
|
|
|
}
|
2017-05-26 06:48:54 +00:00
|
|
|
|
return result;
|
2016-04-02 21:08:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return GetItemsInternal(query);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-09 19:56:38 +00:00
|
|
|
|
public BaseItem[] GetItemList(InternalItemsQuery query)
|
2017-08-01 16:45:57 +00:00
|
|
|
|
{
|
|
|
|
|
query.EnableTotalRecordCount = false;
|
|
|
|
|
|
|
|
|
|
if (query.ItemIds.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
var result = LibraryManager.GetItemList(query);
|
|
|
|
|
|
2017-09-04 19:28:22 +00:00
|
|
|
|
if (query.OrderBy.Length == 0)
|
2017-08-01 16:45:57 +00:00
|
|
|
|
{
|
|
|
|
|
var ids = query.ItemIds.ToList();
|
|
|
|
|
|
|
|
|
|
// Try to preserve order
|
2017-08-09 19:56:38 +00:00
|
|
|
|
return result.OrderBy(i => ids.IndexOf(i.Id.ToString("N"))).ToArray();
|
2017-08-01 16:45:57 +00:00
|
|
|
|
}
|
2017-08-09 19:56:38 +00:00
|
|
|
|
return result.ToArray(result.Count);
|
2017-08-01 16:45:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return GetItemsInternal(query).Items;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 06:48:54 +00:00
|
|
|
|
protected virtual QueryResult<BaseItem> GetItemsInternal(InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
2016-03-19 05:04:38 +00:00
|
|
|
|
if (SourceType == SourceType.Channel)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Don't blow up here because it could cause parent screens with other content to fail
|
2017-05-26 06:48:54 +00:00
|
|
|
|
return ChannelManager.GetChannelItemsInternal(new ChannelItemQuery
|
2016-03-19 05:04:38 +00:00
|
|
|
|
{
|
|
|
|
|
ChannelId = ChannelId,
|
|
|
|
|
FolderId = Id.ToString("N"),
|
|
|
|
|
Limit = query.Limit,
|
|
|
|
|
StartIndex = query.StartIndex,
|
|
|
|
|
UserId = query.User.Id.ToString("N"),
|
2017-09-04 19:28:22 +00:00
|
|
|
|
OrderBy = query.OrderBy
|
2016-03-19 05:04:38 +00:00
|
|
|
|
|
2017-06-23 16:04:45 +00:00
|
|
|
|
}, new SimpleProgress<double>(), CancellationToken.None).Result;
|
2016-03-19 05:04:38 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// Already logged at lower levels
|
2016-07-29 19:18:03 +00:00
|
|
|
|
return new QueryResult<BaseItem>();
|
2016-03-19 05:04:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-20 06:46:51 +00:00
|
|
|
|
|
|
|
|
|
if (query.Recursive)
|
|
|
|
|
{
|
|
|
|
|
return QueryRecursive(query);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-01 20:10:54 +00:00
|
|
|
|
var user = query.User;
|
|
|
|
|
|
2015-01-25 06:34:50 +00:00
|
|
|
|
Func<BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager);
|
|
|
|
|
|
2015-02-07 03:25:23 +00:00
|
|
|
|
IEnumerable<BaseItem> items;
|
|
|
|
|
|
|
|
|
|
if (query.User == null)
|
|
|
|
|
{
|
|
|
|
|
items = query.Recursive
|
|
|
|
|
? GetRecursiveChildren(filter)
|
|
|
|
|
: Children.Where(filter);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
items = query.Recursive
|
2016-05-18 05:34:10 +00:00
|
|
|
|
? GetRecursiveChildren(user, query)
|
2015-02-07 03:25:23 +00:00
|
|
|
|
: GetChildren(user, true).Where(filter);
|
|
|
|
|
}
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2016-08-17 20:52:16 +00:00
|
|
|
|
return PostFilterAndSort(items, query, true, true);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-17 20:52:16 +00:00
|
|
|
|
protected QueryResult<BaseItem> PostFilterAndSort(IEnumerable<BaseItem> items, InternalItemsQuery query, bool collapseBoxSetItems, bool enableSorting)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
2016-08-17 20:52:16 +00:00
|
|
|
|
return UserViewBuilder.PostFilterAndSort(items, this, null, query, LibraryManager, ConfigurationManager, collapseBoxSetItems, enableSorting);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
public virtual List<BaseItem> GetChildren(User user, bool includeLinkedChildren)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//the true root should return our users root folder children
|
2013-12-11 02:51:26 +00:00
|
|
|
|
if (IsPhysicalRoot) return user.RootFolder.GetChildren(user, includeLinkedChildren);
|
2013-07-05 13:47:10 +00:00
|
|
|
|
|
2015-01-25 06:34:50 +00:00
|
|
|
|
var result = new Dictionary<Guid, BaseItem>();
|
2013-09-26 18:45:43 +00:00
|
|
|
|
|
2015-11-23 16:04:57 +00:00
|
|
|
|
AddChildren(user, includeLinkedChildren, result, false, null);
|
2013-09-26 18:45:43 +00:00
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return result.Values.ToList();
|
2013-09-20 02:03:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-05 02:32:40 +00:00
|
|
|
|
protected virtual IEnumerable<BaseItem> GetEligibleChildrenForRecursiveChildren(User user)
|
|
|
|
|
{
|
|
|
|
|
return Children;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-20 02:03:37 +00:00
|
|
|
|
/// <summary>
|
2013-09-26 18:45:43 +00:00
|
|
|
|
/// Adds the children to list.
|
2013-09-20 02:03:37 +00:00
|
|
|
|
/// </summary>
|
2013-09-26 21:20:26 +00:00
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
2016-05-18 05:34:10 +00:00
|
|
|
|
private void AddChildren(User user, bool includeLinkedChildren, Dictionary<Guid, BaseItem> result, bool recursive, InternalItemsQuery query)
|
2013-09-20 02:03:37 +00:00
|
|
|
|
{
|
2014-06-05 02:32:40 +00:00
|
|
|
|
foreach (var child in GetEligibleChildrenForRecursiveChildren(user))
|
2013-09-20 02:03:37 +00:00
|
|
|
|
{
|
|
|
|
|
if (child.IsVisible(user))
|
|
|
|
|
{
|
2016-05-18 05:34:10 +00:00
|
|
|
|
if (query == null || UserViewBuilder.FilterItem(child, query))
|
2013-09-26 21:20:26 +00:00
|
|
|
|
{
|
2015-11-23 16:04:57 +00:00
|
|
|
|
result[child.Id] = child;
|
2013-09-26 21:20:26 +00:00
|
|
|
|
}
|
2013-09-26 18:45:43 +00:00
|
|
|
|
|
2014-02-21 05:04:11 +00:00
|
|
|
|
if (recursive && child.IsFolder)
|
2013-09-26 18:45:43 +00:00
|
|
|
|
{
|
2014-02-21 05:04:11 +00:00
|
|
|
|
var folder = (Folder)child;
|
|
|
|
|
|
2016-05-18 05:34:10 +00:00
|
|
|
|
folder.AddChildren(user, includeLinkedChildren, result, true, query);
|
2013-09-26 18:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-20 02:03:37 +00:00
|
|
|
|
}
|
2013-07-05 13:47:10 +00:00
|
|
|
|
|
|
|
|
|
if (includeLinkedChildren)
|
|
|
|
|
{
|
2014-08-14 13:24:30 +00:00
|
|
|
|
foreach (var child in GetLinkedChildren(user))
|
2013-09-20 02:03:37 +00:00
|
|
|
|
{
|
|
|
|
|
if (child.IsVisible(user))
|
|
|
|
|
{
|
2016-05-18 05:34:10 +00:00
|
|
|
|
if (query == null || UserViewBuilder.FilterItem(child, query))
|
2015-01-25 06:34:50 +00:00
|
|
|
|
{
|
|
|
|
|
result[child.Id] = child;
|
|
|
|
|
}
|
2013-09-20 02:03:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-05 13:47:10 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets allowed recursive children of an item
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="user">The user.</param>
|
2013-07-05 13:47:10 +00:00
|
|
|
|
/// <param name="includeLinkedChildren">if set to <c>true</c> [include linked children].</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <returns>IEnumerable{BaseItem}.</returns>
|
|
|
|
|
/// <exception cref="System.ArgumentNullException"></exception>
|
2015-01-25 06:34:50 +00:00
|
|
|
|
public IEnumerable<BaseItem> GetRecursiveChildren(User user, bool includeLinkedChildren = true)
|
|
|
|
|
{
|
2016-05-18 05:34:10 +00:00
|
|
|
|
return GetRecursiveChildren(user, null);
|
2015-01-25 06:34:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-18 05:34:10 +00:00
|
|
|
|
public virtual IEnumerable<BaseItem> GetRecursiveChildren(User user, InternalItemsQuery query)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
2013-10-04 19:48:31 +00:00
|
|
|
|
throw new ArgumentNullException("user");
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-25 06:34:50 +00:00
|
|
|
|
var result = new Dictionary<Guid, BaseItem>();
|
2013-09-20 02:03:37 +00:00
|
|
|
|
|
2016-05-18 05:34:10 +00:00
|
|
|
|
AddChildren(user, true, result, true, query);
|
2013-08-23 22:13:18 +00:00
|
|
|
|
|
2015-01-25 06:34:50 +00:00
|
|
|
|
return result.Values;
|
2013-08-23 22:13:18 +00:00
|
|
|
|
}
|
2013-09-27 12:24:28 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the recursive children.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>IList{BaseItem}.</returns>
|
|
|
|
|
public IList<BaseItem> GetRecursiveChildren()
|
2015-01-25 06:34:50 +00:00
|
|
|
|
{
|
2016-09-07 17:17:26 +00:00
|
|
|
|
return GetRecursiveChildren(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IList<BaseItem> GetRecursiveChildren(bool includeLinkedChildren)
|
|
|
|
|
{
|
|
|
|
|
return GetRecursiveChildren(i => true, includeLinkedChildren);
|
2015-01-25 06:34:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IList<BaseItem> GetRecursiveChildren(Func<BaseItem, bool> filter)
|
2016-09-07 17:17:26 +00:00
|
|
|
|
{
|
|
|
|
|
return GetRecursiveChildren(filter, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IList<BaseItem> GetRecursiveChildren(Func<BaseItem, bool> filter, bool includeLinkedChildren)
|
2013-09-27 12:24:28 +00:00
|
|
|
|
{
|
2016-05-09 04:56:41 +00:00
|
|
|
|
var result = new Dictionary<Guid, BaseItem>();
|
2013-09-27 12:24:28 +00:00
|
|
|
|
|
2016-10-13 18:43:47 +00:00
|
|
|
|
AddChildrenToList(result, includeLinkedChildren, true, filter);
|
2013-09-27 12:24:28 +00:00
|
|
|
|
|
2016-05-09 04:56:41 +00:00
|
|
|
|
return result.Values.ToList();
|
2013-09-27 12:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds the children to list.
|
|
|
|
|
/// </summary>
|
2016-05-20 21:18:48 +00:00
|
|
|
|
private void AddChildrenToList(Dictionary<Guid, BaseItem> result, bool includeLinkedChildren, bool recursive, Func<BaseItem, bool> filter)
|
2013-09-27 12:24:28 +00:00
|
|
|
|
{
|
|
|
|
|
foreach (var child in Children)
|
|
|
|
|
{
|
|
|
|
|
if (filter == null || filter(child))
|
|
|
|
|
{
|
2016-05-09 04:56:41 +00:00
|
|
|
|
result[child.Id] = child;
|
2013-09-27 12:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-21 20:48:26 +00:00
|
|
|
|
if (recursive && child.IsFolder)
|
2013-09-27 12:24:28 +00:00
|
|
|
|
{
|
2013-11-21 20:48:26 +00:00
|
|
|
|
var folder = (Folder)child;
|
2013-09-27 12:24:28 +00:00
|
|
|
|
|
2016-05-11 14:36:28 +00:00
|
|
|
|
// We can only support includeLinkedChildren for the first folder, or we might end up stuck in a loop of linked items
|
|
|
|
|
folder.AddChildrenToList(result, false, true, filter);
|
2016-05-09 04:56:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (includeLinkedChildren)
|
|
|
|
|
{
|
|
|
|
|
foreach (var child in GetLinkedChildren())
|
|
|
|
|
{
|
|
|
|
|
if (filter == null || filter(child))
|
|
|
|
|
{
|
|
|
|
|
result[child.Id] = child;
|
|
|
|
|
}
|
2013-09-27 12:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-07-05 13:47:10 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the linked children.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>IEnumerable{BaseItem}.</returns>
|
|
|
|
|
public IEnumerable<BaseItem> GetLinkedChildren()
|
|
|
|
|
{
|
|
|
|
|
return LinkedChildren
|
2013-07-06 00:19:44 +00:00
|
|
|
|
.Select(GetLinkedChild)
|
2013-07-05 13:47:10 +00:00
|
|
|
|
.Where(i => i != null);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-14 13:24:30 +00:00
|
|
|
|
protected virtual bool FilterLinkedChildrenPerUser
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<BaseItem> GetLinkedChildren(User user)
|
|
|
|
|
{
|
2014-08-15 16:35:41 +00:00
|
|
|
|
if (!FilterLinkedChildrenPerUser || user == null)
|
2014-08-14 13:24:30 +00:00
|
|
|
|
{
|
|
|
|
|
return GetLinkedChildren();
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-10 18:01:31 +00:00
|
|
|
|
if (LinkedChildren.Length == 0)
|
2017-05-04 18:14:45 +00:00
|
|
|
|
{
|
|
|
|
|
return new List<BaseItem>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var allUserRootChildren = user.RootFolder.Children.OfType<Folder>().ToList();
|
|
|
|
|
|
|
|
|
|
var collectionFolderIds = allUserRootChildren
|
2014-08-14 13:24:30 +00:00
|
|
|
|
.OfType<CollectionFolder>()
|
2015-04-05 15:01:57 +00:00
|
|
|
|
.Where(i => i.IsVisible(user))
|
2017-05-04 18:14:45 +00:00
|
|
|
|
.Select(i => i.Id)
|
2014-08-14 13:24:30 +00:00
|
|
|
|
.ToList();
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2014-08-15 16:35:41 +00:00
|
|
|
|
return LinkedChildren
|
|
|
|
|
.Select(i =>
|
|
|
|
|
{
|
|
|
|
|
var child = GetLinkedChild(i);
|
|
|
|
|
|
2016-10-01 20:29:24 +00:00
|
|
|
|
if (child != null)
|
2014-08-15 16:35:41 +00:00
|
|
|
|
{
|
2016-10-01 20:29:24 +00:00
|
|
|
|
var childLocationType = child.LocationType;
|
|
|
|
|
if (childLocationType == LocationType.Remote || childLocationType == LocationType.Virtual)
|
2014-08-15 16:35:41 +00:00
|
|
|
|
{
|
2016-10-01 20:29:24 +00:00
|
|
|
|
if (!child.IsVisibleStandalone(user))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2014-08-15 16:35:41 +00:00
|
|
|
|
}
|
2017-05-04 18:14:45 +00:00
|
|
|
|
else if (childLocationType == LocationType.FileSystem)
|
2014-08-15 16:35:41 +00:00
|
|
|
|
{
|
2017-05-04 18:14:45 +00:00
|
|
|
|
var itemCollectionFolderIds =
|
|
|
|
|
LibraryManager.GetCollectionFolders(child, allUserRootChildren)
|
|
|
|
|
.Select(f => f.Id).ToList();
|
|
|
|
|
|
|
|
|
|
if (!itemCollectionFolderIds.Any(collectionFolderIds.Contains))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2014-08-15 16:35:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return child;
|
|
|
|
|
})
|
2014-08-14 13:24:30 +00:00
|
|
|
|
.Where(i => i != null);
|
|
|
|
|
}
|
2014-08-11 23:41:11 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the linked children.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>IEnumerable{BaseItem}.</returns>
|
2014-09-01 20:10:54 +00:00
|
|
|
|
public IEnumerable<Tuple<LinkedChild, BaseItem>> GetLinkedChildrenInfos()
|
2014-08-11 23:41:11 +00:00
|
|
|
|
{
|
|
|
|
|
return LinkedChildren
|
2014-09-01 20:10:54 +00:00
|
|
|
|
.Select(i => new Tuple<LinkedChild, BaseItem>(i, GetLinkedChild(i)))
|
2014-08-11 23:41:11 +00:00
|
|
|
|
.Where(i => i.Item2 != null);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-28 21:29:02 +00:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
protected override bool SupportsOwnedItems
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return base.SupportsOwnedItems || SupportsShortcutChildren;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-04 03:38:46 +00:00
|
|
|
|
protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
|
2013-07-05 13:47:10 +00:00
|
|
|
|
{
|
2014-02-10 18:39:41 +00:00
|
|
|
|
var changesFound = false;
|
|
|
|
|
|
2015-08-15 01:44:30 +00:00
|
|
|
|
if (LocationType == LocationType.FileSystem)
|
2014-02-03 05:35:43 +00:00
|
|
|
|
{
|
2014-02-06 04:39:16 +00:00
|
|
|
|
if (RefreshLinkedChildren(fileSystemChildren))
|
|
|
|
|
{
|
2014-02-10 18:39:41 +00:00
|
|
|
|
changesFound = true;
|
2014-02-06 04:39:16 +00:00
|
|
|
|
}
|
2014-02-03 05:35:43 +00:00
|
|
|
|
}
|
2013-07-05 13:47:10 +00:00
|
|
|
|
|
2014-02-10 18:39:41 +00:00
|
|
|
|
var baseHasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return baseHasChanges || changesFound;
|
2013-07-05 13:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Refreshes the linked children.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
2016-12-13 07:36:30 +00:00
|
|
|
|
protected virtual bool RefreshLinkedChildren(IEnumerable<FileSystemMetadata> fileSystemChildren)
|
2013-07-05 13:47:10 +00:00
|
|
|
|
{
|
2015-08-15 01:44:30 +00:00
|
|
|
|
if (SupportsShortcutChildren)
|
|
|
|
|
{
|
2017-08-10 18:01:31 +00:00
|
|
|
|
var newShortcutLinks = fileSystemChildren
|
2016-10-25 19:02:04 +00:00
|
|
|
|
.Where(i => !i.IsDirectory && FileSystem.IsShortcut(i.FullName))
|
2015-08-15 01:44:30 +00:00
|
|
|
|
.Select(i =>
|
2013-07-05 13:47:10 +00:00
|
|
|
|
{
|
2015-08-15 01:44:30 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Found shortcut at {0}", i.FullName);
|
2013-09-08 17:55:37 +00:00
|
|
|
|
|
2015-08-15 01:44:30 +00:00
|
|
|
|
var resolvedPath = FileSystem.ResolveShortcut(i.FullName);
|
2013-09-08 17:55:37 +00:00
|
|
|
|
|
2015-08-15 01:44:30 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(resolvedPath))
|
2013-09-08 17:55:37 +00:00
|
|
|
|
{
|
2015-08-15 01:44:30 +00:00
|
|
|
|
return new LinkedChild
|
|
|
|
|
{
|
|
|
|
|
Path = resolvedPath,
|
|
|
|
|
Type = LinkedChildType.Shortcut
|
|
|
|
|
};
|
|
|
|
|
}
|
2013-09-08 17:55:37 +00:00
|
|
|
|
|
2015-08-15 01:44:30 +00:00
|
|
|
|
Logger.Error("Error resolving shortcut {0}", i.FullName);
|
2013-09-08 17:55:37 +00:00
|
|
|
|
|
2015-08-15 01:44:30 +00:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException("Error resolving shortcut {0}", ex, i.FullName);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.ToList();
|
2013-07-05 13:47:10 +00:00
|
|
|
|
|
2017-08-10 18:01:31 +00:00
|
|
|
|
var currentShortcutLinks = LinkedChildren.Where(i => i.Type == LinkedChildType.Shortcut).ToList();
|
2013-08-04 00:59:23 +00:00
|
|
|
|
|
2017-08-10 18:01:31 +00:00
|
|
|
|
if (!newShortcutLinks.SequenceEqual(currentShortcutLinks, new LinkedChildComparer(FileSystem)))
|
|
|
|
|
{
|
|
|
|
|
Logger.Info("Shortcut links have changed for {0}", Path);
|
|
|
|
|
|
|
|
|
|
newShortcutLinks.AddRange(LinkedChildren.Where(i => i.Type == LinkedChildType.Manual));
|
|
|
|
|
LinkedChildren = newShortcutLinks.ToArray(newShortcutLinks.Count);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-07-05 13:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 02:44:16 +00:00
|
|
|
|
foreach (var child in LinkedChildren)
|
|
|
|
|
{
|
|
|
|
|
// Reset the cached value
|
2015-03-05 02:49:08 +00:00
|
|
|
|
child.ItemId = null;
|
2014-02-27 02:44:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-05 13:47:10 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
2013-09-21 19:24:50 +00:00
|
|
|
|
/// Marks the played.
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="user">The user.</param>
|
2013-09-21 19:24:50 +00:00
|
|
|
|
/// <param name="datePlayed">The date played.</param>
|
2014-10-25 18:32:58 +00:00
|
|
|
|
/// <param name="resetPosition">if set to <c>true</c> [reset position].</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <returns>Task.</returns>
|
2017-08-27 00:32:33 +00:00
|
|
|
|
public override void MarkPlayed(User user,
|
2014-10-25 18:32:58 +00:00
|
|
|
|
DateTime? datePlayed,
|
|
|
|
|
bool resetPosition)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2015-11-22 05:15:00 +00:00
|
|
|
|
var query = new InternalItemsQuery
|
2015-10-02 20:27:05 +00:00
|
|
|
|
{
|
|
|
|
|
User = user,
|
|
|
|
|
Recursive = true,
|
2015-11-06 15:02:22 +00:00
|
|
|
|
IsFolder = false,
|
2016-05-18 05:34:10 +00:00
|
|
|
|
EnableTotalRecordCount = false
|
2015-11-22 05:15:00 +00:00
|
|
|
|
};
|
|
|
|
|
|
2017-08-13 02:09:07 +00:00
|
|
|
|
if (!user.Configuration.DisplayMissingEpisodes)
|
2015-11-22 05:15:00 +00:00
|
|
|
|
{
|
2017-01-09 17:05:34 +00:00
|
|
|
|
query.IsVirtualItem = false;
|
2015-11-22 05:15:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-01 16:45:57 +00:00
|
|
|
|
var itemsResult = GetItemList(query);
|
2015-10-02 20:27:05 +00:00
|
|
|
|
|
2013-04-17 03:37:14 +00:00
|
|
|
|
// Sweep through recursively and update status
|
2017-08-27 00:32:33 +00:00
|
|
|
|
foreach (var item in itemsResult)
|
|
|
|
|
{
|
|
|
|
|
item.MarkPlayed(user, datePlayed, resetPosition);
|
|
|
|
|
}
|
2013-09-21 19:24:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Marks the unplayed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="user">The user.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
2017-08-27 00:32:33 +00:00
|
|
|
|
public override void MarkUnplayed(User user)
|
2013-09-21 19:24:50 +00:00
|
|
|
|
{
|
2017-08-01 16:45:57 +00:00
|
|
|
|
var itemsResult = GetItemList(new InternalItemsQuery
|
2015-10-02 20:28:44 +00:00
|
|
|
|
{
|
|
|
|
|
User = user,
|
|
|
|
|
Recursive = true,
|
2016-05-18 05:34:10 +00:00
|
|
|
|
IsFolder = false,
|
|
|
|
|
EnableTotalRecordCount = false
|
2015-10-02 20:28:44 +00:00
|
|
|
|
|
2017-05-26 06:48:54 +00:00
|
|
|
|
});
|
2015-10-02 20:28:44 +00:00
|
|
|
|
|
2013-09-21 19:24:50 +00:00
|
|
|
|
// Sweep through recursively and update status
|
2017-08-27 00:32:33 +00:00
|
|
|
|
foreach (var item in itemsResult)
|
|
|
|
|
{
|
|
|
|
|
item.MarkUnplayed(user);
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-15 22:19:37 +00:00
|
|
|
|
public override bool IsPlayed(User user)
|
|
|
|
|
{
|
2017-08-01 16:45:57 +00:00
|
|
|
|
var itemsResult = GetItemList(new InternalItemsQuery(user)
|
2016-05-07 02:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
Recursive = true,
|
|
|
|
|
IsFolder = false,
|
2017-01-09 17:05:34 +00:00
|
|
|
|
IsVirtualItem = false,
|
2016-05-18 05:34:10 +00:00
|
|
|
|
EnableTotalRecordCount = false
|
2016-05-07 02:11:22 +00:00
|
|
|
|
|
2017-05-26 06:48:54 +00:00
|
|
|
|
});
|
2016-05-07 02:11:22 +00:00
|
|
|
|
|
2017-08-01 16:45:57 +00:00
|
|
|
|
return itemsResult
|
2014-01-17 18:23:00 +00:00
|
|
|
|
.All(i => i.IsPlayed(user));
|
2014-01-15 22:19:37 +00:00
|
|
|
|
}
|
2014-01-18 05:55:21 +00:00
|
|
|
|
|
|
|
|
|
public override bool IsUnplayed(User user)
|
|
|
|
|
{
|
2014-10-25 18:32:58 +00:00
|
|
|
|
return !IsPlayed(user);
|
2014-01-18 05:55:21 +00:00
|
|
|
|
}
|
2014-07-04 02:22:57 +00:00
|
|
|
|
|
2016-05-02 17:11:45 +00:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public virtual bool SupportsUserDataFromChildren
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// These are just far too slow.
|
|
|
|
|
if (this is ICollectionFolder)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (this is UserView)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (this is UserRootFolder)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-06-19 06:18:29 +00:00
|
|
|
|
if (this is Channel)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (SourceType != SourceType.Library)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-11-21 08:54:53 +00:00
|
|
|
|
var iItemByName = this as IItemByName;
|
|
|
|
|
if (iItemByName != null)
|
|
|
|
|
{
|
|
|
|
|
var hasDualAccess = this as IHasDualAccess;
|
|
|
|
|
if (hasDualAccess == null || hasDualAccess.IsAccessedByName)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-02 17:11:45 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
public override void FillUserDataDtoValues(UserItemDataDto dto, UserItemData userData, BaseItemDto itemDto, User user, ItemFields[] fields)
|
2014-07-04 02:22:57 +00:00
|
|
|
|
{
|
2016-05-02 17:11:45 +00:00
|
|
|
|
if (!SupportsUserDataFromChildren)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-19 06:18:29 +00:00
|
|
|
|
if (itemDto != null)
|
|
|
|
|
{
|
2017-05-21 07:25:49 +00:00
|
|
|
|
if (fields.Contains(ItemFields.RecursiveItemCount))
|
2016-12-13 07:36:30 +00:00
|
|
|
|
{
|
|
|
|
|
itemDto.RecursiveItemCount = GetRecursiveChildCount(user);
|
|
|
|
|
}
|
2016-06-19 06:18:29 +00:00
|
|
|
|
}
|
2014-07-04 02:22:57 +00:00
|
|
|
|
|
2016-12-13 07:36:30 +00:00
|
|
|
|
if (SupportsPlayedStatus)
|
2014-07-04 02:22:57 +00:00
|
|
|
|
{
|
2017-05-26 06:48:54 +00:00
|
|
|
|
var unplayedQueryResult = GetItems(new InternalItemsQuery(user)
|
2016-11-21 08:54:53 +00:00
|
|
|
|
{
|
|
|
|
|
Recursive = true,
|
|
|
|
|
IsFolder = false,
|
|
|
|
|
IsVirtualItem = false,
|
|
|
|
|
EnableTotalRecordCount = true,
|
|
|
|
|
Limit = 0,
|
2017-05-21 07:25:49 +00:00
|
|
|
|
IsPlayed = false,
|
|
|
|
|
DtoOptions = new DtoOptions(false)
|
|
|
|
|
{
|
|
|
|
|
EnableImages = false
|
|
|
|
|
}
|
2016-11-21 08:54:53 +00:00
|
|
|
|
|
2017-05-26 06:48:54 +00:00
|
|
|
|
});
|
2016-11-21 08:54:53 +00:00
|
|
|
|
|
|
|
|
|
double unplayedCount = unplayedQueryResult.TotalRecordCount;
|
|
|
|
|
|
2016-06-15 18:56:37 +00:00
|
|
|
|
dto.UnplayedItemCount = unplayedQueryResult.TotalRecordCount;
|
2016-08-16 17:08:37 +00:00
|
|
|
|
|
2016-12-13 07:36:30 +00:00
|
|
|
|
if (itemDto != null && itemDto.RecursiveItemCount.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if (itemDto.RecursiveItemCount.Value > 0)
|
|
|
|
|
{
|
2017-04-18 20:11:42 +00:00
|
|
|
|
var unplayedPercentage = (unplayedCount / itemDto.RecursiveItemCount.Value) * 100;
|
2016-12-13 07:36:30 +00:00
|
|
|
|
dto.PlayedPercentage = 100 - unplayedPercentage;
|
|
|
|
|
dto.Played = dto.PlayedPercentage.Value >= 100;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2016-08-16 17:08:37 +00:00
|
|
|
|
{
|
2016-12-13 07:36:30 +00:00
|
|
|
|
dto.Played = (dto.UnplayedItemCount ?? 0) == 0;
|
2016-08-16 17:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-04 02:22:57 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2015-11-23 16:04:57 +00:00
|
|
|
|
}
|