From 6d407033ce3be15a5db502d4087f1bd49d49efdd Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 5 Sep 2013 13:05:39 -0400 Subject: fixes #519 - Add third wizard page --- .../Library/LibraryStructureService.cs | 83 +++++++++++++++++++--- 1 file changed, 72 insertions(+), 11 deletions(-) (limited to 'MediaBrowser.Api/Library/LibraryStructureService.cs') diff --git a/MediaBrowser.Api/Library/LibraryStructureService.cs b/MediaBrowser.Api/Library/LibraryStructureService.cs index ac2a10924..68ef58a9d 100644 --- a/MediaBrowser.Api/Library/LibraryStructureService.cs +++ b/MediaBrowser.Api/Library/LibraryStructureService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller; +using System.Threading.Tasks; +using MediaBrowser.Controller; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Entities; @@ -45,6 +46,12 @@ namespace MediaBrowser.Api.Library /// /// The type of the collection. public string CollectionType { get; set; } + + /// + /// Gets or sets a value indicating whether [refresh library]. + /// + /// true if [refresh library]; otherwise, false. + public bool RefreshLibrary { get; set; } } [Route("/Library/VirtualFolders/{Name}", "DELETE")] @@ -62,6 +69,12 @@ namespace MediaBrowser.Api.Library /// /// The name. public string Name { get; set; } + + /// + /// Gets or sets a value indicating whether [refresh library]. + /// + /// true if [refresh library]; otherwise, false. + public bool RefreshLibrary { get; set; } } [Route("/Library/VirtualFolders/{Name}/Name", "POST")] @@ -85,6 +98,12 @@ namespace MediaBrowser.Api.Library /// /// The name. public string NewName { get; set; } + + /// + /// Gets or sets a value indicating whether [refresh library]. + /// + /// true if [refresh library]; otherwise, false. + public bool RefreshLibrary { get; set; } } [Route("/Library/VirtualFolders/{Name}/Paths", "POST")] @@ -108,6 +127,12 @@ namespace MediaBrowser.Api.Library /// /// The name. public string Path { get; set; } + + /// + /// Gets or sets a value indicating whether [refresh library]. + /// + /// true if [refresh library]; otherwise, false. + public bool RefreshLibrary { get; set; } } [Route("/Library/VirtualFolders/{Name}/Paths", "DELETE")] @@ -131,6 +156,12 @@ namespace MediaBrowser.Api.Library /// /// The name. public string Path { get; set; } + + /// + /// Gets or sets a value indicating whether [refresh library]. + /// + /// true if [refresh library]; otherwise, false. + public bool RefreshLibrary { get; set; } } /// @@ -202,7 +233,7 @@ namespace MediaBrowser.Api.Library /// Posts the specified request. /// /// The request. - public void Post(AddVirtualFolder request) + public async void Post(AddVirtualFolder request) { _directoryWatchers.Stop(); @@ -218,20 +249,26 @@ namespace MediaBrowser.Api.Library LibraryHelpers.AddVirtualFolder(request.Name, request.CollectionType, user, _appPaths); } + + // Need to add a delay here or directory watchers may still pick up the changes + await Task.Delay(1000).ConfigureAwait(false); } finally { _directoryWatchers.Start(); } - _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None); + if (request.RefreshLibrary) + { + _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None); + } } /// /// Posts the specified request. /// /// The request. - public void Post(RenameVirtualFolder request) + public async void Post(RenameVirtualFolder request) { _directoryWatchers.Stop(); @@ -247,20 +284,26 @@ namespace MediaBrowser.Api.Library LibraryHelpers.RenameVirtualFolder(request.Name, request.NewName, user, _appPaths); } + + // Need to add a delay here or directory watchers may still pick up the changes + await Task.Delay(1000).ConfigureAwait(false); } finally { _directoryWatchers.Start(); } - _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None); + if (request.RefreshLibrary) + { + _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None); + } } /// /// Deletes the specified request. /// /// The request. - public void Delete(RemoveVirtualFolder request) + public async void Delete(RemoveVirtualFolder request) { _directoryWatchers.Stop(); @@ -276,20 +319,26 @@ namespace MediaBrowser.Api.Library LibraryHelpers.RemoveVirtualFolder(request.Name, user, _appPaths); } + + // Need to add a delay here or directory watchers may still pick up the changes + await Task.Delay(1000).ConfigureAwait(false); } finally { _directoryWatchers.Start(); } - _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None); + if (request.RefreshLibrary) + { + _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None); + } } /// /// Posts the specified request. /// /// The request. - public void Post(AddMediaPath request) + public async void Post(AddMediaPath request) { _directoryWatchers.Stop(); @@ -305,20 +354,26 @@ namespace MediaBrowser.Api.Library LibraryHelpers.AddMediaPath(request.Name, request.Path, user, _appPaths); } + + // Need to add a delay here or directory watchers may still pick up the changes + await Task.Delay(1000).ConfigureAwait(false); } finally { _directoryWatchers.Start(); } - _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None); + if (request.RefreshLibrary) + { + _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None); + } } /// /// Deletes the specified request. /// /// The request. - public void Delete(RemoveMediaPath request) + public async void Delete(RemoveMediaPath request) { _directoryWatchers.Stop(); @@ -334,13 +389,19 @@ namespace MediaBrowser.Api.Library LibraryHelpers.RemoveMediaPath(request.Name, request.Path, user, _appPaths); } + + // Need to add a delay here or directory watchers may still pick up the changes + await Task.Delay(1000).ConfigureAwait(false); } finally { _directoryWatchers.Start(); } - _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None); + if (request.RefreshLibrary) + { + _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None); + } } } } -- cgit v1.2.3