Inheritance: System.EventArgs
        public void TransitionRaisedWhenTransitionOnChild()
        {
            var sm           = new StateMachine("sm");
            var initial      = sm.CreateInitialState("initial");
            var child        = initial.CreateChildStateMachine();
            var childInitial = child.CreateInitialState("childInitial");
            var childState1  = child.CreateState("childState1");
            var evt          = new Event("evt");

            childInitial.TransitionOn(evt).To(childState1);

            TransitionEventArgs <State> ea = null;

            sm.Transition += (o, e) =>
            {
                ea = e;
            };

            evt.Fire();

            Assert.NotNull(ea);
            Assert.AreEqual(childInitial, ea.From);
            Assert.AreEqual(childState1, ea.To);
            Assert.AreEqual(evt, ea.Event);
            Assert.AreEqual(child, ea.StateMachine);
            Assert.False(ea.IsInnerTransition);
            Assert.AreEqual(EventFireMethod.Fire, ea.EventFireMethod);
        }
示例#2
0
        StateMachine_Trigger_TransitionFromCurrentToSame_ConfiggedNotToRaiseExcep_DoesNotRaiseTransitionChangeEvents()
        {
            var config = new StateMachineConfiguration {
                RaiseExceptionBeforeTransitionToSameState = false
            };
            var machine  = new StateMachine <StubStateModel>(config);
            var model    = new StubStateModel();
            var trigger1 = new Trigger("trigger1");

            var state1 = new State <StubStateModel>("state1");
            TransitionEventArgs <StubStateModel> transitioningArgs = null;

            state1.Entered += (s, e) => { transitioningArgs = e; };
            TransitionEventArgs <StubStateModel> transitionedArgs = null;

            state1.Exiting += (s, e) => { transitionedArgs = e; };

            state1.AddTransition(trigger1, state1);
            model.CurrentState = state1;

            // set up scenario where state would transition from current to same state.
            // so no true transition would not occur

            // should not throw exception and that's good enough for us
            machine.Trigger(trigger1, model);

            // verify that no transition events occurred
            Assert.Null(transitioningArgs);
            Assert.Null(transitionedArgs);
        }
        /// <summary>
        /// Traverse the specified connector, if possible.
        /// This is NOT thread-safe, you must call it in a critical section.
        /// </summary>
        /// <param name="connector"></param>
        /// <param name="args">Optional event args related to the connector traversal</param>
        /// <returns>true if the connector was traversed.</returns>
        protected bool TraverseConnector(IUmlConnector connector, TransitionEventArgs args = null)
        {
            bool traversed = false;

            if (CurrentNode == connector.Supplier && connector.CanTraverse &&
                (connector.Consumer.CanEnter || connector.Consumer == connector.Supplier))
            {
                // Broke this condition out separately because the order of TryExit is important.
                if (connector.Supplier.TryExit()
                    // If Consumer is Supplier, just make sure again that Consumer can enter now that it has been exited.
                    && (connector.Consumer != connector.Supplier || connector.Consumer.CanEnter))
                {
                    // Hook up to the connector's traversed event so that the CurrentNode value will be set before the node is entered.
                    // This allows a node's ENTER and DO behaviors to rely on the new current state.
                    connector.Traversed += HandleConnectorTraversed;

                    // Successful traversal will first set the current state in this machine,
                    // then set the new state on this machine's IStatefulModel. This order is important.
                    traversed = connector.Traverse(args);

                    // Traversal attempt is finished.  Whether it succeeded or failed, the event handling is no longer needed.
                    connector.Traversed -= HandleConnectorTraversed;
                }
            }
            return(traversed);
        }
        public void TransitionRaisedWhenInnerSelfTransitionOnChild()
        {
            var sm           = new StateMachine("sm");
            var initial      = sm.CreateInitialState("initial");
            var child        = initial.CreateChildStateMachine();
            var childInitial = child.CreateInitialState("childInitial");
            var evt          = sm.CreateEvent("evt");

            childInitial.InnerSelfTransitionOn(evt);

            TransitionEventArgs <State> ea = null;

            sm.Transition += (o, e) =>
            {
                ea = e;
            };

            evt.Fire();

            Assert.NotNull(ea);
            Assert.AreEqual(childInitial, ea.From);
            Assert.AreEqual(childInitial, ea.To);
            Assert.AreEqual(evt, ea.Event);
            Assert.True(ea.IsInnerTransition);
        }
 public bool Traverse(TransitionEventArgs args)
 {
     if (CanTraverse && Consumer.CanEnter)
     {
         try
         {
             // Perform any effect behavior.  It's okay to do effect here, even if it effects the
             // consumer node, because CanEnter was already affirmed and it won't be checked again.
             DoEffect();
             // Indicate connector traversal.
             OnTraversed();
             // Enter the consuming node.
             Consumer.EnterFrom(this, args);
             return(true);
         }
         catch (Exception e)
         {
             LogService.Log(LogType, LogMessageType.Error, ContainerName, string.Format(CultureInfo.InvariantCulture, "Exception while traversing transition '{0}'->'{1}'", SupplierName, ConsumerName), e);
         }
     }
     else
     {
         LogService.Log(LogType, LogMessageType.Trace, ContainerName,
                        string.Format(CultureInfo.InvariantCulture, "Cannot traverse transition '{0}'->'{1}': Guard not satisfied or cannot enter consumer.", SupplierName, ConsumerName));
     }
     return(false);
 }
示例#6
0
        /// <summary>
        /// Handles the transition update event.
        /// </summary>
        /// <param name="sender">The triggerer object.</param>
        /// <param name="args">The event arguments.</param>
        private void OnTransitionUpdate(object sender, TransitionEventArgs args)
        {
            RemoveTransition(args.Transition);
            AddTransition(args.Transition);

            Redraw();
        }
        private void EntryDisposed(object sender, TransitionEventArgs <StateID, EventID, EventArgs> e)
        {
            scheduler.Dispose();

            operation.OperationCompleted();

            isDisposed = true;
        }
示例#8
0
        /// <summary>Triggers a transition to a new state via a specified link.</summary>
        /// <param name="node">The state node to transition to.</param>
        /// <param name="link">The link which triggered this new state.</param>
        public void Transition(StateMachineNode node, StateMachineLink link)
        {
            var e = new TransitionEventArgs(this.currentNode, node, link);

            nodeTime         = 0f;
            this.currentNode = node;
            OnTransition?.Invoke(this, e);
        }
示例#9
0
        protected virtual void RaiseOnPreTransitionEvent(TransitionType transitionType)
        {
            TransitionEventArgs args = new TransitionEventArgs(transitionType);

            if (OnPreTransition != null)
            {
                OnPreTransition(args);
            }
        }
示例#10
0
        StateMachine_Trigger_ValidTriggerAndTrans_ChoosesFirstTranWthPassGuardNonGlobal_SameAsCurrentState_NoRaised()
        {
            var model   = new StubStateModel();
            var machine = new StateMachine <StubStateModel>();
            TransitionEventArgs <StubStateModel> transitioningArgs = null;

            machine.Transitioning += (s, e) => { transitioningArgs = e; };
            TransitionEventArgs <StubStateModel> transitionedArgs = null;

            machine.Transitioned += (s, e) => { transitionedArgs = e; };

            var trigger1 = new Trigger("t1");
            var trigger2 = new Trigger("t2");

            var state1Mock = new Mock <State <StubStateModel> >("s1");
            var state2Mock = new Mock <State <StubStateModel> >("s2");
            var state3Mock = new Mock <State <StubStateModel> >("s3");
            var state4Mock = new Mock <State <StubStateModel> >("s4");

            var state1 = state1Mock.Object;
            var state2 = state2Mock.Object;
            var state3 = state3Mock.Object;
            var state4 = state4Mock.Object;

            var statetrans1 = new Transition <StubStateModel>(trigger1, state1, state2, m => 1 == 2);
            var statetrans2 = new Transition <StubStateModel>(trigger1, state1, state3, m => 1 == 1);
            var statetrans3 = new Transition <StubStateModel>(trigger2, state1, state3);

            var globaltrans1 = new Transition <StubStateModel>(trigger1, null, state1, m => 1 == 1);

            machine.AddGlobalTransition(globaltrans1);
            state1.AddTransition(statetrans1);
            state1.AddTransition(statetrans2);
            state1.AddTransition(statetrans3);

            model.CurrentState = state1;

            // so when trigger1 is triggered on state model whose current state is state1,
            // it will fall through to the first matching transition with a passing guard, the second state transition to state 1
            // but since this is same state as current state, it shouldn't actually transition.  no events should be called.

            machine.Trigger(trigger1, model);

            // verify that no transition events were calledb
            state1Mock.Verify(s =>
                              s.RaiseEntered(
                                  It.IsAny <StubStateModel>(),
                                  It.IsAny <State <StubStateModel> >(),
                                  It.IsAny <Trigger>()), Times.Never());
            state1Mock.Verify(s =>
                              s.RaiseExiting(
                                  It.IsAny <StubStateModel>(),
                                  It.IsAny <State <StubStateModel> >(),
                                  It.IsAny <Trigger>()), Times.Never());
            Assert.Null(transitioningArgs);
            Assert.Null(transitionedArgs);
        }
示例#11
0
        protected virtual void RaiseOnTransitionInteriorEvent(StaticDoor staticDoor, DaggerfallInterior daggerfallInterior)
        {
            TransitionEventArgs args = new TransitionEventArgs(TransitionType.ToBuildingInterior, staticDoor, daggerfallInterior);

            if (OnTransitionInterior != null)
            {
                OnTransitionInterior(args);
            }
        }
示例#12
0
        protected virtual void RaiseOnTransitionDungeonInteriorEvent(StaticDoor staticDoor, DaggerfallDungeon daggerfallDungeon)
        {
            TransitionEventArgs args = new TransitionEventArgs(TransitionType.ToDungeonInterior, staticDoor, null, daggerfallDungeon);

            if (OnTransitionDungeonInterior != null)
            {
                OnTransitionDungeonInterior(args);
            }
        }
示例#13
0
        protected virtual void RaiseOnTransitionDungeonExteriorEvent()
        {
            TransitionEventArgs args = new TransitionEventArgs(TransitionType.ToDungeonExterior);

            if (OnTransitionDungeonExterior != null)
            {
                OnTransitionDungeonExterior(args);
            }
        }
示例#14
0
        protected virtual void RaiseOnPreTransitionEvent(TransitionType transitionType, StaticDoor staticDoor)
        {
            TransitionEventArgs args = new TransitionEventArgs(TransitionType.ToBuildingInterior, staticDoor);

            if (OnPreTransition != null)
            {
                OnPreTransition(args);
            }
        }
        protected void HandleTransitionFired(object sender, TransitionEventArgs args)
        {
            var transition = sender as UmlTransition;

            lock (_traverseLock)
            {
                TraverseConnector(transition, args);
            }
        }
示例#16
0
 void engine_TransitionRequested(object sender, TransitionEventArgs e)
 {
     if (test.CurrentStep.CommandType != CommandType.TransitionRequested)
     {
         test.CurrentStep.Status  = TestStatus.Failed;
         test.CurrentStep.Message = "Game requested unexpected transition request.";
         engine.Stop();
     }
 }
        private void HandleTransitionFired(object sender, TransitionEventArgs args)
        {
            var transition = sender as UmlTransition;

            // Put a new activity on the dispatcher to try to traverse the fired transition.
            ExecuteExecutable(new DynamicActivity(Name + ".HandleTransitionFired", () => TraverseConnector(transition, args))
            {
                LogType = LogType
            });
        }
示例#18
0
        protected virtual void MachineEnded(object sender, TransitionEventArgs args)
        {
            Tracer <StateMachineState> .WriteInformation("Machine Ended {0} ({1})", new object[]
            {
                this.ToString(),
                base.MachineName
            });

            this.RaiseStateFinished(args);
        }
示例#19
0
 private void _cco_TransitionEvent(int EventNumber, ref int pData, ref string pString)
 {
     if (this.TransitionEvent != null)
     {
         TransitionEventArgs eTE = new TransitionEventArgs(EventNumber, pData, pString);
         TransitionEvent(new object(), eTE);
         pData   = eTE.Data;
         pString = Convert.ToString(eTE.String);
     }
 }
示例#20
0
 protected void HandleTransitionFailed(object sender, TransitionEventArgs args)
 {
     try
     {
         RaiseTransitionFailed(args);
     }
     catch (Exception ex)
     {
         _logger.Error($"{_context}: {ex.GetType().Name} resulted from raising '{nameof(TransitionFailed)}' event in {GetType().Name} '{Name}'.", ex);
     }
 }
示例#21
0
 protected override void RaiseStateFinished(TransitionEventArgs eventArgs)
 {
     this.stopwatch.Stop();
     this.transitionEventArgs = eventArgs;
     if (this.stopwatch.ElapsedMilliseconds < (long)this.minimumStateDuration)
     {
         this.ExtendStateVisibility();
         return;
     }
     base.RaiseStateFinished(this.transitionEventArgs);
 }
示例#22
0
        /// <summary>
        /// State machine transaction begin handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _stateMachine_TransitionBegin(object sender, TransitionEventArgs <NaoState, NaoCommand> e)
        {
            this._logger.InfoFormat("[Robot: {0}] - Transition Begin. Current state: {1}, command: {2}.", _connection.IP, e.StateId.ToString(), e.EventId.ToString());
            this.CurrentExecutingCommand = e.EventId;

            // raise command changed event
            if (this.RobotExecutingCommandChanged != null)
            {
                this.RobotExecutingCommandChanged(this, null);
            }
        }
        void MainMenuScreen_Exiting(object sender, TransitionEventArgs tea)
        {
            //Slide effect from right to left
            float effect = (float)Math.Pow(tea.percent - 1, 2) * 100;

            foreach (MenuEntry entry in MenuEntries)
            {
                entry.Acceleration = new Vector2(effect, 0);
                entry.Position     = entry.InitialPosition - entry.Acceleration;
            }
        }
示例#24
0
        public void TransitionEventArgs_ValidParms_VerifyAssigns()
        {
            var model   = new StubStateModel();
            var from    = new State <StubStateModel>("from");
            var to      = new State <StubStateModel>("to");
            var trigger = new Trigger("trigger");
            var args    = new TransitionEventArgs <StubStateModel>(model, from, to, trigger);

            Assert.Same(from, args.From);
            Assert.Same(to, args.To);
            Assert.Same(model, args.Model);
            Assert.Same(trigger, args.Trigger);
        }
        /// <summary>
        /// Enter this Node from the given originator. It is the originator's responsibility
        /// to check whether this node CanEnter before calling this method.  It was done like that
        /// in order to prevent a Connector to Node traversal getting into an undefined state, which
        /// could happen if both the Connector and the Node check CanEnter where the first check gives
        /// affirmative and the second gives negative.  Solution was to remove second check here.
        /// </summary>
        /// <param name="originator">the originator of the enter message</param>
        /// <param name="args">Optional event args related to the entry of this node.</param>
        public void EnterFrom(object originator, TransitionEventArgs args = null)
        {
            IsActive      = true;
            OriginOfEntry = originator;
            EntryArgs     = args;

            OnEntered();

            // Do whatever needs to be done for connectors on entry.
            EnableConnectors();

            // Call the virtual method that derived classes may modify.
            InternalEnter();
        }
        void MainMenuScreen_Entering(object sender, TransitionEventArgs tea)
        {
            float effect = (float)Math.Pow(tea.percent - 1, 2) * -100;

            foreach (MenuEntry entry in MenuEntries)
            {
                entry.Acceleration = new Vector2(effect, 0);
                entry.Position     = entry.DefaultPosition + entry.Acceleration;
                entry.Opacity      = tea.percent;
            }

            TitlePosition = InitialTitlePosition + new Vector2(0, effect);
            TitleOpacity  = tea.percent;
        }
示例#27
0
        internal static TransitionEventArgs ToTransitionArgs(this Transition transition, TripEventArgs internalArgs)
        {
            var origin         = (DataWaypoint)internalArgs.GetTripOrigin();
            var transitionArgs = new TransitionEventArgs()
            {
                Signal     = origin.Juncture,
                SignalData = origin.Signal,
                Trigger    = internalArgs?.FindTrigger(),
                TripRoute  = internalArgs == null ? null : internalArgs.Waypoints,
                Transition = transition
            };

            return(transitionArgs);
        }
示例#28
0
        private void PauseScreen_Exiting(object sender, TransitionEventArgs e)
        {
            float effect = (float)Math.Pow(e.Percent - 1, 2) * -100;

            foreach (MenuEntry entry in MenuEntries)
            {
                entry.Acceleration = new Vector2(effect, 0);
                entry.Position     = entry.DefaultPosition + entry.Acceleration;
                entry.Scale        = e.Percent;
                entry.Opacity      = e.Percent;
            }

            TitlePosition = InitialTitlePosition - new Vector2(0, effect);
            TitleOpacity  = e.Percent;
        }
示例#29
0
        public void FluentStateMachine_GlobalTransitionings_AddsEachOneToMachine()
        {
            var machine     = new StateMachine <StubStateModel>();
            var machineMock = new Mock <IStateMachine <StubStateModel> >();
            var state1      = new State <StubStateModel>("s1");
            var state2      = new State <StubStateModel>("s2");
            var state3      = new State <StubStateModel>("s3");
            var trigger1    = new Trigger("t1");
            var trigger2    = new Trigger("t2");

            var allStates = new List <State <StubStateModel> >();

            allStates.Add(state1);
            allStates.Add(state2);
            allStates.Add(state3);

            // transition arg
            var arg = new TransitionEventArgs <StubStateModel>(new StubStateModel(),
                                                               state1, state2, trigger1);

            // create some global transitionings
            Action <TransitionEventArgs <StubStateModel> > callback1 = e => { };
            Action <TransitionEventArgs <StubStateModel> > callback2 = e => { };
            Action <TransitionEventArgs <StubStateModel> > callback3 = e => { };

            // put them in an ienum
            var callbacks = new List <Action <TransitionEventArgs <StubStateModel> > >();

            callbacks.Add(callback1);
            callbacks.Add(callback2);
            callbacks.Add(callback3);


            // create a fluent machine, and validate each was added to machine
            //machineMock.Raise(m => m.Transitioning += null, arg);
            machineMock.SetupAllProperties();

            var fluentMachine = new FluentStateMachine <StubStateModel>(
                machineMock.Object,
                allStates,
                null,
                callbacks,
                null,
                null);

            //machineMock.VerifyAll();
        }
 private void OnFired(TransitionEventArgs args)
 {
     if (Fired != null && args != null && args.Trigger != null)
     {
         try
         {
             var msg = string.Format(CultureInfo.InvariantCulture, "Transition '{0}'->'{1}' fired from trigger '{2}'.",
                                     SupplierName, ConsumerName, (args.Trigger != null) ? args.Trigger.Name : "?");
             LogService.Log(LogType, LogMessageType.Trace, ContainerName, msg);
             Fired(this, args);
         }
         catch (Exception e)
         {
             LogService.Log(LogType, LogMessageType.Error, ContainerName,
                            string.Format(CultureInfo.InvariantCulture, "Exception while firing transition '{0}'->'{1}'.", SupplierName, ConsumerName), e);
         }
     }
 }
示例#31
0
 void PlayScreen_Entering(object sender, TransitionEventArgs tea)
 {
     titleColor = Color.Green * TransitionPercent;
     descriptionColor = Color.White * TransitionPercent;
 }
示例#32
0
 /// <summary/>
 protected override void BeginTransition(TransitionEventArgs e) {
    CompleteTransition(e);
 }
示例#33
0
 private void OnTransition(object sender, TransitionEventArgs<State> eventArgs)
 {
     var handler = this.Transition;
     if (handler != null)
         handler(this, eventArgs);
 }
        public void TransitionEventArgs_ValidParms_VerifyAssigns()
        {
            var model = new StubStateModel();
            var from = new State<StubStateModel>("from");
            var to = new State<StubStateModel>("to");
            var trigger = new Trigger("trigger");
            var args = new TransitionEventArgs<StubStateModel>(model, from, to, trigger);

            Assert.Same(from, args.From);
            Assert.Same(to, args.To);
            Assert.Same(model, args.Model);
            Assert.Same(trigger, args.Trigger);
        }
示例#35
0
 protected override bool FooIsTrue(object sender, TransitionEventArgs<StateID, EventID, EventArgs> args)
 {
     return foo;
 }
示例#36
0
        public void FluentStateMachine_GlobalTransitioneds_AddsEachOneToMachine()
        {
            var machine = new StateMachine<StubStateModel>();
            var machineMock = new Mock<IStateMachine<StubStateModel>>();
            var state1 = new State<StubStateModel>("s1");
            var state2 = new State<StubStateModel>("s2");
            var state3 = new State<StubStateModel>("s3");
            var trigger1 = new Trigger("t1");
            var trigger2 = new Trigger("t2");

            var allStates = new List<State<StubStateModel>>();
            allStates.Add(state1);
            allStates.Add(state2);
            allStates.Add(state3);

            // transition arg
            var arg = new TransitionEventArgs<StubStateModel>(new StubStateModel(),
                state1, state2, trigger1);

            // create some global transitionings
            Action<TransitionEventArgs<StubStateModel>> callback1 = e => { };
            Action<TransitionEventArgs<StubStateModel>> callback2 = e => { };
            Action<TransitionEventArgs<StubStateModel>> callback3 = e => { };

            // put them in an ienum
            var callbacks = new List<Action<TransitionEventArgs<StubStateModel>>>();
            callbacks.Add(callback1);
            callbacks.Add(callback2);
            callbacks.Add(callback3);

            // create a fluent machine, and validate each was added to machine
            //machineMock.Raise(m => m.Transitioning += null, arg);
            //machineMock.SetupAllProperties();

            var fluentMachine = new FluentStateMachine<StubStateModel>(
                machineMock.Object,
                allStates,
                null,
                null,
                callbacks,
                null);

            //machineMock.VerifyAll();
        }
示例#37
0
 protected virtual void RaiseOnTransitionInteriorEvent(StaticDoor staticDoor, DaggerfallInterior daggerfallInterior)
 {
     TransitionEventArgs args = new TransitionEventArgs(TransitionType.ToBuildingInterior, staticDoor, daggerfallInterior);
     if (OnTransitionInterior != null)
         OnTransitionInterior(args);
 }
示例#38
0
 protected override void SetFooToTrue(object sender, TransitionEventArgs<StateID, EventID, EventArgs> e)
 {
     Console.Write("Setting foo to true... ");
     foo = true;
 }
示例#39
0
 protected virtual void RaiseOnTransitionExteriorEvent()
 {
     TransitionEventArgs args = new TransitionEventArgs(TransitionType.ToBuildingExterior);
     if (OnTransitionExterior != null)
         OnTransitionExterior(args);
 }
示例#40
0
 protected virtual void RaiseOnTransitionDungeonInteriorEvent(StaticDoor staticDoor, DaggerfallDungeon daggerfallDungeon)
 {
     TransitionEventArgs args = new TransitionEventArgs(TransitionType.ToDungeonInterior, staticDoor, null, daggerfallDungeon);
     if (OnTransitionDungeonInterior != null)
         OnTransitionDungeonInterior(args);
 }
示例#41
0
 protected virtual void RaiseOnPreTransitionEvent(TransitionType transitionType, StaticDoor staticDoor)
 {
     TransitionEventArgs args = new TransitionEventArgs(TransitionType.ToBuildingInterior, staticDoor);
     if (OnPreTransition != null)
         OnPreTransition(args);
 }
示例#42
0
 protected override void ExitS11(object sender, TransitionEventArgs<StateID, EventID, EventArgs> e)
 {
     Console.Write("ExitS11 ");
 }
示例#43
0
 protected override void EntryS2(object sender, TransitionEventArgs<StateID, EventID, EventArgs> e)
 {
     Console.Write("EntryS2 ");
 }
示例#44
0
        void PauseScreen_Exiting(object sender, TransitionEventArgs tea)
        {
            float effect = (float)Math.Pow(tea.percent - 1, 2) * 100;
            foreach (MenuEntry entry in MenuEntries)
            {
                entry.Acceleration = new Vector2(effect, 0);
                entry.Position = entry.DefaultPosition + entry.Acceleration;
                entry.Scale = tea.percent;
                entry.Opacity = tea.percent;
            }

            TitlePosition = InitialTitlePosition - new Vector2(0, effect);
            TitleOpacity = tea.percent;
        }
 void MainMenuScreen_Exiting(object sender, TransitionEventArgs tea)
 {
     //Slide effect from right to left
     float effect = (float)Math.Pow(tea.percent - 1, 2) * 100;
     foreach (MenuEntry entry in MenuEntries)
     {
         entry.Acceleration = new Vector2(effect, 0);
         entry.Position = entry.InitialPosition - entry.Acceleration;
     }
 }