Workflow Core 的Json笔记

内容纲要

Workflow Core 的Json笔记
1,设计项目是,由单独的项目存储那些步骤点,生成单独的dll

json如下

{
  "Id": "HelloWorld11",
  "Version": 1,
  "Steps": [
    {
      "Id": "Hello",
      "StepType": "Test6.Steps.HelloWorld, Test6",
      "NextStepId": "Bye"
    },
    {
      "Id": "Bye",
      "StepType": "Test6.Steps.GoodbyeWorld, Test6"
    }
  ]
}

"StepType": "Test6.Steps.HelloWorld, Test6",
格式是:"{类的完全限定名},{生成的dll程序集名称}"

调用代码

    class Program
    {
        public static void Main(string[] args)
        {
            IServiceProvider serviceProvider = ConfigureServices();

            //start the workflow host
            var host = serviceProvider.GetService<IWorkflowHost>();
            var DefinitionLoader = serviceProvider.GetService<IDefinitionLoader>();
            var jsonstr =System.IO.File.ReadAllText(System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "test1.json"));
            var z = DefinitionLoader.LoadDefinition(jsonstr, Deserializers.Json);
            host.Start();

            Console.WriteLine("Starting workflow...");
            string workflowId = host.StartWorkflow(z.Id).Result;
            Console.WriteLine(workflowId);

            Console.ReadLine();
            host.Stop();
        }

        private static IServiceProvider ConfigureServices()
        {
            //setup dependency injection
            IServiceCollection services = new ServiceCollection();
            services.AddLogging();
            services.AddWorkflow();        

            services.AddTransient<IDefinitionLoader, DefinitionLoader>();
            var serviceProvider = services.BuildServiceProvider();

            //config logging
            var loggerFactory = serviceProvider.GetService<ILoggerFactory>();
            loggerFactory.CreateLogger("Debug");
            return serviceProvider;
        }
    }
点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注