//[Authorize(Policy = Policies.Controller)] public async Task <ActionResult <WorkflowInstance> > StartWorkflow(string id) { string contentReq = null; using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8)) { contentReq = await reader.ReadToEndAsync(); } var logTrace = new LogTrace(); AiLogger.LogInfo(logTrace, "Workflow Start: " + contentReq); object workflowData = contentReq; string workflowId = null; if (id.Equals(CompressJobWorkflow.WorkflowId)) { workflowId = CompressJobWorkflow.WorkflowId; workflowData = NewtonJsonConvert.DeserializeObject <CompressJobData>(contentReq); } else if (id.Equals(WfFileInWorkflow.WorkflowId)) { workflowId = WfFileInWorkflow.WorkflowId; workflowData = NewtonJsonConvert.DeserializeObject <WfFileInData>(contentReq); } else if (id.Equals(Test01UserWorkflow.WorkflowId)) { var wfEvent = Newtonsoft.Json.JsonConvert.DeserializeObject <Pdf4meWorkflowEvent>(contentReq); workflowData = new Pdf4meWorkflowData() { WorkflowEvent = wfEvent }; workflowId = Test01UserWorkflow.WorkflowId; //workflowData = NewtonJsonConvert.DeserializeObject<WfFileInData>(contentReq); } else { var wfEvent = Newtonsoft.Json.JsonConvert.DeserializeObject <Pdf4meWorkflowEvent>(contentReq); workflowData = new Pdf4meWorkflowData() { WorkflowEvent = wfEvent }; workflowId = id; } var instanceId = await _workflowController.StartWorkflow(workflowId, workflowData); var result = await _persistenceProvider.GetWorkflowInstance(instanceId); return(Created(instanceId, _mapper.Map <WorkflowInstance>(result))); }
//[Authorize(Policy = Policies.Viewer)] public async Task <ActionResult <WorkflowInstance> > Get(string id) { var logTrace = new LogTrace(); AiLogger.LogInfo(logTrace, "Workflow Get: " + id); var result = await _persistenceProvider.GetWorkflowInstance(id); if (result == null) { return(NotFound()); } return(Ok(_mapper.Map <WorkflowInstance>(result))); }
public async Task Pdf4meActionHandlerAsync(ProcessingMessage message, CancellationToken token) { var logTrace = new LogTrace(); try { AiLogger.LogInfo(logTrace, "WfMessage to execute: " + JsonConvert.SerializeObject(message)); var msgId = message.MessageId; var docPluginRes = JsonConvert.DeserializeObject <DocPluginRes>(message.MessageBody); await _wfHost.PublishEvent(docPluginRes.WfEventName, docPluginRes.WfEventKey, message.MessageBody); AiLogger.LogInfo(logTrace, "WfMessage executed!"); }catch (Exception e) { AiLogger.LogException(logTrace, e); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime applicationLifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. //app.UseHsts(); } app.Use(async(context, next) => { Console.WriteLine($"method called with path {context.Request.Method}"); await next.Invoke(); Console.WriteLine($"method called with path {context.Request.Method}"); } ); app.UseAuthentication(); //app.UseHttpsRedirection(); app.UseMvc(cfg => { // cfg. }); app.UseRouting(); //app.UseMvcWithDefaultRoute(); app.UseCors(x => x .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); var host = app.ApplicationServices.GetService <IWorkflowHost>(); var defService = app.ApplicationServices.GetService <IDefinitionService>(); var backplane = app.ApplicationServices.GetService <IClusterBackplane>(); defService.LoadDefinitionsFromStorage(); // Register pdf4me Built-in Workflows //Pdf4meWorkflowRegistration.RegisterPdf4meServices(services); //Pdf4meWorkflowRegistration.RegisterPdf4meServices(services); host.RegisterWorkflow <CompressJobWorkflow, CompressJobData>(); host.RegisterWorkflow <CompressUserWorkflow, CompressData>(); host.RegisterWorkflow <WfFileInWorkflow, WfFileInData>(); host.RegisterWorkflow <Test01UserWorkflow, Pdf4meWorkflowData>(); host.RegisterWorkflow <WorkflowDocClassGenModel, MLWorkflowData>(); host.OnStepError += StepErrorEventHandler; backplane.Start(); host.Start(); applicationLifetime.ApplicationStopped.Register(() => { host.Stop(); backplane.Stop(); }); AiLogger.Instance.Init(Configuration.GetValue <string>("AppInsightKey"), "Pdf4meWorkflow"); AiLogger.LogInfo(new LogTrace(), "Init AiLogger for Pdf4meWorkflow : "); var msgHandler = new Pdf4meMessageHandler(host); Pdf4meBusFactory.Instance.SetServiceBusConnection(Configuration.GetValue <string>("ServiceBus")); Pdf4meBusFactory.Instance.RegisterQueueMessageHandler("wfexecution", msgHandler.Pdf4meActionHandlerAsync); }