/// <summary> /// Posts the specified request. /// </summary> /// <param name="request">The request.</param> public async void Post(RenameVirtualFolder request) { _directoryWatchers.Stop(); try { if (string.IsNullOrEmpty(request.UserId)) { LibraryHelpers.RenameVirtualFolder(request.Name, request.NewName, null, _appPaths); } else { var user = _userManager.GetUserById(new Guid(request.UserId)); 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(); } if (request.RefreshLibrary) { _libraryManager.ValidateMediaLibrary(new Progress <double>(), CancellationToken.None); } }
/// <summary> /// Posts the specified request. /// </summary> /// <param name="request">The request.</param> public void Post(RenameVirtualFolder request) { if (string.IsNullOrEmpty(request.UserId)) { LibraryHelpers.RenameVirtualFolder(request.Name, request.NewName, null, _appPaths); } else { var user = _userManager.GetUserById(new Guid(request.UserId)); LibraryHelpers.RenameVirtualFolder(request.Name, request.NewName, user, _appPaths); } }
/// <summary> /// Posts the specified request. /// </summary> /// <param name="request">The request.</param> public void Post(RenameVirtualFolder request) { if (string.IsNullOrEmpty(request.UserId)) { LibraryHelpers.RenameVirtualFolder(request.Name, request.NewName, null, _appPaths); } else { var user = _userManager.GetUserById(new Guid(request.UserId)); LibraryHelpers.RenameVirtualFolder(request.Name, request.NewName, user, _appPaths); } _libraryManager.ValidateMediaLibrary(new Progress <double>(), CancellationToken.None); }
/// <summary> /// Posts the specified request. /// </summary> /// <param name="request">The request.</param> public void Post(RenameVirtualFolder request) { if (string.IsNullOrWhiteSpace(request.Name)) { throw new ArgumentNullException(nameof(request)); } if (string.IsNullOrWhiteSpace(request.NewName)) { throw new ArgumentNullException(nameof(request)); } var rootFolderPath = _appPaths.DefaultUserViewsPath; var currentPath = Path.Combine(rootFolderPath, request.Name); var newPath = Path.Combine(rootFolderPath, request.NewName); if (!Directory.Exists(currentPath)) { throw new FileNotFoundException("The media collection does not exist"); } if (!string.Equals(currentPath, newPath, StringComparison.OrdinalIgnoreCase) && Directory.Exists(newPath)) { throw new ArgumentException("Media library already exists at " + newPath + "."); } _libraryMonitor.Stop(); try { // Changing capitalization. Handle windows case insensitivity if (string.Equals(currentPath, newPath, StringComparison.OrdinalIgnoreCase)) { var tempPath = Path.Combine(rootFolderPath, Guid.NewGuid().ToString("N")); Directory.Move(currentPath, tempPath); currentPath = tempPath; } Directory.Move(currentPath, newPath); } finally { CollectionFolder.OnCollectionFolderChange(); Task.Run(() => { // No need to start if scanning the library because it will handle it if (request.RefreshLibrary) { _libraryManager.ValidateMediaLibrary(new SimpleProgress <double>(), CancellationToken.None); } else { // Need to add a delay here or directory watchers may still pick up the changes var task = Task.Delay(1000); // Have to block here to allow exceptions to bubble Task.WaitAll(task); _libraryMonitor.Start(); } }); } }
/// <summary> /// Posts the specified request. /// </summary> /// <param name="request">The request.</param> public void Post(RenameVirtualFolder request) { if (string.IsNullOrWhiteSpace(request.Name)) { throw new ArgumentNullException("request"); } if (string.IsNullOrWhiteSpace(request.NewName)) { throw new ArgumentNullException("request"); } var rootFolderPath = _appPaths.DefaultUserViewsPath; var currentPath = Path.Combine(rootFolderPath, request.Name); var newPath = Path.Combine(rootFolderPath, request.NewName); if (!_fileSystem.DirectoryExists(currentPath)) { throw new DirectoryNotFoundException("The media collection does not exist"); } if (!string.Equals(currentPath, newPath, StringComparison.OrdinalIgnoreCase) && _fileSystem.DirectoryExists(newPath)) { throw new ArgumentException("There is already a media collection with the name " + newPath + "."); } _libraryMonitor.Stop(); try { // Only make a two-phase move when changing capitalization if (string.Equals(currentPath, newPath, StringComparison.OrdinalIgnoreCase)) { //Create an unique name var temporaryName = Guid.NewGuid().ToString(); var temporaryPath = Path.Combine(rootFolderPath, temporaryName); _fileSystem.MoveDirectory(currentPath, temporaryPath); currentPath = temporaryPath; } _fileSystem.MoveDirectory(currentPath, newPath); } finally { Task.Run(() => { // No need to start if scanning the library because it will handle it if (request.RefreshLibrary) { _libraryManager.ValidateMediaLibrary(new Progress <double>(), CancellationToken.None); } else { // Need to add a delay here or directory watchers may still pick up the changes var task = Task.Delay(1000); // Have to block here to allow exceptions to bubble Task.WaitAll(task); _libraryMonitor.Start(); } }); } }
/// <summary> /// Posts the specified request. /// </summary> /// <param name="request">The request.</param> public void Post(RenameVirtualFolder request) { string rootFolderPath; if (string.IsNullOrEmpty(request.UserId)) { rootFolderPath = _appPaths.DefaultUserViewsPath; } else { var user = _userManager.GetUserById(new Guid(request.UserId)); rootFolderPath = user.RootFolderPath; } var currentPath = Path.Combine(rootFolderPath, request.Name); var newPath = Path.Combine(rootFolderPath, request.NewName); if (!Directory.Exists(currentPath)) { throw new DirectoryNotFoundException("The media collection does not exist"); } if (!string.Equals(currentPath, newPath, StringComparison.OrdinalIgnoreCase) && Directory.Exists(newPath)) { throw new ArgumentException("There is already a media collection with the name " + newPath + "."); } _directoryWatchers.Stop(); _directoryWatchers.TemporarilyIgnore(currentPath); _directoryWatchers.TemporarilyIgnore(newPath); try { // Only make a two-phase move when changing capitalization if (string.Equals(currentPath, newPath, StringComparison.OrdinalIgnoreCase)) { //Create an unique name var temporaryName = Guid.NewGuid().ToString(); var temporaryPath = Path.Combine(rootFolderPath, temporaryName); Directory.Move(currentPath, temporaryPath); currentPath = temporaryPath; } Directory.Move(currentPath, newPath); // Need to add a delay here or directory watchers may still pick up the changes var task = Task.Delay(1000); // Have to block here to allow exceptions to bubble Task.WaitAll(task); } finally { _directoryWatchers.Start(); _directoryWatchers.RemoveTempIgnore(currentPath); _directoryWatchers.RemoveTempIgnore(newPath); } if (request.RefreshLibrary) { _libraryManager.ValidateMediaLibrary(new Progress <double>(), CancellationToken.None); } }