Example #1
0
        protected override void Configure(Stateless.StateMachine <FooState, FooAction> stateMachine, Foo entity)
        {
            stateMachine.Configure(FooState.Unsent)
            .PermitIf(FooAction.Send, FooState.Sent, () => !string.IsNullOrEmpty(entity.Email));

            stateMachine.Configure(FooState.Sent)
            .InternalTransitionIf(FooAction.Send, (x) => !string.IsNullOrEmpty(entity.Email), (t) => { })
            .Permit(FooAction.Accept, FooState.Accepted)
            .Permit(FooAction.Decline, FooState.Declined);
        }
        public Envio(Guid id) : base(new EnvioId(id))
        {
            _stateMachine = new Stateless.StateMachine <EnvioState, Trigger>(() => myState,
                                                                             s => myState = s);

            _stateMachine.Configure(EnvioState.Creado)
            .Permit(Trigger.AsignarDireccionRecogida, EnvioState.DireccionRecogidaAsignada)
            .Permit(Trigger.AsignarDireccionEntrega, EnvioState.DireccionEntregaAsignada);

            _stateMachine.Configure(EnvioState.DireccionRecogidaAsignada)
            .Permit(Trigger.AsignarDireccionEntrega, EnvioState.DireccionesAsignadas);

            _stateMachine.Configure(EnvioState.DireccionEntregaAsignada)
            .Permit(Trigger.AsignarDireccionRecogida, EnvioState.DireccionesAsignadas);

            myState = EnvioState.Creado;

            _bultos = new List <Bulto>();
        }
            public SectionStateTracker(ITeamExplorerSection section, Func <Task> onRefreshed)
            {
                this.section = section;
                machine      = new Stateless.StateMachine <SectionState, string>(SectionState.Idle);
                machine.Configure(SectionState.Idle)
                .PermitIf("IsBusy", SectionState.Busy, () => this.section.IsBusy)
                .IgnoreIf("IsBusy", () => !this.section.IsBusy);
                machine.Configure(SectionState.Busy)
                .Permit("Title", SectionState.Refreshing)
                .PermitIf("IsBusy", SectionState.Idle, () => !this.section.IsBusy)
                .IgnoreIf("IsBusy", () => this.section.IsBusy);
                machine.Configure(SectionState.Refreshing)
                .Ignore("Title")
                .PermitIf("IsBusy", SectionState.Idle, () => !this.section.IsBusy)
                .IgnoreIf("IsBusy", () => this.section.IsBusy)
                .OnExit(() => onRefreshed());

                section.PropertyChanged += TrackState;
            }
        public Lamp()
        {
            _machine =
                new Stateless.StateMachine <LampState, LampTrigger>(LampState.Off);

            _machine.Configure(LampState.Off)
            .OnEntry(() => Console.WriteLine("Dziękuję za wyłączenie światła."), "Send SMS")
            .Permit(LampTrigger.Down, LampState.On)
            //   .PermitReentry(LampTrigger.Up)
            ;

            _machine.Configure(LampState.On)
            .OnEntry(() => Console.WriteLine("Pamiętaj o wyłączeniu światła!"), "Send SMS")
            .Permit(LampTrigger.Up, LampState.Off)
            .PermitReentry(LampTrigger.Down)
            ;

            string graph = UmlDotGraph.Format(_machine.GetInfo());

            Console.WriteLine(graph);
        }
Example #5
0
        /// <summary>
        /// Initialisiert die erlaubten Übergange der States, indem sie immer die Information
        /// Aktueller State + Trigger = Neuer State
        /// speichert.
        /// </summary>
        private void InitStateMachine()
        {
            stateMachine.Configure(States.EnterAmount)
            .OnEntry(() =>
            {
                // Den zu zahlenden Betrag wieder auf 0 setzen.
                SetProperty(nameof(Amount), default(decimal?));
            })
            .Permit(Triggers.AmountOkPressed, States.EnterPin);

            stateMachine.Configure(States.EnterPin)
            .OnEntry(() =>
            {
                // Den PIN wieder leer machen.
                SetProperty(nameof(Pin), default(int));
            })
            // Bedingter Übergang, wenn der PIN gültig ist (1234) wird zu ConfirmPayment
            // gewechselt.
            .PermitIf(Triggers.LastPinNumberEntered, States.ConfirmPayment, () => Pin == 1234)
            .PermitIf(Triggers.LastPinNumberEntered, States.PinError, () => Pin != 1234);

            stateMachine.Configure(States.ConfirmPayment)
            .Permit(Triggers.ConfirmPaymentPressed, States.EnterAmount)
            // Wird die Zahlung bestätigt, wird ein Log Eintrag im Model erstellt.
            .OnExit(() => TransactionLog.Transactions.Add(new Transaction
            {
                Amount = Amount ?? 0
            }));

            stateMachine.Configure(States.PinError)
            .Permit(Triggers.PinAgainPressed, States.EnterPin);

            stateMachine.OnTransitioned((t) =>
            {
                // Wird der State verändert, benachrichtigt dies alle Controls,
                // dessen Sichtbarkeit vom State abhängen.
                PropertyChanged(this, new PropertyChangedEventArgs(nameof(State)));
            });
        }
Example #6
0
 protected override void Configure(Stateless.StateMachine <BarState, BarAction> stateMachine, Bar entity)
 {
     stateMachine.Configure(BarState.Archived)
     .Permit(BarAction.Open, BarState.Opened);
 }
            public SectionStateTracker(ITeamExplorerSection section, Func<Task> onRefreshed)
            {
                this.section = section;
                machine = new Stateless.StateMachine<SectionState, string>(SectionState.Idle);
                machine.Configure(SectionState.Idle)
                    .PermitIf("IsBusy", SectionState.Busy, () => this.section.IsBusy)
                    .IgnoreIf("IsBusy", () => !this.section.IsBusy);
                machine.Configure(SectionState.Busy)
                    .Permit("Title", SectionState.Refreshing)
                    .PermitIf("IsBusy", SectionState.Idle, () => !this.section.IsBusy)
                    .IgnoreIf("IsBusy", () => this.section.IsBusy);
                machine.Configure(SectionState.Refreshing)
                    .Ignore("Title")
                    .PermitIf("IsBusy", SectionState.Idle, () => !this.section.IsBusy)
                    .IgnoreIf("IsBusy", () => this.section.IsBusy)
                    .OnExit(() => onRefreshed());

                section.PropertyChanged += TrackState;
            }
 protected override void Configure(Stateless.StateMachine <EBarState, EBarAction> stateMachine, Bar entity)
 {
     stateMachine.Configure(EBarState.Opened)
     .Permit(EBarAction.Close, EBarState.Closed);
 }