Example #1
0
        private int StartCommand(CommandResource commandResource)
        {
            var commandType =
                _container.GetImplementations(typeof(Command))
                .Single(c => c.Name.Replace("Command", "")
                        .Equals(commandResource.Name, StringComparison.InvariantCultureIgnoreCase));

            dynamic command = Request.Body.FromJson(commandType);

            var trackedCommand = (Command)_commandExecutor.PublishCommandAsync(command);

            return(trackedCommand.Id);
        }
Example #2
0
        public void HandleAsync(DownloadFailedEvent message)
        {
            if (!_configService.AutoRedownloadFailed)
            {
                _logger.Debug("Auto redownloading failed episodes is disabled");
                return;
            }

            if (message.EpisodeIds.Count == 1)
            {
                _logger.Debug("Failed download only contains one episode, searching again");

                _commandExecutor.PublishCommandAsync(new EpisodeSearchCommand(message.EpisodeIds));

                return;
            }

            var seasonNumber     = _episodeService.GetEpisode(message.EpisodeIds.First()).SeasonNumber;
            var episodesInSeason = _episodeService.GetEpisodesBySeason(message.SeriesId, seasonNumber);

            if (message.EpisodeIds.Count == episodesInSeason.Count)
            {
                _logger.Debug("Failed download was entire season, searching again");

                _commandExecutor.PublishCommandAsync(new SeasonSearchCommand
                {
                    SeriesId     = message.SeriesId,
                    SeasonNumber = seasonNumber
                });

                return;
            }

            _logger.Debug("Failed download contains multiple episodes, probably a double episode, searching again");

            _commandExecutor.PublishCommandAsync(new EpisodeSearchCommand(message.EpisodeIds));
        }