support refreshing collection folders through the api

This commit is contained in:
Luke Pulverenti 2013-06-28 20:49:44 -04:00
parent 088d04392f
commit a018d28b12
2 changed files with 35 additions and 16 deletions

View File

@ -785,19 +785,7 @@ namespace MediaBrowser.Api.Images
await _providerManager.SaveImage(entity, memoryStream, mimeType, imageType, imageIndex, CancellationToken.None).ConfigureAwait(false); await _providerManager.SaveImage(entity, memoryStream, mimeType, imageType, imageIndex, CancellationToken.None).ConfigureAwait(false);
var user = entity as User; await entity.RefreshMetadata(CancellationToken.None, forceRefresh: true, forceSave: true, allowSlowProviders: false).ConfigureAwait(false);
if (user != null)
{
await _userManager.UpdateUser(user).ConfigureAwait(false);
}
else
{
await _libraryManager.UpdateItem(entity, ItemUpdateType.ImageUpdate, CancellationToken.None)
.ConfigureAwait(false);
}
await entity.RefreshMetadata(CancellationToken.None, allowSlowProviders: false).ConfigureAwait(false);
} }
} }
} }

View File

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Dto; using System.Linq;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using ServiceStack.ServiceHost; using ServiceStack.ServiceHost;
@ -221,8 +222,17 @@ namespace MediaBrowser.Api
if (folder != null) if (folder != null)
{ {
await folder.ValidateChildren(new Progress<double>(), CancellationToken.None, request.Recursive, // Collection folders don't validate their children so we'll have to simulate that here
request.Forced).ConfigureAwait(false); var collectionFolder = folder as CollectionFolder;
if (collectionFolder != null)
{
await RefreshCollectionFolderChildren(request, collectionFolder).ConfigureAwait(false);
}
else
{
await folder.ValidateChildren(new Progress<double>(), CancellationToken.None, request.Recursive, request.Forced).ConfigureAwait(false);
}
} }
} }
catch (Exception ex) catch (Exception ex)
@ -230,5 +240,26 @@ namespace MediaBrowser.Api
Logger.ErrorException("Error refreshing library", ex); Logger.ErrorException("Error refreshing library", ex);
} }
} }
/// <summary>
/// Refreshes the collection folder children.
/// </summary>
/// <param name="request">The request.</param>
/// <param name="collectionFolder">The collection folder.</param>
/// <returns>Task.</returns>
private async Task RefreshCollectionFolderChildren(RefreshItem request, CollectionFolder collectionFolder)
{
foreach (var child in collectionFolder.Children.ToList())
{
await child.RefreshMetadata(CancellationToken.None, forceRefresh: request.Forced).ConfigureAwait(false);
var folder = child as Folder;
if (folder != null)
{
await folder.ValidateChildren(new Progress<double>(), CancellationToken.None, request.Recursive, request.Forced).ConfigureAwait(false);
}
}
}
} }
} }