2019-07-25 16:10:17 +00:00
|
|
|
|
using System;
|
2020-02-15 19:32:16 +00:00
|
|
|
|
using System.Collections.Generic;
|
2019-07-25 16:10:17 +00:00
|
|
|
|
using System.Linq;
|
2020-10-03 10:48:25 +00:00
|
|
|
|
using Elsa.ActivityResults;
|
2019-09-21 22:02:04 +00:00
|
|
|
|
using Elsa.Attributes;
|
2019-10-19 15:03:52 +00:00
|
|
|
|
using Elsa.Design;
|
2020-10-03 10:48:25 +00:00
|
|
|
|
using Elsa.Serialization;
|
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",
|
2020-02-15 19:32:16 +00:00
|
|
|
|
Description = "Triggers when a user action is received.",
|
|
|
|
|
|
Outcomes = new[] { OutcomeNames.Done, "x => x.state.actions" }
|
2019-09-21 22:02:04 +00:00
|
|
|
|
)]
|
2019-07-25 16:10:17 +00:00
|
|
|
|
public class UserTask : Activity
|
|
|
|
|
|
{
|
2020-10-03 10:48:25 +00:00
|
|
|
|
private readonly ITokenSerializer serializer;
|
|
|
|
|
|
|
2019-09-21 22:02:04 +00:00
|
|
|
|
[ActivityProperty(
|
|
|
|
|
|
Type = ActivityPropertyTypes.List,
|
|
|
|
|
|
Hint = "Enter a comma-separated list of available actions"
|
|
|
|
|
|
)]
|
2020-10-03 10:48:25 +00:00
|
|
|
|
public ICollection<string> Actions { get; set; } = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
public UserTask(ITokenSerializer serializer)
|
2019-07-25 16:10:17 +00:00
|
|
|
|
{
|
2020-10-03 10:48:25 +00:00
|
|
|
|
this.serializer = serializer;
|
2019-07-25 16:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-12 19:15:57 +00:00
|
|
|
|
protected override IActivityExecutionResult OnExecute(ActivityExecutionContext context) => Suspend();
|
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);
|
2020-01-12 19:15:57 +00:00
|
|
|
|
return Done(userAction);
|
2019-07-25 16:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-03 10:48:25 +00:00
|
|
|
|
private string GetUserAction(ActivityExecutionContext context) => (string)context.Input;
|
2019-07-25 16:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|