Skip to content

Commit 2f770d8

Browse files
Ticket #6 : Remove ProcessInstanceContext
1 parent 160301d commit 2f770d8

72 files changed

Lines changed: 712 additions & 187 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/CaseManagement.BPMN/ProcessInstance/Processors/BPMNEndEventProcessor.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
using System;
2-
using System.Threading.Tasks;
3-
using CaseManagement.BPMN.Domains;
1+
using CaseManagement.BPMN.Domains;
42
using CaseManagement.Workflow.Domains;
53
using CaseManagement.Workflow.Engine;
4+
using System;
5+
using System.Threading.Tasks;
66

77
namespace CaseManagement.BPMN.ProcessInstance.Processors
88
{
99
public class BPMNEndEventProcessor : IProcessFlowElementProcessor
1010
{
1111
public Type ProcessFlowElementType => typeof(BPMNEndEvent);
1212

13-
public Task Handle(ProcessFlowInstanceElement pfe, ProcessFlowInstanceExecutionContext context)
13+
public Task Handle(ProcessFlowInstance pf, ProcessFlowInstanceElement pfe)
1414
{
15-
pfe.Finish();
15+
pf.CompleteElement(pfe);
1616
return Task.FromResult(0);
1717
}
1818
}

src/CaseManagement.BPMN/ProcessInstance/Processors/BPMNReceiveTaskProcessor.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,11 @@ public class BPMNReceiveTaskProcessor : IProcessFlowElementProcessor
1010
{
1111
public Type ProcessFlowElementType { get => typeof(BPMNReceiveTask); }
1212

13-
public Task Handle(ProcessFlowInstanceElement pfe, ProcessFlowInstanceExecutionContext context)
13+
public Task Handle(ProcessFlowInstance pf, ProcessFlowInstanceElement pfe)
1414
{
1515
var receiveTask = pfe as BPMNReceiveTask;
16-
receiveTask.Run();
17-
if (context.CallingOperation != receiveTask.OperationId)
18-
{
19-
return Task.FromResult(0);
20-
}
21-
22-
receiveTask.Finish();
16+
pf.LaunchElement(pfe);
17+
pf.CompleteElement(pfe);
2318
return Task.FromResult(0);
2419
}
2520
}

src/CaseManagement.BPMN/ProcessInstance/Processors/BPMNServiceTaskProcessor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ public class BPMNServiceTaskProcessor : IProcessFlowElementProcessor
1111
{
1212
public Type ProcessFlowElementType => typeof(BPMNServiceTask);
1313

14-
public async Task Handle(ProcessFlowInstanceElement pfe, ProcessFlowInstanceExecutionContext context)
14+
public async Task Handle(ProcessFlowInstance pf, ProcessFlowInstanceElement pfe)
1515
{
16-
pfe.Run();
16+
pf.LaunchElement(pfe);
1717
var serviceTask = (BPMNServiceTask)pfe;
1818
var type = Type.GetType(serviceTask.FullQualifiedName);
1919
var instance = Activator.CreateInstance(type) as WorkflowTaskDelegate;
20-
await instance.Handle(context);
21-
pfe.Finish();
20+
await instance.Handle(pf);
21+
pf.CompleteElement(pfe);
2222
}
2323
}
2424
}

src/CaseManagement.BPMN/ProcessInstance/Processors/BPMNStartEventProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public class BPMNStartEventProcessor : IProcessFlowElementProcessor
1010
{
1111
public Type ProcessFlowElementType => typeof(BPMNStartEvent);
1212

13-
public Task Handle(ProcessFlowInstanceElement pfe, ProcessFlowInstanceExecutionContext context)
13+
public Task Handle(ProcessFlowInstance pf, ProcessFlowInstanceElement pfe)
1414
{
15-
pfe.Finish();
15+
pf.CompleteElement(pfe);
1616
return Task.FromResult(0);
1717
}
1818
}

src/CaseManagement.BPMN/ProcessInstance/Processors/BPMNTaskProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public class BPMNTaskProcessor : IProcessFlowElementProcessor
1010
{
1111
public Type ProcessFlowElementType => typeof(BPMNTask);
1212

13-
public Task Handle(ProcessFlowInstanceElement pfe, ProcessFlowInstanceExecutionContext context)
13+
public Task Handle(ProcessFlowInstance pf, ProcessFlowInstanceElement pfe)
1414
{
15-
pfe.Finish();
15+
pf.CompleteElement(pfe);
1616
return Task.FromResult(0);
1717
}
1818
}

src/CaseManagement.CMMN.Host/Delegates/SendEmailTaskDelegate.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using System.Threading.Tasks;
2-
using CaseManagement.Workflow.Engine;
1+
using CaseManagement.Workflow.Domains;
32
using CaseManagement.Workflow.Infrastructure;
3+
using System.Threading.Tasks;
44

55
namespace CaseManagement.CMMN.Host.Delegates
66
{
77
public class SendEmailTaskDelegate : WorkflowTaskDelegate
88
{
9-
public override Task Handle(ProcessFlowInstanceExecutionContext context)
9+
public override Task Handle(ProcessFlowInstance context)
1010
{
1111
return Task.FromResult(0);
1212
}

src/CaseManagement.CMMN/CaseInstance/EventHandlers/ProcessFlowInstanceFormConfirmedEventHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ public async Task Handle(ProcessFlowInstanceFormConfirmedEvent @event)
2626
var flowInstance = await _processFlowInstanceQueryRepository.FindFlowInstanceById(@event.Id);
2727
var flowInstanceElt = flowInstance.Elements.FirstOrDefault(e => e.Id == @event.ElementId) as CMMNPlanItem;
2828
flowInstanceElt.Complete();
29-
var context = new ProcessFlowInstanceExecutionContext(flowInstance);
30-
await _workflowEngine.Start(flowInstance, context);
29+
await _workflowEngine.Start(flowInstance);
3130
_processFlowInstanceCommandRepository.Update(flowInstance);
3231
await _processFlowInstanceCommandRepository.SaveChanges();
3332
}

src/CaseManagement.CMMN/CaseInstance/EventHandlers/ProcessFlowInstanceLaunchedEventHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ public async Task Handle(ProcessFlowInstanceLaunchedEvent @event)
2323
{
2424
var flowInstance = await _processFlowInstanceQueryRepository.FindFlowInstanceById(@event.Id);
2525
flowInstance.Launch();
26-
var context = new ProcessFlowInstanceExecutionContext(flowInstance);
27-
await _workflowEngine.Start(flowInstance, context);
26+
await _workflowEngine.Start(flowInstance);
2827
_processFlowInstanceCommandRepository.Update(flowInstance);
2928
await _processFlowInstanceCommandRepository.SaveChanges();
3029
}

src/CaseManagement.CMMN/CaseInstance/Processors/CMMNPlanItemProcessor.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,35 @@ public CMMNPlanItemProcessor(IBackgroundTaskQueue backgroundTaskQueue, IFormQuer
2424

2525
public override Type ProcessFlowElementType => typeof(CMMNPlanItem);
2626

27-
protected override Task<bool> HandleProcessFlowInstance(ProcessFlowInstanceElement pfe, ProcessFlowInstanceExecutionContext context)
27+
protected override Task<bool> HandleProcessFlowInstance(ProcessFlowInstance pf, ProcessFlowInstanceElement pfe)
2828
{
2929
var planItem = (CMMNPlanItem)pfe;
3030
var processTask = planItem.PlanItemDefinition as CMMNProcessTask;
3131
if (processTask != null)
3232
{
33-
return HandleTask(planItem, processTask, context, HandleProcessTask);
33+
return HandleTask(planItem, processTask, pf, HandleProcessTask);
3434
}
3535

3636
var humanTask = planItem.PlanItemDefinition as CMMNHumanTask;
3737
if (humanTask != null)
3838
{
39-
return HandleTask(planItem, humanTask, context, HandleHumanTask);
39+
return HandleTask(planItem, humanTask, pf, HandleHumanTask);
4040
}
4141

4242
return Task.FromResult(true);
4343
}
4444

45-
protected async Task<bool> HandleTask<T>(CMMNPlanItem planItem, T task, ProcessFlowInstanceExecutionContext context, Func<CMMNPlanItem, T, ProcessFlowInstanceExecutionContext, Task<bool>> callback) where T : CMMNTask
45+
protected async Task<bool> HandleTask<T>(CMMNPlanItem planItem, T task, ProcessFlowInstance pf, Func<CMMNPlanItem, T, ProcessFlowInstance, Task<bool>> callback) where T : CMMNTask
4646
{
47-
if (planItem.ExitCriterions.Any() && planItem.ExitCriterions.Any(s => CheckCriterion(s, context)))
47+
if (planItem.ExitCriterions.Any() && planItem.ExitCriterions.Any(s => CheckCriterion(s, pf)))
4848
{
4949
planItem.Terminate();
5050
return true;
5151
}
5252

5353
if (task.State == CMMNTaskStates.Available)
5454
{
55-
if (planItem.EntryCriterions.Any() && !planItem.EntryCriterions.Any(s => CheckCriterion(s, context)))
55+
if (planItem.EntryCriterions.Any() && !planItem.EntryCriterions.Any(s => CheckCriterion(s, pf)))
5656
{
5757
return true;
5858
}
@@ -63,7 +63,7 @@ protected async Task<bool> HandleTask<T>(CMMNPlanItem planItem, T task, ProcessF
6363
if (manualActivationRule != null)
6464
{
6565
// Note : at the moment the ContextRef is ignored.
66-
if (ExpressionParser.IsValid(manualActivationRule.Expression.Body, context))
66+
if (ExpressionParser.IsValid(manualActivationRule.Expression.Body, pf))
6767
{
6868
planItem.Enable();
6969
return false;
@@ -76,29 +76,29 @@ protected async Task<bool> HandleTask<T>(CMMNPlanItem planItem, T task, ProcessF
7676

7777
if (task.State == CMMNTaskStates.Active)
7878
{
79-
return await callback(planItem, task, context);
79+
return await callback(planItem, task, pf);
8080
}
8181

8282
return true;
8383
}
8484

85-
protected async Task<bool> HandleProcessTask(CMMNPlanItem planItem, CMMNProcessTask processTask, ProcessFlowInstanceExecutionContext context)
85+
protected async Task<bool> HandleProcessTask(CMMNPlanItem planItem, CMMNProcessTask processTask, ProcessFlowInstance pf)
8686
{
8787
var instance = (WorkflowTaskDelegate)Activator.CreateInstance(Type.GetType(processTask.AssemblyQualifiedName));
8888
if (processTask.IsBlocking)
8989
{
90-
await instance.Handle(context);
90+
await instance.Handle(pf);
9191
}
9292
else
9393
{
94-
_backgroundTaskQueue.QueueBackgroundWorkItem((token) => instance.Handle(context));
94+
_backgroundTaskQueue.QueueBackgroundWorkItem((token) => instance.Handle(pf));
9595
}
9696

9797
planItem.Complete();
9898
return true;
9999
}
100100

101-
protected async Task<bool> HandleHumanTask(CMMNPlanItem planItem, CMMNHumanTask humanTask, ProcessFlowInstanceExecutionContext context)
101+
protected async Task<bool> HandleHumanTask(CMMNPlanItem planItem, CMMNHumanTask humanTask, ProcessFlowInstance pf)
102102
{
103103
if (planItem.FormInstance != null && planItem.FormInstance.Status == ProcessFlowInstanceElementFormStatus.Complete)
104104
{
@@ -117,15 +117,15 @@ protected async Task<bool> HandleHumanTask(CMMNPlanItem planItem, CMMNHumanTask
117117
return true;
118118
}
119119

120-
private bool CheckCriterion(CMMNCriterion sCriterion, ProcessFlowInstanceExecutionContext context)
120+
private bool CheckCriterion(CMMNCriterion sCriterion, ProcessFlowInstance pf)
121121
{
122122
foreach (var onPart in sCriterion.SEntry.OnParts)
123123
{
124124
if (onPart is CMMNPlanItemOnPart)
125125
{
126126
if (!string.IsNullOrWhiteSpace(onPart.SourceRef))
127127
{
128-
var elt = context.GetPlanItem(onPart.SourceRef);
128+
var elt = pf.GetPlanItem(onPart.SourceRef);
129129
if (elt == null || elt.Events.Last().Transition != onPart.StandardEvent)
130130
{
131131
return false;
@@ -136,7 +136,7 @@ private bool CheckCriterion(CMMNCriterion sCriterion, ProcessFlowInstanceExecuti
136136

137137
if (sCriterion.SEntry.IfPart != null)
138138
{
139-
return ExpressionParser.IsValid(sCriterion.SEntry.IfPart.Condition, context);
139+
return ExpressionParser.IsValid(sCriterion.SEntry.IfPart.Condition, pf);
140140
}
141141

142142
return true;

src/CaseManagement.CMMN/Domains/CMMNPlanItem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ private CMMNPlanItem(string id, string name, CMMNPlanItemDefinition planItemDefi
4040
public void Enable()
4141
{
4242
var evt = new CMMNPlanItemEnabled();
43+
// DON T USE ANY EVENT ANYMORE.
4344
Events.Add(evt);
4445
PlanItemDefinition.Handle(evt);
4546
}

0 commit comments

Comments
 (0)