added item type to refresh info

This commit is contained in:
Luke Pulverenti
2014-02-08 17:38:02 -05:00
parent 3ffd95a637
commit 7f5a4c2d4e
37 changed files with 278 additions and 188 deletions

View File

@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using MediaBrowser.Controller.Providers;
namespace MediaBrowser.Controller.Entities
{
@@ -56,7 +57,7 @@ namespace MediaBrowser.Controller.Entities
public List<string> PhysicalLocationsList { get; set; }
protected override IEnumerable<FileSystemInfo> GetFileSystemChildren()
protected override IEnumerable<FileSystemInfo> GetFileSystemChildren(DirectoryService directoryService)
{
return CreateResolveArgs().FileSystemChildren;
}
@@ -118,9 +119,9 @@ namespace MediaBrowser.Controller.Entities
/// Get the children of this folder from the actual file system
/// </summary>
/// <returns>IEnumerable{BaseItem}.</returns>
protected override IEnumerable<BaseItem> GetNonCachedChildren()
protected override IEnumerable<BaseItem> GetNonCachedChildren(DirectoryService directoryService)
{
return base.GetNonCachedChildren().Concat(_virtualChildren);
return base.GetNonCachedChildren(directoryService).Concat(_virtualChildren);
}
/// <summary>

View File

@@ -52,7 +52,7 @@ namespace MediaBrowser.Controller.Entities.Audio
}
private readonly Task _cachedTask = Task.FromResult(true);
protected override Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions)
protected override Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, DirectoryService directoryService)
{
if (IsAccessedByName)
{
@@ -60,17 +60,7 @@ namespace MediaBrowser.Controller.Entities.Audio
return _cachedTask;
}
return base.ValidateChildrenInternal(progress, cancellationToken, recursive, refreshChildMetadata, refreshOptions);
}
public override string GetClientTypeName()
{
if (IsAccessedByName)
{
//return "Artist";
}
return base.GetClientTypeName();
return base.ValidateChildrenInternal(progress, cancellationToken, recursive, refreshChildMetadata, refreshOptions, directoryService);
}
public MusicArtist()

View File

@@ -565,8 +565,10 @@ namespace MediaBrowser.Controller.Entities
if (IsFolder || Parent != null)
{
options.DirectoryService = options.DirectoryService ?? new DirectoryService(Logger);
var files = locationType == LocationType.FileSystem || locationType == LocationType.Offline ?
GetFileSystemChildren().ToList() :
GetFileSystemChildren(options.DirectoryService).ToList() :
new List<FileSystemInfo>();
await BeforeRefreshMetadata(options, files, cancellationToken).ConfigureAwait(false);
@@ -609,11 +611,11 @@ namespace MediaBrowser.Controller.Entities
}
}
protected virtual IEnumerable<FileSystemInfo> GetFileSystemChildren()
protected virtual IEnumerable<FileSystemInfo> GetFileSystemChildren(DirectoryService directoryService)
{
var path = ContainingFolderPath;
return new DirectoryInfo(path).EnumerateFileSystemInfos("*", SearchOption.TopDirectoryOnly);
return directoryService.GetFileSystemEntries(path);
}
private async Task<bool> RefreshLocalTrailers(IHasTrailers item, MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
@@ -850,29 +852,6 @@ namespace MediaBrowser.Controller.Entities
return IsParentalAllowed(user);
}
/// <summary>
/// Finds the particular item by searching through our parents and, if not found there, loading from repo
/// </summary>
/// <param name="id">The id.</param>
/// <returns>BaseItem.</returns>
/// <exception cref="System.ArgumentException"></exception>
protected BaseItem FindParentItem(Guid id)
{
if (id == Guid.Empty)
{
throw new ArgumentException();
}
var parent = Parent;
while (parent != null && !parent.IsRoot)
{
if (parent.Id == id) return parent;
parent = parent.Parent;
}
return null;
}
/// <summary>
/// Gets a value indicating whether this instance is folder.
/// </summary>
@@ -1226,10 +1205,13 @@ namespace MediaBrowser.Controller.Entities
/// <summary>
/// Validates that images within the item are still on the file system
/// </summary>
public bool ValidateImages()
public bool ValidateImages(DirectoryService directoryService)
{
var allDirectories = ImageInfos.Select(i => System.IO.Path.GetDirectoryName(i.Path)).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
var allFiles = allDirectories.SelectMany(directoryService.GetFiles).Select(i => i.FullName).ToList();
var deletedImages = ImageInfos
.Where(image => !File.Exists(image.Path))
.Where(image => !allFiles.Contains(image.Path, StringComparer.OrdinalIgnoreCase))
.ToList();
if (deletedImages.Count > 0)

View File

@@ -1,5 +1,6 @@
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using System;
using System.Collections.Generic;
using System.IO;
@@ -7,7 +8,6 @@ using System.Linq;
using System.Runtime.Serialization;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller.Providers;
namespace MediaBrowser.Controller.Entities
{
@@ -61,7 +61,7 @@ namespace MediaBrowser.Controller.Entities
public List<string> PhysicalLocationsList { get; set; }
protected override IEnumerable<FileSystemInfo> GetFileSystemChildren()
protected override IEnumerable<FileSystemInfo> GetFileSystemChildren(DirectoryService directoryService)
{
return CreateResolveArgs().FileSystemChildren;
}
@@ -120,7 +120,7 @@ namespace MediaBrowser.Controller.Entities
/// <param name="refreshChildMetadata">if set to <c>true</c> [refresh child metadata].</param>
/// <param name="refreshOptions">The refresh options.</param>
/// <returns>Task.</returns>
protected override Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions)
protected override Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, DirectoryService directoryService)
{
CreateResolveArgs();
ResetDynamicChildren();

View File

@@ -309,15 +309,19 @@ namespace MediaBrowser.Controller.Entities
/// <returns>Task.</returns>
public Task ValidateChildren(IProgress<double> progress, CancellationToken cancellationToken, bool? recursive = null, bool forceRefreshMetadata = false)
{
var directoryService = new DirectoryService(Logger);
return ValidateChildrenWithCancellationSupport(progress, cancellationToken, recursive ?? true, true,
new MetadataRefreshOptions
{
ReplaceAllMetadata = forceRefreshMetadata
});
ReplaceAllMetadata = forceRefreshMetadata,
DirectoryService = directoryService
}, directoryService);
}
private async Task ValidateChildrenWithCancellationSupport(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions)
private async Task ValidateChildrenWithCancellationSupport(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, DirectoryService directoryService)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -337,7 +341,7 @@ namespace MediaBrowser.Controller.Entities
var linkedCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(innerCancellationTokenSource.Token, cancellationToken);
await ValidateChildrenInternal(progress, linkedCancellationTokenSource.Token, recursive, refreshChildMetadata, refreshOptions).ConfigureAwait(false);
await ValidateChildrenInternal(progress, linkedCancellationTokenSource.Token, recursive, refreshChildMetadata, refreshOptions, directoryService).ConfigureAwait(false);
}
catch (OperationCanceledException ex)
{
@@ -369,8 +373,9 @@ namespace MediaBrowser.Controller.Entities
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
/// <param name="refreshChildMetadata">if set to <c>true</c> [refresh child metadata].</param>
/// <param name="refreshOptions">The refresh options.</param>
/// <param name="directoryService">The directory service.</param>
/// <returns>Task.</returns>
protected async virtual Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions)
protected async virtual Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, DirectoryService directoryService)
{
var locationType = LocationType;
@@ -384,7 +389,7 @@ namespace MediaBrowser.Controller.Entities
try
{
nonCachedChildren = GetNonCachedChildren();
nonCachedChildren = GetNonCachedChildren(directoryService);
}
catch (IOException ex)
{
@@ -482,7 +487,7 @@ namespace MediaBrowser.Controller.Entities
if (recursive)
{
await ValidateSubFolders(ActualChildren.OfType<Folder>().ToList(), progress, cancellationToken).ConfigureAwait(false);
await ValidateSubFolders(ActualChildren.OfType<Folder>().ToList(), directoryService, progress, cancellationToken).ConfigureAwait(false);
}
progress.Report(20);
@@ -586,10 +591,11 @@ namespace MediaBrowser.Controller.Entities
/// Refreshes the children.
/// </summary>
/// <param name="children">The children.</param>
/// <param name="directoryService">The directory service.</param>
/// <param name="progress">The progress.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
private async Task ValidateSubFolders(IList<Folder> children, IProgress<double> progress, CancellationToken cancellationToken)
private async Task ValidateSubFolders(IList<Folder> children, DirectoryService directoryService, IProgress<double> progress, CancellationToken cancellationToken)
{
var list = children;
var childCount = list.Count;
@@ -617,7 +623,7 @@ namespace MediaBrowser.Controller.Entities
}
});
await child.ValidateChildrenWithCancellationSupport(innerProgress, cancellationToken, true, false, null)
await child.ValidateChildrenWithCancellationSupport(innerProgress, cancellationToken, true, false, null, directoryService)
.ConfigureAwait(false);
}
}
@@ -675,9 +681,9 @@ namespace MediaBrowser.Controller.Entities
/// Get the children of this folder from the actual file system
/// </summary>
/// <returns>IEnumerable{BaseItem}.</returns>
protected virtual IEnumerable<BaseItem> GetNonCachedChildren()
protected virtual IEnumerable<BaseItem> GetNonCachedChildren(DirectoryService directoryService)
{
return LibraryManager.ResolvePaths<BaseItem>(GetFileSystemChildren(), this);
return LibraryManager.ResolvePaths<BaseItem>(GetFileSystemChildren(directoryService), this);
}
/// <summary>

View File

@@ -1,4 +1,5 @@
using System.IO;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using System;
using System.Collections.Generic;
@@ -108,7 +109,7 @@ namespace MediaBrowser.Controller.Entities
/// <summary>
/// Validates the images and returns true or false indicating if any were removed.
/// </summary>
bool ValidateImages();
bool ValidateImages(DirectoryService directoryService);
/// <summary>
/// Gets a value indicating whether this instance is owned item.

View File

@@ -113,7 +113,7 @@ namespace MediaBrowser.Controller.Entities.Movies
}
}
private async Task<bool> RefreshSpecialFeatures(MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
private async Task<bool> RefreshSpecialFeatures(MetadataRefreshOptions options, IEnumerable<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
{
var newItems = LoadSpecialFeatures(fileSystemChildren).ToList();
var newItemIds = newItems.Select(i => i.Id).ToList();

View File

@@ -1,4 +1,5 @@
using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying;
@@ -11,7 +12,7 @@ namespace MediaBrowser.Controller.Entities.TV
/// <summary>
/// Class Season
/// </summary>
public class Season : Folder, IHasSeries
public class Season : Folder, IHasSeries, IHasLookupInfo<SeasonInfo>
{
/// <summary>
@@ -241,5 +242,10 @@ namespace MediaBrowser.Controller.Entities.TV
return series == null ? null : series.Name;
}
}
public SeasonInfo GetLookupInfo()
{
return GetItemLookupInfo<SeasonInfo>();
}
}
}

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Controller.Providers;
namespace MediaBrowser.Controller.Entities
{
@@ -13,9 +14,9 @@ namespace MediaBrowser.Controller.Entities
/// Get the children of this folder from the actual file system
/// </summary>
/// <returns>IEnumerable{BaseItem}.</returns>
protected override IEnumerable<BaseItem> GetNonCachedChildren()
protected override IEnumerable<BaseItem> GetNonCachedChildren(DirectoryService directoryService)
{
return base.GetNonCachedChildren().Concat(LibraryManager.RootFolder.VirtualChildren);
return base.GetNonCachedChildren(directoryService).Concat(LibraryManager.RootFolder.VirtualChildren);
}
}
}

View File

@@ -181,7 +181,7 @@ namespace MediaBrowser.Controller.Entities
/// <param name="fileSystemChildren">The file system children.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
private async Task<bool> RefreshAdditionalParts(MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
private async Task<bool> RefreshAdditionalParts(MetadataRefreshOptions options, IEnumerable<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
{
var newItems = LoadAdditionalParts(fileSystemChildren).ToList();

View File

@@ -146,6 +146,7 @@
<Compile Include="Notifications\NotificationUpdateEventArgs.cs" />
<Compile Include="Persistence\IFileOrganizationRepository.cs" />
<Compile Include="Persistence\MediaStreamQuery.cs" />
<Compile Include="Providers\DirectoryService.cs" />
<Compile Include="Providers\ICustomMetadataProvider.cs" />
<Compile Include="Providers\IHasChangeMonitor.cs" />
<Compile Include="Entities\IHasMetadata.cs" />

View File

@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MediaBrowser.Model.Logging;
namespace MediaBrowser.Controller.Providers
{
public class DirectoryService
{
private readonly ILogger _logger;
private readonly Dictionary<string, List<FileSystemInfo>> _cache = new Dictionary<string, List<FileSystemInfo>>(StringComparer.OrdinalIgnoreCase);
public DirectoryService(ILogger logger)
{
_logger = logger;
}
public List<FileSystemInfo> GetFileSystemEntries(string path)
{
List<FileSystemInfo> entries;
if (!_cache.TryGetValue(path, out entries))
{
//_logger.Debug("Getting files for " + path);
entries = new DirectoryInfo(path).EnumerateFileSystemInfos("*", SearchOption.TopDirectoryOnly).ToList();
_cache.Add(path, entries);
}
return entries;
}
public IEnumerable<FileInfo> GetFiles(string path)
{
return GetFileSystemEntries(path).OfType<FileInfo>();
}
public IEnumerable<DirectoryInfo> GetDirectories(string path)
{
return GetFileSystemEntries(path).OfType<DirectoryInfo>();
}
public FileInfo GetFile(string path)
{
var directory = Path.GetDirectoryName(path);
var filename = Path.GetFileName(path);
return GetFiles(directory).FirstOrDefault(i => string.Equals(i.Name, filename, StringComparison.OrdinalIgnoreCase));
}
public DirectoryInfo GetDirectory(string path)
{
var directory = Path.GetDirectoryName(path);
var name = Path.GetFileName(path);
return GetDirectories(directory).FirstOrDefault(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase));
}
}
}

View File

@@ -1,5 +1,5 @@
using System;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities;
using System;
namespace MediaBrowser.Controller.Providers
{

View File

@@ -17,7 +17,7 @@ namespace MediaBrowser.Controller.Providers
public interface ILocalImageFileProvider : ILocalImageProvider
{
List<LocalImageInfo> GetImages(IHasImages item);
List<LocalImageInfo> GetImages(IHasImages item, DirectoryService directoryService);
}
public class LocalImageInfo

View File

@@ -149,4 +149,9 @@ namespace MediaBrowser.Controller.Providers
{
}
public class SeasonInfo : ItemLookupInfo
{
}
}

View File

@@ -1,4 +1,5 @@
using System;
using MediaBrowser.Model.Logging;
using System;
namespace MediaBrowser.Controller.Providers
{
@@ -16,6 +17,8 @@ namespace MediaBrowser.Controller.Providers
/// </summary>
[Obsolete]
public bool ForceSave { get; set; }
public DirectoryService DirectoryService { get; set; }
}
public class ImageRefreshOptions

View File

@@ -18,6 +18,12 @@ namespace MediaBrowser.Controller.Providers
/// <value>The name of the item.</value>
public string ItemName { get; set; }
/// <summary>
/// Gets or sets the type of the item.
/// </summary>
/// <value>The type of the item.</value>
public string ItemType { get; set; }
/// <summary>
/// Gets or sets the name of the series.
/// </summary>