StateMesh.Core
1.0.0
dotnet add package StateMesh.Core --version 1.0.0
NuGet\Install-Package StateMesh.Core -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StateMesh.Core" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StateMesh.Core --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: StateMesh.Core, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install StateMesh.Core as a Cake Addin #addin nuget:?package=StateMesh.Core&version=1.0.0 // Install StateMesh.Core as a Cake Tool #tool nuget:?package=StateMesh.Core&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Description
StateMesh is a workflow engine. It translates the workflow between logic and JSON description. Anyone uses StateMesh could generate their workflow definition from JSON and process it anywhere. Here's a sample.
SAMPLE target flow
ws1---l12---->ws2 ----l23---->ws3----l34----ws4
↑ |
--------l31------------------
Main Class
using StateMesh.Core.Engine;
using StateMesh.Core.Models;
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
namespace StateMesh.Sample
{
class Program
{
static void Main(string[] args)
{
WorkflowDefinition definition = new WorkflowDefinition();
definition.DefinitionId = "single-sample";
definition.Description = "my test sample for workflow engine";
definition.Name = "testsample";
WorkflowState ws1 = new WorkflowState()
{
Id = "ws1",
Name = "ws1name",
Description = "ws1name"
};
WorkflowState ws2 = new WorkflowState()
{
Id = "ws2",
Name = "ws2name",
Description = "ws2name"
};
WorkflowState ws3 = new WorkflowState()
{
Id = "ws3",
Name = "ws3name",
Description = "ws3name"
};
WorkflowState ws4 = new WorkflowState()
{
Id = "ws4",
Name = "finished",
Description = "ws4name"
};
definition.States = new System.Collections.Generic.Dictionary<string, WorkflowState>();
definition.States.Add(ws1.Id, ws1);
definition.States.Add(ws2.Id, ws2);
definition.States.Add(ws3.Id, ws3);
definition.States.Add(ws4.Id, ws4);
WorkflowLine l12 = new WorkflowLine()
{
Id = "l12",
From = ws1.Id,
To = ws2.Id,
DoActions = new System.Collections.Generic.List<WorkflowAction>()
};
l12.DoActions.Add(new WorkflowAction()
{
Id = "internal",
InvokeName = "ReadName",
PackageId = "SELF",
Namespace = "StateMesh.Sample.TestAction",
Parameters = new System.Collections.Generic.List<WorkflowActionParameter>()
{
new WorkflowActionParameter()
{
Id = "testparameter1",
ClassType = typeof(string).ToString(),
IsInput = false,
MappedTo = "myname",
ParameterName = "myname"
},
new WorkflowActionParameter()
{
Id = "testparameter2",
ClassType = typeof(string).ToString(),
IsInput = true,
MappedTo = "filePath",
ParameterName = "filePath"
}
}
});
WorkflowLine l23 = new WorkflowLine()
{
Id = "l23",
From = ws2.Id,
To = ws3.Id,
DoActions = new System.Collections.Generic.List<WorkflowAction>(),
Condition = new WorkflowConditionGroup()
};
l23.Condition.Id = "cc";
l23.Condition.Relationship = "OR";
l23.PreDoActions = new List<WorkflowAction>()
{
new WorkflowAction()
{
Id = "internal",
InvokeName = "ReadName",
PackageId = "SELF",
Namespace = "StateMesh.Sample.TestAction",
Parameters = new System.Collections.Generic.List<WorkflowActionParameter>()
{
new WorkflowActionParameter()
{
Id = "testparameter1",
ClassType = typeof(string).ToString(),
IsInput = false,
MappedTo = "myname",
ParameterName = "myname"
},
new WorkflowActionParameter()
{
Id = "testparameter2",
ClassType = typeof(string).ToString(),
IsInput = true,
MappedTo = "filePath",
ParameterName = "filePath"
}
}
}
};
l23.Condition.Conditions = new System.Collections.Generic.List<WorkflowCondition>()
{
new WorkflowCondition()
{
Id = "cc1",
Action = new WorkflowAction()
{
Id = "internal",
InvokeName = "IsTilerphyApprovaled",
PackageId = "SELF",
Namespace = "StateMesh.Sample.TestAction",
},
Assertions = new System.Collections.Generic.List<WorkflowAssertion>()
{
new WorkflowAssertion()
{
Id = "testassert",
MappedTo = "IsTilerphyApprovaled.Result",
Operation = WorkflowAssertion.String_Equals,
TypeAssertion = typeof(bool).ToString(),
ValueAssertion = true
}
}
}
};
l23.DoActions.Add(new WorkflowAction()
{
Id = "internal",
InvokeName = "HelloWorld",
PackageId = "SELF",
Namespace = "StateMesh.Sample.TestAction"
});
WorkflowLine l31 = new WorkflowLine()
{
Id = "l31",
From = ws3.Id,
To = ws1.Id,
DoActions = new System.Collections.Generic.List<WorkflowAction>()
};
WorkflowLine l34 = new WorkflowLine()
{
Id = "l34",
From = ws3.Id,
To = ws4.Id,
DoActions = new System.Collections.Generic.List<WorkflowAction>()
};
definition.Lines = new System.Collections.Generic.Dictionary<string, WorkflowLine>();
definition.Lines.Add(l12.Id, l12);
definition.Lines.Add(l23.Id, l23);
definition.Lines.Add(l34.Id, l34);
definition.Lines.Add(l31.Id,l31);
definition.HeadState = ws1.Id;
definition.TailState = ws4.Id;
WorkflowPlayer wp = new WorkflowPlayer();
Dictionary<string, Workflow> workflowCache = new Dictionary<string, Workflow>();
IntegratingSpigot.CreateWorkflow = new Func<Workflow, int>((w)=> { workflowCache.Add(w.Id, w); return 1; });
IntegratingSpigot.CreateWorkflowJsonShotcut = new Action<string>((s)=> { Console.WriteLine(s); });
IntegratingSpigot.GetAllWorkflowsWithAutomaticalLines = new Func<List<Workflow>>(()=> { return null; });
IntegratingSpigot.GetAssemblyBytesByPackageId = new Func<string, byte[]>((s)=> { return null; });
IntegratingSpigot.UpdateWorkflow = new Func<Workflow, int>((w)=> { workflowCache[w.Id] = w; return 1; });
IntegratingSpigot.UseDefaultTimer = false;
wp.Start();
Workflow testone = wp.CreateNewWorkflowInstanceFromDefinition(definition);
testone.Context.Add("filePath", @"C:\Users\zbsun\Desktop\approval.txt");
while (true)
{
Console.WriteLine("Exported json: {0}",testone.Export());
if (testone.Status == WorkflowPlayer.WorkflowStatus.Finished
|| testone.Status == WorkflowPlayer.WorkflowStatus.Aborted
|| testone.TailState == testone.CurrentStateId)
{
break;
}
var lines = testone.GetStepableLines();
Console.WriteLine("These line can go: {0}", string.Join(",", lines.Select(a=> a.Id).ToArray()));
Console.Write("Type something, entry to next step.");
string l = Console.ReadLine();
if (l == "q")
{
testone.Status = WorkflowPlayer.WorkflowStatus.Finished;
break;
}
if (l == "") continue;
if (l.StartsWith("load", StringComparison.OrdinalIgnoreCase))
{
string replaceId = testone.Id;
testone = Workflow.Parse(System.IO.File.ReadAllText(l.Substring(5)));
testone.Id = replaceId;
continue;
}
if (testone.Lines.ContainsKey(l))
{
var result = wp.ProcessWorkflowLine(testone, testone.Lines[l]);
Console.WriteLine(string.Join(",", result.Reasons.ToArray()));
}
else
{
Console.WriteLine("{0} is not an available line.", l);
}
}
Console.Write("Workflow finished at state {0}", testone.CurrentStateId);
}
}
}
TestAction
using StateMesh.Core.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace StateMesh.Sample
{
public class TestAction
{
public string OwnerId { get; set; }
public void ReadName(Workflow workflow, string filePath)
{
if (workflow.Context.ContainsKey("myname"))
{
workflow.Context["myname"] = System.IO.File.ReadAllText(filePath);
}
else
{
workflow.Context.Add("myname", System.IO.File.ReadAllText(filePath));
}
}
public void IsTilerphyApprovaled(Workflow workflow)
{
if (workflow.Context.ContainsKey("IsTilerphyApprovaled.Result"))
{
workflow.Context["IsTilerphyApprovaled.Result"] = workflow.Context["myname"].ToString() == "tilerphy";
}
else
{
workflow.Context.Add("IsTilerphyApprovaled.Result", workflow.Context["myname"].ToString() == "tilerphy");
}
}
public void HelloWorld(Workflow workflow)
{
Console.WriteLine("{0} Complete.", this.OwnerId);
}
}
}
Exported Workflow Instance (importable as a Workflow)
{
"Id": "346ca951-4641-42da-9142-879f12f896fc",
"Context": {
"filePath": "C:\\Users\\zbsun\\Desktop\\approval.txt",
"_.linetrace": [{
"Key": "l12",
"Value": 1644809904
}, {
"Key": "l23",
"Value": 1644809906
}, {
"Key": "l12",
"Value": 1644809908
}, {
"Key": "l12",
"Value": 1644809909
}, {
"Key": "l12",
"Value": 1644809910
}, {
"Key": "l31",
"Value": 1644809913
}],
"myname": "tilerphy",
"_.actiontrace": [{
"Key": true,
"Value": "internal"
}, {
"Key": true,
"Value": "internal"
}, {
"Key": true,
"Value": "internal"
}, {
"Key": true,
"Value": "internal"
}, {
"Key": true,
"Value": "internal"
}, {
"Key": true,
"Value": "internal"
}],
"_.linetrace.transition": [{
"Key": "l12",
"Value": 1644809904
}, {
"Key": "l23",
"Value": 1644809906
}, {
"Key": "l31",
"Value": 1644809913
}],
"IsTilerphyApprovaled.Result": true
},
"__Context_Value_Types": {
"filePath": "System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
"_.linetrace": "System.Collections.Generic.List`1[[System.Collections.Generic.KeyValuePair`2[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int64, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
"myname": "System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
"_.actiontrace": "System.Collections.Generic.List`1[[System.Collections.Generic.KeyValuePair`2[[System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
"_.linetrace.transition": "System.Collections.Generic.List`1[[System.Collections.Generic.KeyValuePair`2[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int64, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
"IsTilerphyApprovaled.Result": "System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"
},
"CurrentStateId": "ws1",
"LastChangedTime": 637804067137554237,
"LastOperator": "SYSTEM",
"LastLineId": "l31",
"Status": "Pending",
"DefinitionId": "single-sample",
"HeadState": "ws1",
"TailState": "ws4",
"States": {
"ws1": {
"Id": "ws1",
"Name": "ws1name",
"Description": "ws1name",
"UIStyle": null
},
"ws2": {
"Id": "ws2",
"Name": "ws2name",
"Description": "ws2name",
"UIStyle": null
},
"ws3": {
"Id": "ws3",
"Name": "ws3name",
"Description": "ws3name",
"UIStyle": null
},
"ws4": {
"Id": "ws4",
"Name": "finished",
"Description": "ws4name",
"UIStyle": null
}
},
"Lines": {
"l12": {
"Id": "l12",
"Namespace": null,
"From": "ws1",
"To": "ws2",
"Weight": 0,
"IgnoreDoActionsExceptions": false,
"IsAutomaticalLine": false,
"PreDoActions": null,
"DoActions": [{
"Id": "internal",
"PackageId": "SELF",
"Namespace": "StateMesh.Sample.TestAction",
"InvokeName": "ReadName",
"Parameters": [{
"Id": "testparameter1",
"ParameterName": "myname",
"MappedTo": "myname",
"IsInput": false,
"ClassType": "System.String",
"DefaultValue": null
}, {
"Id": "testparameter2",
"ParameterName": "filePath",
"MappedTo": "filePath",
"IsInput": true,
"ClassType": "System.String",
"DefaultValue": null
}],
"Name": null,
"Description": null,
"UIStyle": null
}],
"Condition": null,
"RollbackActions": null,
"Name": null,
"Description": null,
"UIStyle": null
},
"l23": {
"Id": "l23",
"Namespace": null,
"From": "ws2",
"To": "ws3",
"Weight": 0,
"IgnoreDoActionsExceptions": false,
"IsAutomaticalLine": false,
"PreDoActions": [{
"Id": "internal",
"PackageId": "SELF",
"Namespace": "StateMesh.Sample.TestAction",
"InvokeName": "ReadName",
"Parameters": [{
"Id": "testparameter1",
"ParameterName": "myname",
"MappedTo": "myname",
"IsInput": false,
"ClassType": "System.String",
"DefaultValue": null
}, {
"Id": "testparameter2",
"ParameterName": "filePath",
"MappedTo": "filePath",
"IsInput": true,
"ClassType": "System.String",
"DefaultValue": null
}],
"Name": null,
"Description": null,
"UIStyle": null
}],
"DoActions": [{
"Id": "internal",
"PackageId": "SELF",
"Namespace": "StateMesh.Sample.TestAction",
"InvokeName": "HelloWorld",
"Parameters": null,
"Name": null,
"Description": null,
"UIStyle": null
}],
"Condition": {
"Id": "cc",
"Conditions": [{
"Id": "cc1",
"Action": {
"Id": "internal",
"PackageId": "SELF",
"Namespace": "StateMesh.Sample.TestAction",
"InvokeName": "IsTilerphyApprovaled",
"Parameters": null,
"Name": null,
"Description": null,
"UIStyle": null
},
"Assertions": [{
"Id": "testassert",
"MappedTo": "IsTilerphyApprovaled.Result",
"Operation": "EQ",
"TypeAssertion": "System.Boolean",
"ValueAssertion": true
}],
"Conditions": null,
"Relationship": null
}],
"Relationship": "OR"
},
"RollbackActions": null,
"Name": null,
"Description": null,
"UIStyle": null
},
"l34": {
"Id": "l34",
"Namespace": null,
"From": "ws3",
"To": "ws4",
"Weight": 0,
"IgnoreDoActionsExceptions": false,
"IsAutomaticalLine": false,
"PreDoActions": null,
"DoActions": [],
"Condition": null,
"RollbackActions": null,
"Name": null,
"Description": null,
"UIStyle": null
},
"l31": {
"Id": "l31",
"Namespace": null,
"From": "ws3",
"To": "ws1",
"Weight": 0,
"IgnoreDoActionsExceptions": false,
"IsAutomaticalLine": false,
"PreDoActions": null,
"DoActions": [],
"Condition": null,
"RollbackActions": null,
"Name": null,
"Description": null,
"UIStyle": null
}
},
"DefaultContext": null,
"Name": "testsample",
"Description": "my test sample for workflow engine",
"UIStyle": null
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 3.1
- Newtonsoft.Json (>= 13.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 263 | 2/14/2022 |