예제 #1
0
 public override Task UnregisterClientAsync()
 {
     OperationalClient = null;
     ComponentState    = BotApiComponentState.CreateUnregistered();
     _logger.LogInformation("Fake Bot API Client unregistered.");
     return(Task.CompletedTask);
 }
예제 #2
0
 public override async Task RegisterClientAsync()
 {
     try
     {
         var operationalClientSettings = new FakeOperationalClient.Settings
         {
             Token = _token,
             EmulateRecurrentExceptions        = _emulateRecurrentExceptions,
             RecurrentExceptionDifficultyClass = _recurrentExceptionDifficultyClass
         };
         OperationalClient = new FakeOperationalClient(_operationalClientEmulatedState, operationalClientSettings);
         if (!await OperationalClient.ValidateClientAsync())
         {
             HandleClientInitializationFailed($"Fake Bot API Client registration failed, the token ({OperationalClient.Token.Bar()}) is invalid.");
             return;
         }
         ComponentState = BotApiComponentState.CreateRegistered();
         _logger.LogInformation("Fake Bot API Client registered.");
     }
     catch (Exception e)
     {
         const string errorMessage = "Fake Bot API Client registration failed, an exception has occurred";
         HandleClientInitializationFailed($"{errorMessage}: {e.Message}", $"{errorMessage}.{Environment.NewLine}{e}");
     }
 }
예제 #3
0
        private void AbortPollingUpdates()
        {
            _updatesPollingTimer.Change(Timeout.Infinite, Timeout.Infinite);
            var errorMessage = $"Fake Bot API Poller updates polling stopped, the Fake Bot API Client ({_botApiClient.ComponentState.FooBar()}) cannot be consumed.";

            ComponentState = BotApiComponentState.CreateError(errorMessage);
            _logger.LogError(errorMessage);
        }
예제 #4
0
 public override void RegisterPoller()
 {
     if (_botApiClient.CanConsumeOperationalClient)
     {
         _updatesPollingTimer.Change(TimeSpan.Zero, _timerInterval);
         ComponentState = BotApiComponentState.CreateRegistered();
         _logger.LogInformation("Fake Bot API Poller registered.");
     }
     else
     {
         var errorMessage = $"Fake Bot API Poller registration failed, the Fake Bot API Client ({_botApiClient.ComponentState.FooBar()}) cannot be consumed.";
         ComponentState = BotApiComponentState.CreateError(errorMessage);
         _logger.LogError(errorMessage);
     }
 }
예제 #5
0
 private void HandleClientInitializationFailed(string errorStateDescription, string errorMessage)
 {
     OperationalClient = null;
     ComponentState    = BotApiComponentState.CreateError(errorStateDescription);
     _logger.LogError(errorMessage);
 }
예제 #6
0
 public virtual void UnregisterEndpoint()
 {
     ComponentState = BotApiComponentState.CreateUnregistered();
 }
예제 #7
0
 public override void UnregisterPoller()
 {
     _updatesPollingTimer.Change(Timeout.Infinite, Timeout.Infinite);
     ComponentState = BotApiComponentState.CreateUnregistered();
     _logger.LogInformation("Fake Bot API Poller unregistered.");
 }
예제 #8
0
 public static string FooBar(this BotApiComponentState source)
 {
     return(string.IsNullOrEmpty(source.Description) ? source.State.ToString() : $"{source.State} - {source.Description}");
 }