Skip to content

Instantly share code, notes, and snippets.

@sfmskywalker
sfmskywalker / ServiceCollectionExtensions.cs
Last active August 15, 2024 07:42
Building Workflow Driven .NET Applications With Elsa 2 - Part 3
using System;
using System.IO;
using Elsa.Persistence.EntityFramework.Core.Extensions;
using Elsa.Providers.Workflows;
using Elsa.Server.Hangfire.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Storage.Net;
namespace DocumentManagement.Workflows.Extensions
@sfmskywalker
sfmskywalker / ElsaWorkflows.snippet.cs
Created December 6, 2020 18:48
Elsa Workflows scheduled task snippet
class MyJob : IWorkflow
{
public void Build(IWorkflowBuilder workflow)
{
workflow
.Cron("* * * * * * *")
.WriteLine(() => $"CRON event at {DateTime.Now}");
}
}
@sfmskywalker
sfmskywalker / ConfigureJavaScriptEngineWithCustomFunctions1.cs
Last active August 8, 2021 19:27
Building Workflow Driven .NET Applications With Elsa 2 - Part 7
using System;
using System.Threading;
using System.Threading.Tasks;
using Elsa.Scripting.JavaScript.Events;
using Elsa.Scripting.JavaScript.Messages;
using MediatR;
using Microsoft.AspNetCore.StaticFiles;
namespace DocumentManagement.Workflows.Scripting.JavaScript
{
@sfmskywalker
sfmskywalker / ArchiveDocument.cs
Last active August 4, 2021 18:30
Building Workflow Driven .NET Applications With Elsa 2 - Part 6
using System.Threading.Tasks;
using DocumentManagement.Core.Models;
using DocumentManagement.Core.Services;
using Elsa.ActivityResults;
using Elsa.Attributes;
using Elsa.Expressions;
using Elsa.Providers.WorkflowStorage;
using Elsa.Services;
using Elsa.Services.Models;
@sfmskywalker
sfmskywalker / StartDocumentWorkflows.cs
Last active August 3, 2021 08:43
Building Workflow Driven .NET Applications With Elsa 2 - Part 5
using System.Threading;
using System.Threading.Tasks;
using DocumentManagement.Core.Events;
using Elsa.Models;
using Elsa.Services;
using MediatR;
using Open.Linq.AsyncExtensions;
namespace DocumentManagement.Workflows.Handlers
{
@sfmskywalker
sfmskywalker / CoreServiceCollectionExtensions.cs
Last active August 2, 2021 17:00
Building Workflow Driven .NET Applications With Elsa 2 - Part 4
using DocumentManagement.Core.Options;
using DocumentManagement.Core.Services;
using Microsoft.Extensions.DependencyInjection;
using Storage.Net;
namespace DocumentManagement.Core.Extensions
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddDomainServices(this IServiceCollection services)
@sfmskywalker
sfmskywalker / Startup.cs
Last active August 1, 2021 10:22
Building Workflow Driven .NET Applications With Elsa 2 - Part 2
using DocumentManagement.Workflows.Extensions;
using Elsa.Activities.Email.Options;
using Elsa.Activities.Http.Options;
using Elsa.Persistence.EntityFramework.Sqlite;
using Elsa.Server.Hangfire.Extensions;
using Hangfire;
using Hangfire.SQLite;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
public class AuthenticatingHandler<T> : DelegatingHandler where T : ISecurityTokenAccessor
{
private readonly Policy<HttpResponseMessage> _policy;
private readonly T _securityTokenAccessor;
private IAccessToken _accessToken;
private AuthenticationHeaderValue _authenticationHeader;
public AuthenticatingHandler(T securityTokenAccessor)
{
_securityTokenAccessor = securityTokenAccessor;
@sfmskywalker
sfmskywalker / JsonWorkflowProvider.cs
Created September 11, 2020 18:45
Sample implementation of a JSON file-based workflow provider
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Elsa.Models;
using Elsa.Serialization;
using Elsa.Services;
using Microsoft.Extensions.Configuration;
class ThisIsMyMonday : IWorkflow
{
private ITrashCleanupService _cleanupService;
private IDogWalkingService _dogWalkingService;
private IDishCleaningService _dishCleaningService;
public CleanTrash(ITrashCleanupService cleanupService, IDogWalkingService dogWalkingService, IDishCleaningService dishCleaningService)
{
_cleanupService = cleanupService;
_dogWalkingService = dogWalkingService;