forked from danielgerlag/workflow-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
116 lines (93 loc) · 3.18 KB
/
Copy pathProgram.cs
File metadata and controls
116 lines (93 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using WorkflowCore.Interface;
using WorkflowCore.Models;
using System.Text;
namespace ScratchPad
{
public class Program
{
public static void Main(string[] args)
{
//var s = typeof(HelloWorld).AssemblyQualifiedName;
IServiceProvider serviceProvider = ConfigureServices();
//start the workflow host
var host = serviceProvider.GetService<IWorkflowHost>();
var loader = serviceProvider.GetService<IDefinitionLoader>();
var str = ScratchPad.Properties.Resources.HelloWorld; //Encoding.UTF8.GetString(ScratchPad.Properties.Resources.HelloWorld);
loader.LoadDefinition(str);
//host.RegisterWorkflow<HelloWorldWorkflow>();
host.Start();
host.StartWorkflow("HelloWorld", 1, new MyDataClass() { Value3 = "hi there" });
Console.ReadLine();
host.Stop();
}
private static IServiceProvider ConfigureServices()
{
//setup dependency injection
IServiceCollection services = new ServiceCollection();
services.AddLogging();
services.AddWorkflow();
//services.AddWorkflow(x => x.UseMongoDB(@"mongodb://localhost:27017", "workflow"));
services.AddTransient<GoodbyeWorld>();
var serviceProvider = services.BuildServiceProvider();
//config logging
var loggerFactory = serviceProvider.GetService<ILoggerFactory>();
loggerFactory.AddDebug();
return serviceProvider;
}
}
public class HelloWorld : StepBody
{
public override ExecutionResult Run(IStepExecutionContext context)
{
Console.WriteLine("Hello world");
return ExecutionResult.Next();
}
}
public class GoodbyeWorld : StepBody
{
public override ExecutionResult Run(IStepExecutionContext context)
{
Console.WriteLine("Goodbye world");
return ExecutionResult.Next();
}
}
public class Throw : StepBody
{
public override ExecutionResult Run(IStepExecutionContext context)
{
Console.WriteLine("throwing...");
throw new Exception("up");
}
}
public class PrintMessage : StepBody
{
public string Message { get; set; }
public override ExecutionResult Run(IStepExecutionContext context)
{
Console.WriteLine(Message);
return ExecutionResult.Next();
}
}
public class GenerateMessage : StepBody
{
public string Message { get; set; }
public override ExecutionResult Run(IStepExecutionContext context)
{
Message = "Generated message";
return ExecutionResult.Next();
}
}
public class MyDataClass
{
public int Value1 { get; set; }
public int Value2 { get; set; }
public string Value3 { get; set; }
}
}