From b9876b1d7b8697b8c440f00a993c19edec1b3478 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Tue, 3 Feb 2026 11:00:09 +0000 Subject: [PATCH] Few more tweaks to the workflow engine --- .../Extensions/StageExtensions.cs | 13 +++--- .../Extensions/TaskExtensions.cs | 31 +++++++------- e-suite.Workflow.Core/Interfaces/ITask.cs | 34 +++++++--------- e-suite.Workflow.Core/Interfaces/IWorkflow.cs | 40 +++++++++---------- e-suite.Workflow.Core/TaskBase.cs | 18 ++++----- e-suite.Workflow.Core/Tasks/ApprovalTask.cs | 9 +++-- e-suite.Workflow.Core/Tasks/MilestoneTask.cs | 12 +++--- e-suite.Workflow.Core/Workflow.cs | 16 ++++---- 8 files changed, 86 insertions(+), 87 deletions(-) diff --git a/e-suite.Workflow.Core/Extensions/StageExtensions.cs b/e-suite.Workflow.Core/Extensions/StageExtensions.cs index da977b8..5d249fa 100644 --- a/e-suite.Workflow.Core/Extensions/StageExtensions.cs +++ b/e-suite.Workflow.Core/Extensions/StageExtensions.cs @@ -6,12 +6,13 @@ namespace e_suite.Workflow.Core.Extensions; public static class StageExtensions { - public static bool CanComplete(this IStage stage) - where T : TaskTypeAttribute - { - return stage.Tasks.All(x => - x.IsCompleted()); - } + //Todo can only be on a run-time instance + //public static bool CanComplete(this IStage stage) + // where T : TaskTypeAttribute + //{ + // return stage.Tasks.All(x => + // x.IsCompleted()); + //} private static readonly ConcurrentDictionary> AllowedTasksCache = new(); diff --git a/e-suite.Workflow.Core/Extensions/TaskExtensions.cs b/e-suite.Workflow.Core/Extensions/TaskExtensions.cs index 92b7858..ca32589 100644 --- a/e-suite.Workflow.Core/Extensions/TaskExtensions.cs +++ b/e-suite.Workflow.Core/Extensions/TaskExtensions.cs @@ -101,21 +101,22 @@ public static class TaskExtensions } - public static bool IsCompleted(this ITask task) - { - return task.TaskState.In(TaskState.Completed, TaskState.Cancelled); - } + //Todo can only be on a run-time instance + //public static bool IsCompleted(this ITask task) + //{ + // return task.TaskState.In(TaskState.Completed, TaskState.Cancelled); + //} - public static bool ReadyToActivate(this ITask task) - { - foreach (var predecessor in task.Predecessors) - { - if (!predecessor.IsCompleted()) - { - return false; - } - } + //public static bool ReadyToActivate(this ITask task) + //{ + // foreach (var predecessor in task.Predecessors) + // { + // if (!predecessor.IsCompleted()) + // { + // return false; + // } + // } - return true; - } + // return true; + //} } \ No newline at end of file diff --git a/e-suite.Workflow.Core/Interfaces/ITask.cs b/e-suite.Workflow.Core/Interfaces/ITask.cs index fe45b73..cb0245f 100644 --- a/e-suite.Workflow.Core/Interfaces/ITask.cs +++ b/e-suite.Workflow.Core/Interfaces/ITask.cs @@ -14,13 +14,6 @@ public interface ITask /// ITask Parent { get; } - - //Todo move this out to runtime only. - /// - /// Current state of the Task. - /// - TaskState TaskState { get; set; } - /// /// Name of the task as seen by users, must be unique in the workflow. /// @@ -68,20 +61,21 @@ public interface ITask public IList Tags { get; set; } - /// - /// Called when the task status has been progressed from Pending to Active. - /// - /// Note: You can use this method to set the TaskStatus to ReadyToComplete if there is no manual processing needed for this task. - /// After this method is completed, the TaskStatus must be either Active or ReadyToComplete. - /// - /// - Task OnActivateAsync(); + //Todo can only be on a run-time instance + ///// + ///// Called when the task status has been progressed from Pending to Active. + ///// + ///// Note: You can use this method to set the TaskStatus to ReadyToComplete if there is no manual processing needed for this task. + ///// After this method is completed, the TaskStatus must be either Active or ReadyToComplete. + ///// + ///// + //Task OnActivateAsync(); - /// - /// Called when the task status has been progressed from ReadyToComplete to Completed - /// - /// True when the task completes successfully, false when it is considered failed. - Task OnCompleteAsync(); + ///// + ///// Called when the task status has been progressed from ReadyToComplete to Completed + ///// + ///// True when the task completes successfully, false when it is considered failed. + //Task OnCompleteAsync(); //Todo add support for events (soap, rest, sftp, e-mail) } \ No newline at end of file diff --git a/e-suite.Workflow.Core/Interfaces/IWorkflow.cs b/e-suite.Workflow.Core/Interfaces/IWorkflow.cs index 180a864..bb168ee 100644 --- a/e-suite.Workflow.Core/Interfaces/IWorkflow.cs +++ b/e-suite.Workflow.Core/Interfaces/IWorkflow.cs @@ -25,25 +25,25 @@ public interface IWorkflow : IStage /// string Description { get; set; } - //todo Move this out to runtime only. - /// - /// If the workflow has been paused, will be true. - /// - bool Paused { get; } + //Todo can only be on a run-time instance + ///// + ///// If the workflow has been paused, will be true. + ///// + //bool Paused { get; } + + ///// + ///// Called when the task status has been progressed from Pending to Active. + ///// + ///// Note: You can use this method to set the TaskStatus to ReadyToComplete if there is no manual processing needed for this task. + ///// After this method is completed, the TaskStatus must be either Active or ReadyToComplete. + ///// + ///// + //Task OnActivateAsync(); - /// - /// Called when the task status has been progressed from Pending to Active. - /// - /// Note: You can use this method to set the TaskStatus to ReadyToComplete if there is no manual processing needed for this task. - /// After this method is completed, the TaskStatus must be either Active or ReadyToComplete. - /// - /// - Task OnActivateAsync(); - - /// - /// Called when the task status has been progressed from ReadyToComplete to Completed - /// When this method is completed the state must be either Active, or Completed. - /// - /// - Task OnCompleteAsync(); + ///// + ///// Called when the task status has been progressed from ReadyToComplete to Completed + ///// When this method is completed the state must be either Active, or Completed. + ///// + ///// + //Task OnCompleteAsync(); } \ No newline at end of file diff --git a/e-suite.Workflow.Core/TaskBase.cs b/e-suite.Workflow.Core/TaskBase.cs index 5dd562f..c7915b4 100644 --- a/e-suite.Workflow.Core/TaskBase.cs +++ b/e-suite.Workflow.Core/TaskBase.cs @@ -7,7 +7,6 @@ public abstract class TaskBase : ITask { public Guid Guid { get; set; } = Guid.CreateVersion7(); public required ITask Parent { get; set; } - public TaskState TaskState { get; set; } = TaskState.Pending; public required string Name { get; set; } public string Description { get; set; } = string.Empty; public IList Predecessors { get; set; } = new List(); @@ -19,13 +18,14 @@ public abstract class TaskBase : ITask public required TimeSpan Duration { get; set; } public IList Tags { get; set; } = new List(); - public virtual Task OnActivateAsync() - { - return Task.CompletedTask; - } + //Todo can only be on a run-time instance + //public virtual Task OnActivateAsync() + //{ + // return Task.CompletedTask; + //} - public virtual Task OnCompleteAsync() - { - return Task.FromResult(true); - } + //public virtual Task OnCompleteAsync() + //{ + // return Task.FromResult(true); + //} } \ No newline at end of file diff --git a/e-suite.Workflow.Core/Tasks/ApprovalTask.cs b/e-suite.Workflow.Core/Tasks/ApprovalTask.cs index b9f8e12..cfd8934 100644 --- a/e-suite.Workflow.Core/Tasks/ApprovalTask.cs +++ b/e-suite.Workflow.Core/Tasks/ApprovalTask.cs @@ -10,9 +10,10 @@ public class ApprovalTask : TaskBase, IStage, IFailedLoop public ICollection Tasks { get; } = new List(); - public override Task OnCompleteAsync() - { + //Todo can only be on a run-time instance + //public override Task OnCompleteAsync() + //{ - return Task.FromResult(true); - } + // return Task.FromResult(true); + //} } \ No newline at end of file diff --git a/e-suite.Workflow.Core/Tasks/MilestoneTask.cs b/e-suite.Workflow.Core/Tasks/MilestoneTask.cs index 0c788e5..d4cd94f 100644 --- a/e-suite.Workflow.Core/Tasks/MilestoneTask.cs +++ b/e-suite.Workflow.Core/Tasks/MilestoneTask.cs @@ -1,5 +1,4 @@ using e_suite.Workflow.Core.Attributes; -using e_suite.Workflow.Core.Enums; namespace e_suite.Workflow.Core.Tasks; @@ -9,9 +8,10 @@ namespace e_suite.Workflow.Core.Tasks; [GeneralTask] public class MilestoneTask : TaskBase { - public override async Task OnActivateAsync() - { - await base.OnActivateAsync(); - TaskState = TaskState.ReadyToComplete; - } + //Todo can only be on a run-time instance + //public override async Task OnActivateAsync() + //{ + // await base.OnActivateAsync(); + // TaskState = TaskState.ReadyToComplete; + //} } \ No newline at end of file diff --git a/e-suite.Workflow.Core/Workflow.cs b/e-suite.Workflow.Core/Workflow.cs index 8856bda..0de1fa4 100644 --- a/e-suite.Workflow.Core/Workflow.cs +++ b/e-suite.Workflow.Core/Workflow.cs @@ -21,12 +21,14 @@ public class WorkflowVersion : IWorkflow public WorkflowState CurrentState { get; set; } = WorkflowState.Pending; public required string ActivityNameTemplate { get; set; } public string Description { get; set; } = string.Empty; - public bool Paused { get; } = false; - public async Task OnActivateAsync() - { - } - public async Task OnCompleteAsync() - { - } + //Todo can only be on a run-time instance + //public bool Paused { get; } = false; + //public async Task OnActivateAsync() + //{ + //} + + //public async Task OnCompleteAsync() + //{ + //} } \ No newline at end of file