private void RequireState(PollState state) { if (_activePoll.State != state) { throw new Exception($"State assertion failed. {state} state required. Current state: {_activePoll.State}"); } }
public async Task When_Polling_Results_In_An_Http_Error_The_Returned_PollState_Has_Delay_Set_To_The_Specified_Http_Error_Delay() { // Given: uint httpErrorDelay = 12345; var pollingPolicy = PollingDelays.DefaultPollingErrorDelays; pollingPolicy[HttpChannelPoller.PollingError.ErrorMakingHttpRequest] = httpErrorDelay; var testResponses = new List <Either <HttpError, string> >() { new Either <HttpError, string>(new HttpError(HttpStatusCode.BadRequest)) }; Func <string, Either <DeserializeError, TransportMessage> > deserializeTransportMessage = s => TransportMessageDeserializer.Deserialize(s, new Dictionary <string, Type> { { TestMessage.MessageName, typeof(TestMessage) } }); var initialPollState = BasicInitialPollState(pollingPolicy); // When: PollState newPollStateTask = await MessageEndpointPoller.Execute( initialPollState, new TestHttpService(testResponses), new CancellationToken(), GetHandlerForMessageType, deserializeTransportMessage); // Then Assert.NotNull(newPollStateTask); Assert.AreEqual(httpErrorDelay, newPollStateTask.DelayMs); }
public Poll SetPollState(long pollId, PollState pollState) { if (pollState == PollState.Cancelled || pollState == PollState.Completed) { _castedVotes.Remove(pollId); } else if (pollState == PollState.Started) { _castedVotes.Add(pollId, new ConcurrentDictionary <IKey, TaskCompletionSource <bool> >(new Key32())); } _dataAccessService.SetPollState(pollId, (int)pollState); return(FetchPoll(pollId)); }
/// <summary> /// Broadcasts the polls state of all clients. /// </summary> /// <param name="pollState">Poll state to broadcast.</param> private static void BroadcastPollStateChange(PollState pollState) { var clients = GetClients(); switch (pollState) { case PollState.Open: clients.pollOpened(); break; case PollState.Closed: clients.pollClosed(); break; case PollState.Reset: clients.pollReset(); break; default: break; } }
public async Task Polling_From_Start_Works() { // Given: uint httpErrorDelay = 12345; var pollingPolicy = PollingDelays.DefaultPollingErrorDelays; pollingPolicy[HttpChannelPoller.PollingError.ErrorMakingHttpRequest] = httpErrorDelay; var loc = Path.Combine( TestContext.CurrentContext.TestDirectory, "http-responses\\sample.json"); var content = File.ReadAllText(loc); var testResponses = new List <Either <HttpError, string> >() { new Either <HttpError, string>(content) }; var initialPollState = BasicInitialPollState(pollingPolicy); Either <DeserializeError, TransportMessage> DeserializeTransportMessage(string s) => TransportMessageDeserializer.Deserialize( s, new Dictionary <string, Type> { { TestMessage.MessageName, typeof(TestMessage) } }); // When: PollState newPollStateTask = await MessageEndpointPoller.Execute( initialPollState, new TestHttpService(testResponses), new CancellationToken(), GetHandlerForMessageType, DeserializeTransportMessage); // Then //Assert.AreEqual(httpErrorDelay, newPollStateTask.DelayMs); Assert.AreEqual(4, TestMessageHandler.Counter); }
public PollerEventArgs(PollState theState, bool emailRecieved, Exception ex) { _theState = theState; _emailRecieved = emailRecieved; _ex = ex; }
public PollerEventArgs(PollState theState, bool emailRecieved) : this(theState, emailRecieved, null) { }
public Graph(IDialogService dialogService, GraphSettings graphSettings) { _graphSettings = graphSettings; _dialogService = dialogService; _pollState = PollState.Stopped; }
public async ValueTask <PollState?> SetPollState(string conferenceId, string pollId, PollState state) { var stateKey = GetPollStateKey(conferenceId); using var transaction = _database.CreateTransaction(); var previousPollTask = transaction.HashGetAsync <PollState>(stateKey, pollId); _ = transaction.HashSetAsync(stateKey, pollId, state); await transaction.ExecuteAsync(); return(await previousPollTask); }
public void SetPollState(int pollId, PollState state) { var poll = Get(pollId); poll.PollState = state; _pollRepo.Update(poll); }