2013-09-18 02:43:34 +00:00
|
|
|
|
using MediaBrowser.Common.Extensions;
|
2013-03-04 05:43:06 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-06-21 18:50:44 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-05-06 14:49:17 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
2013-09-18 02:43:34 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Providers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class BaseMetadataProvider
|
|
|
|
|
/// </summary>
|
2013-03-08 05:08:27 +00:00
|
|
|
|
public abstract class BaseMetadataProvider
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the logger.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The logger.</value>
|
2013-03-02 17:59:15 +00:00
|
|
|
|
protected ILogger Logger { get; set; }
|
2013-11-07 15:56:35 +00:00
|
|
|
|
|
2013-03-02 17:59:15 +00:00
|
|
|
|
protected ILogManager LogManager { get; set; }
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-03-04 05:43:06 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the configuration manager.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The configuration manager.</value>
|
|
|
|
|
protected IServerConfigurationManager ConfigurationManager { get; private set; }
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _id
|
|
|
|
|
/// </summary>
|
2013-04-13 18:02:30 +00:00
|
|
|
|
protected readonly Guid Id;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-04-15 20:33:43 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The true task result
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected static readonly Task<bool> TrueTaskResult = Task.FromResult(true);
|
2013-11-07 15:56:35 +00:00
|
|
|
|
|
2013-04-15 20:33:43 +00:00
|
|
|
|
protected static readonly Task<bool> FalseTaskResult = Task.FromResult(false);
|
|
|
|
|
|
2013-04-15 18:45:58 +00:00
|
|
|
|
protected static readonly SemaphoreSlim XmlParsingResourcePool = new SemaphoreSlim(5, 5);
|
2013-06-21 18:50:44 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Supportses the specified item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
|
|
|
|
public abstract bool Supports(BaseItem item);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether [requires internet].
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if [requires internet]; otherwise, <c>false</c>.</value>
|
|
|
|
|
public virtual bool RequiresInternet
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the provider version.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The provider version.</value>
|
|
|
|
|
protected virtual string ProviderVersion
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-25 01:22:21 +00:00
|
|
|
|
public virtual ItemUpdateType ItemUpdateType
|
|
|
|
|
{
|
2013-06-27 23:01:03 +00:00
|
|
|
|
get { return RequiresInternet ? ItemUpdateType.MetadataDownload : ItemUpdateType.MetadataImport; }
|
2013-06-25 01:22:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether [refresh on version change].
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if [refresh on version change]; otherwise, <c>false</c>.</value>
|
|
|
|
|
protected virtual bool RefreshOnVersionChange
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines if this provider is relatively slow and, therefore, should be skipped
|
|
|
|
|
/// in certain instances. Default is whether or not it requires internet. Can be overridden
|
|
|
|
|
/// for explicit designation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if this instance is slow; otherwise, <c>false</c>.</value>
|
|
|
|
|
public virtual bool IsSlow
|
|
|
|
|
{
|
|
|
|
|
get { return RequiresInternet; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="BaseMetadataProvider" /> class.
|
|
|
|
|
/// </summary>
|
2013-03-04 05:43:06 +00:00
|
|
|
|
protected BaseMetadataProvider(ILogManager logManager, IServerConfigurationManager configurationManager)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-03-02 17:59:15 +00:00
|
|
|
|
Logger = logManager.GetLogger(GetType().Name);
|
|
|
|
|
LogManager = logManager;
|
2013-03-04 05:43:06 +00:00
|
|
|
|
ConfigurationManager = configurationManager;
|
2013-04-13 18:02:30 +00:00
|
|
|
|
Id = GetType().FullName.GetMD5();
|
2013-03-02 17:59:15 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes this instance.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual void Initialize()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the persisted last refresh date on the item for this provider.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="value">The value.</param>
|
|
|
|
|
/// <param name="providerVersion">The provider version.</param>
|
|
|
|
|
/// <param name="status">The status.</param>
|
|
|
|
|
/// <exception cref="System.ArgumentNullException">item</exception>
|
2013-11-07 15:56:35 +00:00
|
|
|
|
public virtual void SetLastRefreshed(BaseItem item, DateTime value, string providerVersion,
|
|
|
|
|
ProviderRefreshStatus status = ProviderRefreshStatus.Success)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (item == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("item");
|
|
|
|
|
}
|
2013-04-13 18:02:30 +00:00
|
|
|
|
|
|
|
|
|
BaseProviderInfo data;
|
|
|
|
|
|
|
|
|
|
if (!item.ProviderData.TryGetValue(Id, out data))
|
|
|
|
|
{
|
|
|
|
|
data = new BaseProviderInfo();
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
data.LastRefreshed = value;
|
|
|
|
|
data.LastRefreshStatus = status;
|
|
|
|
|
data.ProviderVersion = providerVersion;
|
|
|
|
|
|
|
|
|
|
// Save the file system stamp for future comparisons
|
2013-05-06 14:49:17 +00:00
|
|
|
|
if (RefreshOnFileSystemStampChange && item.LocationType == LocationType.FileSystem)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-07-02 18:24:54 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
data.FileStamp = GetCurrentFileSystemStamp(item);
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException("Error getting file stamp for {0}", ex, item.Path);
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item.ProviderData[Id] = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the last refreshed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="value">The value.</param>
|
|
|
|
|
/// <param name="status">The status.</param>
|
2013-11-07 15:56:35 +00:00
|
|
|
|
public void SetLastRefreshed(BaseItem item, DateTime value,
|
|
|
|
|
ProviderRefreshStatus status = ProviderRefreshStatus.Success)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
SetLastRefreshed(item, value, ProviderVersion, status);
|
|
|
|
|
}
|
2013-04-13 18:02:30 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns whether or not this provider should be re-fetched. Default functionality can
|
|
|
|
|
/// compare a provided date with a last refresh time. This can be overridden for more complex
|
|
|
|
|
/// determinations.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
|
|
|
|
/// <exception cref="System.ArgumentNullException"></exception>
|
|
|
|
|
public bool NeedsRefresh(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
if (item == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 18:02:30 +00:00
|
|
|
|
BaseProviderInfo data;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-04-13 18:02:30 +00:00
|
|
|
|
if (!item.ProviderData.TryGetValue(Id, out data))
|
|
|
|
|
{
|
|
|
|
|
data = new BaseProviderInfo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NeedsRefreshInternal(item, data);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-23 14:02:56 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether [enforce dont fetch metadata].
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if [enforce dont fetch metadata]; otherwise, <c>false</c>.</value>
|
|
|
|
|
public virtual bool EnforceDontFetchMetadata
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Needses the refresh internal.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="providerInfo">The provider info.</param>
|
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
|
|
|
|
/// <exception cref="System.ArgumentNullException"></exception>
|
|
|
|
|
protected virtual bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
|
|
|
|
{
|
|
|
|
|
if (item == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("item");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (providerInfo == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("providerInfo");
|
|
|
|
|
}
|
2013-04-13 18:02:30 +00:00
|
|
|
|
|
2013-10-10 16:55:07 +00:00
|
|
|
|
if (NeedsRefreshBasedOnCompareDate(item, providerInfo))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-07 15:56:35 +00:00
|
|
|
|
if (RefreshOnFileSystemStampChange && item.LocationType == LocationType.FileSystem &&
|
|
|
|
|
HasFileSystemStampChanged(item, providerInfo))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-10 16:55:07 +00:00
|
|
|
|
if (RefreshOnVersionChange && !String.Equals(ProviderVersion, providerInfo.ProviderVersion))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-04-13 18:02:30 +00:00
|
|
|
|
|
2013-10-10 16:55:07 +00:00
|
|
|
|
if (providerInfo.LastRefreshStatus != ProviderRefreshStatus.Success)
|
2013-04-28 23:39:17 +00:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-06-21 18:50:44 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-01 18:24:27 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Needses the refresh based on compare date.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="providerInfo">The provider info.</param>
|
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
|
|
|
|
protected virtual bool NeedsRefreshBasedOnCompareDate(BaseItem item, BaseProviderInfo providerInfo)
|
|
|
|
|
{
|
|
|
|
|
return CompareDate(item) > providerInfo.LastRefreshed;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines if the item's file system stamp has changed from the last time the provider refreshed
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="providerInfo">The provider info.</param>
|
|
|
|
|
/// <returns><c>true</c> if [has file system stamp changed] [the specified item]; otherwise, <c>false</c>.</returns>
|
|
|
|
|
protected bool HasFileSystemStampChanged(BaseItem item, BaseProviderInfo providerInfo)
|
|
|
|
|
{
|
2013-04-25 17:27:36 +00:00
|
|
|
|
return GetCurrentFileSystemStamp(item) != providerInfo.FileStamp;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Override this to return the date that should be compared to the last refresh date
|
|
|
|
|
/// to determine if this provider should be re-fetched.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns>DateTime.</returns>
|
|
|
|
|
protected virtual DateTime CompareDate(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
return DateTime.MinValue.AddMinutes(1); // want this to be greater than mindate so new items will refresh
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="force">if set to <c>true</c> [force].</param>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <returns>Task{System.Boolean}.</returns>
|
|
|
|
|
/// <exception cref="System.ArgumentNullException"></exception>
|
2013-03-08 05:08:27 +00:00
|
|
|
|
public abstract Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the priority.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The priority.</value>
|
|
|
|
|
public abstract MetadataProviderPriority Priority { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns true or false indicating if the provider should refresh when the contents of it's directory changes
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if [refresh on file system stamp change]; otherwise, <c>false</c>.</value>
|
|
|
|
|
protected virtual bool RefreshOnFileSystemStampChange
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-21 18:50:44 +00:00
|
|
|
|
protected virtual string[] FilestampExtensions
|
|
|
|
|
{
|
|
|
|
|
get { return new string[] { }; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines if the parent's file system stamp should be used for comparison
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
|
|
|
|
protected virtual bool UseParentFileSystemStamp(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
// True when the current item is just a file
|
|
|
|
|
return !item.ResolveArgs.IsDirectory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the item's current file system stamp
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns>Guid.</returns>
|
2013-04-25 17:27:36 +00:00
|
|
|
|
private Guid GetCurrentFileSystemStamp(BaseItem item)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (UseParentFileSystemStamp(item) && item.Parent != null)
|
|
|
|
|
{
|
2013-06-21 18:50:44 +00:00
|
|
|
|
return GetFileSystemStamp(item.Parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return GetFileSystemStamp(item);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-18 02:43:34 +00:00
|
|
|
|
private Dictionary<string, string> _fileStampExtensionsDictionary;
|
2013-11-07 15:56:35 +00:00
|
|
|
|
|
2013-10-14 01:35:47 +00:00
|
|
|
|
private Dictionary<string, string> FileStampExtensionsDictionary
|
2013-09-18 02:43:34 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _fileStampExtensionsDictionary ??
|
|
|
|
|
(_fileStampExtensionsDictionary =
|
2013-11-07 15:56:35 +00:00
|
|
|
|
FilestampExtensions.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase));
|
2013-09-18 02:43:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-07 15:56:35 +00:00
|
|
|
|
|
2013-06-21 18:50:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the file system stamp.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns>Guid.</returns>
|
2013-11-07 15:56:35 +00:00
|
|
|
|
protected virtual Guid GetFileSystemStamp(BaseItem item)
|
2013-06-21 18:50:44 +00:00
|
|
|
|
{
|
|
|
|
|
// If there's no path or the item is a file, there's nothing to do
|
|
|
|
|
if (item.LocationType != LocationType.FileSystem)
|
|
|
|
|
{
|
|
|
|
|
return Guid.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ItemResolveArgs resolveArgs;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
resolveArgs = item.ResolveArgs;
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException("Error determining if path is directory: {0}", ex, item.Path);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!resolveArgs.IsDirectory)
|
|
|
|
|
{
|
|
|
|
|
return Guid.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
|
2013-09-18 02:43:34 +00:00
|
|
|
|
var extensions = FileStampExtensionsDictionary;
|
2013-09-25 15:11:23 +00:00
|
|
|
|
var numExtensions = FilestampExtensions.Length;
|
2013-06-21 18:50:44 +00:00
|
|
|
|
|
|
|
|
|
// Record the name of each file
|
|
|
|
|
// Need to sort these because accoring to msdn docs, our i/o methods are not guaranteed in any order
|
2013-10-14 01:35:47 +00:00
|
|
|
|
AddFiles(sb, resolveArgs.FileSystemChildren, extensions, numExtensions);
|
|
|
|
|
AddFiles(sb, resolveArgs.MetadataFiles, extensions, numExtensions);
|
2013-06-21 18:50:44 +00:00
|
|
|
|
|
|
|
|
|
return sb.ToString().GetMD5();
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-15 22:16:39 +00:00
|
|
|
|
private static readonly Dictionary<string, string> FoldersToMonitor = new[] { "extrafanart", "extrathumbs" }
|
2013-10-14 01:35:47 +00:00
|
|
|
|
.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
2013-11-07 15:56:35 +00:00
|
|
|
|
protected Guid GetFileSystemStamp(IEnumerable<FileSystemInfo> files)
|
|
|
|
|
{
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
var extensions = FileStampExtensionsDictionary;
|
|
|
|
|
var numExtensions = FilestampExtensions.Length;
|
|
|
|
|
|
|
|
|
|
// Record the name of each file
|
|
|
|
|
// Need to sort these because accoring to msdn docs, our i/o methods are not guaranteed in any order
|
|
|
|
|
AddFiles(sb, files, extensions, numExtensions);
|
|
|
|
|
|
|
|
|
|
return sb.ToString().GetMD5();
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-21 18:50:44 +00:00
|
|
|
|
/// <summary>
|
2013-10-14 01:35:47 +00:00
|
|
|
|
/// Adds the files.
|
2013-06-21 18:50:44 +00:00
|
|
|
|
/// </summary>
|
2013-10-14 01:35:47 +00:00
|
|
|
|
/// <param name="sb">The sb.</param>
|
|
|
|
|
/// <param name="files">The files.</param>
|
2013-06-21 18:50:44 +00:00
|
|
|
|
/// <param name="extensions">The extensions.</param>
|
2013-08-07 16:00:20 +00:00
|
|
|
|
/// <param name="numExtensions">The num extensions.</param>
|
2013-10-14 01:35:47 +00:00
|
|
|
|
private void AddFiles(StringBuilder sb, IEnumerable<FileSystemInfo> files, Dictionary<string, string> extensions, int numExtensions)
|
2013-06-21 18:50:44 +00:00
|
|
|
|
{
|
2013-10-14 01:35:47 +00:00
|
|
|
|
foreach (var file in files
|
|
|
|
|
.OrderBy(f => f.Name))
|
2013-06-21 18:50:44 +00:00
|
|
|
|
{
|
2013-10-14 01:35:47 +00:00
|
|
|
|
try
|
2013-07-05 14:54:14 +00:00
|
|
|
|
{
|
2013-10-14 01:35:47 +00:00
|
|
|
|
if ((file.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
|
|
|
|
|
{
|
|
|
|
|
if (FoldersToMonitor.ContainsKey(file.Name))
|
|
|
|
|
{
|
|
|
|
|
sb.Append(file.Name);
|
|
|
|
|
|
2013-11-07 15:56:35 +00:00
|
|
|
|
var children = ((DirectoryInfo)file).EnumerateFiles("*", SearchOption.TopDirectoryOnly).ToList();
|
2013-10-14 01:35:47 +00:00
|
|
|
|
AddFiles(sb, children, extensions, numExtensions);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// It's a file
|
|
|
|
|
else if (numExtensions == 0 || extensions.ContainsKey(file.Extension))
|
|
|
|
|
{
|
|
|
|
|
sb.Append(file.Name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException("Error accessing file attributes for {0}", ex, file.FullName);
|
2013-07-05 14:54:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|