本文整理汇总了C#中State.To方法的典型用法代码示例。如果您正苦于以下问题:C# State.To方法的具体用法?C# State.To怎么用?C# State.To使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类State
的用法示例。
在下文中一共展示了State.To方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public static void Run () {
var model = new StateMachine<Instance>("model");
var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
var target = new State<Instance>("state", model).Entry(i => i.Int1++).Exit(i => i.Int2++);
initial.To(target);
target.To().When<string>(m => m == "internal").Effect(i => i.Int3++);
target.To(target).When<string>(m => m == "external").Effect(i => i.Int3++);
var instance = new Instance("internal");
model.Validate();
model.Initialise(instance);
model.Evaluate(instance, "internal");
Trace.Assert(target == instance.GetCurrent(model.DefaultRegion));
Trace.Assert(1 == instance.Int1);
Trace.Assert(0 == instance.Int2);
Trace.Assert(1 == instance.Int3);
model.Evaluate(instance, "external");
Trace.Assert(target == instance.GetCurrent(model.DefaultRegion));
Trace.Assert(2 == instance.Int1);
Trace.Assert(1 == instance.Int2);
Trace.Assert(2 == instance.Int3);
}
示例2: Run
public static void Run () {
var model = new StateMachine<Instance>("compTest");
var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
var activity1 = new State<Instance>("activity1", model);
var activity2 = new State<Instance>("activity2", model);
var activity3 = new State<Instance>("activity3", model);
var junction1 = new PseudoState<Instance>("junction1", model, PseudoStateKind.Junction);
var junction2 = new PseudoState<Instance>("junction2", model, PseudoStateKind.Junction);
var end = new FinalState<Instance>("end", model);
var subInitial = new PseudoState<Instance>("subInitial", activity2, PseudoStateKind.Initial);
var subEnd = new FinalState<Instance>("subEnd", activity2);
subInitial.To(subEnd);
initial.To(activity1);
activity1.To(activity2);
activity2.To(junction1);
junction1.To(junction2).Else();
junction2.To(activity3).Else();
activity3.To(end);
model.Validate();
var instance = new Instance("transitions");
model.Initialise(instance);
Trace.Assert(model.IsComplete(instance));
}
示例3: Run
public static void Run () {
var model = new StateMachine<Instance>("history");
var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
var shallow = new State<Instance>("shallow", model);
var deep = new State<Instance>("deep", model);
var end = new FinalState<Instance>("final", model);
var s1 = new State<Instance>("s1", shallow);
var s2 = new State<Instance>("s2", shallow);
initial.To(shallow);
new PseudoState<Instance>("shallow", shallow, PseudoStateKind.ShallowHistory).To(s1);
s1.To(s2).When<string>(c => c == "move");
shallow.To(deep).When<string>(c => c == "go deep");
deep.To(shallow).When<string>(c => c == "go shallow");
s2.To(end).When<string>(c => c == "end");
model.Validate();
var instance = new Instance("history");
model.Initialise(instance);
model.Evaluate(instance, "move");
model.Evaluate(instance, "go deep");
model.Evaluate(instance, "go shallow");
model.Evaluate(instance, "end");
Trace.Assert(model.IsComplete(instance));
}
示例4: Run
public static void Run () {
var model = new StateMachine<Instance>("model");
var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
var state1 = new State<Instance>("state1", model);
var state2 = new State<Instance>("state2", model);
var regionA = new Region<Instance>("regionA", state1);
var initialA = new PseudoState<Instance>("initialA", regionA, PseudoStateKind.Initial);
var state3 = new State<Instance>("state3", regionA);
var state8 = new State<Instance>("state8", regionA);
var regionB = new Region<Instance>("regionB", state1);
var initialB = new PseudoState<Instance>("initialB", regionB, PseudoStateKind.Initial);
var state4 = new State<Instance>("state4", regionB);
var state5 = new State<Instance>("state5", regionB);
var regionBa = new Region<Instance>("regionBa", state4);
var initialBa = new PseudoState<Instance>("initialBa", regionBa, PseudoStateKind.Initial);
var state6 = new State<Instance>("state6", regionBa);
var regionBb = new Region<Instance>("regionBb", state4);
var initialBb = new PseudoState<Instance>("initialBb", regionBb, PseudoStateKind.Initial);
var state7 = new State<Instance>("state7", regionBb);
initial.To(state1);
initialA.To(state3);
initialB.To(state4);
initialBa.To(state6);
initialBb.To(state7);
state3.To(state2).When<string>(c => c == "event2");
state3.To(state8).When<string>(c => c == "event1");
state7.To(state5).When<string>(c => c == "event2");
state7.To(state5).When<string>(c => c == "event1");
model.Validate();
var instance = new Instance("p3pp3r");
model.Initialise(instance);
model.Evaluate(instance, "event2");
Trace.Assert(state2 == instance.GetCurrent(model.DefaultRegion), instance.GetCurrent(model.DefaultRegion).ToString() );
Trace.Assert(state4 == instance.GetCurrent(regionB));
}
示例5: DocumentStates
public static List<State<string>> DocumentStates()
{
var draft = new State<string>("draft");
var pending = new State<string>("pending");
var approved = new State<string>("approved");
var deleted = new State<string>("deleted");
var archived = new State<string>("archived");
draft.To(pending).On("send-to-approval");
draft.To(deleted).On("delete");
pending.To(approved).On("approve");
pending.To(deleted).On("delete");
//pending.To(draft).On("reject");
approved.To(archived).On("archive");
archived.To(deleted).On("delete");
archived.To(approved).On("unarchive");
return new List<State<string>> { draft, pending, approved, deleted, archived };
}
示例6: Run
public static void Run () {
// create the state machine model elements
var model = new StateMachine<Instance>("model");
var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
var stateA = new State<Instance>("stateA", model);
var stateB = new State<Instance>("stateB", model).Exit(i => i.Int1++);
var bInitial = new PseudoState<Instance>("bInitial", stateB);
var bStateI = new State<Instance>("bStateI", stateB);
var bStateII = new State<Instance>("bStateII", stateB);
// create the state machine model transitions
initial.To(stateA);
stateA.To(stateB).When<string>(message => message == "move");
bInitial.To(bStateI);
stateB.To(bStateII, TransitionKind.Local).When<string>(message => message == "local");
stateB.To(bStateII, TransitionKind.External).When<string>(message => message == "external");
model.Validate();
// create a state machine instance
var instance = new Instance("local");
// initialise the model and instance
model.Initialise(instance);
// send the machine instance a message for evaluation, this will trigger the transition from stateA to stateB
model.Evaluate(instance, "move");
model.Evaluate(instance, "local");
Trace.Assert(0 == instance.Int1);
model.Evaluate(instance, "external");
Trace.Assert(1 == instance.Int1);
}
示例7: BabyStates
public static List<State<string>> BabyStates()
{
var happy = new State<string>("happy");
var unhappy = new State<string>("unhappy");
var hungry = new State<string>("hungry");
var teething = new State<string>("teething");
var sleepy = new State<string>("sleepy");
var sleeping = new State<string>("sleeping");
var diaper = new State<string>("diaperchange");
happy.To(happy).On("tickle").Do(() => Console.WriteLine("Giggle"));
happy.To(hungry).On("hungry");
happy.To(sleepy).On("sleepy");
happy.To(diaper).On("poo");
happy.To(teething).On("tooth");
unhappy.To(happy).On(s => new[] { "tickle", "rattle", "milk" }.Contains(s));
unhappy.To(unhappy).On(s => !(new[] { "tickle", "rattle", "milk" }.Contains(s)));
hungry.To(happy).On("milk");
hungry.To(hungry).On("lullaby");
sleepy.To(sleepy).On("milk");
sleepy.To(sleeping).On("lullaby");
sleeping.To(unhappy).On("wake").Do(() => Console.WriteLine("Waaaaah! Wahaah!"));
teething.To(sleepy).On("sleepy");
teething.To(diaper).On("poo");
teething.To(hungry).On("hungry");
diaper.To(happy).On("change");
diaper.To(diaper).On("lullaby");
return new List<State<string>> { happy, unhappy, hungry, teething, sleepy, sleeping, diaper };
}
示例8: SimpleBabyStates
public static List<State<string>> SimpleBabyStates()
{
var happy = new State<string>("nappy");
var screaming = new State<string>("screaming");
var sleeping = new State<string>("sleeping");
var diaper = new State<string>("diaperchange");
happy.To(happy).On("tickle").Do(() => Console.WriteLine("Giggle!"));
happy.To(screaming).On("hungry").Do(() => Console.WriteLine("Waah!"));
//happy.To(screaming).On("sleepy");
happy.To(diaper).On("poo").Do(() => Console.WriteLine("..."), () => { throw new Exception(); });
screaming.To(sleeping).On("lullaby");
//screaming.To(sleeping).On("milk");
screaming.To(happy).On("rattle");
sleeping.To(screaming).On("wake").Do(() => Console.WriteLine("Waaaaah! Wahaah!"));
diaper.To(happy).On("change");
diaper.To(screaming).On("lullaby");
//diaper.To(screaming).On("rattle");
return new List<State<string>> { happy, screaming, sleeping, diaper };
}
示例9: Run
public static void Run () {
var model = new StateMachine<Instance>("model");
var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
var stateA = new State<Instance>("stateA", model);
var choice = new PseudoState<Instance>("choice", model, PseudoStateKind.Choice);
initial.To(stateA);
stateA.To(choice).When<string>(message => message == "choose");
choice.To(stateA).Effect(instance => instance.Int1++);
choice.To(stateA).Effect(instance => instance.Int2++);
choice.To(stateA).Effect(instance => instance.Int3++);
model.Validate();
var instance1 = new Instance("instance1");
model.Initialise(instance1);
for (var i = 0; i < 99; i++) {
model.Evaluate(instance1, "choose");
}
Trace.Assert(99 == (instance1.Int1 + instance1.Int2 + instance1.Int3));
Runtime.Extensions.RandomSelector = randRobin;
var instance2 = new Instance("instance2");
model.Initialise(instance2);
for (var i = 0; i < 99; i++) {
model.Evaluate(instance2, "choose");
}
model.Evaluate(instance2, "end");
Trace.Assert(33 == instance2.Int1);
Trace.Assert(33 == instance2.Int2);
Trace.Assert(33 == instance2.Int3);
}
示例10: Run
public static void Run () {
var model = new StateMachine<Instance>("model");
var initial = new PseudoState<Instance>("initial", model);
var stateA = new State<Instance>("stateA", model);
var terminate = new PseudoState<Instance>("terminate", model, PseudoStateKind.Terminate);
initial.To(stateA);
stateA.To(terminate).When<string>(message => message == "1");
model.Validate();
var instance = new Instance("terminate");
model.Initialise(instance);
Trace.Assert(!model.Evaluate(instance, "2"));
Trace.Assert(model.Evaluate(instance, "1"));
Trace.Assert(!model.Evaluate(instance, "1"));
Trace.Assert(instance.IsTerminated);
}
示例11: Run
public static void Run () {
var model = new StateMachine<Instance>("model");
var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
var stateA = new State<Instance>("stateA", model).Exit(i => i.Int1 += 1);
var stateB = new State<Instance>("stateB", model).Entry(i => i.Int1 += 2);
initial.To(stateA);
stateA.To(stateB).When<string>(message => message == "move").Effect(i => i.Int1 += 4);
model.Validate();
var instance = new Instance("callbacks");
model.Initialise(instance);
model.Evaluate(instance, "move");
Trace.Assert(1 == (1 & instance.Int1));
Trace.Assert(2 == (2 & instance.Int1));
Trace.Assert(4 == (4 & instance.Int1));
}
示例12: Run
public static void Run () {
var model = new StateMachine<Instance>("model");
var initial1 = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
var myComposite1 = new State<Instance>("composite1", model);
var state3 = new State<Instance>("state3", model);
var initial2 = new PseudoState<Instance>("initial", myComposite1, PseudoStateKind.Initial);
var state1 = new State<Instance>("state1", myComposite1);
var state2 = new State<Instance>("state2", myComposite1);
initial1.To(myComposite1);
initial2.To(state1);
myComposite1.To(state3).When<string>(c => c == "a");
state1.To(state2).When<string>(c => c == "a");
model.Validate();
var instance = new Instance("brice");
model.Initialise(instance);
model.Evaluate(instance, "a");
Trace.Assert(instance.GetCurrent(myComposite1.DefaultRegion) == state2);
}
示例13: MoodStates
public static List<State<string>> MoodStates()
{
var neutral = new State<string>("neutral");
var drunk = new State<string>("drunk");
var happy = new State<string>("happy");
var moody = new State<string>("moody");
var angry = new State<string>("angry");
neutral.To(happy).On("tickle");
neutral.To(moody).On("hassle");
neutral.To(drunk).On(s => s.Contains("beer"));
moody.To(angry).On("tickle");
moody.To(neutral).On(s => s.Contains("beer"));
happy.To(neutral).On(s => "hassle".Equals(s));
return new List<State<string>> { neutral, moody, happy, angry, drunk };
}
示例14: Run
public static void Run () {
var model = new StateMachine<Instance>("model");
var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
var ortho = new State<Instance>("ortho", model);
var simple = new State<Instance>("simple", model);
var final = new FinalState<Instance>("final", model);
var r1 = new Region<Instance>("r1", ortho);
var r2 = new Region<Instance>("r2", ortho);
var i1 = new PseudoState<Instance>("initial", r1, PseudoStateKind.ShallowHistory);
var i2 = new PseudoState<Instance>("initial", r2, PseudoStateKind.ShallowHistory);
var s1 = new State<Instance>("s1", r1);
var s2 = new State<Instance>("s2", r2);
var f1 = new FinalState<Instance>("f1", r1);
var f2 = new FinalState<Instance>("f2", r2);
initial.To(ortho);
i1.To(s1);
i2.To(s2);
ortho.To(final); // This should happen once all regions in ortho are complete?
s1.To(f1).When<string>(c => c == "complete1");
s2.To(f2).When<string>(c => c == "complete2");
ortho.To(simple).When<string>(c => c == "jump");
simple.To(ortho).When<string>(c => c == "back");
model.Validate();
var instance = new Instance("muximise");
model.Initialise(instance);
/*
console.log("simple.isSimple = " + simple.isSimple());
console.log("simple.isComposite = " + simple.isComposite());
console.log("simple.isOrthogonal = " + simple.isOrthogonal());
console.log("model.isSimple = " + model.isSimple());
console.log("model.isComposite = " + model.isComposite());
console.log("model.isOrthogonal = " + model.isOrthogonal());
console.log("ortho.isSimple = " + ortho.isSimple());
console.log("ortho.isComposite = " + ortho.isComposite());
console.log("ortho.isOrthogonal = " + ortho.isOrthogonal());
*/
Trace.Assert(simple.IsSimple);
Trace.Assert(!model.IsSimple);
Trace.Assert(!ortho.IsSimple);
Trace.Assert(!simple.IsComposite);
Trace.Assert(model.IsComposite);
Trace.Assert(ortho.IsComposite);
Trace.Assert(!simple.IsOrthogonal);
Trace.Assert(!model.IsOrthogonal);
Trace.Assert(ortho.IsOrthogonal);
model.Evaluate(instance, "complete1");
model.Evaluate(instance, "complete2");
Trace.Assert(model.IsComplete(instance));
}