public StateMachineStateless(string _id, Stateless.StateMachine <TState, TTrigger> _sm)
        {
            ID = _id;
            sm = _sm;

            sm.OnTransitioned(TransitionedHandler);
            sm.OnUnhandledTrigger(UnhandledTriggerHandler);
        }
        static public StateMachine <TSCState, TSCEvent> CreatTSCStateMachine(Func <TSCState> stateAccessor, Action <TSCState> stateMutator)
        {
            StateMachine <TSCState, TSCEvent> fsm = new Stateless.StateMachine <TSCState, TSCEvent>(stateAccessor, stateMutator);

            #region define transition
            fsm.Configure(TSCState.Tscnone).
            Permit(TSCEvent.Tscinitial, TSCState.Tscint);

            fsm.Configure(TSCState.Tscint).
            Permit(TSCEvent.SystemStartedUpSuccessfully, TSCState.Paused);

            fsm.Configure(TSCState.Paused).
            Permit(TSCEvent.Tscresumed, TSCState.Auto);

            fsm.Configure(TSCState.Auto).
            Permit(TSCEvent.TcsrequestedToPause, TSCState.Pausing);

            fsm.Configure(TSCState.Pausing).
            Permit(TSCEvent.Tscresumed, TSCState.Auto).
            Permit(TSCEvent.PauseComplete, TSCState.Paused);
            #endregion
            return(fsm);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// コンストラクター
 /// </summary>
 /// <remarks>
 /// 指定のサイズの <see cref="Button"/> オブジェクトを作成します。
 /// ボタンはプッシュ ボタンかトグル ボタンを選択可能です。
 /// </remarks>
 /// <param name="type">ボタン種別</param>
 public Button(ButtonType type)
 {
     this.type = type;
     this.normal = null;
     this.focusedNormal = null;
     this.pressed = null;
     this.focusedPressed = null;
     this.current = normal;
     this.sm = new StateMachine<ButtonState, ButtonTrigger> (ButtonState.Normal);
     switch (type) {
         case ButtonType.Push: {
                 this.sm.Configure (ButtonState.Normal)
                             .Permit (ButtonTrigger.Press, ButtonState.Pressed)
                             .Permit (ButtonTrigger.FocusIn, ButtonState.FocusedNormal)
                             .Ignore (ButtonTrigger.Release)
                             .Ignore (ButtonTrigger.FocusOut)
                             .OnEntry (x => this.current = normal);
                 this.sm.Configure (ButtonState.FocusedNormal)
                               .Permit (ButtonTrigger.Press, ButtonState.FocusedPressed)
                               .Permit (ButtonTrigger.FocusOut, ButtonState.Normal)
                               .Ignore (ButtonTrigger.Release)
                             .OnEntry (x => this.current = focusedNormal ?? normal);
                 this.sm.Configure (ButtonState.Pressed)
                             .Permit (ButtonTrigger.Release, ButtonState.Normal)
                             .Permit (ButtonTrigger.FocusIn, ButtonState.FocusedPressed)
                             .Ignore (ButtonTrigger.Press)
                             .Ignore (ButtonTrigger.FocusOut)
                             .OnEntry (x => this.current = pressed);
                 this.sm.Configure (ButtonState.FocusedPressed)
                             .Permit (ButtonTrigger.Release, ButtonState.FocusedNormal)
                             .Permit (ButtonTrigger.FocusOut, ButtonState.Pressed)
                             .Ignore (ButtonTrigger.Press)
                             .Ignore (ButtonTrigger.FocusIn)
                             .OnEntry (x => this.current = focusedPressed ?? pressed);
                 break;
             }
         case ButtonType.Toggle: {
                 this.sm.Configure (ButtonState.Normal)
                             .Permit (ButtonTrigger.Press, ButtonState.Pressed)
                             .Permit (ButtonTrigger.FocusIn, ButtonState.FocusedNormal)
                             .Ignore (ButtonTrigger.Release)
                             .Ignore (ButtonTrigger.FocusOut)
                             .OnEntry (x => this.current = normal);
                 this.sm.Configure (ButtonState.FocusedNormal)
                               .Permit (ButtonTrigger.Press, ButtonState.FocusedPressed)
                               .Permit (ButtonTrigger.FocusOut, ButtonState.Normal)
                               .Ignore (ButtonTrigger.Release)
                             .OnEntry (x => this.current = focusedNormal ?? normal);
                 this.sm.Configure (ButtonState.Pressed)
                             .Ignore (ButtonTrigger.Release)
                             .Permit (ButtonTrigger.FocusIn, ButtonState.FocusedPressed)
                             .Permit (ButtonTrigger.Press, ButtonState.Normal)
                             .Ignore (ButtonTrigger.FocusOut)
                             .OnEntry (x => this.current = pressed);
                 this.sm.Configure (ButtonState.FocusedPressed)
                             .Ignore (ButtonTrigger.Release)
                             .Permit (ButtonTrigger.FocusOut, ButtonState.Pressed)
                             .Permit (ButtonTrigger.Press, ButtonState.FocusedNormal)
                             .Ignore (ButtonTrigger.FocusIn)
                             .OnEntry (x => this.current = focusedPressed ?? pressed);
                 break;
             }
         default: throw new NotImplementedException ("Sorry");
     }
 }