从控制器 MVC 完成工作流 4 后显示弹出消息
我是 WorkFlow 4 (WF 4) 的初学者,我在 MVC 3 中使用它时遇到了一个严重的问题,我在网上找不到答案。
如果工作流程中发生异常或输出参数中返回任何内容,我需要显示一条弹出消息,我有一个用户可以编辑的页面,最后他将单击“保存”按钮。
单击“保存”按钮将表单提交到控制器并运行工作流程,当工作流程完成时,我得到一个输出,解释通过工作流程更新数据是否成功,然后我需要在完成的操作上显示此状态,但我我无法,因为我异步运行它,这意味着该方法将返回给用户,并且工作流同时调用该事件。
这是我在控制器中的代码:
[HttpPost()]
public ActionResult SaveVehicles(vehiclesData model) {
Services.VehiclesDataUpdate vehiclesDataUpdate = new Services.VehiclesDataUpdate(this.SessionData.DealerLotKey, null, null);
IDictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("VehiclesDataUpdate", vehiclesDataUpdate);
parameters.Add("UnionVehicles", unionVehicles);
parameters.Add("SolrVehicles", solrVehicles);
IDictionary<string, object> outputs = new Dictionary<string, object>();
AutoResetEvent syncEvent = new AutoResetEvent(false);
WorkflowApplication wfApp = new WorkflowApplication(new VehiclesUpdate(), parameters);
wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e) {
outputs = e.Outputs;
syncEvent.Set();
if (!errorExceptions.IsNullOrEmpty()) {
//TODO: Render a parital view to display an error message or the result of the workflow in the ouptput
//TODO: Logging.
}
};
wfApp.Aborted = delegate(WorkflowApplicationAbortedEventArgs e) {
syncEvent.Set();
};
wfApp.Run();
return View(model);
}
当工作流程完成时,如何将某些内容发送回用户?
提前致谢。
I am a beginner in WorkFlow 4 (WF 4), I am running through a serious issue using it in MVC 3, I couldn't find the answer online.
I need to show a popup message if an exception occurred in the workFlow or anything returned in the outpput arguments, I have a page that the user would edit and at the end he will click Save button.
Clicking the Save button will submit the form to the controller and run a workflow, when the workflow completed, I got an output explaining if updating the data through the workflow succeeded or not, then I need to show this status on completed action, but I am unable to since I run it asynchronously which means the method will return to the user and in parallel the workflow is invoking the event.
Here is my code in the controller:
[HttpPost()]
public ActionResult SaveVehicles(vehiclesData model) {
Services.VehiclesDataUpdate vehiclesDataUpdate = new Services.VehiclesDataUpdate(this.SessionData.DealerLotKey, null, null);
IDictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("VehiclesDataUpdate", vehiclesDataUpdate);
parameters.Add("UnionVehicles", unionVehicles);
parameters.Add("SolrVehicles", solrVehicles);
IDictionary<string, object> outputs = new Dictionary<string, object>();
AutoResetEvent syncEvent = new AutoResetEvent(false);
WorkflowApplication wfApp = new WorkflowApplication(new VehiclesUpdate(), parameters);
wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e) {
outputs = e.Outputs;
syncEvent.Set();
if (!errorExceptions.IsNullOrEmpty()) {
//TODO: Render a parital view to display an error message or the result of the workflow in the ouptput
//TODO: Logging.
}
};
wfApp.Aborted = delegate(WorkflowApplicationAbortedEventArgs e) {
syncEvent.Set();
};
wfApp.Run();
return View(model);
}
How can I send something back to the user when workflow completion?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想从 MVC 操作运行工作流,可以采用多种方法。首先,您可以像以前一样使用 WorkflowApplication。我已调整代码以使用更适合 WorkflowApplication 的 AyncController。
然而,这可能并不总是最好的解决方案。一般来说,ASP.NET 服务器会非常繁忙,无法满足所有核心的需求,因此异步处理只会损害扩展能力。现在,如果您的工作流程主要执行异步 IO,这很好,但如果它执行同步 IO 或处理,则最好使用 WorkflowInvoker。
代码会是这样的。
注意:代码仅使用 Notepad++ 编写,因此请注意小的语法错误。
If you want to run a workflow from an MVC action there are several ways you can do so. First fo all you can use the WorkflowApplication as you did. I have adapted the code to use an AyncController that is a better fit with a WorkflowApplication.
However that might not always be the best solution. In general an ASP.NET server is going to be busy enough to keep all cores happy so asynchronous processing is only going to hurt scale ability. Now if your workflow is doing mainly async IO this is fine but if it is doing synchronous IO or processing it might be better to use a WorkflowInvoker instead.
The code would be something like this.
Note: Did the code with just Notepad++ so be aware of small syntax errors.