public void Update() { if (!HasTransition()) { StateUpdated?.Invoke(); } }
public void alertStateUpdated(MedicalState state) { if (StateUpdated != null && states.Contains(state)) { StateUpdated.Invoke(state); } }
private void UpdateState(PlayerState state) { _state.OnExitState(); _states.TryGetValue(state, out _state); _state.OnEnterState(); StateUpdated.Invoke(_state); }
private void OnGameMessageReceived(Message message) { if (!Client.Instance.IsGameStarted) { return; } if (message.Game == null) { return; } var state = message.Game.State; if (state != null) { _state = state; // TODO: CHECK CONDITION if (StateUpdated != null) { StateUpdated.Invoke(_state); } } }
private void MySendOrPostCallback(object state) { DataReceivedInfo data = (DataReceivedInfo)state; StateUpdated?.Invoke(this, new ServerUpdatedEventArgs { Message = data.Data, MessageType = data.MsgType }); }
public Task PrintState() { if (StateUpdated == null) { return(Task.CompletedTask); } return(StateUpdated.Invoke(this)); }
private void Start() { _state = new IdleState(null); _states.Add(PlayerState.IDLE, _state); _states.Add(PlayerState.WALK, new WalkState(null)); _states.Add(PlayerState.PLOW, new PlowState(_shovel)); _states.Add(PlayerState.PICK, new PickState(null)); StateUpdated.Invoke(_state); }
protected virtual void OnStatusUpdated() { _currentState = GetCurrentState(); var e = new IndexingServerStateUpdatedEventArgs { State = _currentState }; StateUpdated?.Invoke(this, e); }
void Cancel() { CleanUp(); state = PendingRideState.Canceled; PostStatus(0).FireAndForgetAsync(Program.ErrorHandler); StateUpdated?.Invoke(this); }
public XModemCommunicator() { _context.PacketsBuilt += (s, e) => { PacketsBuilt?.Invoke(this, e); }; _context.StateUpdated += (s, e) => { StateUpdated?.Invoke(this, e); }; _context.ModeUpdated += (s, e) => { ModeUpdated?.Invoke(this, e); }; }
protected virtual void UpdateState() { if (State == ViewHolderState.Selected) { _isSelected = true; } else if (State == ViewHolderState.Normal) { _isSelected = false; } StateUpdated?.Invoke(this, EventArgs.Empty); }
private async Task ProcessStatusAsync() { try { IEnumerable <CcjRunningRoundState> states; int delay; using (await MixLock.LockAsync()) { await DequeueCoinsFromMixNoLockAsync(State.GetSpentCoins().ToArray()); states = await SatoshiClient.GetAllRoundStatesAsync(); State.UpdateRoundsByStates(states.ToArray()); StateUpdated?.Invoke(this, null); delay = new Random().Next(0, 7); // delay the response to defend timing attack privacy } await Task.Delay(TimeSpan.FromSeconds(delay), Cancel.Token); using (await MixLock.LockAsync()) { await DequeueCoinsFromMixNoLockAsync(State.GetSpentCoins().ToArray()); CcjClientRound inputRegistrableRound = State.GetRegistrableRoundOrDefault(); if (inputRegistrableRound != null) { if (inputRegistrableRound.AliceClient == null) // If didn't register already, check what can we register. { await TryRegisterCoinsAsync(inputRegistrableRound); } else // We registered, let's confirm we're online. { await TryConfirmConnectionAsync(inputRegistrableRound); } } foreach (long ongoingRoundId in State.GetActivelyMixingRounds()) { await TryProcessRoundStateAsync(ongoingRoundId); } } } catch (TaskCanceledException ex) { Logger.LogTrace <CcjClient>(ex); } catch (Exception ex) { Logger.LogError <CcjClient>(ex); } }
bool DriverConfirm(UserRideOffer offer) { //TODO there is the case where there are no riders, and we should go ahead and cancel, but if there were never //any riders, the pending ride maybe shouldn't have been made in the first place? if (offer != this.offer) { return(false); } driverTimer.Stop(); //No longer can the user cancel through the offer offer.Canceled.Remove(OnRideOfferCanceled); offer.Changed -= OnRideOfferCanceled; offer.UserConfirmed(); bool hasPassengers; lock (requests) { if (requests.Any()) { hasPassengers = true; foreach (var rr in requests) { rr.DriverConfirmed(); } } else { hasPassengers = false; } } PostStatus(riderTimer.Interval).FireAndForgetAsync(Program.ErrorHandler); StateUpdated?.Invoke(this); if (hasPassengers) { state = PendingRideState.WaitingOnRiders; riderTimer.Start(); } else { DoneGettingConfirmations().FireAndForgetAsync(Program.ErrorHandler); } return(true); }
async Task DoneGettingConfirmations() { IEnumerable <UserRideRequest> passengers = requests; lock (requests) { if (confirmedRideRequests.Count != requests.Count) { //Can't just use confirmedRideRequsts because it is unordered; we want to maintain the original ordering. passengers = requests.Where((rr) => confirmedRideRequests.Contains(rr)); originalRideModified = true; //Expire the requests of all the others foreach (var rr in requests.Where((r) => !confirmedRideRequests.Contains(r))) { rr.SetExpired(); UserTimedOut?.Invoke(rr.User.UserInfo.UserId, false, this); } } } // If all passengers canceled, cancel the offer. If there were no // passengers (which should only happen in development), confirm // the offer. if (!passengers.Any() && requests.Any()) { Cancel(); return; } state = PendingRideState.Confirmed; if (originalRideModified) { RideInfo = await rideMatcher.MakeBestRide(offer, passengers); } //Now we pass the final info to the ActiveRideCenter ActiveRideId = await ActiveRideCenter.ActiveRideStarted(RideInfo, offer, confirmedRideRequests); PostStatus(0, ActiveRideId).FireAndForgetAsync(Program.ErrorHandler); CleanUp(); StateUpdated?.Invoke(this); }
private void Callback(IAsyncResult ar) { var sb = (StreamAndBuffer)ar.AsyncState; try { int numBytes = sb.stream.EndRead(ar); if (numBytes > 0) { if (Parse(sb.buffer)) { StateUpdated?.Invoke(this, EventArgs.Empty); } sb.stream.BeginRead(sb.buffer, 0, sb.buffer.Length, Callback, sb); } } catch (IOException exc) { _stream = null; Debug.WriteLine("IOException: " + exc.Message); sb.stream.Dispose(); } catch (NullReferenceException) { } }
protected virtual void OnStateUpdated() { StateUpdated?.Invoke(this, EventArgs.Empty); }
private void RaiseStateUpdated() { StateUpdated?.Invoke(this); }
private void OnStateUpdated(StateEventArgs e) { StateUpdated?.Invoke(null, e); }
private async Task ProcessStatusAsync(int minDelayReplySeconds, int maxDelayReplySeconds) { try { IEnumerable <CcjRunningRoundState> states; int delay; using (await MixLock.LockAsync()) { await DequeueCoinsFromMixNoLockAsync(State.GetSpentCoins().ToArray()); states = await SatoshiClient.GetAllRoundStatesAsync(); State.UpdateRoundsByStates(states.ToArray()); // If we don't have enough coin queued to register a round, then dequeue all. CcjClientRound registrableRound = State.GetRegistrableRoundOrDefault(); if (registrableRound != default) { if (!registrableRound.State.HaveEnoughQueued(State.GetAllQueuedCoinAmounts().ToArray())) { await DequeueAllCoinsFromMixNoLockAsync(); } } StateUpdated?.Invoke(this, null); if (maxDelayReplySeconds == minDelayReplySeconds) { delay = minDelayReplySeconds; } if (maxDelayReplySeconds < minDelayReplySeconds || maxDelayReplySeconds <= 0) { delay = 0; } else { delay = new Random().Next(minDelayReplySeconds, maxDelayReplySeconds); // delay the response to defend timing attack privacy } } await Task.Delay(TimeSpan.FromSeconds(delay), Cancel.Token); using (await MixLock.LockAsync()) { foreach (long ongoingRoundId in State.GetActivelyMixingRounds()) { await TryProcessRoundStateAsync(ongoingRoundId); } await DequeueCoinsFromMixNoLockAsync(State.GetSpentCoins().ToArray()); CcjClientRound inputRegistrableRound = State.GetRegistrableRoundOrDefault(); if (!(inputRegistrableRound is null)) { if (inputRegistrableRound.AliceClient is null) // If didn't register already, check what can we register. { await TryRegisterCoinsAsync(inputRegistrableRound); } else // We registered, let's confirm we're online. { await TryConfirmConnectionAsync(inputRegistrableRound); } } } } catch (TaskCanceledException ex) { Logger.LogTrace <CcjClient>(ex); } catch (Exception ex) { Logger.LogError <CcjClient>(ex); } }
protected virtual Task SignalStateUpdated(int id, TaskRunnerState state) { StateUpdated?.Invoke(id, state); return(Task.CompletedTask); }
private async Task TryProcessStatusAsync(IEnumerable <CcjRunningRoundState> states) { states = states ?? Enumerable.Empty <CcjRunningRoundState>(); if (Interlocked.Read(ref _statusProcessing) == 1) // It's ok to wait for status processing next time. { return; } try { Synchronizer.BlockRequests(); Interlocked.Exchange(ref _statusProcessing, 1); using (await MixLock.LockAsync()) { // First, if there's delayed round registration update based on the state. if (DelayedRoundRegistration != null) { CcjClientRound roundRegistered = State.GetSingleOrDefaultRound(DelayedRoundRegistration.AliceClient.RoundId); roundRegistered.Registration = DelayedRoundRegistration; DelayedRoundRegistration = null; // Don't dispose. } await DequeueSpentCoinsFromMixNoLockAsync(); State.UpdateRoundsByStates(ExposedLinks, states.ToArray()); // If we don't have enough coin queued to register a round, then dequeue all. CcjClientRound registrableRound = State.GetRegistrableRoundOrDefault(); if (registrableRound != default) { // If the coordinator increases fees, don't register. Let the users register manually again. bool dequeueBecauseCoordinatorFeeChanged = false; if (CoordinatorFeepercentToCheck != default) { dequeueBecauseCoordinatorFeeChanged = registrableRound.State.CoordinatorFeePercent > CoordinatorFeepercentToCheck; } if (!registrableRound.State.HaveEnoughQueued(State.GetAllQueuedCoinAmounts().ToArray()) || dequeueBecauseCoordinatorFeeChanged) { await DequeueAllCoinsFromMixNoLockAsync("The total value of the registered coins is not enough or the coordinator's fee changed."); } } } StateUpdated?.Invoke(this, null); int delaySeconds = new Random().Next(0, 7); // delay the response to defend timing attack privacy. if (Network == Network.RegTest) { delaySeconds = 0; } await Task.Delay(TimeSpan.FromSeconds(delaySeconds), Cancel.Token); using (await MixLock.LockAsync()) { foreach (long ongoingRoundId in State.GetActivelyMixingRounds()) { await TryProcessRoundStateAsync(ongoingRoundId); } await DequeueSpentCoinsFromMixNoLockAsync(); CcjClientRound inputRegistrableRound = State.GetRegistrableRoundOrDefault(); if (inputRegistrableRound != null) { if (inputRegistrableRound.Registration is null) // If did not register already, check what can we register. { await TryRegisterCoinsAsync(inputRegistrableRound); } else // We registered, let's confirm we're online. { await TryConfirmConnectionAsync(inputRegistrableRound); } } } } catch (TaskCanceledException ex) { Logger.LogTrace <CcjClient>(ex); } catch (Exception ex) { Logger.LogError <CcjClient>(ex); } finally { Interlocked.Exchange(ref _statusProcessing, 0); Synchronizer.EnableRequests(); } }
protected virtual void OnStateUpdated(string login, EmployeeStatus status) { StateUpdated.Invoke(this, new StateUpdatedArgs(login, status)); }
protected void InvokeStateUpdated() => StateUpdated?.Invoke(this);
public void TriggerUpdate(object updateSource, string updateType) { StateUpdated?.Invoke(updateSource, updateType); }
protected virtual void OnStateUpdated(SteamControllerState e) { StateUpdated?.Invoke(this, e); }
private void _timeOut_Elapsed(object sender, ElapsedEventArgs e) { StateUpdated.Invoke(this, new StateUpdatedArgs(Login, Status)); }
protected void updateState(MachineState state, bool invalidateCanDos) { State = state ?? throw new ArgumentNullException(); StateUpdated?.Invoke(this, state, invalidateCanDos); }
protected void RaiseStateChanged() { StateUpdated?.Invoke((TSegmentType)this); }
/// <summary> /// actions to perform when state has been updated /// </summary> protected virtual void OnStateUpdated() { UpdateHighlight(); StateUpdated?.Invoke(); }
protected virtual void OnStateUpdated(EventArgs e) { StateUpdated?.Invoke(this, e); }