コード例 #1
0
ファイル: PostTests.cs プロジェクト: elsa-workflows/elsa-core
        private Save.SaveWorkflowDefinitionRequest CreateWorkflowDefinitionRequest()
        {
            var writeLine = new ActivityDefinition
            {
                ActivityId = _fixture.Create <string>(),
                Type       = nameof(WriteLine),
                Properties = new List <ActivityDefinitionProperty>()
                {
                    ActivityDefinitionProperty.Literal(nameof(WriteLine.Text), "Hello World!")
                }
            };

            var readLine = new ActivityDefinition {
                ActivityId = _fixture.Create <string>(), Type = nameof(ReadLine)
            };
            var activities  = new[] { writeLine, readLine };
            var connections = new[] { new ConnectionDefinition(writeLine.ActivityId, readLine.ActivityId, OutcomeNames.Done) };

            return(_fixture.Build <Save.SaveWorkflowDefinitionRequest>()
                   .With(x => x.Activities, activities)
                   .With(x => x.Connections, connections)
                   .With(x => x.Variables, default(string))
                   .With(x => x.CustomAttributes, default(string))
                   .Create());
        }
コード例 #2
0
 ActivityDefinition GetBlockingActivityDefinition(string id)
 {
     return(new()
     {
         ActivityId = id,
         Type = nameof(SignalReceived),
         Properties = new []
         {
             ActivityDefinitionProperty.Literal(nameof(SignalReceived.Signal), "MySignal"),
         }
     });
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: tle5/elsa-core
        private static async Task Main()
        {
            // Create a service container with Elsa services.
            var services = new ServiceCollection()
                           .AddElsa(options => options
                                    .AddConsoleActivities())
                           .BuildServiceProvider();

            // Run startup actions (not needed when registering Elsa with a Host).
            var startupRunner = services.GetRequiredService <IStartupRunner>();
            await startupRunner.StartupAsync();

            // Define a workflow.
            var workflowDefinition = new WorkflowDefinition
            {
                Id                  = "1",
                DefinitionId        = "SampleWorkflow",
                Version             = 1,
                IsPublished         = true,
                IsLatest            = true,
                PersistenceBehavior = WorkflowPersistenceBehavior.Suspended,
                Activities          = new[]
                {
                    new ActivityDefinition
                    {
                        ActivityId = "activity-1",
                        Type       = nameof(WriteLine),
                        Properties = new List <ActivityDefinitionProperty>()
                        {
                            ActivityDefinitionProperty.Liquid(nameof(WriteLine.Text), "Hello World")
                        }
                    },
                }
            };

            // Serialize workflow definition to JSON.
            var serializer = services.GetRequiredService <IContentSerializer>();
            var json       = serializer.Serialize(workflowDefinition);

            Console.WriteLine(json);

            // Deserialize workflow definition from JSON.
            var deserializedWorkflowDefinition = serializer.Deserialize <WorkflowDefinition>(json);

            // Materialize workflow.
            var materializer      = services.GetRequiredService <IWorkflowBlueprintMaterializer>();
            var workflowBlueprint = await materializer.CreateWorkflowBlueprintAsync(deserializedWorkflowDefinition);

            // Execute workflow.
            var workflowRunner = services.GetRequiredService <IStartsWorkflow>();
            await workflowRunner.StartWorkflowAsync(workflowBlueprint);
        }
コード例 #4
0
 ActivityDefinition GetNonBlockingActivityDefinition(string id)
 {
     return(new()
     {
         ActivityId = id,
         Type = nameof(SetVariable),
         Properties = new []
         {
             ActivityDefinitionProperty.Literal(nameof(SetVariable.VariableName), "Unused"),
             ActivityDefinitionProperty.Literal(nameof(SetVariable.Value), "Unused"),
         }
     });
 }
コード例 #5
0
 public WorkflowDefinition GetExamples()
 {
     return(new()
     {
         Id = Guid.NewGuid().ToString("N"),
         DefinitionId = Guid.NewGuid().ToString("N"),
         Name = "ProcessOrderWorkflow",
         DisplayName = "Process Order Workflow",
         Description = "Process new orders",
         Version = 1,
         IsPublished = true,
         ContextOptions = new WorkflowContextOptions
         {
             ContextFidelity = WorkflowContextFidelity.Burst,
             ContextType = typeof(string)
         },
         Activities = new[]
         {
             new ActivityDefinition
             {
                 ActivityId = "activity-1",
                 Description = "Write \"Hello\"",
                 Type = "WriteLine",
                 Name = "Activity1",
                 DisplayName = "Write \"Hello\"",
                 Properties = new List <ActivityDefinitionProperty>()
                 {
                     ActivityDefinitionProperty.Literal("Text", "Hello")
                 }
             },
             new ActivityDefinition
             {
                 ActivityId = "activity-2",
                 Description = "Write \"World!\"",
                 Type = "WriteLine",
                 Name = "Activity2",
                 DisplayName = "Write \"World!\"",
                 Properties = new List <ActivityDefinitionProperty>()
                 {
                     ActivityDefinitionProperty.Literal("Text", "World!")
                 }
             }
         },
         Connections = new[] { new ConnectionDefinition("activity-1", "activity-2", OutcomeNames.Done) }
     });
 }
コード例 #6
0
 private static WorkflowDefinition GetWorkflowDefinition()
 {
     return(new()
     {
         Id = "1",
         DefinitionId = "SampleWorkflow",
         Version = 1,
         IsPublished = true,
         IsLatest = true,
         PersistenceBehavior = WorkflowPersistenceBehavior.Suspended,
         Activities = new[]
         {
             new ActivityDefinition
             {
                 ActivityId = "1",
                 Type = nameof(SetVariable),
                 Properties = new List <ActivityDefinitionProperty>
                 {
                     ActivityDefinitionProperty.Literal(nameof(SetVariable.VariableName), "MyVariable"),
                     ActivityDefinitionProperty.JavaScript(nameof(SetVariable.Value), @"JSON.parse(""{\""foo\"":\""bar\""}"")"),
                 }
             },
             new ActivityDefinition
             {
                 ActivityId = "2",
                 Type = nameof(SetVariable),
                 Properties = new List <ActivityDefinitionProperty>
                 {
                     ActivityDefinitionProperty.Literal(nameof(SetVariable.VariableName), "MyStringifiedVariable"),
                     ActivityDefinitionProperty.JavaScript(nameof(SetVariable.Value), @"JSON.stringify(MyVariable)"),
                 }
             }
         },
         Connections = new[]
         {
             new ConnectionDefinition("1", "2", OutcomeNames.Done),
         }
     });
 }