diff --git a/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Activities/FetchOrders.cs b/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Activities/FetchOrders.cs
index 9736e1b93..68d870a41 100644
--- a/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Activities/FetchOrders.cs
+++ b/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Activities/FetchOrders.cs
@@ -7,6 +7,9 @@ using Elsa.Workflows.Models;
namespace Elsa.Samples.AspNet.BatchProcessing.Activities;
+///
+/// Fetches orders from the data source.
+///
[Activity("Demo", "Warehousing", "Fetch orders from the data source.")]
[Output(IsSerializable = false)]
public class FetchOrders : CodeActivity>>
@@ -14,24 +17,31 @@ public class FetchOrders : CodeActivity>>
///
/// The total number of orders to fetch.
///
- [Input(Description = "The total number of orders to fetch.")]
- public Input Count { get; set; } = new(100);
-
+ [Input(
+ Description = "The total number of orders to fetch.",
+ DefaultValue = 1000
+ )]
+ public Input Count { get; set; } = new(1000);
+
///
/// The number of orders to fetch per batch.
///
- [Input(Description = "The number of orders to fetch per batch.")]
+ [Input(
+ Description = "The number of orders to fetch per batch.",
+ DefaultValue = 100
+ )]
public Input BatchSize { get; set; } = new(100);
-
+
+ ///
protected override void Execute(ActivityExecutionContext context)
{
var count = Count.Get(context);
var batchSize = BatchSize.Get(context);
var orders = GenerateOrders(count).Chunk(batchSize).ToAsyncEnumerable();
-
+
Result.Set(context, orders);
}
-
+
private IEnumerable GenerateOrders(int count)
{
var orderFaker = new Faker()
diff --git a/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Activities/FetchProducts.cs b/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Activities/FetchProducts.cs
deleted file mode 100644
index ead9d45a1..000000000
--- a/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Activities/FetchProducts.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-using Bogus;
-using Elsa.Extensions;
-using Elsa.Samples.AspNet.BatchProcessing.Models;
-using Elsa.Workflows;
-using Elsa.Workflows.Attributes;
-using Elsa.Workflows.Models;
-using Elsa.Workflows.Options;
-using Elsa.Workflows.Signals;
-
-namespace Elsa.Samples.AspNet.BatchProcessing.Activities;
-
-[Activity("Demo", "Warehousing", "Fetch products from the data source.")]
-[Output(IsSerializable = false)]
-public class FetchProducts : CodeActivity>
-{
- private const string CurrentBathKey = nameof(CurrentBathKey);
-
- ///
- /// The total number of products to fetch.
- ///
- [Input(Description = "The total number of products to fetch.")]
- public Input Count { get; set; } = new(100);
-
- ///
- /// The number of products to fetch per batch.
- ///
- [Input(Description = "The number of products to fetch per batch.")]
- public Input BatchSize { get; set; } = new(100);
-
- protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
- {
- var count = Count.Get(context);
- var batchSize = BatchSize.Get(context);
- var currentBatch = context.ActivityInput.TryGetValue(CurrentBathKey, out var currentBatchValue) ? (int)currentBatchValue : 0;
- var orders = GenerateProducts(count).Skip(currentBatch * batchSize).Take(batchSize).ToList();
-
- Result.Set(context, orders);
- await context.CompleteActivityAsync();
-
- if (orders.Any())
- {
- currentBatch++;
- context.SetProperty(CurrentBathKey, currentBatch);
-
- // Schedule the next batch.
- await context.SendSignalAsync(new ScheduleChildActivity(this, new Dictionary { [CurrentBathKey] = currentBatch }));
- }
- }
-
- private IEnumerable GenerateProducts(int count)
- {
- var productFaker = new Faker()
- .RuleFor(o => o.Id, f => Guid.NewGuid().ToString())
- .RuleFor(o => o.Name, f => Guid.NewGuid().ToString())
- .RuleFor(o => o.Price, f => f.Random.Decimal(0.01m, 1000.00m));
-
- return productFaker.Generate(count);
- }
-}
\ No newline at end of file
diff --git a/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Models/Product.cs b/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Models/Product.cs
deleted file mode 100644
index af72291c9..000000000
--- a/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Models/Product.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-namespace Elsa.Samples.AspNet.BatchProcessing.Models;
-
-public class Product
-{
- public string Id { get; set; } = default!;
- public string Name { get; set; } = default!;
- public decimal Price { get; set; }
-}
\ No newline at end of file
diff --git a/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Program.cs b/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Program.cs
index 53681d835..6bf9d1e5e 100644
--- a/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Program.cs
+++ b/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Program.cs
@@ -1,6 +1,7 @@
using Elsa.EntityFrameworkCore.Modules.Management;
using Elsa.EntityFrameworkCore.Modules.Runtime;
using Elsa.Extensions;
+using Elsa.Samples.AspNet.BatchProcessing.Models;
var builder = WebApplication.CreateBuilder(args);
@@ -28,12 +29,17 @@ builder.Services.AddElsa(elsa =>
elsa.UseDefaultAuthentication(auth => auth.UseAdminApiKey());
elsa.AddActivitiesFrom();
elsa.AddWorkflowsFrom();
+
+ elsa.AddVariableTypeAndAlias("Order", "Warehousing");
+ elsa.AddVariableTypeAndAlias>>("BatchedOrderStream", "Warehousing");
});
+builder.Services.AddHealthChecks();
builder.Services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().WithExposedHeaders("*")));
var app = builder.Build();
app.UseHttpsRedirection();
+app.UseHealthChecks("/");
app.UseCors();
app.UseAuthentication();
app.UseAuthorization();
diff --git a/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Workflows/OrderBatchProcessor.cs b/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Workflows/OrderBatchProcessor.cs
index c8ffdc7b7..42d727eb5 100644
--- a/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Workflows/OrderBatchProcessor.cs
+++ b/samples/aspnet/Elsa.Samples.AspNet.BatchProcessing/Workflows/OrderBatchProcessor.cs
@@ -6,17 +6,24 @@ using Elsa.Workflows.Contracts;
namespace Elsa.Samples.AspNet.BatchProcessing.Workflows;
+///
+/// A workflow that processes orders in batches.
+///
public class OrderBatchProcessor : WorkflowBase
{
+ ///
protected override void Build(IWorkflowBuilder builder)
{
- var orders = builder.WithVariable>();
+ var orders = builder.WithVariable>>();
builder.Root = new Sequence
{
Activities =
{
new WriteLine("Fetching orders..."),
- new FetchOrders(),
+ new FetchOrders
+ {
+ Result = new(orders)
+ },
new ParallelForEach
{
Items = new(orders)