public async Task <HttpResponseMessage> Get()
        {
            var result = await _store.FindAsync();

            var issuesState = new IssuesState();

            issuesState.Issues = result.Select(i => _stateFactory.Create(i));
            return(Request.CreateResponse(HttpStatusCode.OK, issuesState));
        }
Exemple #2
0
        public async Task <HttpResponseMessage> Get()
        {
            var issues = await _store.FindAsync();

            var issuesState = new IssuesState();

            issuesState.Issues = issues.Select(i => _stateFactory.Create(i));
            issuesState.Links.Add(new Link {
                Href = Request.RequestUri, Rel = LinkFactory.Rels.Self
            });
            return(Request.CreateResponse(HttpStatusCode.OK, issuesState));
        }
Exemple #3
0
        private async Task <(State state, BotContext context)> CreateMemberContext(
            MessageEventArgs request,
            long userId)
        {
            (State state, BotContext context)contextState = (null, null);
            var isUserExist = await userService.IsUserExist(userId);

            if (isUserExist)
            {
                contextState.state   = stateFactory.Create(typeof(MemberState));
                contextState.context = new BotContext(contextState.state, serviceFactory, request, userId);
            }
            return(contextState);
        }
        public IAppState Create()
        {
            var state = factory.Create <IAppState>();

            state.Counter           = factory.Create <ICounterState>();
            state.Counter.MyCounter = factory.Create <IMyCounterState>();
            state.MyCounter         = factory.Create <IMyCounterState>();
            state.WeatherState      = factory.Create <IWeatherState>();

            state.Counter.MyCounter.Count = 5;
            state.MyCounter.Count         = 15;

            return(state);
        }
        /// <summary>
        /// Try and change to a new state
        /// </summary>
        /// <param name="type"></param>
        public void ChangeState(Type type)
        {
            var state = _factory.Create(type);

            if (CurrentState == null)
            {
                CurrentState = state;
                CurrentState.Start(null);
                return;
            }

            if (!CurrentState.CanMoveToState(state))
            {
                Debug.LogWarningFormat(
                    "{0} tried to move to {1}",
                    CurrentState.GetType().Name,
                    state.GetType().Name
                    );
                return;
            }

            CurrentState.Exit();
            LastState    = CurrentState;
            CurrentState = state;
            CurrentState.Start(LastState.GetType());
        }
 /// <summary>
 /// Loads the saved state.
 /// </summary>
 /// <returns>The saved state</returns>
 public IState Load()
 {
     if (_state == null)
     {
         _state = _stateFactory.Create();
     }
     return(_state);
 }
        public ConnectionServiceBase(IStateFactory stateFactory, ILogger logger)
        {
            _stateFactory = stateFactory;
            _logger       = logger;

            _currentState = stateFactory.Create(ConnectionState.Disconnected);
            _continue     = true;
        }
Exemple #8
0
        private void ChangeState(TStateType state)
        {
            if (state == null)
            {
                _stateMachine.Stop();
                return;
            }
            var newState = _stateFactory.Create(state);

            _stateMachine.Execute(newState);
        }
Exemple #9
0
        public ProjectionSystem(
            IStateTransitionOrchestrator <TItem> stateTransitionOrchestrator,
            IStateFactory <TItem> uninitialisedStateFactory,
            IStateFactory <TItem> creatingStateFactory,
            IStateFactory <TItem> validStateFactory,
            IStateFactory <TItem> expiredStateFactory,
            IStateFactory <TItem> updatingStateFactory,
            ISyncLockFactory getProjectionLockFactory)
        {
            if (stateTransitionOrchestrator == null)
            {
                throw new ArgumentNullException(nameof(stateTransitionOrchestrator));
            }
            if (uninitialisedStateFactory == null)
            {
                throw new ArgumentNullException(nameof(uninitialisedStateFactory));
            }
            if (creatingStateFactory == null)
            {
                throw new ArgumentNullException(nameof(creatingStateFactory));
            }
            if (validStateFactory == null)
            {
                throw new ArgumentNullException(nameof(validStateFactory));
            }
            if (expiredStateFactory == null)
            {
                throw new ArgumentNullException(nameof(expiredStateFactory));
            }
            if (updatingStateFactory == null)
            {
                throw new ArgumentNullException(nameof(updatingStateFactory));
            }
            if (getProjectionLockFactory == null)
            {
                throw new ArgumentNullException(nameof(getProjectionLockFactory));
            }
            _stateTransitionOrchestrator = stateTransitionOrchestrator;
            _creatingState            = creatingStateFactory.Create(this);
            _validState               = validStateFactory.Create(this);
            _expiredState             = expiredStateFactory.Create(this);
            _updatingState            = updatingStateFactory.Create(this);
            _getProjectionLockFactory = getProjectionLockFactory;

            var initialisationTask = _stateTransitionOrchestrator
                                     .TransitionToState(uninitialisedStateFactory.Create(this));

            if (!initialisationTask.IsCompleted)
            {
                initialisationTask.RunSynchronously();
            }
        }
Exemple #10
0
        /// <summary>
        /// Loads the saved state.
        /// </summary>
        /// <returns>The saved state</returns>
        public IState Load()
        {
            //  pull State object directly out of Session
            IState state = HttpContext.Current.Session[BaseState.SESSION_KEY] as IState;

            if (state == null)
            {
                state = _stateFactory.Create();
                HttpContext.Current.Session[BaseState.SESSION_KEY] = state;
            }
            state.Reset();
            return(state);
        }
 void ConfigureStateFactory_ToReturnState(IStateFactory <Department> stateFactory, IState <Department> state)
 {
     A.CallTo(() => stateFactory.Create(A <IProjectionSystem <Department> > ._)).Returns(state);
 }
 public void MoveToState(ConnectionState desiredState)
 {
     _currentState = _stateFactory.Create(desiredState);
 }
Exemple #13
0
        protected virtual void ChangeState(TStateType state)
        {
            var stateBehaviour = _stateFactory.Create(state);

            _stateMachine.Execute(stateBehaviour);
        }
Exemple #14
0
 public static StateObject <T> Create <T>(IActorStateManager stateManager, string key, Func <T, T, Task> onChange = null, IEqualityComparer <T> equalityComparer = null)
 {
     return(Default.Create <T>(stateManager, key, onChange, equalityComparer));
 }