接下来,启动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
版权申明:本文来源于网友收集或网友投稿,仅供学习交流之用,如果有侵权,请转告版主或者留言,本人立即删除 。
推荐阅读
- 配音|余生,做一个能扛事的成年人
- 清蒸素菜做法大全家常
- 香奈儿|一个半月,马思纯减掉20斤,潘玮柏减掉26斤,明星减肥为何很容易
- 四大洋中面积最小的是哪个 四大洋面积最小的是哪一个
- |逆向思维:不要再努力的学习和工作,这是一个天大的错误
- 最有效的抗真菌软膏
- 胡萝卜减肥 一个月瘦10斤
- 荷马史诗的流传过程,犹如一个奇迹 荷马史诗的故事
- 焦虑症会心慌吗
- 远程开机:一个简单的嵌入式项目开发