jellyfin/MediaBrowser.Providers/Manager/MetadataService.cs

672 lines
27 KiB
C#
Raw Normal View History

2014-09-28 08:27:26 -07:00
using MediaBrowser.Common.Extensions;
2014-02-02 06:36:31 -07:00
using MediaBrowser.Common.IO;
2014-01-28 22:17:58 -07:00
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.Manager
{
2014-01-31 12:55:21 -07:00
public abstract class MetadataService<TItemType, TIdType> : IMetadataService
2014-02-06 20:10:13 -07:00
where TItemType : IHasMetadata, IHasLookupInfo<TIdType>, new()
where TIdType : ItemLookupInfo, new()
{
protected readonly IServerConfigurationManager ServerConfigurationManager;
protected readonly ILogger Logger;
protected readonly IProviderManager ProviderManager;
2014-02-02 06:36:31 -07:00
protected readonly IProviderRepository ProviderRepo;
protected readonly IFileSystem FileSystem;
protected readonly IUserDataManager UserDataManager;
protected MetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IProviderRepository providerRepo, IFileSystem fileSystem, IUserDataManager userDataManager)
{
ServerConfigurationManager = serverConfigurationManager;
Logger = logger;
ProviderManager = providerManager;
2014-02-02 06:36:31 -07:00
ProviderRepo = providerRepo;
FileSystem = fileSystem;
UserDataManager = userDataManager;
}
/// <summary>
/// Saves the provider result.
/// </summary>
2014-02-08 13:02:35 -07:00
/// <param name="item">The item.</param>
/// <param name="result">The result.</param>
2014-09-10 18:57:11 -07:00
/// <param name="directoryService">The directory service.</param>
/// <returns>Task.</returns>
2014-09-10 18:57:11 -07:00
protected Task SaveProviderResult(TItemType item, MetadataStatus result, IDirectoryService directoryService)
{
2014-02-08 13:02:35 -07:00
result.ItemId = item.Id;
result.ItemName = item.Name;
2014-02-08 15:38:02 -07:00
result.ItemType = item.GetType().Name;
2014-02-08 13:02:35 -07:00
var series = item as IHasSeries;
result.SeriesName = series == null ? null : series.SeriesName;
2014-09-10 18:57:11 -07:00
//var locationType = item.LocationType;
//if (locationType == LocationType.FileSystem || locationType == LocationType.Offline)
//{
// if (!string.IsNullOrWhiteSpace(item.Path))
// {
// var file = directoryService.GetFile(item.Path);
// if ((file.Attributes & FileAttributes.Directory) != FileAttributes.Directory && file.Exists)
// {
// result.ItemDateModified = FileSystem.GetLastWriteTimeUtc(file);
// }
// }
//}
result.ItemDateModified = item.DateModified;
2014-02-02 06:36:31 -07:00
return ProviderRepo.SaveMetadataStatus(result, CancellationToken.None);
}
/// <summary>
/// Gets the last result.
/// </summary>
2014-03-16 09:15:10 -07:00
/// <param name="item">The item.</param>
/// <returns>ProviderResult.</returns>
2014-03-16 09:15:10 -07:00
protected MetadataStatus GetLastResult(IHasMetadata item)
{
2014-03-16 09:15:10 -07:00
if (item.DateLastSaved == default(DateTime))
{
return new MetadataStatus { ItemId = item.Id };
}
return ProviderRepo.GetMetadataStatus(item.Id) ?? new MetadataStatus { ItemId = item.Id };
}
2014-02-02 06:36:31 -07:00
public async Task RefreshMetadata(IHasMetadata item, MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken)
{
var itemOfType = (TItemType)item;
var config = ProviderManager.GetMetadataOptions(item);
2014-02-02 06:36:31 -07:00
2014-02-10 11:39:41 -07:00
var updateType = ItemUpdateType.None;
2014-03-16 09:15:10 -07:00
var refreshResult = GetLastResult(item);
2014-01-28 22:17:58 -07:00
refreshResult.LastErrorMessage = string.Empty;
refreshResult.LastStatus = ProviderRefreshStatus.Success;
2014-02-02 06:36:31 -07:00
var itemImageProvider = new ItemImageProvider(Logger, ProviderManager, ServerConfigurationManager, FileSystem);
var localImagesFailed = false;
2014-01-31 12:55:21 -07:00
var allImageProviders = ((ProviderManager)ProviderManager).GetImageProviders(item).ToList();
// Start by validating images
try
{
// Always validate images and check for new locally stored ones.
2014-02-08 15:38:02 -07:00
if (itemImageProvider.ValidateImages(item, allImageProviders.OfType<ILocalImageProvider>(), refreshOptions.DirectoryService))
{
updateType = updateType | ItemUpdateType.ImageUpdate;
}
}
catch (Exception ex)
{
localImagesFailed = true;
2015-01-26 23:50:40 -07:00
Logger.ErrorException("Error validating images for {0}", ex, item.Path ?? item.Name ?? "Unknown name");
refreshResult.AddStatus(ProviderRefreshStatus.Failure, ex.Message);
}
// Next run metadata providers
2014-02-02 06:36:31 -07:00
if (refreshOptions.MetadataRefreshMode != MetadataRefreshMode.None)
{
2014-09-10 18:57:11 -07:00
var providers = GetProviders(item, refreshResult, refreshOptions)
2014-03-24 10:54:45 -07:00
.ToList();
if (providers.Count > 0 || !refreshResult.DateLastMetadataRefresh.HasValue)
{
2014-02-12 22:11:54 -07:00
if (item.BeforeMetadataRefresh())
{
updateType = updateType | ItemUpdateType.MetadataImport;
}
}
if (providers.Count > 0)
{
var id = await CreateInitialLookupInfo(itemOfType, cancellationToken).ConfigureAwait(false);
var result = await RefreshWithProviders(itemOfType, id, refreshOptions, providers, itemImageProvider, cancellationToken).ConfigureAwait(false);
updateType = updateType | result.UpdateType;
refreshResult.AddStatus(result.Status, result.ErrorMessage);
2014-01-28 22:17:58 -07:00
refreshResult.SetDateLastMetadataRefresh(DateTime.UtcNow);
2014-10-13 21:22:17 -07:00
refreshResult.AddMetadataProvidersRefreshed(result.Providers);
MergeIdentities(itemOfType, id);
}
}
// Next run remote image providers, but only if local image providers didn't throw an exception
2014-02-02 06:36:31 -07:00
if (!localImagesFailed && refreshOptions.ImageRefreshMode != ImageRefreshMode.ValidationOnly)
{
2014-09-10 18:57:11 -07:00
var providers = GetNonLocalImageProviders(item, allImageProviders, refreshResult, refreshOptions).ToList();
2014-01-29 10:23:38 -07:00
if (providers.Count > 0)
{
2014-02-02 06:36:31 -07:00
var result = await itemImageProvider.RefreshImages(itemOfType, providers, refreshOptions, config, cancellationToken).ConfigureAwait(false);
2014-01-28 22:17:58 -07:00
updateType = updateType | result.UpdateType;
refreshResult.AddStatus(result.Status, result.ErrorMessage);
refreshResult.SetDateLastImagesRefresh(DateTime.UtcNow);
refreshResult.AddImageProvidersRefreshed(result.Providers);
}
}
2015-01-17 11:15:09 -07:00
updateType = updateType | (await BeforeSave(itemOfType, item.DateLastSaved == default(DateTime) || refreshOptions.ReplaceAllMetadata, updateType).ConfigureAwait(false));
2014-02-11 14:41:01 -07:00
// Save if changes were made, or it's never been saved before
2015-01-17 11:15:09 -07:00
if (refreshOptions.ForceSave || updateType > ItemUpdateType.None || item.DateLastSaved == default(DateTime) || refreshOptions.ReplaceAllMetadata)
{
2015-01-17 11:15:09 -07:00
// If any of these properties are set then make sure the updateType is not None, just to force everything to save
if (refreshOptions.ForceSave || refreshOptions.ReplaceAllMetadata)
2014-09-13 07:10:30 -07:00
{
updateType = updateType | ItemUpdateType.MetadataDownload;
}
// Save to database
await SaveItem(itemOfType, updateType, cancellationToken);
}
2015-01-17 11:15:09 -07:00
if (updateType > ItemUpdateType.None || refreshResult.IsDirty)
{
2014-09-10 18:57:11 -07:00
await SaveProviderResult(itemOfType, refreshResult, refreshOptions.DirectoryService).ConfigureAwait(false);
}
2015-01-26 23:50:40 -07:00
2015-01-28 14:29:02 -07:00
await AfterMetadataRefresh(itemOfType, refreshOptions, cancellationToken).ConfigureAwait(false);
}
private readonly Task _cachedTask = Task.FromResult(true);
protected virtual Task AfterMetadataRefresh(TItemType item, MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken)
{
item.AfterMetadataRefresh();
return _cachedTask;
}
private void MergeIdentities(TItemType item, TIdType id)
{
var hasIdentity = id as IHasIdentities<IItemIdentity>;
if (hasIdentity != null)
{
item.Identities = hasIdentity.Identities.ToList();
}
}
2015-01-17 11:15:09 -07:00
private readonly Task<ItemUpdateType> _cachedResult = Task.FromResult(ItemUpdateType.None);
2014-02-02 22:35:43 -07:00
/// <summary>
/// Befores the save.
2014-02-02 22:35:43 -07:00
/// </summary>
/// <param name="item">The item.</param>
2015-01-17 11:15:09 -07:00
/// <param name="isFullRefresh">if set to <c>true</c> [is full refresh].</param>
/// <param name="currentUpdateType">Type of the current update.</param>
2014-02-02 22:35:43 -07:00
/// <returns>ItemUpdateType.</returns>
2015-01-17 11:15:09 -07:00
protected virtual Task<ItemUpdateType> BeforeSave(TItemType item, bool isFullRefresh, ItemUpdateType currentUpdateType)
2014-02-02 22:35:43 -07:00
{
2015-01-17 11:15:09 -07:00
return _cachedResult;
2014-02-02 22:35:43 -07:00
}
/// <summary>
/// Gets the providers.
/// </summary>
/// <param name="item">The item.</param>
2014-09-10 18:57:11 -07:00
/// <param name="status">The status.</param>
/// <param name="options">The options.</param>
/// <returns>IEnumerable{`0}.</returns>
2014-09-10 18:57:11 -07:00
protected IEnumerable<IMetadataProvider> GetProviders(IHasMetadata item, MetadataStatus status, MetadataRefreshOptions options)
{
// Get providers to refresh
2014-01-31 23:18:16 -07:00
var providers = ((ProviderManager)ProviderManager).GetMetadataProviders<TItemType>(item).ToList();
// Run all if either of these flags are true
2014-09-10 18:57:11 -07:00
var runAllProviders = options.ReplaceAllMetadata || options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh || !status.DateLastMetadataRefresh.HasValue;
if (!runAllProviders)
{
// Avoid implicitly captured closure
var currentItem = item;
2014-09-10 18:57:11 -07:00
var providersWithChanges = providers
.Where(i =>
{
var hasChangeMonitor = i as IHasChangeMonitor;
if (hasChangeMonitor != null)
{
return HasChanged(item, hasChangeMonitor, currentItem.DateLastSaved, options.DirectoryService);
}
var hasFileChangeMonitor = i as IHasItemChangeMonitor;
if (hasFileChangeMonitor != null)
{
return HasChanged(item, hasFileChangeMonitor, status, options.DirectoryService);
}
return false;
})
.ToList();
2014-02-10 11:39:41 -07:00
if (providersWithChanges.Count == 0)
{
2014-02-10 11:39:41 -07:00
providers = new List<IMetadataProvider<TItemType>>();
}
else
{
providers = providers.Where(i =>
{
// If any provider reports a change, always run local ones as well
if (i is ILocalMetadataProvider)
{
return true;
}
var anyRemoteProvidersChanged = providersWithChanges.OfType<IRemoteMetadataProvider>()
.Any();
// If any remote providers changed, run them all so that priorities can be honored
if (i is IRemoteMetadataProvider)
{
return anyRemoteProvidersChanged;
}
// Run custom providers if they report a change or any remote providers change
return anyRemoteProvidersChanged || providersWithChanges.Contains(i);
}).ToList();
}
}
return providers;
}
2014-09-10 18:57:11 -07:00
protected virtual IEnumerable<IImageProvider> GetNonLocalImageProviders(IHasMetadata item, IEnumerable<IImageProvider> allImageProviders, MetadataStatus status, ImageRefreshOptions options)
2014-01-29 10:23:38 -07:00
{
// Get providers to refresh
2014-01-31 12:55:21 -07:00
var providers = allImageProviders.Where(i => !(i is ILocalImageProvider)).ToList();
2014-01-29 10:23:38 -07:00
// Run all if either of these flags are true
2014-09-10 18:57:11 -07:00
var runAllProviders = options.ImageRefreshMode == ImageRefreshMode.FullRefresh || !status.DateLastImagesRefresh.HasValue;
2014-01-29 10:23:38 -07:00
if (!runAllProviders)
{
2014-09-10 18:57:11 -07:00
providers = providers
.Where(i =>
{
var hasChangeMonitor = i as IHasChangeMonitor;
if (hasChangeMonitor != null)
{
return HasChanged(item, hasChangeMonitor, status.DateLastImagesRefresh.Value, options.DirectoryService);
}
var hasFileChangeMonitor = i as IHasItemChangeMonitor;
if (hasFileChangeMonitor != null)
{
return HasChanged(item, hasFileChangeMonitor, status, options.DirectoryService);
}
2014-09-10 18:57:11 -07:00
return false;
})
2014-01-29 10:23:38 -07:00
.ToList();
}
return providers;
}
2014-02-08 13:02:35 -07:00
protected Task SaveItem(TItemType item, ItemUpdateType reason, CancellationToken cancellationToken)
{
return item.UpdateToRepository(reason, cancellationToken);
}
public bool CanRefresh(IHasMetadata item)
{
return item is TItemType;
}
2015-01-28 14:29:02 -07:00
protected virtual async Task<RefreshResult> RefreshWithProviders(TItemType item,
TIdType id,
MetadataRefreshOptions options,
List<IMetadataProvider> providers,
ItemImageProvider imageService,
2014-10-25 11:32:58 -07:00
CancellationToken cancellationToken)
{
2014-01-28 22:17:58 -07:00
var refreshResult = new RefreshResult
{
2014-02-10 11:39:41 -07:00
UpdateType = ItemUpdateType.None,
2014-01-28 22:17:58 -07:00
Providers = providers.Select(i => i.GetType().FullName.GetMD5()).ToList()
};
var customProviders = providers.OfType<ICustomMetadataProvider<TItemType>>().ToList();
2014-09-28 13:49:43 -07:00
var logName = item.LocationType == LocationType.Remote ? item.Name ?? item.Path : item.Path ?? item.Name;
foreach (var provider in customProviders.Where(i => i is IPreRefreshProvider))
{
2014-09-28 13:49:43 -07:00
await RunCustomProvider(provider, item, logName, options, refreshResult, cancellationToken).ConfigureAwait(false);
}
2014-01-30 14:23:54 -07:00
var temp = CreateNew();
temp.Path = item.Path;
var successfulProviderCount = 0;
var failedProviderCount = 0;
// If replacing all metadata, run internet providers first
if (options.ReplaceAllMetadata)
{
2014-09-28 13:49:43 -07:00
var remoteResult = await ExecuteRemoteProviders(item, temp, logName, id, providers.OfType<IRemoteMetadataProvider<TItemType, TIdType>>(), cancellationToken)
.ConfigureAwait(false);
2014-10-28 16:17:55 -07:00
refreshResult.UpdateType = refreshResult.UpdateType | remoteResult.UpdateType;
refreshResult.Status = remoteResult.Status;
refreshResult.ErrorMessage = remoteResult.ErrorMessage;
successfulProviderCount += remoteResult.Successes;
failedProviderCount += remoteResult.Failures;
}
var hasLocalMetadata = false;
var userDataList = new List<UserItemData>();
2014-10-28 16:17:55 -07:00
var localProviders = providers.OfType<ILocalMetadataProvider<TItemType>>().ToList();
2014-10-28 16:17:55 -07:00
foreach (var provider in localProviders)
{
var providerName = provider.GetType().Name;
2014-09-28 13:49:43 -07:00
Logger.Debug("Running {0} for {1}", providerName, logName);
var itemInfo = new ItemInfo { Path = item.Path, IsInMixedFolder = item.IsInMixedFolder };
try
{
2014-10-25 11:32:58 -07:00
var localItem = await provider.GetMetadata(itemInfo, options.DirectoryService, cancellationToken).ConfigureAwait(false);
if (localItem.HasMetadata)
{
2014-02-08 21:52:52 -07:00
if (imageService.MergeImages(item, localItem.Images))
{
2014-02-22 14:05:00 -07:00
refreshResult.UpdateType = refreshResult.UpdateType | ItemUpdateType.ImageUpdate;
2014-02-08 21:52:52 -07:00
}
userDataList = localItem.UserDataLIst;
MergeData(localItem.Item, temp, new List<MetadataFields>(), !options.ReplaceAllMetadata, true);
refreshResult.UpdateType = refreshResult.UpdateType | ItemUpdateType.MetadataImport;
// Only one local provider allowed per item
2015-02-25 11:11:49 -07:00
if (IsFullLocalMetadata(localItem.Item))
{
hasLocalMetadata = true;
}
successfulProviderCount++;
break;
}
2014-09-28 13:49:43 -07:00
Logger.Debug("{0} returned no metadata for {1}", providerName, logName);
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
failedProviderCount++;
Logger.ErrorException("Error in {0}", ex, provider.Name);
// If a local provider fails, consider that a failure
refreshResult.Status = ProviderRefreshStatus.Failure;
refreshResult.ErrorMessage = ex.Message;
if (options.MetadataRefreshMode != MetadataRefreshMode.FullRefresh)
{
// If the local provider fails don't continue with remote providers because the user's saved metadata could be lost
return refreshResult;
}
}
}
2014-02-08 13:02:35 -07:00
// Local metadata is king - if any is found don't run remote providers
2014-02-15 09:36:09 -07:00
if (!options.ReplaceAllMetadata && (!hasLocalMetadata || options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh))
{
2014-09-28 13:49:43 -07:00
var remoteResult = await ExecuteRemoteProviders(item, temp, logName, id, providers.OfType<IRemoteMetadataProvider<TItemType, TIdType>>(), cancellationToken)
.ConfigureAwait(false);
refreshResult.UpdateType = refreshResult.UpdateType | remoteResult.UpdateType;
if (remoteResult.Status != ProviderRefreshStatus.Success)
{
refreshResult.Status = remoteResult.Status;
refreshResult.ErrorMessage = remoteResult.ErrorMessage;
}
successfulProviderCount += remoteResult.Successes;
}
2014-10-28 16:17:55 -07:00
// If no local providers and doing a full refresh, take data from item itself
if (options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh &&
localProviders.Count == 0 &&
refreshResult.UpdateType > ItemUpdateType.None)
{
2015-01-24 15:33:26 -07:00
// TODO: If the new metadata from above has some blank data, this can cause old data to get filled into those empty fields
2014-10-28 16:17:55 -07:00
MergeData(item, temp, new List<MetadataFields>(), false, true);
}
2014-02-10 11:39:41 -07:00
if (refreshResult.UpdateType > ItemUpdateType.None)
2014-01-31 23:18:16 -07:00
{
MergeData(temp, item, item.LockedFields, true, true);
}
var isUnidentified = failedProviderCount > 0 && successfulProviderCount == 0;
if (item.IsUnidentified != isUnidentified)
{
item.IsUnidentified = isUnidentified;
refreshResult.UpdateType = refreshResult.UpdateType | ItemUpdateType.MetadataImport;
}
foreach (var provider in customProviders.Where(i => !(i is IPreRefreshProvider)))
2014-02-02 06:36:31 -07:00
{
2014-09-28 13:49:43 -07:00
await RunCustomProvider(provider, item, logName, options, refreshResult, cancellationToken).ConfigureAwait(false);
2014-02-02 06:36:31 -07:00
}
await ImportUserData(item, userDataList, cancellationToken).ConfigureAwait(false);
return refreshResult;
}
2015-02-25 11:11:49 -07:00
protected virtual bool IsFullLocalMetadata(TItemType item)
{
return true;
}
private async Task ImportUserData(TItemType item, List<UserItemData> userDataList, CancellationToken cancellationToken)
{
var hasUserData = item as IHasUserData;
if (hasUserData != null)
{
foreach (var userData in userDataList)
{
await UserDataManager.SaveUserData(userData.UserId, hasUserData, userData, UserDataSaveReason.Import, cancellationToken)
.ConfigureAwait(false);
}
}
}
2014-09-28 13:49:43 -07:00
private async Task RunCustomProvider(ICustomMetadataProvider<TItemType> provider, TItemType item, string logName, MetadataRefreshOptions options, RefreshResult refreshResult, CancellationToken cancellationToken)
{
2014-09-28 13:49:43 -07:00
Logger.Debug("Running {0} for {1}", provider.GetType().Name, logName);
try
{
2014-06-09 12:16:14 -07:00
refreshResult.UpdateType = refreshResult.UpdateType | await provider.FetchAsync(item, options, cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
2014-10-13 21:22:17 -07:00
refreshResult.Status = ProviderRefreshStatus.Failure;
refreshResult.ErrorMessage = ex.Message;
Logger.ErrorException("Error in {0}", ex, provider.Name);
}
}
2014-02-02 06:36:31 -07:00
protected virtual TItemType CreateNew()
{
return new TItemType();
}
2014-01-30 14:23:54 -07:00
2014-09-28 13:49:43 -07:00
private async Task<RefreshResult> ExecuteRemoteProviders(TItemType item, TItemType temp, string logName, TIdType id, IEnumerable<IRemoteMetadataProvider<TItemType, TIdType>> providers, CancellationToken cancellationToken)
{
var refreshResult = new RefreshResult();
foreach (var provider in providers)
{
var providerName = provider.GetType().Name;
2014-09-28 13:49:43 -07:00
Logger.Debug("Running {0} for {1}", providerName, logName);
if (id != null)
2014-02-08 13:02:35 -07:00
{
MergeNewData(temp, id);
}
2014-02-06 20:10:13 -07:00
try
{
var result = await provider.GetMetadata(id, cancellationToken).ConfigureAwait(false);
if (result.HasMetadata)
{
2014-09-22 14:56:54 -07:00
NormalizeRemoteResult(result.Item);
MergeData(result.Item, temp, new List<MetadataFields>(), false, false);
refreshResult.UpdateType = refreshResult.UpdateType | ItemUpdateType.MetadataDownload;
refreshResult.Successes++;
}
else
{
refreshResult.Failures++;
2014-09-28 13:49:43 -07:00
Logger.Debug("{0} returned no metadata for {1}", providerName, logName);
}
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
refreshResult.Failures++;
refreshResult.Status = ProviderRefreshStatus.CompletedWithErrors;
refreshResult.ErrorMessage = ex.Message;
Logger.ErrorException("Error in {0}", ex, provider.Name);
}
}
return refreshResult;
}
2014-09-22 14:56:54 -07:00
private void NormalizeRemoteResult(TItemType item)
{
if (!ServerConfigurationManager.Configuration.FindInternetTrailers)
{
var hasTrailers = item as IHasTrailers;
if (hasTrailers != null)
{
hasTrailers.RemoteTrailers.Clear();
}
}
}
private async Task<TIdType> CreateInitialLookupInfo(TItemType item, CancellationToken cancellationToken)
{
var info = item.GetLookupInfo();
var hasIdentity = info as IHasIdentities<IItemIdentity>;
if (hasIdentity != null)
{
2014-08-17 08:38:19 -07:00
try
{
await hasIdentity.FindIdentities(ProviderManager, cancellationToken).ConfigureAwait(false);
2014-08-17 08:38:19 -07:00
}
catch (Exception ex)
{
Logger.ErrorException("Error in identity providers", ex);
}
}
return info;
}
2014-02-08 13:02:35 -07:00
private void MergeNewData(TItemType source, TIdType lookupInfo)
{
// Copy new provider id's that may have been obtained
foreach (var providerId in source.ProviderIds)
{
2014-02-12 22:11:54 -07:00
var key = providerId.Key;
// Don't replace existing Id's.
if (!lookupInfo.ProviderIds.ContainsKey(key))
{
lookupInfo.ProviderIds[key] = providerId.Value;
}
2014-02-08 13:02:35 -07:00
}
}
2015-01-28 14:29:02 -07:00
protected abstract void MergeData(TItemType source,
TItemType target,
List<MetadataFields> lockedFields,
bool replaceData,
2014-10-28 16:17:55 -07:00
bool mergeMetadataSettings);
public virtual int Order
{
get
{
return 0;
}
}
2014-02-13 21:00:13 -07:00
2014-09-10 18:57:11 -07:00
private bool HasChanged(IHasMetadata item, IHasItemChangeMonitor changeMonitor, MetadataStatus status, IDirectoryService directoryService)
{
try
{
return changeMonitor.HasChanged(item, status, directoryService);
}
catch (Exception ex)
{
Logger.ErrorException("Error in {0}.HasChanged", ex, changeMonitor.GetType().Name);
return false;
}
}
2014-02-13 21:00:13 -07:00
private bool HasChanged(IHasMetadata item, IHasChangeMonitor changeMonitor, DateTime date, IDirectoryService directoryService)
{
try
{
return changeMonitor.HasChanged(item, directoryService, date);
}
catch (Exception ex)
{
Logger.ErrorException("Error in {0}.HasChanged", ex, changeMonitor.GetType().Name);
return false;
}
}
}
public class RefreshResult
{
public ItemUpdateType UpdateType { get; set; }
public ProviderRefreshStatus Status { get; set; }
public string ErrorMessage { get; set; }
2014-01-28 22:17:58 -07:00
public List<Guid> Providers { get; set; }
public int Successes { get; set; }
public int Failures { get; set; }
}
}