/// <summary>
        /// Creates a state machine for the given rule settings.
        /// Check https://github.com/Timmeey86/binokel-deluxe/wiki/(Concept)-State-Machines for an overview of possible states and transitions.
        /// </summary>
        /// <param name="ruleSettings">The settings for this game.</param>
        /// <param name="dealerPosition">The Position of the dealing player for this game, starting at zero.</param>
        public void RefreshStateMachine(RuleSettings ruleSettings, int dealerPosition)
        {
            var amountOfCards = ruleSettings.SevensAreIncluded ? 48 : 40;
            var dabbSize      = ruleSettings.SevensAreIncluded && ruleSettings.GameType == GameType.ThreePlayerGame ? 6 : 4;

            // Configure initial attributes
            var properties = new SingleGameProperties
            {
                NumberOfPlayers       = ruleSettings.GameType == GameType.ThreePlayerGame ? 3 : 4,
                DealerPosition        = dealerPosition,
                RemainingCards        = amountOfCards - dabbSize,
                CurrentPlayerPosition = -1,
                NextPlayerPosition    = -1,
                TrickWinnerPosition   = -1,
            };

            this.stateMachine = new Stateless.StateMachine <SingleGameState, Common.GameTrigger>(SingleGameState.Initial);

            // Ignore triggers which should not be available.
            this.stateMachine.OnUnhandledTrigger((state, trigger) => { });

            this.stateMachine.Configure(SingleGameState.Initial)
            .Permit(Common.GameTrigger.GameStarted, SingleGameState.Dealing);

            this.ConfigureDealingPhase(properties);
            this.ConfigureBiddingPhase(properties);
            this.ConfigureDabbPhase(properties);
            this.ConfigureDurchPhase();
            this.ConfigureBettelPhase();
            this.ConfigureMeldingPhase(properties);
            this.ConfigureTrickTakingPhase(properties);
            this.ConfigureEndPhase(properties);
        }
Пример #2
0
 Task IStateMachineConfiguration <TEntity, TState, TTrigger> .ConfigureAsync(Stateless.StateMachine <TState, TTrigger> stateMachine,
                                                                             TEntity entity,
                                                                             CancellationToken cancellationToken)
 {
     Configure(stateMachine, entity);
     return(Task.CompletedTask);
 }
Пример #3
0
        public StateMachine(Stateless.StateMachine <TState, TTrigger> stateMachine)
        {
            if (stateMachine == null)
            {
                throw new ArgumentNullException(nameof(stateMachine));
            }

            _stateMachine = stateMachine;
        }
Пример #4
0
 public reportTabViewModel(Stateless.StateMachine <ViewState, ViewTrigger> .TriggerWithParameters <string> w1, Machine machine, Cluster corentCluster)
 {
     this.corentCluster = corentCluster;
     this.w1            = w1;
     this.machine       = machine;
     openImg            = new DelegateCommand <string>(
         (string r) => { machine.Fire(w1, r); }
         );
 }
Пример #5
0
        public async Task ConfigureAsync(Stateless.StateMachine <BarState, BarAction> stateMachine, Bar entity, CancellationToken cancellationToken)
        {
            var configuration = _factory(entity.State);

            if (configuration != null)
            {
                await configuration.ConfigureAsync(stateMachine, entity, cancellationToken);
            }
        }
Пример #6
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);
        }
Пример #7
0
        /// <summary>
        /// Initialisiert die State Machine und die Commands.
        /// </summary>
        public MainViewModel()
        {
            stateMachine = new Stateless.StateMachine <States, Triggers>(States.EnterAmount);
            InitStateMachine();

            // Damit nicht bei jedem get ein neuer Command erstellt wird, weisen wir sie im
            // Konstruktor zu.
            AmountOkCommand       = CreateStateChangingCommand(Triggers.AmountOkPressed);
            ConfirmPaymentCommand = CreateStateChangingCommand(Triggers.ConfirmPaymentPressed);
            PinAgainCommand       = CreateStateChangingCommand(Triggers.PinAgainPressed);
            PinNumberCommand      = CreatePinNumberCommand();
        }
Пример #8
0
        void TransitionedHandler(Stateless.StateMachine <VehicleState, VehicleTrigger> .Transition transition)
        {
            string Destination = transition.Destination.ToString();
            string Source      = transition.Source.ToString();
            string Trigger     = transition.Trigger.ToString();
            string IsReentry   = transition.IsReentry.ToString();

            LogHelper.Log(logger: NLog.LogManager.GetCurrentClassLogger(), LogLevel: NLog.LogLevel.Debug, Class: nameof(AVEHICLE), Device: DEVICE_NAME_OHx,
                          Data: $"Vh:{VEHICLE_ID} message state,From:{Source} to:{Destination} by:{Trigger}.IsReentry:{IsReentry}",
                          VehicleID: VEHICLE_ID,
                          CarrierID: CST_ID);
        }
        //Task TransitionedHandler(Stateless.StateMachine<TState, TTrigger>.Transition transition)
        void TransitionedHandler(Stateless.StateMachine <TState, TTrigger> .Transition transition)
        {
            string Destination = transition.Destination.ToString();
            string Source      = transition.Source.ToString();
            string Trigger     = transition.Trigger.ToString();
            string IsReentry   = transition.IsReentry.ToString();

            LogCollection.VHStateDebug(string.Format("VH-[{0}] state,From:{1} to:{2} by:{3}.IsReentry:{4}"
                                                     , ID
                                                     , Source
                                                     , Destination
                                                     , Trigger
                                                     , IsReentry));
        }
Пример #10
0
        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);
        }
Пример #13
0
        public async Task <IStateMachine <TState, TTrigger> > GetStateMachineAsync <TEntity, TState, TTrigger>(
            TEntity entity,
            Func <TEntity, TState> stateAccessor,
            Action <TEntity, TState> stateMutator,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            if (stateAccessor == null)
            {
                throw new ArgumentNullException(nameof(stateAccessor));
            }
            if (stateMutator == null)
            {
                throw new ArgumentNullException(nameof(stateMutator));
            }

            Stateless.StateMachine <TState, TTrigger> stateMachine;

            try
            {
                stateMachine = new Stateless.StateMachine <TState, TTrigger>(() => stateAccessor(entity),
                                                                             state => stateMutator(entity, state));
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException($"Error constructing state machine for entity {typeof(TEntity)}", ex);
            }

            var configurator = ConfiguratorProvider.GetConfigurator <TEntity, TState, TTrigger>(_serviceProvider);

            if (configurator != null)
            {
                await configurator.ConfigureAsync(stateMachine, entity, cancellationToken).ConfigureAwait(false);
            }

            return(new StateMachine <TState, TTrigger>(stateMachine));
        }
Пример #14
0
 public ClusterTab(Machine machine, Stateless.StateMachine <ViewState, ViewTrigger> .TriggerWithParameters <Entities.Cluster> w)
 {
     this.w  = w;
     Machine = machine;
     InitializeComponent();
 }
Пример #15
0
        public static Stateless.StateMachine <TState, TTrigger> .StateConfiguration InternalTransitionIf <TState, TTrigger>(this Stateless.StateMachine <TState, TTrigger> .StateConfiguration configuration,
                                                                                                                            TTrigger trigger,
                                                                                                                            Func <bool> guard,
                                                                                                                            string guardDescription = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            return(configuration.InternalTransitionIf(trigger, x => guard.Invoke(), () => { }, guardDescription));
        }
Пример #16
0
        public static Stateless.StateMachine <TState, TTrigger> .StateConfiguration InternalTransition <TState, TTrigger>(this Stateless.StateMachine <TState, TTrigger> .StateConfiguration configuration,
                                                                                                                          TTrigger trigger)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            return(configuration.InternalTransition(trigger, () => { }));
        }
Пример #17
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);
 }
Пример #20
0
 protected abstract void Configure(Stateless.StateMachine <TState, TTrigger> stateMachine, TEntity entity);
Пример #21
0
 public ReportTab(Stateless.StateMachine <ViewState, ViewTrigger> .TriggerWithParameters <string> w1, Machine machine, Cluster corentCluster)
 {
     DataContext = new reportTabViewModel(w1, machine, corentCluster);
     InitializeComponent();
 }