elsa-core/src/samples/Sample09/Program.cs
Sipke Schoorstra aef8741d84
Add Liquid expressions (#111)
* Reorganize projects

* Implement Liquid expression evaluator

* Refactor activity references to use `Name`
2019-10-27 15:38:37 +01:00

46 lines
1.6 KiB
C#

using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using Elsa.Activities.Console.Extensions;
using Elsa.Models;
using Elsa.Serialization;
using Elsa.Serialization.Formatters;
using Elsa.Services;
using Microsoft.Extensions.DependencyInjection;
namespace Sample09
{
/// <summary>
/// A simple console program that loads & executes a workflow designed with the HTML5 workflow designer.
/// </summary>
internal class Program
{
private static async Task Main()
{
var json = await ReadEmbeddedResourceAsync("Sample09.calculator.json");
var services = BuildServices();
var serializer = services.GetRequiredService<IWorkflowSerializer>();
var workflow = serializer.Deserialize<WorkflowDefinitionVersion>(json, JsonTokenFormatter.FormatName);
var invoker = services.GetRequiredService<IWorkflowInvoker>();
await invoker.StartAsync(workflow);
}
private static IServiceProvider BuildServices()
{
return new ServiceCollection()
.AddElsa()
.AddConsoleActivities()
.AddSingleton(Console.In)
.BuildServiceProvider();
}
private static async Task<string> ReadEmbeddedResourceAsync(string resourceName)
{
var assembly = typeof(Program).GetTypeInfo().Assembly;
using var reader = new StreamReader(assembly.GetManifestResourceStream(resourceName));
return await reader.ReadToEndAsync();
}
}
}