Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rcarubbi/carubbi.statemachine
Generic State Machine Aspect-oriented-programming based Implementation
https://github.com/rcarubbi/carubbi.statemachine
aop csharp generic-state-machine state-machine
Last synced: about 2 months ago
JSON representation
Generic State Machine Aspect-oriented-programming based Implementation
- Host: GitHub
- URL: https://github.com/rcarubbi/carubbi.statemachine
- Owner: rcarubbi
- Created: 2016-10-24T01:04:31.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-04T12:17:32.000Z (about 6 years ago)
- Last Synced: 2023-03-22T22:11:01.667Z (almost 2 years ago)
- Topics: aop, csharp, generic-state-machine, state-machine
- Language: C#
- Homepage:
- Size: 363 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Carubbi.StateMachine
Generic State Machine Aspect-oriented-programming based ImplementationJust create your entity like this:
```csharp
[InitialState("State1")]
public class Entity : IStatedEntity
{[Transition(From = "State1", To = "State2")]
[Transition(From = "State3", To = "State1")]
public void Method1()
{
Trace.WriteLine("Method1");
}[Transition(From = "State2", To = "State1")]
public string Method2()
{
Trace.WriteLine("Method2");
return string.Empty;
}[Transition(From = "State2", To = "State3")]
[Transition(From = "State3", To = "State4")]
public int Method3(int p1, int p2)
{
Trace.WriteLine("Method3");
return p1 + p2;
}public StateMachine StateMachine { get; set; }
}
```and use it this way:
```csharp[TestMethod]
public void TestMethod1()
{
StateMachine.Configure();
var ent = new Entity
{
StateMachine =
{
IgnoreInvalidOperations = true
}
};ent.StateMachine.TransitionStarted += StateMachine_TransitionStarted;
ent.StateMachine.TransitionEnded += StateMachine_TransitionEnded;Trace.WriteLine(ent.StateMachine.CurrentState);
ent.Method1();
Trace.WriteLine(ent.StateMachine.CurrentState);
ent.Method2();
Trace.WriteLine(ent.StateMachine.CurrentState);
ent.Method1();
Trace.WriteLine(ent.StateMachine.CurrentState);
var result = ent.Method3(2, 4);
Trace.WriteLine(ent.StateMachine.CurrentState);
var result2 = ent.Method3(4, 4);
Trace.WriteLine(ent.StateMachine.CurrentState);
var result3 = ent.Method3(4, 4);
Trace.WriteLine(ent.StateMachine.CurrentState);
}private void StateMachine_TransitionEnded(object sender, TransitionEventArgs e)
{}
private void StateMachine_TransitionStarted(object sender, TransitionStartedEventArgs e)
{
}
}
```