예제 #1
0
        /// <summary>
        /// Posts the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        public 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);
                }
            }
            finally
            {
                _directoryWatchers.Start();
            }

            _libraryManager.ValidateMediaLibrary(new Progress <double>(), CancellationToken.None);
        }
예제 #2
0
        /// <summary>
        /// Deletes the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        public void Delete(RemoveMediaPath request)
        {
            _directoryWatchers.Stop();

            try
            {
                if (string.IsNullOrEmpty(request.UserId))
                {
                    LibraryHelpers.RemoveMediaPath(request.Name, request.Path, null, _appPaths);
                }
                else
                {
                    var user = _userManager.GetUserById(new Guid(request.UserId));

                    LibraryHelpers.RemoveMediaPath(request.Name, request.Path, user, _appPaths);
                }
            }
            finally
            {
                _directoryWatchers.Start();
            }

            _libraryManager.ValidateMediaLibrary(new Progress <double>(), CancellationToken.None);
        }
예제 #3
0
        /// <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();
                    }
                });
            }
        }