/// <summary> /// Posts the specified request. /// </summary> /// <param name="request">The request.</param> public async void Post(AddVirtualFolder request) { _directoryWatchers.Stop(); try { if (string.IsNullOrEmpty(request.UserId)) { LibraryHelpers.AddVirtualFolder(request.Name, request.CollectionType, null, _appPaths); } else { var user = _userManager.GetUserById(new Guid(request.UserId)); 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(); } 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(AddVirtualFolder request) { var name = _fileSystem.GetValidFilename(request.Name); string rootFolderPath; if (string.IsNullOrEmpty(request.UserId)) { rootFolderPath = _appPaths.DefaultUserViewsPath; } else { var user = _userManager.GetUserById(new Guid(request.UserId)); rootFolderPath = user.RootFolderPath; } var virtualFolderPath = Path.Combine(rootFolderPath, name); if (Directory.Exists(virtualFolderPath)) { throw new ArgumentException("There is already a media collection with the name " + name + "."); } _directoryWatchers.Stop(); _directoryWatchers.TemporarilyIgnore(virtualFolderPath); try { Directory.CreateDirectory(virtualFolderPath); if (!string.IsNullOrEmpty(request.CollectionType)) { var path = Path.Combine(virtualFolderPath, request.CollectionType + ".collection"); File.Create(path); } // 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(virtualFolderPath); } 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(AddVirtualFolder request) { if (string.IsNullOrWhiteSpace(request.Name)) { throw new ArgumentNullException("request"); } var name = _fileSystem.GetValidFilename(request.Name); var rootFolderPath = _appPaths.DefaultUserViewsPath; var virtualFolderPath = Path.Combine(rootFolderPath, name); if (Directory.Exists(virtualFolderPath)) { throw new ArgumentException("There is already a media collection with the name " + name + "."); } _libraryMonitor.Stop(); try { Directory.CreateDirectory(virtualFolderPath); if (!string.IsNullOrEmpty(request.CollectionType)) { var path = Path.Combine(virtualFolderPath, request.CollectionType + ".collection"); File.Create(path); } } 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(AddVirtualFolder request) { if (string.IsNullOrEmpty(request.UserId)) { LibraryHelpers.AddVirtualFolder(request.Name, null, _appPaths); } else { var user = _userManager.GetUserById(new Guid(request.UserId)); LibraryHelpers.AddVirtualFolder(request.Name, user, _appPaths); } }
/// <summary> /// Posts the specified request. /// </summary> /// <param name="request">The request.</param> public Task Post(AddVirtualFolder request) { var libraryOptions = request.LibraryOptions ?? new LibraryOptions(); if (request.Paths != null && request.Paths.Length > 0) { libraryOptions.PathInfos = request.Paths.Select(i => new MediaPathInfo { Path = i }).ToArray(); } return(_libraryManager.AddVirtualFolder(request.Name, request.CollectionType, libraryOptions, request.RefreshLibrary)); }
/// <summary> /// Posts the specified request. /// </summary> /// <param name="request">The request.</param> public void Post(AddVirtualFolder request) { if (string.IsNullOrEmpty(request.UserId)) { LibraryHelpers.AddVirtualFolder(request.Name, request.CollectionType, null, _appPaths); } else { var user = _userManager.GetUserById(new Guid(request.UserId)); LibraryHelpers.AddVirtualFolder(request.Name, request.CollectionType, user, _appPaths); } _libraryManager.ValidateMediaLibrary(new Progress <double>(), CancellationToken.None); }
/// <summary> /// Posts the specified request. /// </summary> /// <param name="request">The request.</param> public void Post(AddVirtualFolder request) { _libraryManager.AddVirtualFolder(request.Name, request.CollectionType, request.Paths, request.RefreshLibrary); }
/// <summary> /// Posts the specified request. /// </summary> /// <param name="request">The request.</param> public void Post(AddVirtualFolder request) { if (string.IsNullOrWhiteSpace(request.Name)) { throw new ArgumentNullException("request"); } var name = _fileSystem.GetValidFilename(request.Name); var rootFolderPath = _appPaths.DefaultUserViewsPath; var virtualFolderPath = Path.Combine(rootFolderPath, name); while (_fileSystem.DirectoryExists(virtualFolderPath)) { name += "1"; virtualFolderPath = Path.Combine(rootFolderPath, name); } if (request.Paths != null) { var invalidpath = request.Paths.FirstOrDefault(i => !_fileSystem.DirectoryExists(i)); if (invalidpath != null) { throw new ArgumentException("The specified path does not exist: " + invalidpath + "."); } } _libraryMonitor.Stop(); try { _fileSystem.CreateDirectory(virtualFolderPath); if (!string.IsNullOrEmpty(request.CollectionType)) { var path = Path.Combine(virtualFolderPath, request.CollectionType + ".collection"); using (File.Create(path)) { } } if (request.Paths != null) { foreach (var path in request.Paths) { LibraryHelpers.AddMediaPath(_fileSystem, name, path, _appPaths); } } } 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(AddVirtualFolder request) { var libraryOptions = request.LibraryOptions ?? new LibraryOptions(); _libraryManager.AddVirtualFolder(request.Name, request.CollectionType, request.Paths, libraryOptions, request.RefreshLibrary); }