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


C# Machine.On方法代码示例

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


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

示例1: Init

        public void Init()
        {
            var mocker = new AutoMocker();

            var machine = new Machine<State, Trigger>(State.First,
                mocker.Get<ILoggerFactory>(),
                mocker.Get<IObservableProvider>());

            machine.On(State.First).
                OnEntry(() =>
                {
                    Assert.Equal(State.First, machine.State);

                    System.Console.WriteLine($"first {machine.State}");
                })
                .Permit(Trigger.ChangeToSecond, State.Second)
                .Permit(Trigger.ChangeToFirst, State.First);

            machine.On(State.Second).
                OnEntry(() =>
                {
                    Assert.Equal(State.Second, machine.State);

                    System.Console.WriteLine($"second {machine.State}");
                })
                .Permit(Trigger.ChangeToSecond, State.Second)
                .Permit(Trigger.ChangeToThird, State.Third);

            machine.On(State.Third).
                OnEntry(() =>
                {
                    Assert.Equal(State.Third, machine.State);
                });

            machine.OnNext(Trigger.ChangeToFirst);

            Assert.Equal(State.First, machine.State);

            machine.OnNext(Trigger.ChangeToThird);

            Assert.Equal(State.First, machine.State);

            machine.OnNext(Trigger.ChangeToSecond);

            Assert.Equal(State.Second, machine.State);

            machine.OnNext(Trigger.ChangeToThird);

            Assert.Equal(State.Third, machine.State);

            machine.OnNext(Trigger.ChangeToFirst);


        }
开发者ID:RossMerr,项目名称:Caudex.StateMachine,代码行数:54,代码来源:Class1.cs

示例2: Node

        public Node(IVoteReceived voteReceived, 
            IAppendEntry appendEntry, 
            IHartbeatTimer hartbeat, 
            ILoggerFactory loggerFactory, 
            IObservableProvider observableProvider,
            ILogReplication logReplication,
            ServerIdentifier serverIdentifier)
        {
            _logReplication = logReplication;
            _serverIdentifier = serverIdentifier;
            _hartbeatTimer = hartbeat;

            _stateMachine = new Machine<ServerStateType, ServerStateType>(ServerStateType.Candidate,
                loggerFactory, observableProvider);

            _stateMachine.On(ServerStateType.Follower)
                .OnEntry(() =>
                {
                    hartbeat.Subscribe(_stateMachine);
                })
                .OnEntrySubscribe<Follower>()
                .Permit(ServerStateType.Candidate, ServerStateType.Candidate);

            _stateMachine.On(ServerStateType.Candidate)
                .OnEntrySubscribe<Candidate>()
                .OnEntry(hartbeat.Reset)
                .Permit(ServerStateType.Follower, ServerStateType.Follower)
                .Permit(ServerStateType.Leader, ServerStateType.Leader)
                .Permit(ServerStateType.Candidate, ServerStateType.Candidate);

            _stateMachine.On(ServerStateType.Leader)
                .OnEntrySubscribe<Leader>()
                .Permit(ServerStateType.Follower, ServerStateType.Follower);

            _voteReceivedeDispose = voteReceived.Subscribe(_stateMachine);
            _appendEntryDispose = appendEntry.Subscribe(_stateMachine);
            _stateMachine.OnNext(ServerStateType.Follower);
        }
开发者ID:RossMerr,项目名称:Caudex.Rafting,代码行数:38,代码来源:Node.cs


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