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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-23 20:43:11 +00:00
|
|
|
|
protected override bool OnCanExecute(ActivityExecutionContext context)
|
2019-07-25 16:10:17 +00:00
|
|
|
|
{
|
|
|
|
|
|
var userAction = GetUserAction(context);
|
|
|
|
|
|
|
|
|
|
|
|
return Actions.Contains(userAction, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-23 20:43:11 +00:00
|
|
|
|
protected override IActivityExecutionResult OnExecute(ActivityExecutionContext context)
|
2019-07-25 16:10:17 +00:00
|
|
|
|
{
|
2019-12-25 11:10:39 +00:00
|
|
|
|
return Suspend(true);
|
2019-07-25 16:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-23 20:43:11 +00:00
|
|
|
|
protected override IActivityExecutionResult OnResume(ActivityExecutionContext context)
|
2019-07-25 16:10:17 +00:00
|
|
|
|
{
|
|
|
|
|
|
var userAction = GetUserAction(context);
|
|
|
|
|
|
return Outcome(userAction);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-23 20:43:11 +00:00
|
|
|
|
private string GetUserAction(ActivityExecutionContext context) => context.Input?.GetValue<string>();
|
2019-07-25 16:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|