Asp.Net MVC Core
Thanks for creating this project, it's great.
How could I handle user actions in a .Net MVC application?
For instance, I'd like the user to complete and submit a form, take the form data and perform tasks with it.
Any guidance or documentation in this area would be helpful.
Ok after some experimentation I wrote some middleware which can interact with my workflows. At the moment it simply passed the request path to the workflow then sends a string to the browser.
public async Task InvokeAsync(HttpContext context)
{
var id = await _workflowHost.StartWorkflow(nameof(MvcViewWorkflow), new MvcViewData { RequestPath = context.Request.Path.ToString()});
var instance = await _workflowProvider.GetWorkflowInstance(id);
while (instance.CompleteTime == null)
{
instance = await _workflowProvider.GetWorkflowInstance(id);
}
var result = (MvcViewData)instance.Data;
await context.Response.WriteAsync(result.OutputString);
}
My first question is, is there a better way to check if the workflow is complete? I am worried about excessive database calls here, so I wouldn't be able to use the above in production.
Here is the code for my workflows
public class MvcViewWorkflow : IWorkflow<MvcViewData>
{
public string Id => nameof(MvcViewWorkflow);
public int Version => 0;
public void Build(IWorkflowBuilder<MvcViewData> builder)
{
builder
.StartWith<GetMvcViewData>()
.If(data => data.RequestPath == "/").Do(then => then
.StartWith<GetMvcViewData>()
.Output(data => data.OutputString, data => "home page!"))
.If(data => data.RequestPath != "/").Do(then => then
.StartWith<GetMvcViewData>()
.Input(data => data.Url, data => data.RequestPath)
.Output(data => data.OutputString, data => $"this was the request: {data.Url}"));
}
}
public class GetMvcViewData : StepBody
{
public string Url { get; set; }
public override ExecutionResult Run(IStepExecutionContext context)
{
return ExecutionResult.Next();
}
}
public class MvcViewData
{
public string RequestPath { get; set; }
public string OutputString { get; set; }
}
My ultimate aim is to combine some user forms with automated workflows. I'll be happy to contribute a version to your sample projects, coming from an Asp.Net perspective I found it difficult to see how the workflows can be integrated into a web solution.
Hi @jmdon1 maybe you can create an end workflow step, and implement in that step the code that send the notification for the completition of the workflow. You can use something like signalR or Rabbitmq to manage the notification part.
@jmdon1 the WaitFor step was intended as a way of a workflow to wait on an external event and receive external data in that event and then continue to execute based on what it received. Here and external event may be either a user doing something on the UI or a back-end service invoking it
@jmdon1 Hi, I would be interested to know how you got on with this in the end. Thanks.
@jmdon1 @mostaruk As part of testing out Workflow Core I created repository that provides a simple demonstration of using Workflow Core in an ASP.NET Core website:
https://github.com/jeremycook/WorkflowCoreWebsite
I suspect that what you have in mind may be something more complicated and integrated than what I've done. However, I believe that what I've done demonstrates the core functionality that you could build a more integrated system upon.
Hi, I would like to do something similar as well with the workflow. Basically, I would like to use it to do various activities (steps), but need a way to determine when the workflow is complete and return some data (that is evaluated in the workflow) back to the caller. Is there a way that I would be able to determine that the workflow is completed?
hi, In the Web project, I see that your case is host.start, but without host.stop, does that mean you don't need to stop it in the Web?