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