2023-01-04 19:36:38 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-12-25 21:23:23 +00:00
|
|
|
using Elsa.Extensions;
|
2023-03-03 21:47:23 +00:00
|
|
|
using Elsa.Mediator.Contracts;
|
|
|
|
|
using Elsa.Workflows.Runtime.Contracts;
|
2023-01-04 19:36:38 +00:00
|
|
|
using Elsa.Workflows.Runtime.Notifications;
|
|
|
|
|
|
2023-06-08 10:01:26 +00:00
|
|
|
namespace Elsa.Samples.AspNet.RunTaskIntegration.Handlers;
|
2023-01-04 19:36:38 +00:00
|
|
|
|
|
|
|
|
public class OrderFoodTaskHandler : INotificationHandler<RunTaskRequest>
|
|
|
|
|
{
|
|
|
|
|
private readonly ITaskReporter _taskReporter;
|
|
|
|
|
|
|
|
|
|
public OrderFoodTaskHandler(ITaskReporter taskReporter)
|
|
|
|
|
{
|
|
|
|
|
_taskReporter = taskReporter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task HandleAsync(RunTaskRequest notification, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
if (notification.TaskName != "OrderFood")
|
|
|
|
|
return;
|
|
|
|
|
|
2023-12-25 21:23:23 +00:00
|
|
|
var args = notification.TaskPayload!;
|
|
|
|
|
var foodName = args.GetValue<string>("Food");
|
2023-01-04 19:36:38 +00:00
|
|
|
|
|
|
|
|
Console.WriteLine("Preparing {0}...", foodName);
|
|
|
|
|
await Task.Delay(1000, cancellationToken);
|
|
|
|
|
Console.WriteLine("Food is ready for delivery!");
|
|
|
|
|
|
|
|
|
|
await _taskReporter.ReportCompletionAsync(notification.TaskId, foodName, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
}
|