Esempio n. 1
0
 public override Task UnregisterClientAsync()
 {
     OperationalClient = null;
     ComponentState    = BotApiComponentState.CreateUnregistered();
     _logger.LogInformation("Fake Bot API Client unregistered.");
     return(Task.CompletedTask);
 }
Esempio n. 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}");
     }
 }
Esempio n. 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);
        }
Esempio n. 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);
     }
 }
Esempio n. 5
0
 private void HandleClientInitializationFailed(string errorStateDescription, string errorMessage)
 {
     OperationalClient = null;
     ComponentState    = BotApiComponentState.CreateError(errorStateDescription);
     _logger.LogError(errorMessage);
 }
 public virtual void UnregisterEndpoint()
 {
     ComponentState = BotApiComponentState.CreateUnregistered();
 }
Esempio n. 7
0
 public override void UnregisterPoller()
 {
     _updatesPollingTimer.Change(Timeout.Infinite, Timeout.Infinite);
     ComponentState = BotApiComponentState.CreateUnregistered();
     _logger.LogInformation("Fake Bot API Poller unregistered.");
 }
Esempio n. 8
0
 public static string FooBar(this BotApiComponentState source)
 {
     return(string.IsNullOrEmpty(source.Description) ? source.State.ToString() : $"{source.State} - {source.Description}");
 }