protected override void Execute(CodeActivityContext context) { IDbContext dbContext = context.GetExtension <IDbContext>(); Int64 id = InboxId.Get(context); InboxInfo ii = new InboxInfo() { Id = id }; dbContext.Execute(String.Empty, "a2workflow.[Inbox.Remove]", ii); }
public static async Task <WorkflowResult> ResumeWorkflow(IApplicationHost host, IDbContext dbContext, ResumeWorkflowInfo info) { AppWorkflow aw = null; var result = new WorkflowResult { InboxIds = new List <Int64>() }; try { InboxInfo inbox = await InboxInfo.Load(dbContext, info.Id, info.UserId); result.ProcessId = inbox.ProcessId; var def = WorkflowDefinition.Load(inbox); Activity root = def.LoadFromSource(host); aw = Create(dbContext, root, null, def.Identity); aw._application.Extensions.Add(result); aw._application.Extensions.Add(dbContext); WorkflowApplicationInstance instance = WorkflowApplication.GetInstance(inbox.WorkflowId, aw._application.InstanceStore); aw._application.Load(instance, _wfTimeSpan); foreach (var bm in aw._application.GetBookmarks()) { if (bm.BookmarkName == inbox.Bookmark) { var rr = new RequestResult { Answer = info.Answer, Comment = info.Comment, Params = info.Params, UserId = info.UserId, InboxId = info.Id }; aw._application.ResumeBookmark(bm.BookmarkName, rr); return(result); // already resumed } } // if a bookmark is not found aw._application.Unload(); } catch (Exception ex) { if (!CatchWorkflow(aw, ex)) { throw; } } finally { ProcessFinally(aw); } return(result); }
public static WorkflowDefinition Load(InboxInfo info) { return(new WorkflowDefinition(info.Kind, info.Definition)); }
public static async Task <WorkflowResult> ResumeWorkflow(IApplicationHost host, IDbContext dbContext, IMessaging messaging, ResumeWorkflowInfo info) { AppWorkflow aw = null; var profiler = host.Profiler; var result = new WorkflowResult { InboxIds = new List <Int64>() }; try { InboxInfo inbox = await InboxInfo.Load(dbContext, info.Id, info.UserId); if (inbox == null) { throw new WorkflowException("The task is already done by another user"); } using (profiler.CurrentRequest.Start(ProfileAction.Workflow, $"Load '{inbox.Kind}'")) { result.ProcessId = inbox.ProcessId; var def = WorkflowDefinition.Load(inbox); Activity root = def.LoadFromSource(host, dbContext); aw = Create(dbContext, root, null, def.Identity); aw._application.Extensions.Add(result); aw._application.Extensions.Add(dbContext); aw._application.Extensions.Add(messaging); aw._application.Extensions.Add(host); WorkflowApplicationInstance instance = WorkflowApplication.GetInstance(inbox.WorkflowId, aw._application.InstanceStore); aw._application.Load(instance, _wfTimeSpan); } foreach (var bm in aw._application.GetBookmarks()) { if (bm.BookmarkName == inbox.Bookmark) { var rr = new RequestResult { Answer = info.Answer, Comment = info.Comment, Params = info.Params, UserId = info.UserId, InboxId = info.Id }; using (profiler.CurrentRequest.Start(ProfileAction.Workflow, $"Resume '{bm.BookmarkName}'")) { aw._application.ResumeBookmark(bm.BookmarkName, rr); } return(result); // already resumed } } // if a bookmark is not found aw._application.Unload(); } catch (Exception ex) { if (!CatchWorkflow(aw, ex)) { throw; } } finally { ProcessFinally(aw); } return(result); }