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()); }
ActivityDefinition GetBlockingActivityDefinition(string id) { return(new() { ActivityId = id, Type = nameof(SignalReceived), Properties = new [] { ActivityDefinitionProperty.Literal(nameof(SignalReceived.Signal), "MySignal"), } }); }
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); }
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"), } }); }
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) } }); }
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), } }); }