forked from danielgerlag/workflow-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
90 lines (73 loc) · 3.24 KB
/
Program.cs
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
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using WorkflowCore.Interface;
namespace WorkflowCore.Sample08
{
public class Program
{
public static void Main(string[] args)
{
IServiceProvider serviceProvider = ConfigureServices();
//start the workflow host
var host = serviceProvider.GetService<IWorkflowHost>();
host.RegisterWorkflow<HumanWorkflow>();
host.Start();
Console.WriteLine("Starting workflow...");
string workflowId = host.StartWorkflow("HumanWorkflow").Result;
var timer = new Timer(new TimerCallback((state) => { PrintOptions(host, workflowId); }), null, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10));
Thread.Sleep(1000);
Console.WriteLine();
Console.WriteLine("Open user actions are");
var openItems = host.GetOpenUserActions(workflowId);
foreach (var item in openItems)
{
Console.WriteLine(item.Prompt + ", Assigned to " + item.AssignedPrincipal);
Console.WriteLine("Options are ");
foreach (var option in item.Options)
{
Console.WriteLine(" - " + option.Key + " : " + option.Value + ", ");
}
//Thread.Sleep(500);
Console.ReadLine();
Console.WriteLine();
Console.WriteLine("Choosing " + item.Options.First().Key);
host.PublishUserAction(openItems.First().Key, @"domain\john", item.Options.First().Value).Wait();
}
Console.ReadLine();
host.Stop();
}
private static void PrintOptions(IWorkflowHost host, string workflowId)
{
var openItems = host.GetOpenUserActions(workflowId);
foreach (var item in openItems)
{
Console.WriteLine(item.Prompt + ", Assigned to " + item.AssignedPrincipal);
Console.WriteLine("Options are ");
foreach (var option in item.Options)
{
Console.WriteLine(" - " + option.Key + " : " + option.Value + ", ");
}
}
}
private static IServiceProvider ConfigureServices()
{
//setup dependency injection
IServiceCollection services = new ServiceCollection();
services.AddLogging();
services.AddWorkflow();
//services.AddWorkflow(x => x.UseMongoDB(@"mongodb://localhost:27017", "workflow3"));
//services.AddWorkflow(x => x.UseSqlServer(@"Server=.;Database=WorkflowCore3;Trusted_Connection=True;", true, true));
//services.AddWorkflow(x => x.UseSqlite(@"Data Source=database2.db;", true));
var serviceProvider = services.BuildServiceProvider();
//config logging
var loggerFactory = serviceProvider.GetService<ILoggerFactory>();
loggerFactory.AddDebug(LogLevel.Debug);
return serviceProvider;
}
}
}