Workflow Core 的Json笔记

2019年7月31日 5644点热度 8人点赞 1条评论
内容目录

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;
        }
    }

痴者工良

高级程序员劝退师

文章评论