Пример #1
0
        private void updateBayeuxClientState(BayeuxClientStateUpdater_createDelegate create, BayeuxClientStateUpdater_postCreateDelegate postCreate)
        {
            LogHelper.Log($"BayeauxClient: updateBayeuxClientState()...");

            stateUpdateInProgressMutex.WaitOne();
            ++stateUpdateInProgress;
            stateUpdateInProgressMutex.ReleaseMutex();

            BayeuxClientState newState = null;
            BayeuxClientState oldState = bayeuxClientState;

            newState = create(oldState);

            LogHelper.Log($"BayeauxClient: updateBayeuxClientState() old state: {oldState}, new state: {newState}");

            if (newState == null)
            {
                throw new SystemException();
            }

            if (!oldState.isUpdateableTo(newState))
            {
                LogHelper.Log($"BayeauxClient: updateBayeuxClientState() State is not updatable from {oldState} to {newState}");
                return;
            }

            bayeuxClientState = newState;

            postCreate?.Invoke();

            if (oldState.Type != newState.Type)
            {
                newState.enter(oldState.Type);
            }

            LogHelper.Log($"BayeauxClient: updateBayeuxClientState() executing on {newState}...");
            newState.execute();
            LogHelper.Log($"BayeauxClient: updateBayeuxClientState() executed on {newState}.");

            // Notify threads waiting in waitFor()
            stateUpdateInProgressMutex.WaitOne();
            --stateUpdateInProgress;

            if (stateUpdateInProgress == 0)
            {
                stateChanged.Set();
            }
            stateUpdateInProgressMutex.ReleaseMutex();

            LogHelper.Log($"BayeauxClient: updateBayeuxClientState() done.");
        }
Пример #2
0
        private void UpdateBayeuxClientState(
            BayeuxClientStateUpdater_createDelegate create,
            BayeuxClientStateUpdater_postCreateDelegate postCreate)
        {
            lock (_stateUpdateInProgressLock)
            {
                ++_stateUpdateInProgress;
            }

            var oldState = _bayeuxClientState;

            var newState = create(oldState);

            if (newState == null)
            {
                throw new SystemException();
            }

            if (!oldState.IsUpdateableTo(newState))
            {
                _logger?.LogDebug($"State not updateable : {oldState} -> {newState}");
                return;
            }

            _bayeuxClientState = newState;

            postCreate?.Invoke();

            if (oldState.Type != newState.Type)
            {
                newState.Enter(oldState.Type);
            }

            newState.Execute();

            // Notify threads waiting in waitFor()
            lock (_stateUpdateInProgressLock)
            {
                --_stateUpdateInProgress;

                if (_stateUpdateInProgress == 0)
                {
                    _stateChanged.Set();
                }
            }
        }
        private void updateBayeuxClientState(BayeuxClientStateUpdater_createDelegate create, BayeuxClientStateUpdater_postCreateDelegate postCreate)
        {
            stateUpdateInProgressMutex.WaitOne();
            ++stateUpdateInProgress;
            stateUpdateInProgressMutex.ReleaseMutex();

            BayeuxClientState newState = null;
            BayeuxClientState oldState = bayeuxClientState;

            newState = create(oldState);
            if (newState == null)
            {
                throw new SystemException();
            }

            if (!oldState.isUpdateableTo(newState))
            {
                Console.WriteLine("State not updateable : {0} -> {1}", oldState, newState);
                return;
            }

            bayeuxClientState = newState;

            if (postCreate != null)
            {
                postCreate();
            }

            if (oldState.Type != newState.Type)
            {
                newState.enter(oldState.Type);
            }

            newState.execute();

            // Notify threads waiting in waitFor()
            stateUpdateInProgressMutex.WaitOne();
            --stateUpdateInProgress;

            if (stateUpdateInProgress == 0)
            {
                stateChanged.Set();
            }
            stateUpdateInProgressMutex.ReleaseMutex();
        }
 private void UpdateBayeuxClientState(BayeuxClientStateUpdater_createDelegate create)
 {
     UpdateBayeuxClientState(create, null);
 }
Пример #5
0
        private void updateBayeuxClientState(BayeuxClientStateUpdater_createDelegate create, BayeuxClientStateUpdater_postCreateDelegate postCreate)
        {
            stateUpdateInProgressMutex.WaitOne();
            ++stateUpdateInProgress;
            stateUpdateInProgressMutex.ReleaseMutex();

            BayeuxClientState newState = null;
            BayeuxClientState oldState = bayeuxClientState;

            newState = create(oldState);
            if (newState == null)
                throw new SystemException();

            if (!oldState.isUpdateableTo(newState))
            {
                //Console.WriteLine("State not updateable : {0} -> {1}", oldState, newState);
                return;
            }

            bayeuxClientState = newState;

            if (postCreate != null) postCreate();

            if (oldState.Type != newState.Type)
                newState.enter(oldState.Type);

            newState.execute();

            // Notify threads waiting in waitFor()
            stateUpdateInProgressMutex.WaitOne();
            --stateUpdateInProgress;

            if (stateUpdateInProgress == 0)
                stateChanged.Set();
            stateUpdateInProgressMutex.ReleaseMutex();
        }
Пример #6
0
 private void updateBayeuxClientState(BayeuxClientStateUpdater_createDelegate create)
 {
     updateBayeuxClientState(create, null);
 }