当前位置: 首页>>代码示例>>C#>>正文


C# StateMachine.CreateEvent方法代码示例

本文整理汇总了C#中StateMechanic.StateMachine.CreateEvent方法的典型用法代码示例。如果您正苦于以下问题:C# StateMachine.CreateEvent方法的具体用法?C# StateMachine.CreateEvent怎么用?C# StateMachine.CreateEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StateMechanic.StateMachine的用法示例。


在下文中一共展示了StateMachine.CreateEvent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CurrentChildStateReflectsCurrentStateOfChild

        public void CurrentChildStateReflectsCurrentStateOfChild()
        {
            var sm = new StateMachine("state machine");
            var initialState = sm.CreateInitialState("initial state");
            var state1 = sm.CreateState("state1");
            var childSm = state1.CreateChildStateMachine();
            var childInitialState = childSm.CreateInitialState("childInitialState");
            var childState1 = childSm.CreateState("childState1");

            var evt = sm.CreateEvent("evt");
            var evt2 = sm.CreateEvent("evt2");

            initialState.TransitionOn(evt).To(state1);
            childInitialState.TransitionOn(evt).To(childState1);
            state1.TransitionOn(evt2).To(initialState);

            Assert.AreEqual(initialState, sm.CurrentChildState);

            evt.Fire();

            Assert.AreEqual(childInitialState, sm.CurrentChildState);

            evt.Fire();

            Assert.AreEqual(childState1, sm.CurrentChildState);

            evt2.Fire();

            Assert.AreEqual(initialState, sm.CurrentChildState);
        }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:30,代码来源:StateMachineStateTests.cs

示例2: RecursiveFireDoesNotThrowIfTransitionNotFound

        public void RecursiveFireDoesNotThrowIfTransitionNotFound()
        {
            var sm = new StateMachine("sm");
            var initialState = sm.CreateInitialState("initialState");
            var state1 = sm.CreateState("state1");
            var evt = sm.CreateEvent("evt");
            var evt2 = sm.CreateEvent("evt2");

            initialState.TransitionOn(evt).To(state1).WithHandler(i => Assert.DoesNotThrow(() => evt2.Fire()));
            try { evt.TryFire(); } catch { }
        }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:11,代码来源:EventFireTests.cs

示例3: OuterEventTryFireReturnsTrueIfRecursiveTransitionNotFoundAndFiredWithTryFire

        public void OuterEventTryFireReturnsTrueIfRecursiveTransitionNotFoundAndFiredWithTryFire()
        {
            var sm = new StateMachine("sm");
            var initialState = sm.CreateInitialState("initialState");
            var state1 = sm.CreateState("state1");
            var evt = sm.CreateEvent("evt");
            var evt2 = sm.CreateEvent("evt2");

            initialState.TransitionOn(evt).To(state1).WithHandler(i => evt2.TryFire());

            Assert.True(evt.TryFire());
        }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:12,代码来源:EventFireTests.cs

示例4: OuterEventFireThrowsIfRecursiveTransitionNotFound

        public void OuterEventFireThrowsIfRecursiveTransitionNotFound()
        {
            var sm = new StateMachine("sm");
            var initialState = sm.CreateInitialState("initialState");
            var state1 = sm.CreateState("state1");
            var evt = sm.CreateEvent("evt");
            var evt2 = sm.CreateEvent("evt2");

            initialState.TransitionOn(evt).To(state1).WithHandler(i => evt2.Fire());

            var e = Assert.Throws<TransitionNotFoundException>(() => evt.Fire());
            Assert.AreEqual(state1, e.From);
            Assert.AreEqual(evt2, e.Event);
            Assert.AreEqual(sm, e.StateMachine);
        }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:15,代码来源:EventFireTests.cs

示例5: IndicatesWhetherInState

        public void IndicatesWhetherInState()
        {
            var sm = new StateMachine("State Machine");
            var state1 = sm.CreateInitialState("State 1");
            var state2 = sm.CreateState("State 2");
            var state3 = sm.CreateState("State 3");

            var evt = sm.CreateEvent("Event");
            var group1 = new StateGroup("Group 1");
            var group2 = new StateGroup("Group 2");

            state1.AddToGroup(group1);
            state2.AddToGroup(group2);
            state3.AddToGroup(group2);

            state1.TransitionOn(evt).To(state2);
            state2.TransitionOn(evt).To(state3);

            Assert.True(group1.IsCurrent);
            Assert.False(group2.IsCurrent);

            evt.Fire();

            Assert.False(group1.IsCurrent);
            Assert.True(group2.IsCurrent);

            evt.Fire();

            Assert.False(group1.IsCurrent);
            Assert.True(group2.IsCurrent);
        }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:31,代码来源:StateGroupTests.cs

示例6: TransitionRaisedWhenTransitionOnChild

        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 = sm.CreateEvent("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.False(ea.IsInnerTransition);
        }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:25,代码来源:TransitionNotificationTests.cs

示例7: TryFireReturnsFalseIfTransitionNotFound

        public void TryFireReturnsFalseIfTransitionNotFound()
        {
            var sm = new StateMachine("sm");
            var initialState = sm.CreateInitialState("initialState");
            var evt = sm.CreateEvent("evt");

            Assert.False(evt.TryFire());
        }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:8,代码来源:EventFireTests.cs

示例8: ThrowsIfForcedTransitionToAStateBelongingToAChildStateMachine

 public void ThrowsIfForcedTransitionToAStateBelongingToAChildStateMachine()
 {
     var sm = new StateMachine("State Machine");
     var evt = sm.CreateEvent("Event");
     var state = sm.CreateInitialState("Initial State");
     var subSm = state.CreateChildStateMachine();
     var subState = subSm.CreateInitialState("Child Initial State");
     
     Assert.Throws<InvalidStateTransitionException>(() => sm.ForceTransition(subState, evt));
 }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:10,代码来源:AssertionTests.cs

示例9: EventFireInTransitionHandlerIsQueued

        public void EventFireInTransitionHandlerIsQueued()
        {
            var sm = new StateMachine("sm");
            var initial = sm.CreateInitialState("initial");
            var state1 = sm.CreateState("state1");
            var state2 = sm.CreateState("state2");
            var state3 = sm.CreateState("state3");

            var evt = sm.CreateEvent("evt");
            var evt2 = sm.CreateEvent("evt2");

            initial.TransitionOn(evt).To(state1).WithHandler(i => evt2.Fire());
            initial.TransitionOn(evt2).To(state2);
            state1.TransitionOn(evt2).To(state3);

            evt.Fire();

            Assert.AreEqual(state3, sm.CurrentState);
        }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:19,代码来源:TransitionTests.cs

示例10: DoesNotThrowIfParentEventUsedInChildStateMachine

        public void DoesNotThrowIfParentEventUsedInChildStateMachine()
        {
            var sm = new StateMachine("State Machine");
            var state = sm.CreateInitialState("Initial State");
            var subSm = state.CreateChildStateMachine();
            var subState = subSm.CreateInitialState("Child Initial State");
            var evt = sm.CreateEvent("Event");

            Assert.DoesNotThrow(() => subState.TransitionOn(evt).To(subState));
        }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:10,代码来源:AssertionTests.cs

示例11: FireThrowsIfTransitionNotFound

        public void FireThrowsIfTransitionNotFound()
        {
            var sm = new StateMachine("sm");
            var initialState = sm.CreateInitialState("initialState");
            var evt = sm.CreateEvent("evt");

            var e = Assert.Throws<TransitionNotFoundException>(() => evt.Fire());
            Assert.AreEqual(initialState, e.From);
            Assert.AreEqual(evt, e.Event);
            Assert.AreEqual(sm, e.StateMachine);
        }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:11,代码来源:EventFireTests.cs

示例12: NormalSelfTransitionShouldFireExitAndEntry

        public void NormalSelfTransitionShouldFireExitAndEntry()
        {
            var events = new List<string>();
            var sm = new StateMachine("State Machine");
            var evt = sm.CreateEvent("Event");
            var state1 = sm.CreateInitialState("State 1").WithEntry(i => events.Add("State 1 Entry")).WithExit(i => events.Add("State 1 Exit"));
            state1.TransitionOn(evt).To(state1).WithHandler(i => events.Add("Transition 1 1"));

            evt.Fire();

            Assert.That(events, Is.EquivalentTo(new[] { "State 1 Exit", "Transition 1 1", "State 1 Entry" }));
        }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:12,代码来源:HandlerTests.cs

示例13: ThrowsIfChildStateUsedInParentStateMachine

        public void ThrowsIfChildStateUsedInParentStateMachine()
        {
            var sm = new StateMachine("State Machine");
            var state = sm.CreateInitialState("Initial State");
            var subSm = state.CreateChildStateMachine();
            var subState = subSm.CreateInitialState("Child Initial State");
            var evt = sm.CreateEvent("Event");

            var e = Assert.Throws<InvalidStateTransitionException>(() => state.TransitionOn(evt).To(subState));
            Assert.AreEqual(state, e.From);
            Assert.AreEqual(subState, e.To);
        }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:12,代码来源:AssertionTests.cs

示例14: InnerSelfTransitionOnEventTShouldNotFireExitAndEntry

        public void InnerSelfTransitionOnEventTShouldNotFireExitAndEntry()
        {
            var events = new List<string>();
            var sm = new StateMachine("State Machine");
            var evt = sm.CreateEvent<int>("Event");
            var state1 = sm.CreateInitialState("State 1").WithEntry(i => events.Add("State 1 Entry")).WithExit(i => events.Add("State 1 Exit"));
            state1.InnerSelfTransitionOn(evt).WithHandler(i => events.Add("Transition 1 1 Inner"));

            evt.Fire(3);

            Assert.That(events, Is.EquivalentTo(new[] { "Transition 1 1 Inner" }));
        }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:12,代码来源:HandlerTests.cs

示例15: CorrectHandlersAreInvokedInNormalTransition

        public void CorrectHandlersAreInvokedInNormalTransition()
        {
            var events = new List<string>();
            var sm = new StateMachine("State Machine");
            var evt = sm.CreateEvent("Event");
            var state1 = sm.CreateInitialState("State 1").WithExit(i => events.Add("State 1 Exit"));
            var state2 = sm.CreateState("State 2").WithEntry(i => events.Add("State 2 Entry"));
            var transition = state1.TransitionOn(evt).To(state2).WithHandler(i => events.Add("Transition 1 2"));

            evt.Fire();

            Assert.That(events, Is.EquivalentTo(new[] { "State 1 Exit", "Transition 1 2", "State 2 Entry" }));
        }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:13,代码来源:HandlerTests.cs


注:本文中的StateMechanic.StateMachine.CreateEvent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。