internal static IReadOnlyDictionary <string, object> GetContent <T>(this T workflowData) { FatalException.ArgumentNullException(workflowData, nameof(workflowData)); return(GetProperties(workflowData) .ToDictionary(p => p.Name, p => p.GetValue(workflowData))); }
internal static async Task <IWorkflow> RunWorkflowAsync(this IWorkflow workflow, Step step) { FatalException.ArgumentNullException(workflow, nameof(workflow)); FatalException.ArgumentNullException(step, nameof(step)); do { if (step == null || workflow == null) { break; } var previousBuffer = step; workflow.WorkflowStatus.Current.Step = step; workflow.WorkflowStatus.Current.Workflow = workflow; workflow = await step.RunAsync(workflow); if (workflow == null) { break; } workflow.WorkflowStatus.Previous.Step = previousBuffer; workflow.WorkflowStatus.Previous.Workflow = workflow.Clone(); step = workflow.WorkflowStatus.Next; }while (!(step?.StepSettings?.ExitFromFlow ?? false)); return(workflow); }
internal static void SetContent <T>(this T workflowData, IReadOnlyDictionary <string, object> content, bool overwrite) { FatalException.ArgumentNullException(workflowData, nameof(workflowData)); FatalException.ArgumentNullException(content, nameof(content)); var properties = GetProperties(workflowData); foreach (var p in properties) { foreach (var(key, value) in content) { if ( p.Name == key && p.PropertyType == value.GetType() && p.GetValue(workflowData) != null && !overwrite) { p.SetValue(workflowData, value); } } } }
internal async Task <IWorkflow> RunAsync(IWorkflow workflow) //todo implement with cancellation token { FatalException.ArgumentNullException(workflow, nameof(workflow)); return(await Task.Run(() => InvokeFunction( () => { _logger.Log(workflow); if (Validate(workflow)) { return Run(workflow); } if (workflow.WorkflowStatus.Next == null) { return null; } workflow.WorkflowStatus.Next.StepSettings.ExitFromFlow = true; return workflow; }, () => { if (StepSettings.RunPreviousOnError) { return workflow.RunPrevious().Result; } if (StepSettings.OnFailedStep != null) { Task.Run(() => InvokeAction(StepSettings.OnFailedStep)); } return null; }))); }
private bool Validate(IWorkflow workflow) { var isValid = true; if (_workflowDataValidators == null || _workflowDataValidators.Any(v => v == null)) { return(true); } foreach (var validator in _workflowDataValidators) { if (StepSettings.ExitOnFirstFailedValidation && !isValid) { break; } if (validator.IsValid(workflow)) { continue; } isValid = false; if (StepSettings.ThrowOnFailedValidation) { throw FatalException.GetFatalException(string.Empty); } if (validator.OnValidationFailed == null) { continue; } InvokeAction(() => validator.OnValidationFailed.Invoke(workflow)); } return(isValid); }