Skip to content

Instantly share code, notes, and snippets.

class CleanTrash : IWorkflow
{
private ITrashCleanupService _cleanupService;
public CleanTrash(ITrashCleanupService cleanupService)
{
_cleanupService = cleanupService;
}
public void Build(IWorkflowBuilder workflow)
@sfmskywalker
sfmskywalker / QuartzJob.snippet.cs
Created December 6, 2020 18:16
Simple Quartz.NET job example
services.AddQuartz(quartz =>
{
quartz.AddJob<MyJob>(j => j.WithIdentity("MyJob"));
quartz.AddTrigger(t => t
.ForJob("MyJob")
.StartNow()
.WithCronSchedule("* * * * * * *"));
});
@sfmskywalker
sfmskywalker / RecurringTask.snippet.cs
Created December 6, 2020 17:49
Sample code showing a simple recurring background task implementation
// Do some work every minute.
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while(!stoppingToken.IsCancellationRequested)
{
// Do work.
// Wait for a minute.
await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken);
}
@sfmskywalker
sfmskywalker / get-and-execute-workflow.cs
Created September 11, 2020 18:51
Get a workflow by ID and execute it
using System;
using System.Threading;
using System.Threading.Tasks;
using Elsa.Models;
using Elsa.Services;
using Elsa.Services.Models;
using Microsoft.Extensions.DependencyInjection;
namespace Sample
{
@sfmskywalker
sfmskywalker / Index.razor
Last active November 3, 2019 11:17
Index.razor - Building Workflow Driven .NET Core Applications with Elsa
@page "/"
<div class="form-signup">
<EditForm Model="@RegistrationModel" OnValidSubmit="@HandleFormSubmission" hidden="@ShowConfirmation">
<h1 class="h3 mb-3 font-weight-normal">Please register</h1>
<DataAnnotationsValidator/>
<ValidationSummary/>
@sfmskywalker
sfmskywalker / DeleteUser.cs
Created November 2, 2019 10:47
DeleteUser.cs - Building Workflow Driven .NET Core Applications with Elsa
using System.Threading;
using System.Threading.Tasks;
using Elsa.Attributes;
using Elsa.Expressions;
using Elsa.Results;
using Elsa.Samples.UserRegistration.Web.Models;
using Elsa.Services;
using Elsa.Services.Models;
using MongoDB.Driver;
@sfmskywalker
sfmskywalker / ActivateUser.cs
Created November 2, 2019 10:36
ActivateUser.cs - Building Workflow Driven .NET Core Applications with Elsa
using System.Threading;
using System.Threading.Tasks;
using Elsa.Attributes;
using Elsa.Expressions;
using Elsa.Results;
using Elsa.Samples.UserRegistration.Web.Models;
using Elsa.Services;
using Elsa.Services.Models;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
@sfmskywalker
sfmskywalker / CreateUser.cs
Last active November 2, 2019 10:32
CreateUser.cs - Building Workflow Driven .NET Core Applications with Elsa
using System.Threading;
using System.Threading.Tasks;
using Elsa.Attributes;
using Elsa.Expressions;
using Elsa.Extensions;
using Elsa.Results;
using Elsa.Samples.UserRegistration.Web.Models;
using Elsa.Samples.UserRegistration.Web.Services;
using Elsa.Services;
using Elsa.Services.Models;
@sfmskywalker
sfmskywalker / UserServiceCollectionExtensions.cs
Created November 2, 2019 10:06
UserServiceCollectionExtensions.cs - Building Workflow Driven .NET Core Applications with Elsa
using Elsa.Samples.UserRegistration.Web.Activities;
using Microsoft.Extensions.DependencyInjection;
namespace Elsa.Samples.UserRegistration.Web.Extensions
{
public static class UserServiceCollectionExtensions
{
public static IServiceCollection AddUserActivities(this IServiceCollection services)
{
return services
@sfmskywalker
sfmskywalker / LiquidConfigurationHandler.cs
Created November 2, 2019 09:59
LiquidConfigurationHandler.cs - Building Workflow Driven .NET Core Applications with Elsa
using System.Threading;
using System.Threading.Tasks;
using Elsa.Samples.UserRegistration.Web.Models;
using Elsa.Scripting.Liquid.Messages;
using Fluid;
using MediatR;
namespace Elsa.Samples.UserRegistration.Web.Handlers
{
/// <summary>