< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.Library.Validators.GenresValidator
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/Library/Validators/GenresValidator.cs
Line coverage
100%
Covered lines: 4
Uncovered lines: 0
Coverable lines: 4
Total lines: 81
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/Library/Validators/GenresValidator.cs

#LineLine coverage
 1using System;
 2using System.Threading;
 3using System.Threading.Tasks;
 4using MediaBrowser.Controller.Library;
 5using MediaBrowser.Controller.Persistence;
 6using Microsoft.Extensions.Logging;
 7
 8namespace Emby.Server.Implementations.Library.Validators
 9{
 10    /// <summary>
 11    /// Class GenresValidator.
 12    /// </summary>
 13    public class GenresValidator
 14    {
 15        /// <summary>
 16        /// The library manager.
 17        /// </summary>
 18        private readonly ILibraryManager _libraryManager;
 19        private readonly IItemRepository _itemRepo;
 20
 21        /// <summary>
 22        /// The logger.
 23        /// </summary>
 24        private readonly ILogger<GenresValidator> _logger;
 25
 26        /// <summary>
 27        /// Initializes a new instance of the <see cref="GenresValidator"/> class.
 28        /// </summary>
 29        /// <param name="libraryManager">The library manager.</param>
 30        /// <param name="logger">The logger.</param>
 31        /// <param name="itemRepo">The item repository.</param>
 32        public GenresValidator(ILibraryManager libraryManager, ILogger<GenresValidator> logger, IItemRepository itemRepo
 33        {
 1934            _libraryManager = libraryManager;
 1935            _logger = logger;
 1936            _itemRepo = itemRepo;
 1937        }
 38
 39        /// <summary>
 40        /// Runs the specified progress.
 41        /// </summary>
 42        /// <param name="progress">The progress.</param>
 43        /// <param name="cancellationToken">The cancellation token.</param>
 44        /// <returns>Task.</returns>
 45        public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
 46        {
 47            var names = _itemRepo.GetGenreNames();
 48
 49            var numComplete = 0;
 50            var count = names.Count;
 51
 52            foreach (var name in names)
 53            {
 54                try
 55                {
 56                    var item = _libraryManager.GetGenre(name);
 57
 58                    await item.RefreshMetadata(cancellationToken).ConfigureAwait(false);
 59                }
 60                catch (OperationCanceledException)
 61                {
 62                    // Don't clutter the log
 63                    throw;
 64                }
 65                catch (Exception ex)
 66                {
 67                    _logger.LogError(ex, "Error refreshing {GenreName}", name);
 68                }
 69
 70                numComplete++;
 71                double percent = numComplete;
 72                percent /= count;
 73                percent *= 100;
 74
 75                progress.Report(percent);
 76            }
 77
 78            progress.Report(100);
 79        }
 80    }
 81}