MyLab.TaskApp by Andrey O.

<PackageReference Include="MyLab.TaskApp" Version="1.0.0" />

 TaskLogicApiHandler

using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using MyLab.LogDsl; using MyLab.StatusProvider; using Newtonsoft.Json; using System.Threading; using System.Threading.Tasks; namespace MyLab.TaskApp { internal class TaskLogicApiHandler { public static async Task GetStatus(IApplicationBuilder app, HttpContext context) { IAppStatusService val = app.ApplicationServices.GetService(typeof(IAppStatusService)); if (val == null) { context.Response.StatusCode = 404; await context.Response.WriteAsync("No status found", default(CancellationToken)); } else { string text = JsonConvert.SerializeObject((object)val.GetStatus().get_Task(), new JsonSerializerSettings { Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore }); context.Response.StatusCode = 200; context.Response.Headers.Append("Content-Type", "application/json"); await context.Response.WriteAsync(text, default(CancellationToken)); } } public static async Task StartLogic(IApplicationBuilder app, HttpContext context) { ITaskLogic taskLogic = (ITaskLogic)app.ApplicationServices.GetService(typeof(ITaskLogic)); if (taskLogic == null) { context.Response.StatusCode = 404; await context.Response.WriteAsync("No task logic found", default(CancellationToken)); } else { IAppStatusService val = app.ApplicationServices.GetService(typeof(IAppStatusService)); if (val == null) { context.Response.StatusCode = 404; await context.Response.WriteAsync("No status found", default(CancellationToken)); } else if (val.GetStatus().get_Task().get_Processing()) { context.Response.StatusCode = 208; await context.Response.WriteAsync("Already processing", default(CancellationToken)); } else { ILogger logger = ((ILoggerFactory)app.ApplicationServices.GetService(typeof(ILoggerFactory))).CreateLogger("TaskLogic"); TaskLogicPerformer taskLogicPerformer = new TaskLogicPerformer(taskLogic, val); taskLogicPerformer.Logger = LoggerExtensions.Dsl(logger); taskLogicPerformer.PerformLogicParallel(); context.Response.StatusCode = 200; } } } } }