Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
 public void alertStateUpdated(MedicalState state)
 {
     if (StateUpdated != null && states.Contains(state))
     {
         StateUpdated.Invoke(state);
     }
 }
Exemplo n.º 3
0
 public void Update()
 {
     if (!HasTransition())
     {
         StateUpdated?.Invoke();
     }
 }
Exemplo n.º 4
0
 private void UpdateState(PlayerState state)
 {
     _state.OnExitState();
     _states.TryGetValue(state, out _state);
     _state.OnEnterState();
     StateUpdated.Invoke(_state);
 }
Exemplo n.º 5
0
        public void NotProcessDuplicate()
        {
            var loggerMock         = new Mock <ILogger <BusinessEntitySaga> >();
            var businessEntitySaga = new BusinessEntitySaga(loggerMock.Object)
            {
                Data = new BusinessEntitySagaData
                {
                    StateDetails = new Dictionary <int, StateDetail>
                    {
                        { 123, new StateDetail() }
                    }
                }
            };
            var context = new TestableMessageHandlerContext();
            var message = new StateUpdated
            {
                BusinessEntityId = "qwerty",
                Details          = new StateDetail
                {
                    Id           = 123,
                    State        = "NEWSTATE",
                    TimeStampUtc = DateTime.UtcNow
                }
            };

            businessEntitySaga.Handle(message, context);

            // TODO verify business logic not executed twice
            Assert.Single(businessEntitySaga.Data.StateDetails);
        }
        private void MySendOrPostCallback(object state)
        {
            DataReceivedInfo data = (DataReceivedInfo)state;

            StateUpdated?.Invoke(this, new ServerUpdatedEventArgs {
                Message = data.Data, MessageType = data.MsgType
            });
        }
Exemplo n.º 7
0
 public Task PrintState()
 {
     if (StateUpdated == null)
     {
         return(Task.CompletedTask);
     }
     return(StateUpdated.Invoke(this));
 }
Exemplo n.º 8
0
        protected virtual void OnStatusUpdated()
        {
            _currentState = GetCurrentState();
            var e = new IndexingServerStateUpdatedEventArgs {
                State = _currentState
            };

            StateUpdated?.Invoke(this, e);
        }
Exemplo n.º 9
0
 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);
 }
Exemplo n.º 10
0
        void Form1_stationListUpdated(GenericDeviceState state)
        {
            if (this.stationsListBox.InvokeRequired)
            {
                StateUpdated d = new StateUpdated(Form1_stationListUpdated);
                this.Invoke(d, new object[] { state });
            }
            else
            {
                if (state is OnkyoState)
                {
                    OnkyoState st = (OnkyoState)state;
                    stationsListBox.Items.Clear();
                    stationsListBox.Items.AddRange(st.CurrentList);
                    seekLabel.Text   = st.CurrentSeekPosition;
                    volumeLabel.Text = st.CurrentVolume.ToString();
                    powerLabel.Text  = st.CurrentPowerState ? "On" : "Off";
                }
                if (state is HeatmiserState)
                {
                    HeatmiserState st = (HeatmiserState)state;
                    tempValueLabel.Text         = st.CurrentAirTemp.ToString().Insert(2, ".") + "C";
                    setTempValueLabel.Text      = st.SetRoomTemp.ToString() + "C";
                    hotWaterValueLabel.Text     = st.IsHotWater ? "Yes" : "No";
                    heatingValueLabel.Text      = st.IsHeating ? "Yes" : "No";
                    holidayValueLabel.Text      = st.IsOnHoliday ? "Yes" : "No";
                    rateOfChangeValueLabel.Text = st.RateOfChange.ToString() + "Min";
                }
                if (state is PCState)
                {
                    if (((PCState)state).PCName == "StudyPC")
                    {
                        studyPCOnOffLabel.Text = ((PCState)state).IsOn ? "On" : "Off";
                    }
                    else if (((PCState)state).PCName == "LoungePC")
                    {
                        mediaCenterOnOffLabel.Text = ((PCState)state).IsOn ? "On" : "Off";
                    }
                }
                if (state is HolidayManagerState)
                {
                    HolidayManagerState st = (HolidayManagerState)state;

                    //DialogResult dr = DialogResult.Yes;
                    //if (holidaysDataGrid.DataSource != null) {
                    //    dr = MessageBox.Show("Holiday list updated. Refresh the screen?", "Holidays Updated", MessageBoxButtons.YesNo);
                    //}

                    //if (dr == DialogResult.Yes) {
                    List <PlannedHoliday> copy = st.PlannedHolidays.ToList <PlannedHoliday>();
                    System.ComponentModel.BindingList <PlannedHoliday> bl = new System.ComponentModel.BindingList <PlannedHoliday>(copy);
                    bl.AllowNew = bl.AllowRemove = bl.AllowEdit = true;
                    holidaysDataGrid.DataSource = bl;
                    //}
                }
            }
        }
Exemplo n.º 11
0
        void Cancel()
        {
            CleanUp();

            state = PendingRideState.Canceled;

            PostStatus(0).FireAndForgetAsync(Program.ErrorHandler);

            StateUpdated?.Invoke(this);
        }
Exemplo n.º 12
0
 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);
     };
 }
Exemplo n.º 13
0
        protected virtual void UpdateState()
        {
            if (State == ViewHolderState.Selected)
            {
                _isSelected = true;
            }
            else if (State == ViewHolderState.Normal)
            {
                _isSelected = false;
            }

            StateUpdated?.Invoke(this, EventArgs.Empty);
        }
Exemplo n.º 14
0
        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);
            }
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        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) { }
        }
Exemplo n.º 18
0
        public void ProcessNewMessage()
        {
            var loggerMock         = new Mock <ILogger <BusinessEntitySaga> >();
            var businessEntitySaga = new BusinessEntitySaga(loggerMock.Object)
            {
                Data = new BusinessEntitySagaData()
            };
            var context = new TestableMessageHandlerContext();
            var message = new StateUpdated
            {
                BusinessEntityId = "qwerty",
                Details          = new StateDetail
                {
                    Id           = 123,
                    State        = "NEWSTATE",
                    TimeStampUtc = DateTime.UtcNow
                }
            };

            businessEntitySaga.Handle(message, context);

            // TODO verify business logic is executed
            Assert.Single(businessEntitySaga.Data.StateDetails);
        }
Exemplo n.º 19
0
 protected virtual void OnStateUpdated(EventArgs e)
 {
     StateUpdated?.Invoke(this, e);
 }
Exemplo n.º 20
0
 protected virtual void OnStateUpdated()
 {
     StateUpdated?.Invoke(this, EventArgs.Empty);
 }
Exemplo n.º 21
0
        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);
            }
        }
Exemplo n.º 22
0
        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();
            }
        }
Exemplo n.º 23
0
 protected void RaiseStateChanged()
 {
     StateUpdated?.Invoke((TSegmentType)this);
 }
Exemplo n.º 24
0
 protected void InvokeStateUpdated() => StateUpdated?.Invoke(this);
Exemplo n.º 25
0
 public void TriggerUpdate(object updateSource, string updateType)
 {
     StateUpdated?.Invoke(updateSource, updateType);
 }
Exemplo n.º 26
0
 private void RaiseStateUpdated()
 {
     StateUpdated?.Invoke(this);
 }
Exemplo n.º 27
0
 protected void updateState(MachineState state, bool invalidateCanDos)
 {
     State = state ?? throw new ArgumentNullException();
     StateUpdated?.Invoke(this, state, invalidateCanDos);
 }
Exemplo n.º 28
0
 private void OnStateUpdated(StateEventArgs e)
 {
     StateUpdated?.Invoke(null, e);
 }
Exemplo n.º 29
0
 /// <summary>
 /// actions to perform when state has been updated
 /// </summary>
 protected virtual void OnStateUpdated()
 {
     UpdateHighlight();
     StateUpdated?.Invoke();
 }
Exemplo n.º 30
0
 protected virtual void OnStateUpdated(SteamControllerState e)
 {
     StateUpdated?.Invoke(this, e);
 }