Add convenience methods to access activity input, output and workflow context
This commit is contained in:
parent
70d3569343
commit
25e5a1ca57
|
|
@ -58,7 +58,11 @@ namespace Elsa.Services.Models
|
|||
activity.Data = ActivityInstance.Data;
|
||||
return activity;
|
||||
}
|
||||
|
||||
|
||||
public T GetInput<T>() => (T)Input!;
|
||||
public object? GetOutputFrom(string activityName) => WorkflowExecutionContext.GetOutputFrom(activityName);
|
||||
public T GetOutputFrom<T>(string activityName) => (T)GetOutputFrom(activityName)!;
|
||||
public void SetWorkflowContext(object? value) => WorkflowExecutionContext.SetWorkflowContext(value);
|
||||
public T GetWorkflowContext<T>() => WorkflowExecutionContext.GetWorkflowContext<T>();
|
||||
}
|
||||
}
|
||||
|
|
@ -27,7 +27,7 @@ namespace Elsa.Services.Models
|
|||
IsFirstPass = true;
|
||||
Serializer = serviceProvider.GetRequiredService<JsonSerializer>();
|
||||
}
|
||||
|
||||
|
||||
public IWorkflowBlueprint WorkflowBlueprint { get; }
|
||||
public IServiceProvider ServiceProvider { get; }
|
||||
public WorkflowInstance WorkflowInstance { get; }
|
||||
|
|
@ -49,7 +49,7 @@ namespace Elsa.Services.Models
|
|||
foreach (var activity in activities)
|
||||
ScheduleActivity(activity);
|
||||
}
|
||||
|
||||
|
||||
public void PostScheduleActivities(IEnumerable<ScheduledActivity> activities)
|
||||
{
|
||||
foreach (var activity in activities)
|
||||
|
|
@ -68,7 +68,7 @@ namespace Elsa.Services.Models
|
|||
get => WorkflowInstance.CorrelationId;
|
||||
set => WorkflowInstance.CorrelationId = value;
|
||||
}
|
||||
|
||||
|
||||
public bool DeleteCompletedInstances { get; set; }
|
||||
public ICollection<ExecutionLogEntry> ExecutionLog => WorkflowInstance.ExecutionLog;
|
||||
public WorkflowStatus Status => WorkflowInstance.Status;
|
||||
|
|
@ -98,11 +98,9 @@ namespace Elsa.Services.Models
|
|||
public IActivityBlueprint? GetActivityBlueprintById(string id) => WorkflowBlueprint.Activities.FirstOrDefault(x => x.Id == id);
|
||||
public IActivityBlueprint? GetActivityBlueprintByName(string name) => WorkflowBlueprint.Activities.FirstOrDefault(x => x.Name == name);
|
||||
|
||||
private JObject Serialize(IActivity activity) => JObject.FromObject(activity);
|
||||
|
||||
public void SchedulePostActivities()
|
||||
{
|
||||
while(HasPostScheduledActivities)
|
||||
while (HasPostScheduledActivities)
|
||||
ScheduleActivity(WorkflowInstance.PostScheduledActivities.Pop());
|
||||
}
|
||||
|
||||
|
|
@ -112,5 +110,9 @@ namespace Elsa.Services.Models
|
|||
var activityInstance = WorkflowInstance.Activities.Single(x => x.Id == activityBlueprint.Id);
|
||||
return activityInstance.Output;
|
||||
}
|
||||
|
||||
public T GetOutputFrom<T>(string activityName) => (T)GetOutputFrom(activityName)!;
|
||||
public void SetWorkflowContext(object? value) => WorkflowContext = value;
|
||||
public T GetWorkflowContext<T>() => (T)WorkflowContext!;
|
||||
}
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ namespace Elsa.Samples.ContextualWorkflowHttp.Workflows
|
|||
.ReceiveHttpPostRequest<Document>("/documents")
|
||||
|
||||
// Store the document as the workflow context. It will be saved automatically when the workflow gets suspended.
|
||||
.Then(context => context.WorkflowExecutionContext.WorkflowContext = (Document)((HttpRequestModel)context.Input!).Body!)
|
||||
.Then(context => context.SetWorkflowContext(context.GetInput<HttpRequestModel>().GetBody<Document>()))
|
||||
|
||||
// Write an HTTP response.
|
||||
.WriteHttpResponse(
|
||||
|
|
@ -57,7 +57,7 @@ namespace Elsa.Samples.ContextualWorkflowHttp.Workflows
|
|||
});
|
||||
}
|
||||
|
||||
private static Document GetDocument(ActivityExecutionContext context) => (Document)context.WorkflowExecutionContext.WorkflowContext!;
|
||||
private static Document GetDocument(ActivityExecutionContext context) => context.GetWorkflowContext<Document>();
|
||||
private static string GetDocumentId(ActivityExecutionContext context) => GetDocument(context).DocumentId;
|
||||
|
||||
private static void StoreComment(ActivityExecutionContext context)
|
||||
|
|
|
|||
Loading…
Reference in a new issue