本文整理汇总了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);
}
示例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);
}