2019-07-25 16:10:17 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
2019-09-21 22:02:04 +00:00
|
|
|
|
using Elsa.Attributes;
|
2019-10-19 15:03:52 +00:00
|
|
|
|
using Elsa.Design;
|
2019-07-25 16:10:17 +00:00
|
|
|
|
using Elsa.Services;
|
|
|
|
|
|
using Elsa.Services.Models;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Elsa.Activities.UserTask.Activities
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Stores a set of possible user actions and halts the workflow until one of the actions has been performed.
|
|
|
|
|
|
/// </summary>
|
2019-09-21 22:02:04 +00:00
|
|
|
|
[ActivityDefinition(
|
|
|
|
|
|
Category = "User Tasks",
|
|
|
|
|
|
Description = "Triggers when a user action is received."
|
|
|
|
|
|
)]
|
2019-07-25 16:10:17 +00:00
|
|
|
|
public class UserTask : Activity
|
|
|
|
|
|
{
|
2019-09-21 22:02:04 +00:00
|
|
|
|
[ActivityProperty(
|
|
|
|
|
|
Type = ActivityPropertyTypes.List,
|
|
|
|
|
|
Hint = "Enter a comma-separated list of available actions"
|
|
|
|
|
|
)]
|
2019-07-25 16:10:17 +00:00
|
|
|
|
public string[] Actions
|
|
|
|
|
|
{
|
|
|
|
|
|
get => GetState(() => new string[0]);
|
|
|
|
|
|
set => SetState(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override bool OnCanExecute(WorkflowExecutionContext context)
|
|
|
|
|
|
{
|
|
|
|
|
|
var userAction = GetUserAction(context);
|
|
|
|
|
|
|
|
|
|
|
|
return Actions.Contains(userAction, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-24 14:25:16 +00:00
|
|
|
|
protected override IActivityExecutionResult OnExecute(WorkflowExecutionContext context)
|
2019-07-25 16:10:17 +00:00
|
|
|
|
{
|
|
|
|
|
|
return Halt(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-24 14:25:16 +00:00
|
|
|
|
protected override IActivityExecutionResult OnResume(WorkflowExecutionContext context)
|
2019-07-25 16:10:17 +00:00
|
|
|
|
{
|
|
|
|
|
|
var userAction = GetUserAction(context);
|
|
|
|
|
|
return Outcome(userAction);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-21 22:02:04 +00:00
|
|
|
|
private string GetUserAction(WorkflowExecutionContext context) =>
|
|
|
|
|
|
(string) context.Workflow.Input.GetVariable("UserAction");
|
2019-07-25 16:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|