示例#1
0
        /// <summary>
        /// Posts the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        public void Post(AddMediaPath request)
        {
            if (string.IsNullOrWhiteSpace(request.Name))
            {
                throw new ArgumentNullException("request");
            }

            _libraryMonitor.Stop();

            try
            {
                _libraryManager.AddMediaPath(request.Name, request.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();
                    }
                });
            }
        }
示例#2
0
        public ActionResult AddMediaPath(
            [FromBody, Required] MediaPathDto mediaPathDto,
            [FromQuery] bool refreshLibrary = false)
        {
            _libraryMonitor.Stop();

            try
            {
                var mediaPath = mediaPathDto.PathInfo ?? new MediaPathInfo {
                    Path = mediaPathDto.Path
                };

                _libraryManager.AddMediaPath(mediaPathDto.Name, mediaPath);
            }
            finally
            {
                Task.Run(async() =>
                {
                    // No need to start if scanning the library because it will handle it
                    if (refreshLibrary)
                    {
                        await _libraryManager.ValidateMediaLibrary(new SimpleProgress <double>(), CancellationToken.None).ConfigureAwait(false);
                    }
                    else
                    {
                        // Need to add a delay here or directory watchers may still pick up the changes
                        // Have to block here to allow exceptions to bubble
                        await Task.Delay(1000).ConfigureAwait(false);
                        _libraryMonitor.Start();
                    }
                });
            }

            return(NoContent());
        }