Example #1
0
        /// <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);
            }
        }
Example #2
0
        /// <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);
            }
        }
Example #3
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);
        }