Exemplo n.º 1
0
 public Account ToAccount(ILibraryManager libraryManager, IUserManager userManager)
 {
     return(new Account
     {
         Library = libraryManager.Get(new SqlId(LibraryId)),
         User = userManager.Get(new SqlId(UserId)),
         Id = new SqlId(Id)
     });
 }
Exemplo n.º 2
0
        /// <inheritdoc />
        public async Task Run(TaskParameters arguments, IProgress <float> progress, CancellationToken cancellationToken)
        {
            string path = arguments["path"].As <string>();

            try
            {
                progress.Report(0);
                Track track = await _identifier.IdentifyTrack(path);

                progress.Report(25);

                if (track.Episode == null)
                {
                    throw new TaskFailedException($"No episode identified for the track at {path}");
                }
                if (track.Episode.ID == 0)
                {
                    if (track.Episode.Slug != null)
                    {
                        track.Episode = await _libraryManager.Get <Episode>(track.Episode.Slug);
                    }
                    else if (track.Episode.Path != null)
                    {
                        track.Episode = await _libraryManager.GetOrDefault <Episode>(x => x.Path.StartsWith(track.Episode.Path));

                        if (track.Episode == null)
                        {
                            throw new TaskFailedException($"No episode found for the track at: {path}.");
                        }
                    }
                    else
                    {
                        throw new TaskFailedException($"No episode identified for the track at {path}");
                    }
                }

                progress.Report(50);
                await _libraryManager.Create(track);

                progress.Report(100);
            }
            catch (IdentificationFailedException ex)
            {
                throw new TaskFailedException(ex);
            }
        }