本文整理汇总了C#中StateMechanic.StateMachine.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# StateMachine.Reset方法的具体用法?C# StateMachine.Reset怎么用?C# StateMachine.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StateMechanic.StateMachine
的用法示例。
在下文中一共展示了StateMachine.Reset方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResetResetsCurrentStateOfStateMachine
public void ResetResetsCurrentStateOfStateMachine()
{
var sm = new StateMachine("sm");
var initial = sm.CreateInitialState("initial");
var state1 = sm.CreateState("state1");
var evt = sm.CreateEvent("evt");
initial.TransitionOn(evt).To(state1);
evt.Fire();
sm.Reset();
Assert.AreEqual(initial, sm.CurrentState);
}
示例2: ResettingStateMachineRemovesFault
public void ResettingStateMachineRemovesFault()
{
var exception = new Exception("foo");
var sm = new StateMachine("sm");
var initial = sm.CreateInitialState("initial").WithEntry(i => { throw exception; });
var evt = sm.CreateEvent("evt");
initial.TransitionOn(evt).To(initial);
Assert.Throws<TransitionFailedException>(() => evt.TryFire());
sm.Reset();
Assert.False(sm.IsFaulted);
Assert.Null(sm.Fault);
}
示例3: ResetResetsStateOfChildStateMachines
public void ResetResetsStateOfChildStateMachines()
{
var parent = new StateMachine("parent");
var initialState = parent.CreateInitialState("initialState");
var state1 = parent.CreateState("state1");
var child = state1.CreateChildStateMachine();
var substate1 = child.CreateInitialState("substate1");
var substate2 = child.CreateState("substate2");
var evt = parent.CreateEvent("evt");
initialState.TransitionOn(evt).To(state1);
substate1.TransitionOn(evt).To(substate2);
evt.Fire();
evt.Fire();
parent.Reset();
Assert.IsNull(child.CurrentState);
}
示例4: ResetEmptiesTransitionQueue
public void ResetEmptiesTransitionQueue()
{
var sm = new StateMachine("parent");
var state1 = sm.CreateInitialState("state1");
var state2 = sm.CreateState("state2");
var evt = new Event("evt");
state1.TransitionOn(evt).To(state2).WithHandler(i =>
{
evt.Fire();
sm.Reset();
});
state2.TransitionOn(evt).To(state1);
evt.Fire();
// Make sure that the queued event didn't get fired
Assert.AreEqual(state2, sm.CurrentState);
// Make sure nothing's been queued
evt.Fire();
Assert.AreEqual(state1, sm.CurrentState);
}
示例5: StateMachineDoesNotResetUntilActionIsInvoked
public void StateMachineDoesNotResetUntilActionIsInvoked()
{
// Need to transition, so we can tell when it's reset
var sm = new StateMachine("sm");
var initial = sm.CreateInitialState("initial");
var state1 = sm.CreateState("state1");
var evt = new Event("evt");
initial.TransitionOn(evt).To(state1);
evt.Fire();
var synchronizer = new Mock<IStateMachineSynchronizer>();
sm.Synchronizer = synchronizer.Object;
Action resetAction = null;
synchronizer.Setup(x => x.Reset(It.IsAny<Action>())).Callback((Action action) => resetAction = action);
sm.Reset();
Assert.AreEqual(state1, sm.CurrentState);
Assert.NotNull(resetAction);
resetAction();
Assert.AreEqual(initial, sm.CurrentState);
}
示例6: ResetCallsSynchronizerReset
public void ResetCallsSynchronizerReset()
{
var synchronizer = new Mock<IStateMachineSynchronizer>();
var sm = new StateMachine("sm");
sm.Synchronizer = synchronizer.Object;
sm.Reset();
synchronizer.Verify(x => x.Reset(It.IsAny<Action>()));
}
示例7: TransitionGuards
public static void TransitionGuards()
{
var stateMachine = new StateMachine();
var stateA = stateMachine.CreateInitialState("State A");
var stateB = stateMachine.CreateState("State B");
var stateC = stateMachine.CreateState("State C");
var eventE = new Event("Event E");
///////////////////////
bool allowTransitionToStateB = false;
stateA.TransitionOn(eventE).To(stateB).WithGuard(info => allowTransitionToStateB);
stateA.TransitionOn(eventE).To(stateC);
eventE.Fire();
Assert.AreEqual(stateC, stateMachine.CurrentState);
///////////////////////
stateMachine.Reset();
///////////////////////
// Alternatively...
allowTransitionToStateB = true;
eventE.Fire();
Assert.AreEqual(stateB, stateMachine.CurrentState);
///////////////////////
}
示例8: SerializationAndDeserialization
public static void SerializationAndDeserialization()
{
var stateMachine = new StateMachine();
var stateA = stateMachine.CreateInitialState("StateA");
var stateB = stateMachine.CreateState("StateB");
var evt = new Event();
stateA.TransitionOn(evt).To(stateB);
// Move us out of the default state
evt.Fire();
Assert.AreEqual(stateB, stateMachine.CurrentState);
string serialized = stateMachine.Serialize();
// Reset the state machine
stateMachine.Reset();
Assert.AreEqual(stateA, stateMachine.CurrentState);
// Deserialize into it
stateMachine.Deserialize(serialized);
Assert.AreEqual(stateB, stateMachine.CurrentState);
}
示例9: DynamicTransitions
public static void DynamicTransitions()
{
var stateMachine = new StateMachine();
var stateA = stateMachine.CreateInitialState("State A");
var stateB = stateMachine.CreateState("State B");
var stateC = stateMachine.CreateState("State C");
var eventE = new Event("Event E");
///////////////////////
State stateToTransitionTo = stateB;
stateA.TransitionOn(eventE).ToDynamic(info => stateToTransitionTo);
eventE.Fire();
Assert.AreEqual(stateB, stateMachine.CurrentState);
///////////////////////
stateMachine.Reset();
///////////////////////
// Alternatively...
stateToTransitionTo = stateC;
eventE.Fire();
Assert.AreEqual(stateC, stateMachine.CurrentState);
}