Exemple #1
0
 public TvShowNotificationEngine(
     ITvShowSearcher tvShowSearcher,
     ITvShowNotifier notifier,
     ILogger <ChatBot> logger,
     TvShowNotificationsRepository notificationRequestRepository)
 {
     _tvShowSearcher = tvShowSearcher;
     _notifier       = notifier;
     _logger         = logger;
     _notificationRequestRepository = notificationRequestRepository;
 }
Exemple #2
0
        public TvShowNotificationEngine CreateTvShowNotificationEngine(DiscordClient client, ILogger logger)
        {
            var settings = _settingsProvider.Provide();

            ITvShowNotifier tvShowNotifier = null;

            if (settings.NotificationMode == NotificationMode.PrivateMessage)
            {
                tvShowNotifier = new PrivateMessageTvShowNotifier(client, _settingsProvider, logger);
            }
            else if (settings.NotificationMode == NotificationMode.Channels)
            {
                tvShowNotifier = new ChannelTvShowNotifier(client, _settingsProvider, settings.NotificationChannels.Select(x => ulong.Parse(x)).ToArray(), logger);
            }
            else
            {
                throw new Exception($"Could not create tv show notifier of type \"{settings.NotificationMode}\"");
            }

            return(new TvShowNotificationEngine(GetTvShowClient <ITvShowSearcher>(settings), tvShowNotifier, logger, _notificationsRepository));
        }
Exemple #3
0
        private async Task Connected()
        {
            try
            {
                if (_movieNotificationEngine != null)
                {
                    await _movieNotificationEngine.StopAsync();
                }

                if (_currentSettings.MovieDownloadClient != DownloadClient.Disabled && _currentSettings.NotificationMode != NotificationMode.Disabled)
                {
                    IMovieNotifier movieNotifier = null;

                    if (_currentSettings.NotificationMode == NotificationMode.PrivateMessage)
                    {
                        movieNotifier = new PrivateMessageMovieNotifier(_client, _logger);
                    }
                    else if (_currentSettings.NotificationMode == NotificationMode.Channels)
                    {
                        movieNotifier = new ChannelMovieNotifier(_client, _currentSettings.NotificationChannels, _logger);
                    }
                    else
                    {
                        throw new Exception($"Could not create movie notifier of type \"{_currentSettings.NotificationMode}\"");
                    }

                    _movieNotificationEngine = new MovieNotificationEngine(GetMovieClient <IMovieSearcher>(_currentSettings), movieNotifier, _logger, _movieNotificationRequestRepository);
                    _movieNotificationEngine.Start();
                }
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex, "Error while starting movie notification engine: " + ex.Message);
            }

            try
            {
                if (_tvShowNotificationEngine != null)
                {
                    await _tvShowNotificationEngine.StopAsync();
                }

                if (_currentSettings.TvShowDownloadClient != DownloadClient.Disabled && _currentSettings.NotificationMode != NotificationMode.Disabled)
                {
                    ITvShowNotifier tvShowNotifier = null;

                    if (_currentSettings.NotificationMode == NotificationMode.PrivateMessage)
                    {
                        tvShowNotifier = new PrivateMessageTvShowNotifier(_client, _logger);
                    }
                    else if (_currentSettings.NotificationMode == NotificationMode.Channels)
                    {
                        tvShowNotifier = new ChannelTvShowNotifier(_client, _currentSettings.NotificationChannels, _logger);
                    }
                    else
                    {
                        throw new Exception($"Could not create tv show notifier of type \"{_currentSettings.NotificationMode}\"");
                    }

                    _tvShowNotificationEngine = new TvShowNotificationEngine(GetTvShowClient <ITvShowSearcher>(_currentSettings), tvShowNotifier, _logger, _tvShowNotificationRequestRepository);
                    _tvShowNotificationEngine.Start();
                }
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex, "Error while starting tv show notification engine: " + ex.Message);
            }
        }