Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7. Conditional branches #18

Open
wants to merge 1 commit into
base: dependency-injection
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 26 additions & 3 deletions Backend/WorkflowLib/ActionProvider.cs
Expand Up @@ -9,13 +9,18 @@ public class ActionProvider : IWorkflowActionProvider
{
private readonly Dictionary<string, Func<ProcessInstance, WorkflowRuntime, string, CancellationToken, Task>>
_asyncActions = new();

private readonly Dictionary<string, Func<ProcessInstance, WorkflowRuntime, string, bool>>
_syncConditions = new();

private IHubContext<ProcessConsoleHub> _processConsoleHub;

public ActionProvider(IHubContext<ProcessConsoleHub> processConsoleHub)
{
_processConsoleHub = processConsoleHub;
_asyncActions.Add(nameof(SendMessageToProcessConsoleAsync), SendMessageToProcessConsoleAsync);
_syncConditions.Add(nameof(IsHighPriority),IsHighPriority);
_syncConditions.Add(nameof(IsMediumPriority), IsMediumPriority);
}

public void ExecuteAction(string name, ProcessInstance processInstance, WorkflowRuntime runtime,
Expand All @@ -39,7 +44,12 @@ public ActionProvider(IHubContext<ProcessConsoleHub> processConsoleHub)
public bool ExecuteCondition(string name, ProcessInstance processInstance, WorkflowRuntime runtime,
string actionParameter)
{
throw new NotImplementedException();
if (!_syncConditions.ContainsKey(name))
{
throw new NotImplementedException($"Sync Condition with name {name} isn't implemented");
}

return _syncConditions[name].Invoke(processInstance, runtime, actionParameter);
}

public Task<bool> ExecuteConditionAsync(string name, ProcessInstance processInstance, WorkflowRuntime runtime,
Expand All @@ -55,7 +65,7 @@ public bool IsActionAsync(string name, string schemeCode)

public bool IsConditionAsync(string name, string schemeCode)
{
throw new NotImplementedException();
return false; //we have no async conditions now
}

public List<string> GetActions(string schemeCode, NamesSearchType namesSearchType)
Expand All @@ -65,7 +75,7 @@ public List<string> GetActions(string schemeCode, NamesSearchType namesSearchTyp

public List<string> GetConditions(string schemeCode, NamesSearchType namesSearchType)
{
return new List<string>();
return _syncConditions.Keys.ToList();
}

//it is internal just to have possibility to use nameof()
Expand All @@ -78,4 +88,17 @@ public List<string> GetConditions(string schemeCode, NamesSearchType namesSearch
message = actionParameter
}, cancellationToken: token);
}

private bool IsHighPriority(ProcessInstance processInstance, WorkflowRuntime runtime, string actionParameter)
{
dynamic report = processInstance.GetParameter<DynamicParameter>("Report");
return (report.CompanySize == "Big" && report.Position == "Management")
|| (report.CompanySize == "Small" && report.Position == "Development");
}

private bool IsMediumPriority(ProcessInstance processInstance, WorkflowRuntime runtime, string actionParameter)
{
dynamic report = processInstance.GetParameter<DynamicParameter>("Report");
return report.Position != "Other" && !IsHighPriority(processInstance, runtime, actionParameter);
}
}