• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# StateMechanic.StateMachine类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



StateMachine类属于StateMechanic命名空间,在下文中一共展示了StateMachine类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 = new Event("evt");
            var evt2 = new Event("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:canton7,项目名称:StateMechanic,代码行数:30,代码来源:StateMachineStateTests.cs


示例2: FormatsStateMachines

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

            var child1 = state1.CreateChildStateMachine("child1");
            var state11 = child1.CreateInitialState("state11");
            var state12 = child1.CreateState("state12");

            var child2 = state2.CreateChildStateMachine("child2");
            var state21 = child2.CreateInitialState("state21");
            var state22 = child2.CreateState("state22");

            var evt1 = new Event("evt1");
            var evt2 = new Event<string>("evt2");

            state1.InnerSelfTransitionOn(evt1);
            state1.TransitionOn(evt2).To(state2);

            state11.TransitionOn(evt2).ToDynamic(_ => state12);
            state12.TransitionOn(evt1).To(state11);

            state21.TransitionOn(evt1).To(state22);
            state21.TransitionOn(evt2).To(state22);

            var dot = sm.FormatDot(colorize: true);
            var dgml = sm.FormatDgml(colorize: true);
        }
开发者ID:canton7,项目名称:StateMechanic,代码行数:29,代码来源:PrinterTests.cs


示例3: 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


示例4: FormatsStateMachinesWithNoNames

        public void FormatsStateMachinesWithNoNames()
        {
            var sm = new StateMachine();
            var state1 = sm.CreateInitialState();
            var state2 = sm.CreateState();

            var child1 = state1.CreateChildStateMachine();
            var state11 = child1.CreateInitialState();
            var state12 = child1.CreateState();

            var child2 = state2.CreateChildStateMachine();
            var state21 = child2.CreateInitialState();
            var state22 = child2.CreateState();

            var evt1 = new Event();
            var evt2 = new Event<string>();

            state1.InnerSelfTransitionOn(evt1);
            state1.TransitionOn(evt2).To(state2);

            state11.TransitionOn(evt2).ToDynamic(_ => state12);
            state12.TransitionOn(evt1).To(state11);

            state21.TransitionOn(evt1).To(state22);

            var dot = sm.FormatDot();
            var dgml = sm.FormatDgml();
        }
开发者ID:canton7,项目名称:StateMechanic,代码行数:28,代码来源:PrinterTests.cs


示例5: NoEventsAreQueuedIfAGuardThrowsAnException

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

            var evt = new Event("evt");
            var evt2 = new Event("evt2");

            var exception = new Exception("foo");
            state1.TransitionOn(evt).To(state2).WithGuard(i =>
            {
                evt.Fire();
                throw exception;
            });
            state1.TransitionOn(evt2).To(state2);
            state2.TransitionOn(evt).To(state1);

            Assert.Throws<Exception>(() => evt.Fire());

            // Make sure that an event wasn't queued
            evt2.Fire();

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


示例6: InitialStateTAddedToParentStateMachine

 public void InitialStateTAddedToParentStateMachine()
 {
     var stateMachine = new StateMachine<StateData>("State Machine");
     var state = stateMachine.CreateInitialState("State", new StateData());
     Assert.AreEqual(state, stateMachine.InitialState);
     Assert.That(stateMachine.States, Is.EquivalentTo(new[] { state }));
 }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:7,代码来源:IntrospectionTests.cs


示例7: ForcefullyTransitioningFromChildStateMachineCallsExitHandlerOnCurrentState

        public void ForcefullyTransitioningFromChildStateMachineCallsExitHandlerOnCurrentState()
        {
            StateHandlerInfo<State> state22ExitInfo = null;

            var sm = new StateMachine("State Machine");
            var evt1 = new Event("Event 1");
            var state1 = sm.CreateInitialState("State 1");
            var state2 = sm.CreateState("State 2");
            var subSm = state2.CreateChildStateMachine();
            var state21 = subSm.CreateInitialState("State 2.1");
            var state22 = subSm.CreateState("State 2.2").WithExit(i => state22ExitInfo = i);

            state1.TransitionOn(evt1).To(state2);
            state21.TransitionOn(evt1).To(state22);

            // Enter state2, and start child state machine
            evt1.Fire();
            // Enter State 2.2
            evt1.Fire();
            // Transition from state2 to state1, exiting the child state machine
            sm.ForceTransition(state1, evt1);

            Assert.NotNull(state22ExitInfo);
            Assert.AreEqual(state22, state22ExitInfo.From);
            Assert.AreEqual(state1, state22ExitInfo.To);
            Assert.AreEqual(evt1, state22ExitInfo.Event);
        }
开发者ID:canton7,项目名称:StateMechanic,代码行数:27,代码来源:HandlerOrderTests.cs


示例8: TransitionNotFoundRaisedWhenTransitionNotFoundOnChild

        public void TransitionNotFoundRaisedWhenTransitionNotFoundOnChild()
        {
            var sm = new StateMachine("sm");
            var initial = sm.CreateInitialState("initial");
            var state1 = sm.CreateState("state 1");
            var child = initial.CreateChildStateMachine();
            var childInitial = child.CreateInitialState("childInitial");
            var evt = new Event("evt");

            state1.InnerSelfTransitionOn(evt);

            TransitionNotFoundEventArgs<State> ea = null;
            sm.TransitionNotFound += (o, e) =>
            {
                ea = e;
            };

            evt.TryFire();

            Assert.NotNull(ea);
            Assert.AreEqual(evt, ea.Event);
            Assert.AreEqual(initial, ea.From);
            Assert.AreEqual(sm, ea.StateMachine);
            Assert.AreEqual(EventFireMethod.TryFire, ea.EventFireMethod);
        }
开发者ID:canton7,项目名称:StateMechanic,代码行数:25,代码来源:TransitionNotificationTests.cs


示例9: CancellationTokenCancelsOperation

        public void CancellationTokenCancelsOperation()
        {
            var sm = new StateMachine("sm");
            var initial = sm.CreateInitialState("initial");
            var doingOperation = sm.CreateState("doingOperation");
            var completedOperation = sm.CreateState("completedOperation");
            var evt = new Event("evt");

            initial.TransitionOn(evt).To(doingOperation);
            doingOperation.TransitionOn(evt).To(completedOperation);

            var cts = new CancellationTokenSource();

            var op = new Operation<State>(evt, doingOperation, completedOperation);

            var task = op.TryFireAsync(cts.Token);

            Assert.False(task.IsCompleted);
            Assert.False(task.IsCanceled);

            cts.Cancel();

            Assert.True(task.IsCanceled);

            // Check nothing explodes
            evt.Fire();
        }
开发者ID:canton7,项目名称:StateMechanic,代码行数:27,代码来源:OperationTests.cs


示例10: 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


示例11: 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


示例12: StateMachineStartsInInitialState

        public void StateMachineStartsInInitialState()
        {
            var sm = new StateMachine("state machine");
            var initialState = sm.CreateInitialState("initial state");
            var state1 = sm.CreateState("state1");

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


示例13: 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


示例14: ThrowsIfForcedTransitionOnAChildEvent

        public void ThrowsIfForcedTransitionOnAChildEvent()
        {
            var sm = new StateMachine("State Machine");
            var state1 = sm.CreateInitialState("Initial State");
            var state2 = sm.CreateState("State 2");
            var subSm = state1.CreateChildStateMachine();
            var evt = subSm.CreateEvent("Event");

            Assert.Throws<InvalidEventTransitionException>(() => sm.ForceTransition(state2, evt));
        }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:10,代码来源:AssertionTests.cs


示例15: 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


示例16: TryFireReturnsFalseIfTransitionNotFound

        public void TryFireReturnsFalseIfTransitionNotFound()
        {
            var sm = new StateMachine("sm");
            var initialState = sm.CreateInitialState("initialState");
            var state1 = sm.CreateState("state1");
            var evt = new Event("evt");
            state1.InnerSelfTransitionOn(evt);

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


示例17: AddStateAddsState

        public void AddStateAddsState()
        {
            var sm = new StateMachine("sm");
            var state = sm.CreateInitialState("state");
            var group = new StateGroup("group");

            group.AddState(state);

            Assert.That(group.States, Is.EquivalentTo(new[] { state }));
        }
开发者ID:canton7,项目名称:StateMechanic,代码行数:10,代码来源:StateGroupTests.cs


示例18: ChildStateMachineStartsInInitialStateIfParentStateIsInitialState

        public void ChildStateMachineStartsInInitialStateIfParentStateIsInitialState()
        {
            var parent = new StateMachine("parent");
            var initial = parent.CreateInitialState("initial");
            var child = initial.CreateChildStateMachine();
            var childInitial = child.CreateInitialState("childInitial");

            Assert.AreEqual(childInitial, child.CurrentState);
            Assert.AreEqual(childInitial, child.InitialState);
        }
开发者ID:canton7,项目名称:StateMechanic,代码行数:10,代码来源:StateMachineStateTests.cs


示例19: ChildStateMachineStartsInNoStateIfParentStateIsNotInitialState

        public void ChildStateMachineStartsInNoStateIfParentStateIsNotInitialState()
        {
            var parent = new StateMachine("parent");
            var initial = parent.CreateInitialState("initial");
            var state1 = parent.CreateState("state1");
            var child = state1.CreateChildStateMachine();
            var childInitial = child.CreateInitialState("childInitial");

            Assert.AreEqual(null, child.CurrentState);
            Assert.AreEqual(childInitial, child.InitialState);
        }
开发者ID:canton7,项目名称:StateMechanic,代码行数:11,代码来源:StateMachineStateTests.cs


示例20: DynamicTransitionStateSelectorThrowsIfNullIsSet

        public void DynamicTransitionStateSelectorThrowsIfNullIsSet()
        {
            var sm = new StateMachine("sm");
            var state1 = sm.CreateInitialState("state1");
            var evt = new Event<string>("evt");

            Assert.Throws<ArgumentNullException>(() => state1.TransitionOn(evt).To(null));

            var transition = state1.TransitionOn(evt).ToDynamic(i => null);
            Assert.Throws<ArgumentNullException>(() => transition.StateSelector = null);
        }
开发者ID:canton7,项目名称:StateMechanic,代码行数:11,代码来源:DynamicTransitionTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# StatsdClient.Statsd类代码示例发布时间:2022-05-26
下一篇:
C# MDBservice.PM类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap