async Task StartWorkflowInt() { var info = new StartWorkflowInfo() { Source = "file:Workflows/SimpleWorkflow_v1", UserId = 50, // predefined user id }; WorkflowResult result = await _workflow.StartWorkflow(info); Assert.AreNotEqual(0, result.ProcessId); }
protected override void Execute(NativeActivityContext context) { Boolean waitComplete = WaitComplete.Get <Boolean>(context); IDbContext dbContext = context.GetExtension <IDbContext>(); var messaging = context.GetExtension <IMessaging>(); IApplicationHost host = context.GetExtension <IApplicationHost>(); context.DoTrack(dbContext, TrackBefore.Get <TrackRecord>(context)); context.DoModelState(dbContext, StateBefore.Get <ModelStateInfo>(context)); var pi = ProcessInfo.Get <StartProcessInfo>(context); String bookmark = null; var process = Process.GetProcessFromContext(context); if (waitComplete) { bookmark = Guid.NewGuid().ToString(); var wfResult = context.GetExtension <WorkflowResult>(); // TODO: WAIT COMPLETE FOR CHILDREN //Int64 pid = process.CreateChildren(dbContext, kind, docId, bookmark, Mark.Get<String>(context)); } var sfi = new StartWorkflowInfo() { UserId = process.Owner, Source = pi.Workflow, DataSource = pi.DataSource, Schema = pi.Schema, Model = pi.ModelName, ModelId = pi.ModelId, ActionBase = pi.ActionBase, Parent = process.Id }; var task = AppWorkflow.StartWorkflow(host, dbContext, messaging, sfi); task.Wait(); WorkflowResult result = task.Result; if (waitComplete) { context.CreateBookmark(bookmark, new BookmarkCallback(this.ContinueAt)); } else { Result.Set(context, String.Empty); } }
internal static Process Create(WorkflowDefinition def, StartWorkflowInfo info) { var p = new Process { Kind = def.Name, Definition = def.Definition, ActionBase = info.ActionBase, Source = def.Source, Owner = info.UserId, DataSource = info.DataSource, Schema = info.Schema, ModelName = info.Model, ModelId = info.ModelId }; return(p); }
public static WorkflowResult AutoStart(Int64 processId, IApplicationHost host, IDbContext dbContext, IMessaging messaging, ILogger logger) { var p = dbContext.Load <Process>(null, "a2workflow.[ProcessStart.Load]", new { Id = processId }); StartWorkflowInfo info = new StartWorkflowInfo() { ProcessId = p.Id, UserId = 0, // System ActionBase = p.ActionBase, Source = p.Source, DataSource = p.DataSource, Schema = p.Schema, Model = p.ModelName, ModelId = p.ModelId }; return(StartWorkflow(host, dbContext, messaging, info).Result); }
public async Task LoadProcessModel() { Int64 modelId = 123; // predefined Int64 userId = 50; // predefined String bookmark = "Bookmark1"; var info = new StartWorkflowInfo() { Source = "file:Workflows/LoadModel_v1", UserId = userId, Schema = "a2test", Model = "SimpleModel", ActionBase = "simple/model", ModelId = modelId }; WorkflowResult result = await _workflow.StartWorkflow(info); Assert.AreNotEqual(0, result.ProcessId); var pm = await _dbContext.LoadModelAsync(String.Empty, "a2workflow.[Process.Load]", new { UserId = userId, Id = result.ProcessId } ); var dt = new DataTester(pm, "Process.Inboxes"); dt.IsArray(1); dt.AreArrayValueEqual(bookmark, 0, "Bookmark"); dt.AreArrayValueEqual("User", 0, "For"); dt.AreArrayValueEqual("ObjectName", 0, "Text"); dt.AreArrayValueEqual(userId, 0, "ForId"); Int64 inboxId = dt.GetArrayValue <Int64>(0, "Id"); var rInfo = new ResumeWorkflowInfo() { Id = inboxId, UserId = userId }; var resumeResult = await _workflow.ResumeWorkflow(rInfo); Assert.AreEqual(resumeResult.ProcessId, result.ProcessId); }
public async Task SimpleRequest() { Int64 modelId = 123; // predefined Int64 userId = 50; // predefined String bookmark = "Bookmark1"; var info = new StartWorkflowInfo() { Source = "file:Workflows/SimpleRequest_v1", UserId = userId, Schema = "a2test", Model = "SimpleModel", ActionBase = "simple/model", ModelId = modelId }; WorkflowResult result = await _workflow.StartWorkflow(info); Assert.AreNotEqual(0, result.ProcessId); var pm = await _dbContext.LoadModelAsync(String.Empty, "a2workflow.[Process.Load]", new { UserId = userId, Id = result.ProcessId } ); var dt = new DataTester(pm, "Process"); dt.AreValueEqual(result.ProcessId, "Id"); dt.AreValueEqual("a2test", "Schema"); dt.AreValueEqual("SimpleModel", "Model"); dt.AreValueEqual(modelId, "ModelId"); dt.AreValueEqual(userId, "Owner"); dt.AreValueEqual("simple/model", "ActionBase"); dt = new DataTester(pm, "Process.Inboxes"); dt.IsArray(1); dt.AreArrayValueEqual(bookmark, 0, "Bookmark"); dt.AreArrayValueEqual("User", 0, "For"); dt.AreArrayValueEqual(userId, 0, "ForId"); dt.AreArrayValueEqual("inbox/action", 0, "Action"); Int64 inboxId = dt.GetArrayValue <Int64>(0, "Id"); Assert.AreEqual(inboxId, result.InboxIds[0]); dt = new DataTester(pm, "Process.Workflow"); dt.AreValueEqual("Idle", "ExecutionStatus"); var rInfo = new ResumeWorkflowInfo() { Id = inboxId, Answer = "OK", UserId = userId }; var resumeResult = await _workflow.ResumeWorkflow(rInfo); Assert.AreEqual(resumeResult.ProcessId, result.ProcessId); Assert.AreEqual(resumeResult.InboxIds.Count, 0); pm = await _dbContext.LoadModelAsync(String.Empty, "a2workflow.[Process.Load]", new { UserId = userId, Id = result.ProcessId } ); dt = new DataTester(pm, "Process.Workflow"); dt.AreValueEqual("Closed", "ExecutionStatus"); pm = await _dbContext.LoadModelAsync(String.Empty, "a2workflow.[Inbox.Debug.Load]", new { UserId = userId, Id = inboxId } ); dt = new DataTester(pm, "Inbox"); dt.AreValueEqual(inboxId, "Id"); dt.AreValueEqual(bookmark, "Bookmark"); dt.AreValueEqual(userId, "UserRemoved"); dt.AreValueEqual("OK", "Answer"); dt.AreValueEqual(true, "Void"); }
public async Task RequestResultParams() { Int64 userId = 50; // predefined String bookmark1 = "Bookmark1"; var info = new StartWorkflowInfo() { Source = "file:Workflows/RequestResultParams_v1", UserId = userId }; WorkflowResult result = await _workflow.StartWorkflow(info); Assert.AreNotEqual(0, result.ProcessId); var pm = await _dbContext.LoadModelAsync(String.Empty, "a2workflow.[Process.Load]", new { UserId = userId, Id = result.ProcessId } ); var dt = new DataTester(pm, "Process"); dt.AreValueEqual(result.ProcessId, "Id"); dt.AreValueEqual(userId, "Owner"); dt = new DataTester(pm, "Process.Inboxes"); dt.IsArray(1); dt.AreArrayValueEqual(bookmark1, 0, "Bookmark"); dt.AreArrayValueEqual("User", 0, "For"); dt.AreArrayValueEqual(userId, 0, "ForId"); Int64 inboxId = dt.GetArrayValue <Int64>(0, "Id"); Assert.AreEqual(inboxId, result.InboxIds[0]); dt = new DataTester(pm, "Process.Workflow"); dt.AreValueEqual("Idle", "ExecutionStatus"); ExpandoObject resumeParams = new ExpandoObject(); resumeParams.Set("Id", 500L); resumeParams.Set("Text", "ParamText"); var rInfo = new ResumeWorkflowInfo() { Id = inboxId, Answer = "OK", UserId = userId, Params = resumeParams }; var resumeResult = await _workflow.ResumeWorkflow(rInfo); Assert.AreEqual(resumeResult.ProcessId, result.ProcessId); Assert.AreEqual(resumeResult.InboxIds.Count, 1); pm = await _dbContext.LoadModelAsync(String.Empty, "a2workflow.[Process.Load]", new { UserId = userId, Id = result.ProcessId } ); dt = new DataTester(pm, "Process.Inboxes"); dt.IsArray(1); inboxId = dt.GetArrayValue <Int64>(0, "Id"); rInfo = new ResumeWorkflowInfo() { Id = inboxId, UserId = userId }; resumeResult = await _workflow.ResumeWorkflow(rInfo); Assert.AreEqual(resumeResult.ProcessId, result.ProcessId); Assert.AreEqual(resumeResult.InboxIds.Count, 0); pm = await _dbContext.LoadModelAsync(String.Empty, "a2workflow.[Process.Load]", new { UserId = userId, Id = result.ProcessId } ); dt = new DataTester(pm, "Process.TrackRecords"); dt.IsArray(1); dt.AreArrayValueEqual("Id:500 Text:ParamText", 0, "Message"); dt.AreArrayValueEqual(userId, 0, "UserId"); }
public async Task <WorkflowResult> StartWorkflow(StartWorkflowInfo info) { return(await AppWorkflow.StartWorkflow(_host, _dbContext, _messaging, info)); }
public static async Task <WorkflowResult> StartWorkflow(IApplicationHost host, IDbContext dbContext, StartWorkflowInfo info) { AppWorkflow aw = null; var profiler = host.Profiler; var result = new WorkflowResult { InboxIds = new List <Int64>() }; try { WorkflowDefinition def = null; Activity root = null; Process process = null; using (profiler.CurrentRequest.Start(ProfileAction.Workflow, $"Load '{info.Source}'")) { def = WorkflowDefinition.Create(info.Source); root = def.LoadFromSource(host); process = Process.Create(def, info); } // workflow arguments IDictionary <String, Object> args = new Dictionary <String, Object> { { "Process", process }, { "Comment", info.Comment } }; aw = Create(dbContext, root, args, def.Identity); aw._application.Extensions.Add(result); aw._application.Extensions.Add(dbContext); process.DbContext = dbContext; process.WorkflowId = aw._application.Id; await process.Start(dbContext); using (profiler.CurrentRequest.Start(ProfileAction.Workflow, $"Run. Process.Id = {process.Id}, Workflow.Id={process.WorkflowId}")) { aw._application.Run(_wfTimeSpan); result.ProcessId = process.Id; return(result); } } catch (Exception ex) { if (!CatchWorkflow(aw, ex)) { throw; } return(result); } finally { ProcessFinally(aw); } }