一个适合于.NET Core的超轻量级工作流引擎:Workflow-Core( 二 )

接下来,启动workflow 主机,并启动一次workflow,将整个窗体代码贴一下,这样比较清晰
using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Logging;using Microsoft.Extensions.Logging.Console;using Microsoft.Extensions.Logging.Debug;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;using WorkflowCore.Interface;using WorkflowCore.Services;using WorkFlowCoreTest.MyWorkflow;namespace WorkFlowCoreTest{/// <summary>/// Interaction logic for MainWindow.xaml/// </summary>public partial class MainWindow : Window{IServiceProvider serviceProvider = null;bool serviceStarted = false;public MainWindow(){InitializeComponent();}private void StartWorkflow(){if (serviceProvider == null){serviceProvider = ConfigureServices();var host1 = serviceProvider.GetService<IWorkflowHost>();host1.RegisterWorkflow<HelloWorkflow>();host1.RegisterWorkflow<HelloWorkflow2>();}var host = serviceProvider.GetService<IWorkflowHost>();var wd = host.Registry.GetDefinition("HelloWorkflow");// 如果host启动了,不能再次启动,但没有判断方法if (!serviceStarted){host.Start();serviceStarted = true;}// 启动workflow工作流host.StartWorkflow("HelloWorkflow", 1, data: null); ////host.StartWorkflow("HelloWorkflow");//, 2, data: null, 默认会启用版本高的}private void StopWorkflow(){var host = serviceProvider.GetService<IWorkflowHost>();host.Stop();serviceStarted = false;}/// <summary>/// 配置workflow/// </summary>/// <returns></returns>private IServiceProvider ConfigureServices(){//setup dependency injectionIServiceCollection services = new ServiceCollection();services.AddLogging();services.AddWorkflow();//services.AddWorkflow(x => x.UseMongoDB(@"mongodb://localhost:27017", "workflow"));// 这些个构造函数带参数的,需要添加到transient中services.AddTransient<HelloWorld>();services.AddTransient<GoodbyeWorld>();services.AddTransient<SleepStep>();var serviceProvider = services.BuildServiceProvider();//config loggingvar loggerFactory = serviceProvider.GetService<ILoggerFactory>();loggerFactory.AddProvider(new DebugLoggerProvider());return serviceProvider;}private void startButton_Click(object sender, RoutedEventArgs e){StartWorkflow();}private void stopButton_Click(object sender, RoutedEventArgs e){StopWorkflow();}}}就这样一个简单的Workflow Core例子就完成了,总体来说,还是很简单,清晰的 。
 

出处:
https://www.cnblogs.com/keep-study-to-die/p/12001408.html
 
版权申明:本文来源于网友收集或网友投稿,仅供学习交流之用,如果有侵权,请转告版主或者留言,本人立即删除 。




推荐阅读