2022-01-04 08:42:12 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
using Elsa.Activities.Console;
|
|
|
|
|
|
using Elsa.Activities.Workflows;
|
|
|
|
|
|
using Elsa.Contracts;
|
|
|
|
|
|
using Elsa.Dsl.Abstractions;
|
|
|
|
|
|
using Elsa.Dsl.Contracts;
|
|
|
|
|
|
using Elsa.Dsl.Extensions;
|
|
|
|
|
|
using Elsa.Extensions;
|
|
|
|
|
|
using Elsa.Models;
|
2022-02-01 19:45:11 +00:00
|
|
|
|
using Elsa.Modules.Http;
|
|
|
|
|
|
using Elsa.Modules.Scheduling.Triggers;
|
2022-01-04 08:42:12 +00:00
|
|
|
|
using Elsa.Persistence.InMemory.Extensions;
|
2022-01-12 10:15:07 +00:00
|
|
|
|
using Elsa.Scripting.JavaScript.Extensions;
|
2022-01-04 08:42:12 +00:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
|
|
var serviceProvider = CreateServices();
|
|
|
|
|
|
var typeSystem = serviceProvider.GetRequiredService<ITypeSystem>();
|
|
|
|
|
|
var dslEngine = serviceProvider.GetRequiredService<IDslEngine>();
|
|
|
|
|
|
var functionActivityRegistry = serviceProvider.GetRequiredService<IFunctionActivityRegistry>();
|
|
|
|
|
|
|
|
|
|
|
|
typeSystem.Register<int>("int");
|
|
|
|
|
|
typeSystem.Register<float>("float");
|
|
|
|
|
|
typeSystem.Register<string>("string");
|
|
|
|
|
|
typeSystem.Register("Variable<>", typeof(Variable<>));
|
|
|
|
|
|
typeSystem.Register<Sequence>();
|
|
|
|
|
|
typeSystem.Register<ReadLine>();
|
|
|
|
|
|
typeSystem.Register<WriteLine>();
|
|
|
|
|
|
typeSystem.Register<HttpTrigger>();
|
2022-01-12 13:39:19 +00:00
|
|
|
|
typeSystem.Register<Timer>();
|
2022-01-04 08:42:12 +00:00
|
|
|
|
|
|
|
|
|
|
functionActivityRegistry.RegisterFunction("print", nameof(WriteLine), new[] { nameof(WriteLine.Text) });
|
|
|
|
|
|
functionActivityRegistry.RegisterFunction("read", nameof(ReadLine), new[] { nameof(ReadLine.Output) });
|
|
|
|
|
|
|
|
|
|
|
|
var assembly = Assembly.GetExecutingAssembly();
|
|
|
|
|
|
var resource = assembly.GetManifestResourceStream("Elsa.Samples.Console2.Sample1.elsa");
|
|
|
|
|
|
|
|
|
|
|
|
var script = await new StreamReader(resource!).ReadToEndAsync();
|
|
|
|
|
|
var workflowDefinition = dslEngine.Parse(script);
|
|
|
|
|
|
|
2022-03-04 18:59:44 +00:00
|
|
|
|
var workflowEngine = serviceProvider.GetRequiredService<IWorkflowRunner>();
|
|
|
|
|
|
await workflowEngine.RunAsync(workflowDefinition);
|
2022-01-04 08:42:12 +00:00
|
|
|
|
|
|
|
|
|
|
IServiceProvider CreateServices()
|
|
|
|
|
|
{
|
|
|
|
|
|
var services = new ServiceCollection();
|
|
|
|
|
|
|
|
|
|
|
|
services
|
|
|
|
|
|
.AddElsa()
|
|
|
|
|
|
.AddLogging(logging => logging.AddConsole().SetMinimumLevel(LogLevel.Warning))
|
|
|
|
|
|
.AddInMemoryPersistence()
|
|
|
|
|
|
.AddJavaScriptExpressions();
|
|
|
|
|
|
|
|
|
|
|
|
return services.BuildServiceProvider();
|
|
|
|
|
|
}
|