diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-10-25 14:32:58 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-10-25 14:32:58 -0400 |
| commit | d74e3b2dea894a7cdc3defac418069081dd2ae22 (patch) | |
| tree | 9618eea91bf12790b51eeb0138a01f1641968043 /MediaBrowser.Controller/Providers | |
| parent | c8a735bcb1ba71e9501d18b3044aa30793ff97ee (diff) | |
connect updates
Diffstat (limited to 'MediaBrowser.Controller/Providers')
3 files changed, 56 insertions, 16 deletions
diff --git a/MediaBrowser.Controller/Providers/DirectoryService.cs b/MediaBrowser.Controller/Providers/DirectoryService.cs index 6f70df4352..4fdc08da0c 100644 --- a/MediaBrowser.Controller/Providers/DirectoryService.cs +++ b/MediaBrowser.Controller/Providers/DirectoryService.cs @@ -9,35 +9,47 @@ namespace MediaBrowser.Controller.Providers { public interface IDirectoryService { - List<FileSystemInfo> GetFileSystemEntries(string path); + IEnumerable<FileSystemInfo> GetFileSystemEntries(string path); IEnumerable<FileSystemInfo> GetFiles(string path); IEnumerable<FileSystemInfo> GetFiles(string path, bool clearCache); FileSystemInfo GetFile(string path); + Dictionary<string, FileSystemInfo> GetFileSystemDictionary(string path); } public class DirectoryService : IDirectoryService { private readonly ILogger _logger; - private readonly ConcurrentDictionary<string, List<FileSystemInfo>> _cache = new ConcurrentDictionary<string, List<FileSystemInfo>>(StringComparer.OrdinalIgnoreCase); + private readonly ConcurrentDictionary<string, Dictionary<string,FileSystemInfo>> _cache = + new ConcurrentDictionary<string, Dictionary<string, FileSystemInfo>>(StringComparer.OrdinalIgnoreCase); public DirectoryService(ILogger logger) { _logger = logger; } - public List<FileSystemInfo> GetFileSystemEntries(string path) + public DirectoryService() + : this(new NullLogger()) + { + } + + public IEnumerable<FileSystemInfo> GetFileSystemEntries(string path) { return GetFileSystemEntries(path, false); } - private List<FileSystemInfo> GetFileSystemEntries(string path, bool clearCache) + public Dictionary<string, FileSystemInfo> GetFileSystemDictionary(string path) + { + return GetFileSystemDictionary(path, false); + } + + private Dictionary<string, FileSystemInfo> GetFileSystemDictionary(string path, bool clearCache) { - List<FileSystemInfo> entries; + Dictionary<string, FileSystemInfo> entries; if (clearCache) { - List<FileSystemInfo> removed; + Dictionary<string, FileSystemInfo> removed; _cache.TryRemove(path, out removed); } @@ -46,21 +58,36 @@ namespace MediaBrowser.Controller.Providers { //_logger.Debug("Getting files for " + path); + entries = new Dictionary<string, FileSystemInfo>(StringComparer.OrdinalIgnoreCase); + try { - entries = new DirectoryInfo(path).EnumerateFileSystemInfos("*", SearchOption.TopDirectoryOnly).ToList(); + var list = new DirectoryInfo(path) + .EnumerateFileSystemInfos("*", SearchOption.TopDirectoryOnly); + + // Seeing dupes on some users file system for some reason + foreach (var item in list) + { + entries[item.FullName] = item; + } } catch (DirectoryNotFoundException) { - entries = new List<FileSystemInfo>(); } + //var group = entries.ToLookup(i => Path.GetDirectoryName(i.FullName)).ToList(); + _cache.TryAdd(path, entries); } return entries; } + private IEnumerable<FileSystemInfo> GetFileSystemEntries(string path, bool clearCache) + { + return GetFileSystemDictionary(path, clearCache).Values; + } + public IEnumerable<FileSystemInfo> GetFiles(string path) { return GetFiles(path, false); @@ -74,9 +101,13 @@ namespace MediaBrowser.Controller.Providers public FileSystemInfo 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)); + var dict = GetFileSystemDictionary(directory, false); + + FileSystemInfo entry; + dict.TryGetValue(path, out entry); + + return entry; } } } diff --git a/MediaBrowser.Controller/Providers/ILocalMetadataProvider.cs b/MediaBrowser.Controller/Providers/ILocalMetadataProvider.cs index 75aad4063c..61bc3b87ba 100644 --- a/MediaBrowser.Controller/Providers/ILocalMetadataProvider.cs +++ b/MediaBrowser.Controller/Providers/ILocalMetadataProvider.cs @@ -17,9 +17,12 @@ namespace MediaBrowser.Controller.Providers /// Gets the metadata. /// </summary> /// <param name="info">The information.</param> + /// <param name="directoryService">The directory service.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task{MetadataResult{`0}}.</returns> - Task<LocalMetadataResult<TItemType>> GetMetadata(ItemInfo info, CancellationToken cancellationToken); + Task<LocalMetadataResult<TItemType>> GetMetadata(ItemInfo info, + IDirectoryService directoryService, + CancellationToken cancellationToken); } public class ItemInfo diff --git a/MediaBrowser.Controller/Providers/MetadataRefreshOptions.cs b/MediaBrowser.Controller/Providers/MetadataRefreshOptions.cs index e7dcd03b5b..a9e1555098 100644 --- a/MediaBrowser.Controller/Providers/MetadataRefreshOptions.cs +++ b/MediaBrowser.Controller/Providers/MetadataRefreshOptions.cs @@ -1,5 +1,4 @@ using MediaBrowser.Model.Entities; -using System; using System.Collections.Generic; using System.Linq; @@ -17,18 +16,24 @@ namespace MediaBrowser.Controller.Providers public bool ForceSave { get; set; } public MetadataRefreshOptions() + : this(new DirectoryService()) + { + } + + public MetadataRefreshOptions(IDirectoryService directoryService) + : base(directoryService) { MetadataRefreshMode = MetadataRefreshMode.Default; } - public MetadataRefreshOptions(MetadataRefreshOptions copy) + public MetadataRefreshOptions( MetadataRefreshOptions copy) + : base(copy.DirectoryService) { MetadataRefreshMode = copy.MetadataRefreshMode; ForceSave = copy.ForceSave; ReplaceAllMetadata = copy.ReplaceAllMetadata; ImageRefreshMode = copy.ImageRefreshMode; - DirectoryService = copy.DirectoryService; ReplaceAllImages = copy.ReplaceAllImages; ReplaceImages = copy.ReplaceImages.ToList(); } @@ -37,15 +42,16 @@ namespace MediaBrowser.Controller.Providers public class ImageRefreshOptions { public ImageRefreshMode ImageRefreshMode { get; set; } - public IDirectoryService DirectoryService { get; set; } + public IDirectoryService DirectoryService { get; private set; } public bool ReplaceAllImages { get; set; } public List<ImageType> ReplaceImages { get; set; } - public ImageRefreshOptions() + public ImageRefreshOptions(IDirectoryService directoryService) { ImageRefreshMode = ImageRefreshMode.Default; + DirectoryService = directoryService; ReplaceImages = new List<ImageType>(); } |
