Skip to content

Commit 894398a

Browse files
authored
Merge pull request #156 from Miggleness/master
Assign workflow instance name/identifier
2 parents 259bcf1 + 5bc845b commit 894398a

File tree

10 files changed

+34
-30
lines changed

10 files changed

+34
-30
lines changed

src/WorkflowCore/Interface/IWorkflowController.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ namespace WorkflowCore.Interface
77
{
88
public interface IWorkflowController
99
{
10-
Task<string> StartWorkflow(string workflowId, object data = null);
11-
Task<string> StartWorkflow(string workflowId, int? version, object data = null);
12-
Task<string> StartWorkflow<TData>(string workflowId, TData data = null) where TData : class;
13-
Task<string> StartWorkflow<TData>(string workflowId, int? version, TData data = null) where TData : class;
10+
Task<string> StartWorkflow(string workflowId, object data = null, string reference=null);
11+
Task<string> StartWorkflow(string workflowId, int? version, object data = null, string reference=null);
12+
Task<string> StartWorkflow<TData>(string workflowId, TData data = null, string reference=null) where TData : class;
13+
Task<string> StartWorkflow<TData>(string workflowId, int? version, TData data = null, string reference=null) where TData : class;
1414

1515
Task PublishEvent(string eventName, string eventKey, object eventData, DateTime? effectiveDate = null);
1616
void RegisterWorkflow<TWorkflow>() where TWorkflow : IWorkflow, new();

src/WorkflowCore/Services/WorkflowController.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@ public WorkflowController(IPersistenceProvider persistenceStore, IDistributedLoc
2929
_logger = loggerFactory.CreateLogger<WorkflowController>();
3030
}
3131

32-
public Task<string> StartWorkflow(string workflowId, object data = null)
32+
public Task<string> StartWorkflow(string workflowId, object data = null, string reference=null)
3333
{
34-
return StartWorkflow(workflowId, null, data);
34+
return StartWorkflow(workflowId, null, data, reference);
3535
}
3636

37-
public Task<string> StartWorkflow(string workflowId, int? version, object data = null)
37+
public Task<string> StartWorkflow(string workflowId, int? version, object data = null, string reference=null)
3838
{
39-
return StartWorkflow<object>(workflowId, version, data);
39+
return StartWorkflow<object>(workflowId, version, data, reference);
4040
}
4141

42-
public Task<string> StartWorkflow<TData>(string workflowId, TData data = null)
42+
public Task<string> StartWorkflow<TData>(string workflowId, TData data = null, string reference=null)
4343
where TData : class
4444
{
45-
return StartWorkflow<TData>(workflowId, null, data);
45+
return StartWorkflow<TData>(workflowId, null, data, reference);
4646
}
4747

48-
public async Task<string> StartWorkflow<TData>(string workflowId, int? version, TData data = null)
48+
public async Task<string> StartWorkflow<TData>(string workflowId, int? version, TData data = null, string reference=null)
4949
where TData : class
5050
{
5151

@@ -63,7 +63,8 @@ public async Task<string> StartWorkflow<TData>(string workflowId, int? version,
6363
Description = def.Description,
6464
NextExecution = 0,
6565
CreateTime = DateTime.Now.ToUniversalTime(),
66-
Status = WorkflowStatus.Runnable
66+
Status = WorkflowStatus.Runnable,
67+
Reference = reference
6768
};
6869

6970
if ((def.DataType != null) && (data == null))

src/WorkflowCore/Services/WorkflowHost.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,27 @@ public WorkflowHost(IPersistenceProvider persistenceStore, IQueueProvider queueP
4343
persistenceStore.EnsureStoreExists();
4444
}
4545

46-
public Task<string> StartWorkflow(string workflowId, object data = null)
46+
public Task<string> StartWorkflow(string workflowId, object data = null, string reference=null)
4747
{
48-
return _workflowController.StartWorkflow(workflowId, data);
48+
return _workflowController.StartWorkflow(workflowId, data, reference);
4949
}
5050

51-
public Task<string> StartWorkflow(string workflowId, int? version, object data = null)
51+
public Task<string> StartWorkflow(string workflowId, int? version, object data = null, string reference=null)
5252
{
53-
return _workflowController.StartWorkflow<object>(workflowId, version, data);
53+
return _workflowController.StartWorkflow<object>(workflowId, version, data, reference);
5454
}
5555

56-
public Task<string> StartWorkflow<TData>(string workflowId, TData data = null)
56+
public Task<string> StartWorkflow<TData>(string workflowId, TData data = null, string reference=null)
5757
where TData : class
5858
{
59-
return _workflowController.StartWorkflow<TData>(workflowId, null, data);
59+
return _workflowController.StartWorkflow<TData>(workflowId, null, data, reference);
6060
}
6161

6262

63-
public Task<string> StartWorkflow<TData>(string workflowId, int? version, TData data = null)
63+
public Task<string> StartWorkflow<TData>(string workflowId, int? version, TData data = null, string reference=null)
6464
where TData : class
6565
{
66-
return _workflowController.StartWorkflow(workflowId, version, data);
66+
return _workflowController.StartWorkflow(workflowId, version, data, reference);
6767
}
6868

6969
public Task PublishEvent(string eventName, string eventKey, object eventData, DateTime? effectiveDate = null)

src/extensions/WorkflowCore.WebAPI/Controllers/WorkflowsController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public async Task<IActionResult> Get(string id)
4545

4646
[HttpPost("{id}")]
4747
[HttpPost("{id}/{version}")]
48-
public async Task<IActionResult> Post(string id, int? version, [FromBody]JObject data)
48+
public async Task<IActionResult> Post(string id, int? version, string reference, [FromBody]JObject data)
4949
{
5050
string workflowId = null;
5151
var def = _registry.GetDefinition(id, version);
@@ -55,11 +55,11 @@ public async Task<IActionResult> Post(string id, int? version, [FromBody]JObject
5555
{
5656
var dataStr = JsonConvert.SerializeObject(data);
5757
var dataObj = JsonConvert.DeserializeObject(dataStr, def.DataType);
58-
workflowId = await _workflowHost.StartWorkflow(id, version, dataObj);
58+
workflowId = await _workflowHost.StartWorkflow(id, version, dataObj, reference);
5959
}
6060
else
6161
{
62-
workflowId = await _workflowHost.StartWorkflow(id, version, null);
62+
workflowId = await _workflowHost.StartWorkflow(id, version, null, reference);
6363
}
6464

6565
return Ok(workflowId);

src/samples/WorkflowCore.Sample01/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void Main(string[] args)
2222
host.RegisterWorkflow<HelloWorldWorkflow>();
2323
host.Start();
2424

25-
host.StartWorkflow("HelloWorld", 1, null);
25+
host.StartWorkflow("HelloWorld");
2626

2727
Console.ReadLine();
2828
host.Stop();

src/samples/WorkflowCore.Sample02/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static void Main(string[] args)
2121
host.RegisterWorkflow<SimpleDecisionWorkflow>();
2222
host.Start();
2323

24-
host.StartWorkflow("Simple Decision Workflow", 1, null);
24+
host.StartWorkflow("Simple Decision Workflow");
2525

2626
Console.ReadLine();
2727
host.Stop();

src/samples/WorkflowCore.Sample05/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void Main(string[] args)
2222
host.RegisterWorkflow<DeferSampleWorkflow>();
2323
host.Start();
2424

25-
host.StartWorkflow("DeferSampleWorkflow", 1, null);
25+
host.StartWorkflow("DeferSampleWorkflow", 1, null, null);
2626

2727
Console.ReadLine();
2828
host.Stop();

src/samples/WorkflowCore.Sample06/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void Main(string[] args)
2222
host.RegisterWorkflow<MultipleOutcomeWorkflow>();
2323
host.Start();
2424

25-
host.StartWorkflow("MultipleOutcomeWorkflow", 1, null);
25+
host.StartWorkflow("MultipleOutcomeWorkflow", 1, null, null);
2626

2727
Console.ReadLine();
2828
host.Stop();

src/samples/WorkflowCore.Sample15/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void Main(string[] args)
1818
host.RegisterWorkflow<HelloWorldWorkflow>();
1919
host.Start();
2020

21-
host.StartWorkflow("HelloWorld", 1, null);
21+
host.StartWorkflow("HelloWorld", 1, null, null);
2222

2323
Console.ReadLine();
2424
host.Stop();

test/WorkflowCore.UnitTests/BasePersistenceFixture.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public void GetWorkflowInstance_should_retrieve_workflow()
4949
Status = WorkflowStatus.Runnable,
5050
NextExecution = 0,
5151
Version = 1,
52-
WorkflowDefinitionId = "My Workflow"
52+
WorkflowDefinitionId = "My Workflow",
53+
Reference = "My Reference"
5354
};
5455
workflow.ExecutionPointers.Add(new ExecutionPointer()
5556
{
@@ -76,7 +77,8 @@ public void PersistWorkflow()
7677
NextExecution = 0,
7778
Version = 1,
7879
WorkflowDefinitionId = "My Workflow",
79-
CreateTime = new DateTime(2000, 1, 1).ToUniversalTime()
80+
CreateTime = new DateTime(2000, 1, 1).ToUniversalTime(),
81+
Reference = "My Reference"
8082
};
8183
oldWorkflow.ExecutionPointers.Add(new ExecutionPointer()
8284
{
@@ -87,6 +89,7 @@ public void PersistWorkflow()
8789
var workflowId = Subject.CreateNewWorkflow(oldWorkflow).Result;
8890
var newWorkflow = Utils.DeepCopy(oldWorkflow);
8991
newWorkflow.Data = oldWorkflow.Data;
92+
newWorkflow.Reference = oldWorkflow.Reference;
9093
newWorkflow.NextExecution = 7;
9194
newWorkflow.ExecutionPointers.Add(new ExecutionPointer() { Id = Guid.NewGuid().ToString(), Active = true, StepId = 1 });
9295

0 commit comments

Comments
 (0)