From 12fbdf39586afc0ff66851e629db72bf89c34ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Milewski?= Date: Thu, 22 Aug 2024 15:22:22 +0200 Subject: [PATCH] 0.13.x --- .../Activities/Classes/ActivityWrapper.cs | 26 +++-- .../Activities/Events/ExecutionRequest.cs | 23 +++- .../Interfaces/IActivityBehavior.cs | 8 +- Core/Stateflows.Common/Events/Event.cs | 18 +-- .../Stateflows.Common/Interfaces/IBehavior.cs | 3 + .../Utilities/StateflowsJsonConverter.cs | 4 + .../Sequence/ExecutionSequenceObserver.cs | 2 +- .../Stateflows.Common.Transport.csproj | 4 - .../ActivitiesDependencyInjection.cs | 9 +- .../Classes/IterativeActivityNode.cs | 2 +- .../Classes/ParalellActivityNode.cs | 2 +- .../Classes/StructuredActivityNode.cs | 2 +- .../Classes/ActivityInitializationContext.cs | 26 ++++- .../Activities/Context/ContextHolder.cs | 2 +- .../Context/Interfaces/IActionContext.cs | 2 +- .../{IOutput.cs => IActionOutput.cs} | 3 + .../Interfaces/IActivityFlowContext.cs | 15 +-- .../IActivityInitializationContext.cs | 2 +- .../Interfaces/IExceptionHandlerContext.cs | 9 +- Core/Stateflows/Activities/Engine/Executor.cs | 23 ++-- .../Stateflows/Activities/Engine/Inspector.cs | 2 +- .../Stateflows/Activities/Engine/NodeScope.cs | 66 ++++++++++- .../Stateflows/Activities/Engine/Processor.cs | 12 +- .../EventHandlers/ExecutionHandler.cs | 44 ------- .../EventHandlers/SetGlobalValuesHandler.cs | 32 +++++ .../Extensions/BuilderExtensions.cs | 14 +-- .../Context}/IActivityContext.cs | 2 +- .../Interfaces/Context/IExceptionContext.cs | 9 ++ .../Interfaces/Context/IFlowContext.cs | 16 +++ .../Context}/INodeContext.cs | 3 +- .../Interfaces/Model/IActionNode.cs | 3 +- .../Activities/Interfaces/Model/IActivity.cs | 1 - .../Interfaces/Model/IControlFlow.cs | 12 ++ .../Activities/Interfaces/Model/IFlow.cs | 16 +-- .../Model/IStructuredActivityNode.cs | 6 +- .../Registration/Builders/ActivityBuilder.cs | 12 +- .../Interfaces/Base/IObjectFlowBase.cs | 4 +- ...ctionBuilderControlFlowsTypedExtensions.cs | 4 +- ...ActionBuilderObjectFlowsTypedExtensions.cs | 4 +- ...ctionBuilderControlFlowsTypedExtensions.cs | 4 +- ...ActionBuilderObjectFlowsTypedExtensions.cs | 4 +- .../ActivityBuilderEventsTypedExtensions.cs | 39 +++++++ .../ActivityBuilderTypedExtensions.cs | 12 +- .../DataStoreBuilderFlowsTypedExtensions.cs | 4 +- ...isionBuilderControlFlowsTypedExtensions.cs | 4 +- ...cisionBuilderObjectFlowsTypedExtensions.cs | 4 +- .../Flows/ForkBuilderFlowsTypedExtensions.cs | 4 +- ...itialBuilderControlFlowsTypedExtensions.cs | 4 +- .../Flows/InputBuilderFlowsTypedExtensions.cs | 4 +- .../JoinBuilderControlFlowsTypedExtensions.cs | 4 +- .../Flows/JoinBuilderFlowsTypedExtensions.cs | 4 +- ...MergeBuilderControlFlowsTypedExtensions.cs | 4 +- .../MergeBuilderObjectFlowsTypedExtensions.cs | 4 +- ...ivityBuilderControlFlowsTypedExtensions.cs | 4 +- ...uredActivityBuilderFlowsTypedExtensions.cs | 4 +- ...tructuredActivityBuilderTypedExtensions.cs | 12 +- ...ctionBuilderControlFlowsTypedExtensions.cs | 4 +- ...ivityBuilderControlFlowsTypedExtensions.cs | 4 +- ...uredActivityBuilderFlowsTypedExtensions.cs | 4 +- ...tructuredActivityBuilderTypedExtensions.cs | 12 +- ...ctionBuilderControlFlowsTypedExtensions.cs | 4 +- .../TypedActionBuilderFlowsTypedExtensions.cs | 4 +- .../Interfaces/IActivityBuilder.cs | 2 +- .../Classes/BaseActivityBuilder.cs | 30 +++++ .../Classes/IntegratedActivityBuilder.cs | 53 --------- .../Classes/StateActionActivityBuilder.cs | 42 +++++++ .../Classes/TransitionActivityBuilder.cs | 43 +++++++ .../CompositeStateBuilderExtensions.cs | 45 +++---- .../DefaultTransitionBuilderExtensions.cs | 99 ++++++++++++++++ .../StateMachines/Extensions/Delegates.cs | 17 ++- .../InternalTransitionBuilderExtensions.cs | 98 ++++++++++++++++ .../Extensions/StateBuilderExtensions.cs | 47 ++++---- .../Extensions/TransitionBuilderExtensions.cs | 86 ++++++++------ .../TypedCompositeStateBuilderExtensions.cs | 16 +-- .../Extensions/TypedStateBuilderExtensions.cs | 16 +-- .../Base/IStateActionInitialization.cs | 11 ++ .../Interfaces/Base/ISubscription.cs | 10 ++ .../Base/ITransitionInitialization.cs | 12 ++ .../Interfaces/IStateActionActivityBuilder.cs | 11 ++ .../Interfaces/ITransitionActivityBuilder.cs | 15 +++ .../Activities/Utils/ObjectExtensions.cs | 9 ++ .../Common/Classes/BaseValueAccessor.cs | 2 +- .../Common/Classes/ContextValuesCollection.cs | 2 +- .../Common/Engine/StateflowsEngine.cs | 39 +++---- .../Common/Events/SetGlobalValues.cs | 10 ++ .../Interfaces/Context}/IExecutionContext.cs | 5 +- .../Common/Interfaces/IContextValues.cs | 6 +- .../Interfaces/Model/IFinalizer.cs | 2 +- .../Interfaces/Model/IInitializer.cs | 5 +- .../Common/Scheduler/ThreadScheduler.cs | 2 +- Core/Stateflows/DependencyInjection.cs | 1 - .../StateMachines/Context/ContextHolder.cs | 2 +- .../Context/Interfaces/IGuardContext.cs | 8 -- .../Interfaces/IStateMachineActionContext.cs | 5 - .../Context/Interfaces/ITransitionContext.cs | 7 -- .../StateMachines/Engine/Executor.cs | 6 +- .../Engine/Plugins/Notifications.cs | 4 +- .../Engine/Plugins/TimeEvents.cs | 2 +- .../Extensions/BuilderExtensions.cs | 8 +- .../StateMachines/Helpers/TransitionGuard.cs | 6 +- .../Interfaces/IGuardInspectionContext.cs | 2 +- .../Context}/IStateContext.cs | 2 +- .../Context}/IStateMachineContext.cs | 2 +- .../Interfaces/Context/ITransitionContext.cs | 9 ++ .../IStateMachineExceptionHandler.cs | 2 +- .../Interfaces/IStateMachineObserver.cs | 4 +- .../Interfaces/Model/ICompositeState.cs | 10 +- .../Interfaces/Model/IDefaultTransition.cs | 17 +++ .../StateMachines/Interfaces/Model/IState.cs | 6 +- .../Interfaces/Model/ITransition.cs | 19 +-- .../Builders/TransitionBuilder.cs | 10 +- .../Registration/Interfaces/Base/IGuard.cs | 2 +- ...BuilderDefaultTransitionTypedExtensions.cs | 4 +- ...uilderInternalTransitionTypedExtensions.cs | 2 +- ...orStateBuilderTransitionTypedExtensions.cs | 4 +- ...BuilderDefaultTransitionTypedExtensions.cs | 4 +- ...uilderInternalTransitionTypedExtensions.cs | 2 +- ...edStateBuilderTransitionTypedExtensions.cs | 4 +- .../CompositeStateBuilderTypedExtensions.cs | 8 +- ...zedCompositeStateBuilderTypedExtensions.cs | 8 +- ...BuilderDefaultTransitionTypedExtensions.cs | 6 +- ...uilderInternalTransitionTypedExtensions.cs | 2 +- ...teStateBuilderTransitionTypedExtensions.cs | 16 ++- ...BuilderDefaultTransitionTypedExtensions.cs | 6 +- ...uilderInternalTransitionTypedExtensions.cs | 2 +- ...teStateBuilderTransitionTypedExtensions.cs | 6 +- ...BuilderDefaultTransitionTypedExtensions.cs | 6 +- ...uilderInternalTransitionTypedExtensions.cs | 2 +- ...teStateBuilderTransitionTypedExtensions.cs | 6 +- ...BuilderDefaultTransitionTypedExtensions.cs | 4 +- ...uilderInternalTransitionTypedExtensions.cs | 2 +- .../StateBuilderTransitionTypedExtensions.cs | 4 +- ...StateMachineBuilderEventsSyncExtensions.cs | 34 ------ ...tateMachineBuilderEventsTypedExtensions.cs | 39 +++++++ ...StateMachineBuilderEventsSyncExtensions.cs | 34 ------ ...tateMachineBuilderEventsTypedExtensions.cs | 39 +++++++ ...StateMachineBuilderEventsSyncExtensions.cs | 34 ------ ...tateMachineBuilderEventsTypedExtensions.cs | 3 +- ...lizedStateMachineBuilderTypedExtensions.cs | 8 +- .../StateMachineBuilderTypedExtensions.cs | 8 +- .../TransitionBuilderSyncExtensions.cs | 6 +- ...pedCompositeStateBuilderTypedExtensions.cs | 8 +- ...zedCompositeStateBuilderTypedExtensions.cs | 8 +- ...BuilderDefaultTransitionTypedExtensions.cs | 6 +- ...uilderInternalTransitionTypedExtensions.cs | 2 +- ...teStateBuilderTransitionTypedExtensions.cs | 6 +- ...BuilderDefaultTransitionTypedExtensions.cs | 6 +- ...uilderInternalTransitionTypedExtensions.cs | 6 +- ...teStateBuilderTransitionTypedExtensions.cs | 6 +- ...BuilderDefaultTransitionTypedExtensions.cs | 6 +- ...uilderInternalTransitionTypedExtensions.cs | 2 +- ...teStateBuilderTransitionTypedExtensions.cs | 6 +- ...BuilderDefaultTransitionTypedExtensions.cs | 4 +- ...uilderInternalTransitionTypedExtensions.cs | 2 +- ...edStateBuilderTransitionTypedExtensions.cs | 4 +- .../StateMachinesDependencyInjection.cs | 2 +- .../Stateflows.Locks.DistributedLock.csproj | 4 - Stateflows.sln | 6 + ...teflows.Storage.EntityFrameworkCore.csproj | 4 - .../Tests/Exceptions.cs | 2 +- .../Tests/Execution.cs | 1 + .../Activity.IntegrationTests/Tests/Guard.cs | 96 +++++++++++++++ .../StateMachines/EverythingStateMachine.cs | 7 +- .../Classes/StateMachines/StateMachine1.cs | 1 + .../StateMachines/TypedStateMachine.cs | 2 +- .../Classes/StateMachines/TypedValue.cs | 2 +- .../Classes/States/State1.cs | 2 +- .../Transitions/SomeEventTransition.cs | 2 +- .../Classes/Transitions/ValueTransition.cs | 2 +- .../Tests/Activities.cs | 11 +- .../Tests/Behaviors.cs | 110 +++++++++++++++++- .../Tests/Composite.cs | 7 +- .../Tests/Initialization.cs | 6 +- Transport/@stateflows/common/package.json | 6 +- .../common/src/behaviors/activity.ts | 4 +- .../common/src/behaviors/state-machine.ts | 4 +- Transport/@stateflows/common/src/index.ts | 5 +- .../src/interfaces/activity.behavior.ts | 3 + .../common/src/interfaces/activity.locator.ts | 4 +- .../common/src/interfaces/activity.ts | 3 - ...e-machine.ts => state-machine.behavior.ts} | 2 +- .../src/interfaces/state-machine.locator.ts | 4 +- .../@stateflows/http-client/package.json | 8 +- .../@stateflows/signalr-client/package.json | 8 +- .../Stateflows.Transport.Http.csproj | 5 - 185 files changed, 1421 insertions(+), 744 deletions(-) rename Core/Stateflows/Activities/Context/Interfaces/{IOutput.cs => IActionOutput.cs} (84%) delete mode 100644 Core/Stateflows/Activities/EventHandlers/ExecutionHandler.cs create mode 100644 Core/Stateflows/Activities/EventHandlers/SetGlobalValuesHandler.cs rename Core/Stateflows/Activities/{Context/Interfaces => Interfaces/Context}/IActivityContext.cs (89%) create mode 100644 Core/Stateflows/Activities/Interfaces/Context/IExceptionContext.cs create mode 100644 Core/Stateflows/Activities/Interfaces/Context/IFlowContext.cs rename Core/Stateflows/Activities/{Context/Interfaces => Interfaces/Context}/INodeContext.cs (92%) create mode 100644 Core/Stateflows/Activities/Interfaces/Model/IControlFlow.cs create mode 100644 Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderEventsTypedExtensions.cs create mode 100644 Core/Stateflows/Activities/StateMachines/Classes/BaseActivityBuilder.cs delete mode 100644 Core/Stateflows/Activities/StateMachines/Classes/IntegratedActivityBuilder.cs create mode 100644 Core/Stateflows/Activities/StateMachines/Classes/StateActionActivityBuilder.cs create mode 100644 Core/Stateflows/Activities/StateMachines/Classes/TransitionActivityBuilder.cs create mode 100644 Core/Stateflows/Activities/StateMachines/Extensions/DefaultTransitionBuilderExtensions.cs create mode 100644 Core/Stateflows/Activities/StateMachines/Extensions/InternalTransitionBuilderExtensions.cs create mode 100644 Core/Stateflows/Activities/StateMachines/Interfaces/Base/IStateActionInitialization.cs create mode 100644 Core/Stateflows/Activities/StateMachines/Interfaces/Base/ISubscription.cs create mode 100644 Core/Stateflows/Activities/StateMachines/Interfaces/Base/ITransitionInitialization.cs create mode 100644 Core/Stateflows/Activities/StateMachines/Interfaces/IStateActionActivityBuilder.cs create mode 100644 Core/Stateflows/Activities/StateMachines/Interfaces/ITransitionActivityBuilder.cs create mode 100644 Core/Stateflows/Common/Events/SetGlobalValues.cs rename Core/Stateflows/{Activities/Context/Interfaces => Common/Interfaces/Context}/IExecutionContext.cs (53%) rename Core/Stateflows/{StateMachines => Common}/Interfaces/Model/IFinalizer.cs (76%) rename Core/Stateflows/{StateMachines => Common}/Interfaces/Model/IInitializer.cs (76%) delete mode 100644 Core/Stateflows/StateMachines/Context/Interfaces/IGuardContext.cs rename Core/Stateflows/StateMachines/{Context/Interfaces => Interfaces/Context}/IStateContext.cs (81%) rename Core/Stateflows/StateMachines/{Context/Interfaces => Interfaces/Context}/IStateMachineContext.cs (75%) create mode 100644 Core/Stateflows/StateMachines/Interfaces/Context/ITransitionContext.cs create mode 100644 Core/Stateflows/StateMachines/Interfaces/Model/IDefaultTransition.cs delete mode 100644 Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/FinalizedStateMachineBuilderEventsSyncExtensions.cs create mode 100644 Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/FinalizedStateMachineBuilderEventsTypedExtensions.cs delete mode 100644 Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/InitializedStateMachineBuilderEventsSyncExtensions.cs create mode 100644 Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/InitializedStateMachineBuilderEventsTypedExtensions.cs delete mode 100644 Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/StateMachineBuilderEventsSyncExtensions.cs create mode 100644 Tests/Activity.IntegrationTests/Tests/Guard.cs create mode 100644 Transport/@stateflows/common/src/interfaces/activity.behavior.ts delete mode 100644 Transport/@stateflows/common/src/interfaces/activity.ts rename Transport/@stateflows/common/src/interfaces/{state-machine.ts => state-machine.behavior.ts} (89%) diff --git a/Core/Stateflows.Common/Activities/Classes/ActivityWrapper.cs b/Core/Stateflows.Common/Activities/Classes/ActivityWrapper.cs index 4b653129..6f69992a 100644 --- a/Core/Stateflows.Common/Activities/Classes/ActivityWrapper.cs +++ b/Core/Stateflows.Common/Activities/Classes/ActivityWrapper.cs @@ -1,9 +1,7 @@ using System; using System.Threading.Tasks; -using System.Collections.Generic; using Stateflows.Activities; using Stateflows.Activities.Events; -using System.Linq; namespace Stateflows.Common.Activities.Classes { @@ -18,15 +16,23 @@ public ActivityWrapper(IBehavior consumer) Behavior = consumer; } - public Task> ExecuteAsync(Event initializationEvent, IEnumerable inputTokens = null) - => Behavior.RequestAsync(new ExecutionRequest() - { - InitializationEvent = initializationEvent, - InputTokens = inputTokens ?? new object[0], - }); + public Task> ExecuteAsync(Event initializationEvent, Action inputBuilder = null) + { + var request = new ExecutionRequest() { InitializationEvent = initializationEvent }; + + inputBuilder?.Invoke(request); + + return Behavior.RequestAsync(request); + } - public Task> ExecuteAsync(IEnumerable inputTokens = null) - => Behavior.RequestAsync(new ExecutionRequest() { InputTokens = inputTokens ?? new object[0] }); + public Task> ExecuteAsync(Action inputBuilder = null) + { + var request = new ExecutionRequest(); + + inputBuilder?.Invoke(request); + + return Behavior.RequestAsync(request); + } public Task SendAsync(TEvent @event) where TEvent : Event, new() diff --git a/Core/Stateflows.Common/Activities/Events/ExecutionRequest.cs b/Core/Stateflows.Common/Activities/Events/ExecutionRequest.cs index c2e23894..d35b0ee3 100644 --- a/Core/Stateflows.Common/Activities/Events/ExecutionRequest.cs +++ b/Core/Stateflows.Common/Activities/Events/ExecutionRequest.cs @@ -1,14 +1,29 @@ -using Newtonsoft.Json; -using Stateflows.Common; +using System.Linq; using System.Collections.Generic; +using Newtonsoft.Json; +using Stateflows.Common; +using Stateflows.Common.Utilities; namespace Stateflows.Activities.Events { - public sealed class ExecutionRequest : Request + public interface IInputContainer + { + void AddInputToken(TToken token); + + void AddInputTokens(IEnumerable tokens); + } + + public sealed class ExecutionRequest : Request, IInputContainer { public Event InitializationEvent { get; set; } = new Initialize(); [JsonProperty(TypeNameHandling = TypeNameHandling.None)] - public IEnumerable InputTokens { get; set; } + public List InputTokens { get; set; } = new List(); + + public void AddInputToken(TToken token) + => InputTokens.Add(new TokenHolder() { Payload = token }); + + public void AddInputTokens(IEnumerable tokens) + => InputTokens.AddRange(tokens.Select(token => new TokenHolder() { Payload = token })); } } diff --git a/Core/Stateflows.Common/Activities/Interfaces/IActivityBehavior.cs b/Core/Stateflows.Common/Activities/Interfaces/IActivityBehavior.cs index d656a864..a496faf9 100644 --- a/Core/Stateflows.Common/Activities/Interfaces/IActivityBehavior.cs +++ b/Core/Stateflows.Common/Activities/Interfaces/IActivityBehavior.cs @@ -1,5 +1,5 @@ -using System.Threading.Tasks; -using System.Collections.Generic; +using System; +using System.Threading.Tasks; using Stateflows.Common; using Stateflows.Activities.Events; @@ -7,7 +7,7 @@ namespace Stateflows.Activities { public interface IActivityBehavior : IBehavior { - Task> ExecuteAsync(Event initializationEvent, IEnumerable inputTokens = null); - Task> ExecuteAsync(IEnumerable inputTokens = null); + Task> ExecuteAsync(Event initializationEvent, Action inputBuilder = null); + Task> ExecuteAsync(Action inputBuilder = null); } } diff --git a/Core/Stateflows.Common/Events/Event.cs b/Core/Stateflows.Common/Events/Event.cs index 79350049..aeb3a6bd 100644 --- a/Core/Stateflows.Common/Events/Event.cs +++ b/Core/Stateflows.Common/Events/Event.cs @@ -17,15 +17,15 @@ public class Event public virtual string Name => GetType().GetEventName(); } - //public class Event : Event - //{ - // public Event() - // { - // Payload = default; - // } - - // public TPayload Payload { get; set; } - //} + public class Event : Event + { + public Event() + { + Payload = default; + } + + public TPayload Payload { get; set; } + } public static class EventInfo where TEvent : Event, new() diff --git a/Core/Stateflows.Common/Interfaces/IBehavior.cs b/Core/Stateflows.Common/Interfaces/IBehavior.cs index 44994400..4c6b0473 100644 --- a/Core/Stateflows.Common/Interfaces/IBehavior.cs +++ b/Core/Stateflows.Common/Interfaces/IBehavior.cs @@ -20,6 +20,9 @@ Task> SendCompoundAsync(params Event[] events) Task> RequestAsync(Request request) where TResponse : Response, new(); + Task> FinalizeAsync() + => RequestAsync(new FinalizationRequest()); + Task> ResetAsync(ResetMode resetMode = ResetMode.Full) => RequestAsync(new ResetRequest() { Mode = resetMode }); diff --git a/Core/Stateflows.Common/Utilities/StateflowsJsonConverter.cs b/Core/Stateflows.Common/Utilities/StateflowsJsonConverter.cs index 20b7dd1c..f0276e27 100644 --- a/Core/Stateflows.Common/Utilities/StateflowsJsonConverter.cs +++ b/Core/Stateflows.Common/Utilities/StateflowsJsonConverter.cs @@ -36,6 +36,10 @@ public static T CloneObject(T value) where T : class => DeserializeObject(SerializePolymorphicObject(value)) as T; + [DebuggerStepThrough] + public static T Clone(T value) + => (T)DeserializeObject(SerializePolymorphicObject(value)); + /// /// Serializes the specified object to a JSON string. /// diff --git a/Core/Stateflows.Testing/StateMachines/Sequence/ExecutionSequenceObserver.cs b/Core/Stateflows.Testing/StateMachines/Sequence/ExecutionSequenceObserver.cs index 5bd40b80..216750f0 100644 --- a/Core/Stateflows.Testing/StateMachines/Sequence/ExecutionSequenceObserver.cs +++ b/Core/Stateflows.Testing/StateMachines/Sequence/ExecutionSequenceObserver.cs @@ -71,7 +71,7 @@ Task IStateMachineObserver.AfterTransitionEffectAsync(ITransitionContext return Task.CompletedTask; } - Task IStateMachineObserver.AfterTransitionGuardAsync(IGuardContext context, bool guardResult) + Task IStateMachineObserver.AfterTransitionGuardAsync(ITransitionContext context, bool guardResult) { SequenceBuilder.TransitionGuard(context.Event.Name, context.SourceState.Name, context.TargetState?.Name); diff --git a/Core/Stateflows.Transport.Common/Stateflows.Common.Transport.csproj b/Core/Stateflows.Transport.Common/Stateflows.Common.Transport.csproj index bb2faf7a..3b3de483 100644 --- a/Core/Stateflows.Transport.Common/Stateflows.Common.Transport.csproj +++ b/Core/Stateflows.Transport.Common/Stateflows.Common.Transport.csproj @@ -35,8 +35,4 @@ - - - - diff --git a/Core/Stateflows/Activities/ActivitiesDependencyInjection.cs b/Core/Stateflows/Activities/ActivitiesDependencyInjection.cs index 06b164e0..3aa8424c 100644 --- a/Core/Stateflows/Activities/ActivitiesDependencyInjection.cs +++ b/Core/Stateflows/Activities/ActivitiesDependencyInjection.cs @@ -1,16 +1,16 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; using System.Collections.Generic; using Microsoft.Extensions.DependencyInjection; +using Stateflows.Common; using Stateflows.Common.Interfaces; using Stateflows.Common.Registration.Interfaces; using Stateflows.Activities.Engine; +using Stateflows.Activities.Context; using Stateflows.Activities.Registration; using Stateflows.Activities.EventHandlers; using Stateflows.Activities.Registration.Builders; using Stateflows.Activities.Registration.Interfaces; -using System; -using Stateflows.Activities.Context; -using Stateflows.Activities.Context.Interfaces; namespace Stateflows.Activities { @@ -48,6 +48,7 @@ private static ActivitiesRegister EnsureActivitiesServices(this IStateflowsBuild .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() .AddTransient(provider => ContextHolder.ActivityContext.Value ?? throw new InvalidOperationException($"No service for type '{typeof(IActivityContext).FullName}' is available in this context.") diff --git a/Core/Stateflows/Activities/Classes/IterativeActivityNode.cs b/Core/Stateflows/Activities/Classes/IterativeActivityNode.cs index 3786c936..871f6912 100644 --- a/Core/Stateflows/Activities/Classes/IterativeActivityNode.cs +++ b/Core/Stateflows/Activities/Classes/IterativeActivityNode.cs @@ -1,6 +1,6 @@ namespace Stateflows.Activities { - public sealed class IterativeActivityNode : IBaseStructuredActivityNode + public sealed class IterativeActivityNode : IStructuredActivityNode { public static string Name => ActivityNode>.Name; } diff --git a/Core/Stateflows/Activities/Classes/ParalellActivityNode.cs b/Core/Stateflows/Activities/Classes/ParalellActivityNode.cs index 8dd41d15..0be344dc 100644 --- a/Core/Stateflows/Activities/Classes/ParalellActivityNode.cs +++ b/Core/Stateflows/Activities/Classes/ParalellActivityNode.cs @@ -1,6 +1,6 @@ namespace Stateflows.Activities { - public sealed class ParallelActivityNode : IBaseStructuredActivityNode + public sealed class ParallelActivityNode : IStructuredActivityNode { public static string Name => ActivityNode>.Name; } diff --git a/Core/Stateflows/Activities/Classes/StructuredActivityNode.cs b/Core/Stateflows/Activities/Classes/StructuredActivityNode.cs index 485457a1..aeb0270c 100644 --- a/Core/Stateflows/Activities/Classes/StructuredActivityNode.cs +++ b/Core/Stateflows/Activities/Classes/StructuredActivityNode.cs @@ -1,6 +1,6 @@ namespace Stateflows.Activities { - public sealed class StructuredActivityNode : ActivityNode, IBaseStructuredActivityNode + public sealed class StructuredActivityNode : ActivityNode, IStructuredActivityNode { public static string Name => ActivityNode.Name; } diff --git a/Core/Stateflows/Activities/Context/Classes/ActivityInitializationContext.cs b/Core/Stateflows/Activities/Context/Classes/ActivityInitializationContext.cs index 2bccbb27..4e5dbdc3 100644 --- a/Core/Stateflows/Activities/Context/Classes/ActivityInitializationContext.cs +++ b/Core/Stateflows/Activities/Context/Classes/ActivityInitializationContext.cs @@ -2,6 +2,10 @@ using Stateflows.Activities.Engine; using Stateflows.Activities.Context.Interfaces; using Stateflows.Activities.Inspection.Interfaces; +using System.Collections.Generic; +using Stateflows.Activities.Extensions; +using System.Linq; +using Stateflows.Utils; namespace Stateflows.Activities.Context.Classes { @@ -11,21 +15,31 @@ internal class ActivityInitializationContext : IRootContext where TInitializationEvent : Event, new() { - public ActivityInitializationContext(RootContext context, NodeScope nodeScope, TInitializationEvent initializationEvent) + public ActivityInitializationContext(RootContext context, NodeScope nodeScope, TInitializationEvent initializationEvent, List inputTokens) : base(context, nodeScope) { InitializationEvent = initializationEvent; + InputTokens = inputTokens ?? new List(); } - public ActivityInitializationContext(BaseContext context, TInitializationEvent initializationEvent) + public ActivityInitializationContext(BaseContext context, TInitializationEvent initializationEvent, List inputTokens) : base(context) { InitializationEvent = initializationEvent; + InputTokens = inputTokens ?? new List(); } IActivityContext IActivityActionContext.Activity => Activity; public TInitializationEvent InitializationEvent { get; } + + public List InputTokens; + + public void Output(TToken token) + => OutputRange(new TToken[] { token }); + + public void OutputRange(IEnumerable tokens) + => InputTokens.AddRange(tokens.Select(token => token.ToTokenHolder()).ToArray()); } internal class ActivityInitializationContext : @@ -33,12 +47,12 @@ internal class ActivityInitializationContext : IActivityInitializationInspectionContext, IRootContext { - public ActivityInitializationContext(BaseContext context, Event initializationEvent) - : base(context, initializationEvent) + public ActivityInitializationContext(BaseContext context, Event initializationEvent, List inputTokens) + : base(context, initializationEvent, inputTokens) { } - public ActivityInitializationContext(RootContext context, NodeScope nodeScope, Event initializationEvent) - : base(context, nodeScope, initializationEvent) + public ActivityInitializationContext(RootContext context, NodeScope nodeScope, Event initializationEvent, List inputTokens) + : base(context, nodeScope, initializationEvent, inputTokens) { } IActivityInspectionContext IActivityInitializationInspectionContext.Activity => Activity; diff --git a/Core/Stateflows/Activities/Context/ContextHolder.cs b/Core/Stateflows/Activities/Context/ContextHolder.cs index 1f448a31..5fe0c169 100644 --- a/Core/Stateflows/Activities/Context/ContextHolder.cs +++ b/Core/Stateflows/Activities/Context/ContextHolder.cs @@ -1,5 +1,5 @@ using System.Threading; -using Stateflows.Activities.Context.Interfaces; +using Stateflows.Common; namespace Stateflows.Activities.Context { diff --git a/Core/Stateflows/Activities/Context/Interfaces/IActionContext.cs b/Core/Stateflows/Activities/Context/Interfaces/IActionContext.cs index 9069601f..df1c85ac 100644 --- a/Core/Stateflows/Activities/Context/Interfaces/IActionContext.cs +++ b/Core/Stateflows/Activities/Context/Interfaces/IActionContext.cs @@ -3,7 +3,7 @@ public interface ITypedActionContext : IActivityNodeContext { } - public interface IActionContext : ITypedActionContext, IInput, IOutput + public interface IActionContext : ITypedActionContext, IInput, IActionOutput { } public interface IActionContext : IActionContext, ITokenContext diff --git a/Core/Stateflows/Activities/Context/Interfaces/IOutput.cs b/Core/Stateflows/Activities/Context/Interfaces/IActionOutput.cs similarity index 84% rename from Core/Stateflows/Activities/Context/Interfaces/IOutput.cs rename to Core/Stateflows/Activities/Context/Interfaces/IActionOutput.cs index 9ff1ebba..a20d15da 100644 --- a/Core/Stateflows/Activities/Context/Interfaces/IOutput.cs +++ b/Core/Stateflows/Activities/Context/Interfaces/IActionOutput.cs @@ -7,7 +7,10 @@ public interface IOutput void Output(TToken token); void OutputRange(IEnumerable tokens); + } + public interface IActionOutput : IOutput + { void PassTokensOfTypeOn(); void PassAllTokensOn(); diff --git a/Core/Stateflows/Activities/Context/Interfaces/IActivityFlowContext.cs b/Core/Stateflows/Activities/Context/Interfaces/IActivityFlowContext.cs index bb2247b6..3ba1b8b6 100644 --- a/Core/Stateflows/Activities/Context/Interfaces/IActivityFlowContext.cs +++ b/Core/Stateflows/Activities/Context/Interfaces/IActivityFlowContext.cs @@ -1,18 +1,5 @@ -using System; - -namespace Stateflows.Activities.Context.Interfaces +namespace Stateflows.Activities.Context.Interfaces { - public interface IFlowContext - { - ISourceNodeContext SourceNode { get; } - - INodeContext TargetNode { get; } - - Type TokenType { get; } - - int Weight { get; } - } - public interface IIncomingFlowContext : IFlowContext { bool Activated { get; } diff --git a/Core/Stateflows/Activities/Context/Interfaces/IActivityInitializationContext.cs b/Core/Stateflows/Activities/Context/Interfaces/IActivityInitializationContext.cs index 0f566dfb..d86140fe 100644 --- a/Core/Stateflows/Activities/Context/Interfaces/IActivityInitializationContext.cs +++ b/Core/Stateflows/Activities/Context/Interfaces/IActivityInitializationContext.cs @@ -2,7 +2,7 @@ namespace Stateflows.Activities.Context.Interfaces { - public interface IActivityInitializationContext : IActivityActionContext + public interface IActivityInitializationContext : IActivityActionContext, IOutput where TInitializationRequest : Event { TInitializationRequest InitializationEvent { get; } diff --git a/Core/Stateflows/Activities/Context/Interfaces/IExceptionHandlerContext.cs b/Core/Stateflows/Activities/Context/Interfaces/IExceptionHandlerContext.cs index 511b3cfc..07c684fe 100644 --- a/Core/Stateflows/Activities/Context/Interfaces/IExceptionHandlerContext.cs +++ b/Core/Stateflows/Activities/Context/Interfaces/IExceptionHandlerContext.cs @@ -2,14 +2,7 @@ namespace Stateflows.Activities.Context.Interfaces { - public interface IExceptionContext - { - INodeContext ProtectedNode { get; } - - INodeContext NodeOfOrigin { get; } - } - - public interface IExceptionHandlerContext : IExceptionContext, IActivityNodeContext, IOutput + public interface IExceptionHandlerContext : IExceptionContext, IActivityNodeContext, IActionOutput where TException : Exception { TException Exception { get; } diff --git a/Core/Stateflows/Activities/Engine/Executor.cs b/Core/Stateflows/Activities/Engine/Executor.cs index 6fdf88de..e8d5ad2c 100644 --- a/Core/Stateflows/Activities/Engine/Executor.cs +++ b/Core/Stateflows/Activities/Engine/Executor.cs @@ -13,7 +13,6 @@ using Stateflows.Activities.Streams; using Stateflows.Activities.Registration; using Stateflows.Activities.Context.Classes; -using System.Net; namespace Stateflows.Activities.Engine { @@ -161,13 +160,14 @@ public bool Initialized } } - public async Task InitializeAsync(Event @event) + public async Task InitializeAsync(Event @event, IEnumerable input = null) { Debug.Assert(Context != null, $"Context is unavailable. Is activity '{Graph.Name}' hydrated?"); if (!Initialized) { - var result = await DoInitializeActivityAsync(@event); + var context = new ActivityInitializationContext(Context, NodeScope, @event, null); + var result = await DoInitializeActivityAsync(context); if ( result == InitializationStatus.InitializedImplicitly || @@ -176,7 +176,9 @@ public async Task InitializeAsync(Event @event) { Context.Initialized = true; - await ExecuteGraphAsync(); + input = input?.Concat(context.InputTokens).ToArray() ?? context.InputTokens.ToArray(); + + await ExecuteGraphAsync(input); if (result == InitializationStatus.InitializedExplicitly) { @@ -305,9 +307,9 @@ private async Task DoProcessAsync(TEvent @event) return await ExecuteGraphAsync(); } - private async Task ExecuteGraphAsync() + private async Task ExecuteGraphAsync(IEnumerable input = null) { - (var output, var finalized) = await DoExecuteStructuredNodeAsync(Graph, NodeScope); + (var output, var finalized) = await DoExecuteStructuredNodeAsync(Graph, NodeScope, input); if (finalized) { @@ -517,15 +519,14 @@ await Task.WhenAll( return result; } - public async Task DoInitializeActivityAsync(Event @event) + public async Task DoInitializeActivityAsync(ActivityInitializationContext context) { InitializationStatus result; - var initializer = Graph.Initializers.ContainsKey(@event.Name) - ? Graph.Initializers[@event.Name] + var initializer = Graph.Initializers.ContainsKey(context.InitializationEvent.Name) + ? Graph.Initializers[context.InitializationEvent.Name] : Graph.DefaultInitializer; - var context = new ActivityInitializationContext(Context, NodeScope, @event); await Inspector.BeforeActivityInitializationAsync(context); if (initializer != null) @@ -540,7 +541,7 @@ public async Task DoInitializeActivityAsync(Event @event) } catch (Exception e) { - await Inspector.OnActivityInitializationExceptionAsync(context, @event, e); + await Inspector.OnActivityInitializationExceptionAsync(context, context.InitializationEvent, e); result = InitializationStatus.NotInitialized; } diff --git a/Core/Stateflows/Activities/Engine/Inspector.cs b/Core/Stateflows/Activities/Engine/Inspector.cs index 350c494d..25ee6294 100644 --- a/Core/Stateflows/Activities/Engine/Inspector.cs +++ b/Core/Stateflows/Activities/Engine/Inspector.cs @@ -197,7 +197,7 @@ public async Task AfterNodeActivateAsync(ActionContext context) public async Task OnActivityInitializationExceptionAsync(BaseContext context, Event initializationEvent, Exception exception) { - var exceptionContext = new ActivityInitializationContext(context, initializationEvent); + var exceptionContext = new ActivityInitializationContext(context, initializationEvent, null); await ExceptionHandlers.RunSafe(h => h.OnActivityInitializationExceptionAsync(exceptionContext, exception), nameof(OnActivityInitializationExceptionAsync), Logger); await Inspectors.RunSafe(i => i.OnActivityInitializationExceptionAsync(exceptionContext, exception), nameof(OnActivityInitializationExceptionAsync), Logger); diff --git a/Core/Stateflows/Activities/Engine/NodeScope.cs b/Core/Stateflows/Activities/Engine/NodeScope.cs index 86b3f99e..eef606c1 100644 --- a/Core/Stateflows/Activities/Engine/NodeScope.cs +++ b/Core/Stateflows/Activities/Engine/NodeScope.cs @@ -73,6 +73,64 @@ private NodeScope(NodeScope nodeScope, Node node, Guid threadId) public NodeScope CreateChildScope(Node node = null, Guid? threadId = null) => ChildScope = new NodeScope(this, node ?? Node, threadId ?? ThreadId); + public TDefaultInitializer GetDefaultInitializer(IActivityInitializationContext context) + where TDefaultInitializer : class, IDefaultInitializer + { + ContextValues.GlobalValuesHolder.Value = context.Activity.Values; + ContextValues.StateValuesHolder.Value = null; + ContextValues.SourceStateValuesHolder.Value = null; + ContextValues.TargetStateValuesHolder.Value = null; + + ContextHolder.NodeContext.Value = null; + ContextHolder.FlowContext.Value = null; + ContextHolder.ActivityContext.Value = context.Activity; + ContextHolder.ExecutionContext.Value = context; + ContextHolder.ExceptionContext.Value = null; + + var initializer = ServiceProvider.GetService(); + + return initializer; + } + + public TInitializer GetInitializer(IActivityInitializationContext context) + where TInitializer : class, IInitializer + where TInitializationEvent : Event, new() + { + ContextValues.GlobalValuesHolder.Value = context.Activity.Values; + ContextValues.StateValuesHolder.Value = null; + ContextValues.SourceStateValuesHolder.Value = null; + ContextValues.TargetStateValuesHolder.Value = null; + + ContextHolder.NodeContext.Value = null; + ContextHolder.FlowContext.Value = null; + ContextHolder.ActivityContext.Value = context.Activity; + ContextHolder.ExecutionContext.Value = context; + ContextHolder.ExceptionContext.Value = null; + + var initializer = ServiceProvider.GetService(); + + return initializer; + } + + public TFinalizer GetFinalizer(IActivityActionContext context) + where TFinalizer : class, IFinalizer + { + ContextValues.GlobalValuesHolder.Value = context.Activity.Values; + ContextValues.StateValuesHolder.Value = null; + ContextValues.SourceStateValuesHolder.Value = null; + ContextValues.TargetStateValuesHolder.Value = null; + + ContextHolder.NodeContext.Value = null; + ContextHolder.FlowContext.Value = null; + ContextHolder.ActivityContext.Value = context.Activity; + ContextHolder.ExecutionContext.Value = context; + ContextHolder.ExceptionContext.Value = null; + + var initializer = ServiceProvider.GetService(); + + return initializer; + } + public TAction GetAction(IActionContext context) where TAction : class, IActionNode { @@ -144,7 +202,7 @@ public TSendEventAction GetSendEventAction(IActionCont } public TStructuredActivity GetStructuredActivity(IActionContext context) - where TStructuredActivity : class, IBaseStructuredActivityNode + where TStructuredActivity : class, IStructuredActivityNode { ContextValues.GlobalValuesHolder.Value = context.Activity.Values; ContextValues.StateValuesHolder.Value = null; @@ -179,7 +237,7 @@ public TExceptionHandler GetExceptionHandler(IExc } public TFlow GetFlow(IActivityFlowContext context) - where TFlow : IBaseFlow + where TFlow : IEdge { ContextValues.GlobalValuesHolder.Value = context.Activity.Values; ContextValues.StateValuesHolder.Value = null; @@ -196,11 +254,11 @@ public TFlow GetFlow(IActivityFlowContext context) } public TControlFlow GetControlFlow(IActivityFlowContext context) - where TControlFlow : class, IBaseControlFlow + where TControlFlow : class, IControlFlow => GetFlow(context); public TFlow GetObjectFlow(IActivityFlowContext context) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow => GetFlow(context); public TTransformationFlow GetObjectTransformationFlow(IActivityFlowContext context) diff --git a/Core/Stateflows/Activities/Engine/Processor.cs b/Core/Stateflows/Activities/Engine/Processor.cs index 9b747c48..a4dbf121 100644 --- a/Core/Stateflows/Activities/Engine/Processor.cs +++ b/Core/Stateflows/Activities/Engine/Processor.cs @@ -1,19 +1,19 @@ using System; using System.Linq; +using System.Reflection; using System.Threading.Tasks; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using Microsoft.Extensions.DependencyInjection; +using Stateflows.Utils; using Stateflows.Common; using Stateflows.Common.Context; using Stateflows.Common.Interfaces; using Stateflows.Common.Extensions; using Stateflows.Activities.Models; +using Stateflows.Activities.Events; using Stateflows.Activities.Registration; using Stateflows.Activities.Context.Classes; -using Stateflows.Activities.EventHandlers; -using Stateflows.Activities.Events; -using System.Reflection; namespace Stateflows.Activities.Engine { @@ -115,6 +115,8 @@ private async Task ExecuteBehaviorAsync(TEvent @event, Even { Event currentEvent = @event; + IEnumerable input = null; + if (@event is ExecutionRequest executionRequest) { if (executor.Graph.Interactive || executor.BehaviorStatus != BehaviorStatus.NotInitialized) @@ -125,12 +127,14 @@ private async Task ExecuteBehaviorAsync(TEvent @event, Even context.SetEvent(executionRequest.InitializationEvent); currentEvent = executionRequest.InitializationEvent; + + input = executionRequest.InputTokens?.ToArray() ?? Array.Empty(); } var attributes = currentEvent.GetType().GetCustomAttributes(); if (!executor.Initialized && !attributes.Any()) { - result = await executor.InitializeAsync(currentEvent); + result = await executor.InitializeAsync(currentEvent, input); } if (result != EventStatus.Initialized) diff --git a/Core/Stateflows/Activities/EventHandlers/ExecutionHandler.cs b/Core/Stateflows/Activities/EventHandlers/ExecutionHandler.cs deleted file mode 100644 index ba664930..00000000 --- a/Core/Stateflows/Activities/EventHandlers/ExecutionHandler.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Threading.Tasks; -using Stateflows.Common; -using Stateflows.Activities.Events; -using Stateflows.Activities.Extensions; -using Stateflows.Activities.Inspection.Interfaces; - -namespace Stateflows.Activities.EventHandlers -{ - internal class ExecutionHandler : IActivityEventHandler - { - public Type EventType => typeof(ExecutionRequest); - - public async Task TryHandleEventAsync(IEventInspectionContext context) - where TEvent : Event, new() - { - if (context.Event is ExecutionRequest executionRequest) - { - var executor = context.Activity.GetExecutor(); - - if (executor.Graph.Interactive || executor.BehaviorStatus != BehaviorStatus.NotInitialized) - { - return EventStatus.NotConsumed; - } - - var status = await executor.InitializeAsync(executionRequest.InitializationEvent ?? new Initialize()); - - executionRequest.Respond( - new ExecutionResponse() - { - //ExecutionStatus = status, - OutputTokens = status == EventStatus.Initialized - ? await executor.GetResultAsync() - : null - } - ); - - return EventStatus.Consumed; - } - - return EventStatus.NotConsumed; - } - } -} diff --git a/Core/Stateflows/Activities/EventHandlers/SetGlobalValuesHandler.cs b/Core/Stateflows/Activities/EventHandlers/SetGlobalValuesHandler.cs new file mode 100644 index 00000000..7a3e3c50 --- /dev/null +++ b/Core/Stateflows/Activities/EventHandlers/SetGlobalValuesHandler.cs @@ -0,0 +1,32 @@ +using System; +using System.Threading.Tasks; +using Stateflows.Common; +using Stateflows.Common.Classes; +using Stateflows.Activities.Inspection.Interfaces; + +namespace Stateflows.Activities.EventHandlers +{ + internal class SetGlobalValuesHandler : IActivityEventHandler + { + public Type EventType => typeof(SetGlobalValues); + + public Task TryHandleEventAsync(IEventInspectionContext context) + where TEvent : Event, new() + { + if (context.Event is SetGlobalValues @event) + { + var values = context.Activity.Values as ContextValuesCollection; + + values.Values.Clear(); + foreach (var entry in @event.Values) + { + values.Values[entry.Key] = entry.Value; + } + + return Task.FromResult(EventStatus.Consumed); + } + + return Task.FromResult(EventStatus.NotConsumed); + } + } +} diff --git a/Core/Stateflows/Activities/Extensions/BuilderExtensions.cs b/Core/Stateflows/Activities/Extensions/BuilderExtensions.cs index ef6a3da2..247ae76b 100644 --- a/Core/Stateflows/Activities/Extensions/BuilderExtensions.cs +++ b/Core/Stateflows/Activities/Extensions/BuilderExtensions.cs @@ -10,7 +10,7 @@ namespace Stateflows.Activities.Extensions internal static class BuilderExtensions { public static void AddStructuredActivityEvents(this StructuredActivityBuilder builder) - where TStructuredActivity : class, IBaseStructuredActivityNode + where TStructuredActivity : class, IStructuredActivityNode { if (typeof(IStructuredActivityNodeInitialization).IsAssignableFrom(typeof(TStructuredActivity))) { @@ -44,9 +44,9 @@ public static void AddStructuredActivityEvents(this Structu } public static void AddObjectFlowEvents(this IObjectFlowBuilder builder) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow { - if (typeof(IBaseFlow).GetProperty(nameof(IBaseFlow.Weight)).IsImplementedIn()) + if (typeof(IEdge).GetProperty(nameof(IEdge.Weight)).IsImplementedIn()) { var objectFlow = FormatterServices.GetUninitializedObject(typeof(TFlow)) as TFlow; @@ -74,7 +74,7 @@ public static void AddObjectFlowEvents(this IObjectFlowBuilder(this IObjectFlowBuilder builder) where TTransformationFlow : class, IFlowTransformation { - if (typeof(IBaseFlow).GetProperty(nameof(IBaseFlow.Weight)).IsImplementedIn()) + if (typeof(IEdge).GetProperty(nameof(IEdge.Weight)).IsImplementedIn()) { var objectFlow = FormatterServices.GetUninitializedObject(typeof(TTransformationFlow)) as TTransformationFlow; @@ -119,7 +119,7 @@ public static void AddObjectTransformationFlowEvents(this IObjectFlowBuilder builder) where TTransformationFlow : class, IFlowTransformation { - if (typeof(IBaseFlow).GetProperty(nameof(IBaseFlow.Weight)).IsImplementedIn()) + if (typeof(IEdge).GetProperty(nameof(IEdge.Weight)).IsImplementedIn()) { var objectFlow = FormatterServices.GetUninitializedObject(typeof(TTransformationFlow)) as TTransformationFlow; @@ -145,9 +145,9 @@ public static void AddElseObjectTransformationFlowEvents(this IControlFlowBuilder builder) - where TFlow : class, IBaseControlFlow + where TFlow : class, IControlFlow { - if (typeof(IBaseFlow).GetProperty(nameof(IBaseFlow.Weight)).IsImplementedIn()) + if (typeof(IEdge).GetProperty(nameof(IEdge.Weight)).IsImplementedIn()) { var objectFlow = FormatterServices.GetUninitializedObject(typeof(TFlow)) as TFlow; diff --git a/Core/Stateflows/Activities/Context/Interfaces/IActivityContext.cs b/Core/Stateflows/Activities/Interfaces/Context/IActivityContext.cs similarity index 89% rename from Core/Stateflows/Activities/Context/Interfaces/IActivityContext.cs rename to Core/Stateflows/Activities/Interfaces/Context/IActivityContext.cs index e0605e3d..3d68cbe5 100644 --- a/Core/Stateflows/Activities/Context/Interfaces/IActivityContext.cs +++ b/Core/Stateflows/Activities/Interfaces/Context/IActivityContext.cs @@ -1,6 +1,6 @@ using Stateflows.Common.Context.Interfaces; -namespace Stateflows.Activities.Context.Interfaces +namespace Stateflows.Activities { public interface IActivityContext : IBehaviorContext { diff --git a/Core/Stateflows/Activities/Interfaces/Context/IExceptionContext.cs b/Core/Stateflows/Activities/Interfaces/Context/IExceptionContext.cs new file mode 100644 index 00000000..6180b157 --- /dev/null +++ b/Core/Stateflows/Activities/Interfaces/Context/IExceptionContext.cs @@ -0,0 +1,9 @@ +namespace Stateflows.Activities +{ + public interface IExceptionContext + { + INodeContext ProtectedNode { get; } + + INodeContext NodeOfOrigin { get; } + } +} diff --git a/Core/Stateflows/Activities/Interfaces/Context/IFlowContext.cs b/Core/Stateflows/Activities/Interfaces/Context/IFlowContext.cs new file mode 100644 index 00000000..d5735811 --- /dev/null +++ b/Core/Stateflows/Activities/Interfaces/Context/IFlowContext.cs @@ -0,0 +1,16 @@ +using System; +using Stateflows.Activities.Context.Interfaces; + +namespace Stateflows.Activities +{ + public interface IFlowContext + { + ISourceNodeContext SourceNode { get; } + + INodeContext TargetNode { get; } + + Type TokenType { get; } + + int Weight { get; } + } +} diff --git a/Core/Stateflows/Activities/Context/Interfaces/INodeContext.cs b/Core/Stateflows/Activities/Interfaces/Context/INodeContext.cs similarity index 92% rename from Core/Stateflows/Activities/Context/Interfaces/INodeContext.cs rename to Core/Stateflows/Activities/Interfaces/Context/INodeContext.cs index d47becbb..c2fe99f5 100644 --- a/Core/Stateflows/Activities/Context/Interfaces/INodeContext.cs +++ b/Core/Stateflows/Activities/Interfaces/Context/INodeContext.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; +using Stateflows.Activities.Context.Interfaces; -namespace Stateflows.Activities.Context.Interfaces +namespace Stateflows.Activities { public interface INodeContext { diff --git a/Core/Stateflows/Activities/Interfaces/Model/IActionNode.cs b/Core/Stateflows/Activities/Interfaces/Model/IActionNode.cs index 4eda5be9..59de2946 100644 --- a/Core/Stateflows/Activities/Interfaces/Model/IActionNode.cs +++ b/Core/Stateflows/Activities/Interfaces/Model/IActionNode.cs @@ -1,5 +1,4 @@ -using System; -using System.Threading; +using System.Threading; using System.Threading.Tasks; namespace Stateflows.Activities diff --git a/Core/Stateflows/Activities/Interfaces/Model/IActivity.cs b/Core/Stateflows/Activities/Interfaces/Model/IActivity.cs index 2f6adca9..593374b5 100644 --- a/Core/Stateflows/Activities/Interfaces/Model/IActivity.cs +++ b/Core/Stateflows/Activities/Interfaces/Model/IActivity.cs @@ -1,6 +1,5 @@ using System.Reflection; using Stateflows.Activities.Attributes; -using Stateflows.Activities.Registration.Interfaces; namespace Stateflows.Activities { diff --git a/Core/Stateflows/Activities/Interfaces/Model/IControlFlow.cs b/Core/Stateflows/Activities/Interfaces/Model/IControlFlow.cs new file mode 100644 index 00000000..b97d226f --- /dev/null +++ b/Core/Stateflows/Activities/Interfaces/Model/IControlFlow.cs @@ -0,0 +1,12 @@ +using System.Threading.Tasks; + +namespace Stateflows.Activities +{ + public interface IControlFlow : IEdge + { } + + public interface IControlFlowGuard : IControlFlow + { + Task GuardAsync(); + } +} diff --git a/Core/Stateflows/Activities/Interfaces/Model/IFlow.cs b/Core/Stateflows/Activities/Interfaces/Model/IFlow.cs index 406904ff..e43908c0 100644 --- a/Core/Stateflows/Activities/Interfaces/Model/IFlow.cs +++ b/Core/Stateflows/Activities/Interfaces/Model/IFlow.cs @@ -2,29 +2,21 @@ namespace Stateflows.Activities { - public interface IBaseFlow + public interface IEdge { int Weight => 1; } - public interface IBaseFlow : IBaseFlow + public interface IFlow : IEdge { } - public interface IFlowGuard : IBaseFlow + public interface IFlowGuard : IFlow { Task GuardAsync(TToken token); } - public interface IFlowTransformation : IBaseFlow + public interface IFlowTransformation : IFlow { Task TransformAsync(TToken token); } - - public interface IBaseControlFlow : IBaseFlow - { } - - public interface IControlFlowGuard : IBaseControlFlow - { - Task GuardAsync(); - } } diff --git a/Core/Stateflows/Activities/Interfaces/Model/IStructuredActivityNode.cs b/Core/Stateflows/Activities/Interfaces/Model/IStructuredActivityNode.cs index 0c05fad1..d9dc7c07 100644 --- a/Core/Stateflows/Activities/Interfaces/Model/IStructuredActivityNode.cs +++ b/Core/Stateflows/Activities/Interfaces/Model/IStructuredActivityNode.cs @@ -2,15 +2,15 @@ namespace Stateflows.Activities { - public interface IBaseStructuredActivityNode : IActivityNode + public interface IStructuredActivityNode : IActivityNode { } - public interface IStructuredActivityNodeInitialization : IBaseStructuredActivityNode + public interface IStructuredActivityNodeInitialization : IStructuredActivityNode { Task OnInitializeAsync(); } - public interface IStructuredActivityNodeFinalization : IBaseStructuredActivityNode + public interface IStructuredActivityNodeFinalization : IStructuredActivityNode { Task OnFinalizeAsync(); } diff --git a/Core/Stateflows/Activities/Registration/Builders/ActivityBuilder.cs b/Core/Stateflows/Activities/Registration/Builders/ActivityBuilder.cs index 1dfd2183..cec79b71 100644 --- a/Core/Stateflows/Activities/Registration/Builders/ActivityBuilder.cs +++ b/Core/Stateflows/Activities/Registration/Builders/ActivityBuilder.cs @@ -3,14 +3,13 @@ using Microsoft.Extensions.DependencyInjection; using Stateflows.Common; using Stateflows.Common.Models; +using Stateflows.Common.Extensions; using Stateflows.Activities.Models; -using Stateflows.Activities.Extensions; using Stateflows.Activities.Context.Classes; using Stateflows.Activities.Context.Interfaces; using Stateflows.Activities.Registration.Extensions; using Stateflows.Activities.Registration.Interfaces; using Stateflows.Activities.Registration.Interfaces.Base; -using Stateflows.Common.Extensions; namespace Stateflows.Activities.Registration.Builders { @@ -57,7 +56,11 @@ public IActivityBuilder AddDefaultInitializer(Func { - var context = new ActivityInitializationContext(c, c.Context.Event as Initialize); + var context = new ActivityInitializationContext( + c, + c.Context.Event as Initialize, + (c as ActivityInitializationContext).InputTokens + ); return actionAsync(context); }); @@ -78,7 +81,8 @@ public IActivityBuilder AddInitializer(Func( c, - c.Context.Event as TInitializationEvent + c.Context.Event as TInitializationEvent, + (c as ActivityInitializationContext).InputTokens ); try diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Base/IObjectFlowBase.cs b/Core/Stateflows/Activities/Registration/Interfaces/Base/IObjectFlowBase.cs index 8b00ed26..9e859c4d 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Base/IObjectFlowBase.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Base/IObjectFlowBase.cs @@ -22,7 +22,7 @@ TReturn AddFlow(ObjectFlowBuildAction buildAction = null) => AddFlow(ActivityNode.Name, buildAction); TReturn AddFlow(string targetNodeName) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow { (this as IInternal).Services.AddServiceType(); @@ -33,7 +33,7 @@ TReturn AddFlow(string targetNodeName) } TReturn AddFlow() - where TFlow : class, IBaseFlow + where TFlow : class, IFlow where TTargetNode : class, IActivityNode => AddFlow(ActivityNode.Name); diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/AcceptEventActionBuilder/Flows/AcceptEventActionBuilderControlFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/AcceptEventActionBuilder/Flows/AcceptEventActionBuilderControlFlowsTypedExtensions.cs index 9cfee951..72cd7d42 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/AcceptEventActionBuilder/Flows/AcceptEventActionBuilderControlFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/AcceptEventActionBuilder/Flows/AcceptEventActionBuilderControlFlowsTypedExtensions.cs @@ -14,7 +14,7 @@ public static IAcceptEventActionBuilder AddControlFlow(this IAccept [DebuggerHidden] public static IAcceptEventActionBuilder AddControlFlow(this IAcceptEventActionBuilder builder, string targetNodeName) - where TControlFlow : class, IBaseControlFlow + where TControlFlow : class, IControlFlow { (builder as IInternal).Services.AddServiceType(); @@ -26,7 +26,7 @@ public static IAcceptEventActionBuilder AddControlFlow(this IAccep [DebuggerHidden] public static IAcceptEventActionBuilder AddControlFlow(this IAcceptEventActionBuilder builder) - where TFlow : class, IBaseControlFlow + where TFlow : class, IControlFlow where TTargetNode : class, IActivityNode => builder.AddControlFlow(ActivityNode.Name); } diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/AcceptEventActionBuilder/Flows/AcceptEventActionBuilderObjectFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/AcceptEventActionBuilder/Flows/AcceptEventActionBuilderObjectFlowsTypedExtensions.cs index eb30745a..5b38d9bf 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/AcceptEventActionBuilder/Flows/AcceptEventActionBuilderObjectFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/AcceptEventActionBuilder/Flows/AcceptEventActionBuilderObjectFlowsTypedExtensions.cs @@ -14,7 +14,7 @@ public static IAcceptEventActionBuilder AddFlow(this IAccep [DebuggerHidden] public static IAcceptEventActionBuilder AddFlow(this IAcceptEventActionBuilder builder, string targetNodeName) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow { (builder as IInternal).Services.AddServiceType(); @@ -26,7 +26,7 @@ public static IAcceptEventActionBuilder AddFlow(this IAcceptEvent [DebuggerHidden] public static IAcceptEventActionBuilder AddFlow(this IAcceptEventActionBuilder builder) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow where TTargetNode : class, IActivityNode => builder.AddFlow(ActivityNode.Name); diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActionBuilder/Flows/ActionBuilderControlFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActionBuilder/Flows/ActionBuilderControlFlowsTypedExtensions.cs index 21c62cef..f61bad20 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActionBuilder/Flows/ActionBuilderControlFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActionBuilder/Flows/ActionBuilderControlFlowsTypedExtensions.cs @@ -14,7 +14,7 @@ public static IActionBuilder AddControlFlow(this IActionBuilder bui [DebuggerHidden] public static IActionBuilder AddControlFlow(this IActionBuilder builder, string targetNodeName) - where TControlFlow : class, IBaseControlFlow + where TControlFlow : class, IControlFlow { (builder as IInternal).Services.AddServiceType(); @@ -26,7 +26,7 @@ public static IActionBuilder AddControlFlow(this IActionBuilder bu [DebuggerHidden] public static IActionBuilder AddControlFlow(this IActionBuilder builder) - where TFlow : class, IBaseControlFlow + where TFlow : class, IControlFlow where TTargetNode : class, IActivityNode => builder.AddControlFlow(ActivityNode.Name); } diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActionBuilder/Flows/ActionBuilderObjectFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActionBuilder/Flows/ActionBuilderObjectFlowsTypedExtensions.cs index e69577eb..276f1ff6 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActionBuilder/Flows/ActionBuilderObjectFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActionBuilder/Flows/ActionBuilderObjectFlowsTypedExtensions.cs @@ -14,7 +14,7 @@ public static IActionBuilder AddFlow(this IActionBuilder bu [DebuggerHidden] public static IActionBuilder AddFlow(this IActionBuilder builder, string targetNodeName) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow { (builder as IInternal).Services.AddServiceType(); @@ -26,7 +26,7 @@ public static IActionBuilder AddFlow(this IActionBuilder builder, [DebuggerHidden] public static IActionBuilder AddFlow(this IActionBuilder builder) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow where TTargetNode : class, IActivityNode => builder.AddFlow(ActivityNode.Name); diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderEventsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderEventsTypedExtensions.cs new file mode 100644 index 00000000..50f3a327 --- /dev/null +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderEventsTypedExtensions.cs @@ -0,0 +1,39 @@ +using System.Diagnostics; +using Stateflows.Common; +using Stateflows.Common.Extensions; +using Stateflows.Activities.Context.Classes; +using Stateflows.Activities.Registration.Interfaces; + +namespace Stateflows.Activities.Typed +{ + public static class ActivityBuilderEventsTypedExtensions + { + [DebuggerHidden] + public static IActivityBuilder AddDefaultInitializer(this IActivityBuilder builder) + where TInitializer : class, IDefaultInitializer + { + (builder as IInternal).Services.AddServiceType(); + + return builder.AddDefaultInitializer(c => (c as BaseContext).NodeScope.GetDefaultInitializer(c)?.OnInitializeAsync()); + } + + [DebuggerHidden] + public static IActivityBuilder AddInitializer(this IActivityBuilder builder) + where TInitializationEvent : Event, new() + where TInitializer : class, IInitializer + { + (builder as IInternal).Services.AddServiceType(); + + return builder.AddInitializer(c => (c as BaseContext).NodeScope.GetInitializer(c)?.OnInitializeAsync(c.InitializationEvent)); + } + + [DebuggerHidden] + public static IActivityBuilder AddFinalizer(this IActivityBuilder builder) + where TFinalizer : class, IFinalizer + { + (builder as IInternal).Services.AddServiceType(); + + return builder.AddFinalizer(c => (c as BaseContext).NodeScope.GetFinalizer(c)?.OnFinalizeAsync()); + } + } +} diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderTypedExtensions.cs index 8ac68388..dd692bce 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderTypedExtensions.cs @@ -150,12 +150,12 @@ public static IActivityBuilder AddSendEventAction(this #region AddStructuredActivity [DebuggerHidden] public static IActivityBuilder AddStructuredActivity(this IActivityBuilder builder, ReactiveStructuredActivityBuildAction buildAction) - where TStructuredActivity : class, IBaseStructuredActivityNode + where TStructuredActivity : class, IStructuredActivityNode => AddStructuredActivity(builder, ActivityNode.Name, buildAction); [DebuggerHidden] public static IActivityBuilder AddStructuredActivity(this IActivityBuilder builder, string structuredActivityName, ReactiveStructuredActivityBuildAction buildAction = null) - where TStructuredActivity : class, IBaseStructuredActivityNode + where TStructuredActivity : class, IStructuredActivityNode { (builder as IInternal).Services.AddServiceType(); @@ -175,12 +175,12 @@ public static IActivityBuilder AddStructuredActivity(this I #region AddParallelActivity [DebuggerHidden] public static IActivityBuilder AddParallelActivity(this IActivityBuilder builder, ParallelActivityBuildAction buildAction = null, int chunkSize = 1) - where TStructuredActivity : class, IBaseStructuredActivityNode + where TStructuredActivity : class, IStructuredActivityNode => AddParallelActivity(builder, ActivityNode.Name, buildAction, chunkSize); [DebuggerHidden] public static IActivityBuilder AddParallelActivity(this IActivityBuilder builder, string structuredActivityName, ParallelActivityBuildAction buildAction = null, int chunkSize = 1) - where TParallelActivity : class, IBaseStructuredActivityNode + where TParallelActivity : class, IStructuredActivityNode { (builder as IInternal).Services.AddServiceType(); @@ -201,12 +201,12 @@ public static IActivityBuilder AddParallelActivity(this IActivityBuilder builder, IterativeActivityBuildAction buildAction = null, int chunkSize = 1) - where TStructuredActivity : class, IBaseStructuredActivityNode + where TStructuredActivity : class, IStructuredActivityNode => AddIterativeActivity(builder, ActivityNode.Name, buildAction, chunkSize); [DebuggerHidden] public static IActivityBuilder AddIterativeActivity(this IActivityBuilder builder, string structuredActivityName, IterativeActivityBuildAction buildAction = null, int chunkSize = 1) - where TStructuredActivity : class, IBaseStructuredActivityNode + where TStructuredActivity : class, IStructuredActivityNode { (builder as IInternal).Services.AddServiceType(); return builder.AddIterativeActivity( diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/DataStoreBuilder/Flows/DataStoreBuilderFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/DataStoreBuilder/Flows/DataStoreBuilderFlowsTypedExtensions.cs index 6c09eb90..3212fd7e 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/DataStoreBuilder/Flows/DataStoreBuilderFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/DataStoreBuilder/Flows/DataStoreBuilderFlowsTypedExtensions.cs @@ -14,7 +14,7 @@ public static IDataStoreBuilder AddFlow(this IDataStoreBuil [DebuggerHidden] public static IDataStoreBuilder AddFlow(this IDataStoreBuilder builder, string targetNodeName) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow { (builder as IInternal).Services.AddServiceType(); return builder.AddFlow( @@ -25,7 +25,7 @@ public static IDataStoreBuilder AddFlow(this IDataStoreBuilder bu [DebuggerHidden] public static IDataStoreBuilder AddFlow(this IDataStoreBuilder builder) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow where TTargetNode : class, IActivityNode => builder.AddFlow(ActivityNode.Name); diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/DecisionBuilder/Flows/DecisionBuilderControlFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/DecisionBuilder/Flows/DecisionBuilderControlFlowsTypedExtensions.cs index 09e298ff..12ef7569 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/DecisionBuilder/Flows/DecisionBuilderControlFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/DecisionBuilder/Flows/DecisionBuilderControlFlowsTypedExtensions.cs @@ -14,7 +14,7 @@ public static IDecisionBuilder AddFlow(this IDecisionBuilder builde [DebuggerHidden] public static IDecisionBuilder AddFlow(this IDecisionBuilder builder, string targetNodeName) - where TControlFlow : class, IBaseControlFlow + where TControlFlow : class, IControlFlow { (builder as IInternal).Services.AddServiceType(); @@ -26,7 +26,7 @@ public static IDecisionBuilder AddFlow(this IDecisionBuilder build [DebuggerHidden] public static IDecisionBuilder AddFlow(this IDecisionBuilder builder) - where TFlow : class, IBaseControlFlow + where TFlow : class, IControlFlow where TTargetNode : class, IActivityNode => builder.AddFlow(ActivityNode.Name); } diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/DecisionBuilder/Flows/DecisionBuilderObjectFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/DecisionBuilder/Flows/DecisionBuilderObjectFlowsTypedExtensions.cs index 6bacd276..3373b7b4 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/DecisionBuilder/Flows/DecisionBuilderObjectFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/DecisionBuilder/Flows/DecisionBuilderObjectFlowsTypedExtensions.cs @@ -14,7 +14,7 @@ public static IDecisionBuilder AddFlow(this IDecisi [DebuggerHidden] public static IDecisionBuilder AddFlow(this IDecisionBuilder builder, string targetNodeName) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow { (builder as IInternal).Services.AddServiceType(); @@ -26,7 +26,7 @@ public static IDecisionBuilder AddFlow(this IDecisionBuil [DebuggerHidden] public static IDecisionBuilder AddFlow(this IDecisionBuilder builder) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow where TTargetNode : class, IActivityNode => builder.AddFlow(ActivityNode.Name); diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ForkBuilder/Flows/ForkBuilderFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ForkBuilder/Flows/ForkBuilderFlowsTypedExtensions.cs index 06c09428..92f0c80b 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ForkBuilder/Flows/ForkBuilderFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ForkBuilder/Flows/ForkBuilderFlowsTypedExtensions.cs @@ -14,7 +14,7 @@ public static IForkBuilder AddFlow(this IForkBuilder builde [DebuggerHidden] public static IForkBuilder AddFlow(this IForkBuilder builder, string targetNodeName) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow { (builder as IInternal).Services.AddServiceType(); return builder.AddFlow( @@ -25,7 +25,7 @@ public static IForkBuilder AddFlow(this IForkBuilder builder, str [DebuggerHidden] public static IForkBuilder AddFlow(this IForkBuilder builder) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow where TTargetNode : class, IActivityNode => builder.AddFlow(ActivityNode.Name); diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/InitialBuilder/Flows/InitialBuilderControlFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/InitialBuilder/Flows/InitialBuilderControlFlowsTypedExtensions.cs index 3fc73f41..23a76eee 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/InitialBuilder/Flows/InitialBuilderControlFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/InitialBuilder/Flows/InitialBuilderControlFlowsTypedExtensions.cs @@ -14,7 +14,7 @@ public static IInitialBuilder AddControlFlow(this IInitialBuilder b [DebuggerHidden] public static IInitialBuilder AddControlFlow(this IInitialBuilder builder, string targetNodeName) - where TControlFlow : class, IBaseControlFlow + where TControlFlow : class, IControlFlow { (builder as IInternal).Services.AddServiceType(); @@ -26,7 +26,7 @@ public static IInitialBuilder AddControlFlow(this IInitialBuilder [DebuggerHidden] public static IInitialBuilder AddControlFlow(this IInitialBuilder builder) - where TFlow : class, IBaseControlFlow + where TFlow : class, IControlFlow where TTargetNode : class, IActivityNode => AddControlFlow(builder, ActivityNode.Name); } diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/InputBuilder/Flows/InputBuilderFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/InputBuilder/Flows/InputBuilderFlowsTypedExtensions.cs index c3cca673..7d35ae3d 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/InputBuilder/Flows/InputBuilderFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/InputBuilder/Flows/InputBuilderFlowsTypedExtensions.cs @@ -12,12 +12,12 @@ public static IInputBuilder AddFlow(this IInputBuilder buil [DebuggerHidden] public static IInputBuilder AddFlow(this IInputBuilder builder, string targetNodeName) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow => (builder as IActionBuilder).AddFlow(targetNodeName) as IInputBuilder; [DebuggerHidden] public static IInputBuilder AddFlow(this IInputBuilder builder) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow where TTargetNode : class, IActivityNode => builder.AddFlow(ActivityNode.Name); diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/JoinBuilder/Flows/JoinBuilderControlFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/JoinBuilder/Flows/JoinBuilderControlFlowsTypedExtensions.cs index 0127233a..74662d1e 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/JoinBuilder/Flows/JoinBuilderControlFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/JoinBuilder/Flows/JoinBuilderControlFlowsTypedExtensions.cs @@ -14,7 +14,7 @@ public static void AddControlFlow(this IJoinBuilder builder, Contro [DebuggerHidden] public static void AddControlFlow(this IJoinBuilder builder, string targetNodeName) - where TControlFlow : class, IBaseControlFlow + where TControlFlow : class, IControlFlow { (builder as IInternal).Services.AddServiceType(); @@ -26,7 +26,7 @@ public static void AddControlFlow(this IJoinBuilder builder, strin [DebuggerHidden] public static void AddControlFlow(this IJoinBuilder builder) - where TFlow : class, IBaseControlFlow + where TFlow : class, IControlFlow where TTargetNode : class, IActivityNode => builder.AddControlFlow(ActivityNode.Name); } diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/JoinBuilder/Flows/JoinBuilderFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/JoinBuilder/Flows/JoinBuilderFlowsTypedExtensions.cs index d3ea6720..65dd374c 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/JoinBuilder/Flows/JoinBuilderFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/JoinBuilder/Flows/JoinBuilderFlowsTypedExtensions.cs @@ -14,7 +14,7 @@ public static void AddFlow(this IJoinBuilder builder, Objec [DebuggerHidden] public static void AddFlow(this IJoinBuilder builder, string targetNodeName) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow { (builder as IInternal).Services.AddServiceType(); builder.AddFlow( @@ -25,7 +25,7 @@ public static void AddFlow(this IJoinBuilder builder, string targ [DebuggerHidden] public static void AddFlow(this IJoinBuilder builder) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow where TTargetNode : class, IActivityNode => builder.AddFlow(ActivityNode.Name); diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/MergeBuilder/Flows/MergeBuilderControlFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/MergeBuilder/Flows/MergeBuilderControlFlowsTypedExtensions.cs index 53b0b25d..a414e925 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/MergeBuilder/Flows/MergeBuilderControlFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/MergeBuilder/Flows/MergeBuilderControlFlowsTypedExtensions.cs @@ -14,7 +14,7 @@ public static void AddControlFlow(this IMergeBuilder builder, Contr [DebuggerHidden] public static void AddControlFlow(this IMergeBuilder builder, string targetNodeName) - where TControlFlow : class, IBaseControlFlow + where TControlFlow : class, IControlFlow { (builder as IInternal).Services.AddServiceType(); @@ -26,7 +26,7 @@ public static void AddControlFlow(this IMergeBuilder builder, stri [DebuggerHidden] public static void AddControlFlow(this IMergeBuilder builder) - where TFlow : class, IBaseControlFlow + where TFlow : class, IControlFlow where TTargetNode : class, IActivityNode => builder.AddControlFlow(ActivityNode.Name); } diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/MergeBuilder/Flows/MergeBuilderObjectFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/MergeBuilder/Flows/MergeBuilderObjectFlowsTypedExtensions.cs index facecaee..2cd9c1d3 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/MergeBuilder/Flows/MergeBuilderObjectFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/MergeBuilder/Flows/MergeBuilderObjectFlowsTypedExtensions.cs @@ -14,7 +14,7 @@ public static void AddFlow(this IMergeBuilder builder, Obje [DebuggerHidden] public static void AddFlow(this IMergeBuilder builder, string targetNodeName) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow { (builder as IInternal).Services.AddServiceType(); builder.AddFlow( @@ -25,7 +25,7 @@ public static void AddFlow(this IMergeBuilder builder, string tar [DebuggerHidden] public static void AddFlow(this IMergeBuilder builder) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow where TTargetNode : class, IActivityNode => builder.AddFlow(ActivityNode.Name); diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/Flows/ReactiveStructuredActivityBuilderControlFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/Flows/ReactiveStructuredActivityBuilderControlFlowsTypedExtensions.cs index 091dec5f..35a7f688 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/Flows/ReactiveStructuredActivityBuilderControlFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/Flows/ReactiveStructuredActivityBuilderControlFlowsTypedExtensions.cs @@ -12,12 +12,12 @@ public static IReactiveStructuredActivityBuilder AddControlFlow(thi [DebuggerHidden] public static IReactiveStructuredActivityBuilder AddControlFlow(this IReactiveStructuredActivityBuilder builder, string targetNodeName) - where TControlFlow : class, IBaseControlFlow + where TControlFlow : class, IControlFlow => (builder as IActionBuilder).AddControlFlow(targetNodeName) as IReactiveStructuredActivityBuilder; [DebuggerHidden] public static IReactiveStructuredActivityBuilder AddControlFlow(this IReactiveStructuredActivityBuilder builder) - where TControlFlow : class, IBaseControlFlow + where TControlFlow : class, IControlFlow where TTargetNode : class, IActivityNode => builder.AddControlFlow(ActivityNode.Name); } diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/Flows/ReactiveStructuredActivityBuilderFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/Flows/ReactiveStructuredActivityBuilderFlowsTypedExtensions.cs index 3c0694e9..b0a3f107 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/Flows/ReactiveStructuredActivityBuilderFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/Flows/ReactiveStructuredActivityBuilderFlowsTypedExtensions.cs @@ -12,12 +12,12 @@ public static IReactiveStructuredActivityBuilder AddFlow(th [DebuggerHidden] public static IReactiveStructuredActivityBuilder AddFlow(this IReactiveStructuredActivityBuilder builder, string targetNodeName) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow => (builder as IActionBuilder).AddFlow(targetNodeName) as IReactiveStructuredActivityBuilder; [DebuggerHidden] public static IReactiveStructuredActivityBuilder AddFlow(this IReactiveStructuredActivityBuilder builder) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow where TTargetNode : class, IActivityNode => builder.AddFlow(ActivityNode.Name); diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderTypedExtensions.cs index af8fb482..e33d1962 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderTypedExtensions.cs @@ -152,12 +152,12 @@ public static IReactiveStructuredActivityBuilder AddSendEventAction(this IReactiveStructuredActivityBuilder builder, ReactiveStructuredActivityBuildAction buildAction) - where TStructuredActivity : class, IBaseStructuredActivityNode + where TStructuredActivity : class, IStructuredActivityNode => AddStructuredActivity(builder, ActivityNode.Name, buildAction); [DebuggerHidden] public static IReactiveStructuredActivityBuilder AddStructuredActivity(this IReactiveStructuredActivityBuilder builder, string structuredActivityName, ReactiveStructuredActivityBuildAction buildAction = null) - where TStructuredActivity : class, IBaseStructuredActivityNode + where TStructuredActivity : class, IStructuredActivityNode { (builder as IInternal).Services.AddServiceType(); @@ -177,12 +177,12 @@ public static IReactiveStructuredActivityBuilder AddStructuredActivity(this IReactiveStructuredActivityBuilder builder, ParallelActivityBuildAction buildAction = null, int chunkSize = 1) - where TStructuredActivity : class, IBaseStructuredActivityNode + where TStructuredActivity : class, IStructuredActivityNode => AddParallelActivity(builder, ActivityNode.Name, buildAction, chunkSize); [DebuggerHidden] public static IReactiveStructuredActivityBuilder AddParallelActivity(this IReactiveStructuredActivityBuilder builder, string structuredActivityName, ParallelActivityBuildAction buildAction = null, int chunkSize = 1) - where TStructuredActivity : class, IBaseStructuredActivityNode + where TStructuredActivity : class, IStructuredActivityNode { (builder as IInternal).Services.AddServiceType(); @@ -203,12 +203,12 @@ public static IReactiveStructuredActivityBuilder AddParallelActivity(this IReactiveStructuredActivityBuilder builder, IterativeActivityBuildAction buildAction = null, int chunkSize = 1) - where TIterativeActivity : class, IBaseStructuredActivityNode + where TIterativeActivity : class, IStructuredActivityNode => AddIterativeActivity(builder, ActivityNode.Name, buildAction, chunkSize); [DebuggerHidden] public static IReactiveStructuredActivityBuilder AddIterativeActivity(this IReactiveStructuredActivityBuilder builder, string structuredActivityName, IterativeActivityBuildAction buildAction = null, int chunkSize = 1) - where TIterativeActivity : class, IBaseStructuredActivityNode + where TIterativeActivity : class, IStructuredActivityNode { (builder as IInternal).Services.AddServiceType(); return builder.AddIterativeActivity( diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/SendEventActionBuilder/Flows/SendEventActionBuilderControlFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/SendEventActionBuilder/Flows/SendEventActionBuilderControlFlowsTypedExtensions.cs index 9fdd9af3..8875513e 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/SendEventActionBuilder/Flows/SendEventActionBuilderControlFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/SendEventActionBuilder/Flows/SendEventActionBuilderControlFlowsTypedExtensions.cs @@ -14,7 +14,7 @@ public static ISendEventActionBuilder AddControlFlow(this ISendEven [DebuggerHidden] public static ISendEventActionBuilder AddControlFlow(this ISendEventActionBuilder builder, string targetNodeName) - where TControlFlow : class, IBaseControlFlow + where TControlFlow : class, IControlFlow { (builder as IInternal).Services.AddServiceType(); @@ -26,7 +26,7 @@ public static ISendEventActionBuilder AddControlFlow(this ISendEve [DebuggerHidden] public static ISendEventActionBuilder AddControlFlow(this ISendEventActionBuilder builder) - where TFlow : class, IBaseControlFlow + where TFlow : class, IControlFlow where TTargetNode : class, IActivityNode => builder.AddControlFlow(ActivityNode.Name); } diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/Flows/StructuredActivityBuilderControlFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/Flows/StructuredActivityBuilderControlFlowsTypedExtensions.cs index 11edb834..c1b2a3c1 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/Flows/StructuredActivityBuilderControlFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/Flows/StructuredActivityBuilderControlFlowsTypedExtensions.cs @@ -12,12 +12,12 @@ public static IStructuredActivityBuilder AddControlFlow(this IStruc [DebuggerHidden] public static IStructuredActivityBuilder AddControlFlow(this IStructuredActivityBuilder builder, string targetNodeName) - where TControlFlow : class, IBaseControlFlow + where TControlFlow : class, IControlFlow => (builder as IActionBuilder).AddControlFlow(targetNodeName) as IStructuredActivityBuilder; [DebuggerHidden] public static IStructuredActivityBuilder AddControlFlow(this IStructuredActivityBuilder builder) - where TControlFlow : class, IBaseControlFlow + where TControlFlow : class, IControlFlow where TTargetNode : class, IActivityNode => builder.AddControlFlow(ActivityNode.Name); } diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/Flows/StructuredActivityBuilderFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/Flows/StructuredActivityBuilderFlowsTypedExtensions.cs index 0ec8459a..09624876 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/Flows/StructuredActivityBuilderFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/Flows/StructuredActivityBuilderFlowsTypedExtensions.cs @@ -12,12 +12,12 @@ public static IStructuredActivityBuilder AddFlow(this IStru [DebuggerHidden] public static IStructuredActivityBuilder AddFlow(this IStructuredActivityBuilder builder, string targetNodeName) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow => (builder as IActionBuilder).AddFlow(targetNodeName) as IStructuredActivityBuilder; [DebuggerHidden] public static IStructuredActivityBuilder AddFlow(this IStructuredActivityBuilder builder) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow where TTargetNode : class, IActivityNode => builder.AddFlow(ActivityNode.Name); diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderTypedExtensions.cs index 73246b65..ef9a4dcf 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderTypedExtensions.cs @@ -91,12 +91,12 @@ public static IStructuredActivityBuilder AddSendEventAction(this IStructuredActivityBuilder builder, StructuredActivityBuildAction buildAction = null) - where TStructuredActivity : class, IBaseStructuredActivityNode + where TStructuredActivity : class, IStructuredActivityNode => AddStructuredActivity(builder, ActivityNode.Name, buildAction); [DebuggerHidden] public static IStructuredActivityBuilder AddStructuredActivity(this IStructuredActivityBuilder builder, string structuredActivityName, StructuredActivityBuildAction buildAction = null) - where TStructuredActivity : class, IBaseStructuredActivityNode + where TStructuredActivity : class, IStructuredActivityNode { (builder as IInternal).Services.AddServiceType(); @@ -116,12 +116,12 @@ public static IStructuredActivityBuilder AddStructuredActivity(this IStructuredActivityBuilder builder, ParallelActivityBuildAction buildAction = null, int chunkSize = 1) - where TStructuredActivity : class, IBaseStructuredActivityNode + where TStructuredActivity : class, IStructuredActivityNode => AddParallelActivity(builder, ActivityNode.Name, buildAction, chunkSize); [DebuggerHidden] public static IStructuredActivityBuilder AddParallelActivity(this IStructuredActivityBuilder builder, string structuredActivityName, ParallelActivityBuildAction buildAction = null, int chunkSize = 1) - where TStructuredActivity : class, IBaseStructuredActivityNode + where TStructuredActivity : class, IStructuredActivityNode { (builder as IInternal).Services.AddServiceType(); @@ -142,12 +142,12 @@ public static IStructuredActivityBuilder AddParallelActivity(this IStructuredActivityBuilder builder, IterativeActivityBuildAction buildAction = null, int chunkSize = 1) - where TStructuredActivity : class, IBaseStructuredActivityNode + where TStructuredActivity : class, IStructuredActivityNode => AddIterativeActivity(builder, ActivityNode.Name, buildAction, chunkSize); [DebuggerHidden] public static IStructuredActivityBuilder AddIterativeActivity(this IStructuredActivityBuilder builder, string structuredActivityName, IterativeActivityBuildAction buildAction = null, int chunkSize = 1) - where TStructuredActivity : class, IBaseStructuredActivityNode + where TStructuredActivity : class, IStructuredActivityNode { (builder as IInternal).Services.AddServiceType(); return builder.AddIterativeActivity( diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/TypedActionBuilder/Flows/TypedActionBuilderControlFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/TypedActionBuilder/Flows/TypedActionBuilderControlFlowsTypedExtensions.cs index 785c203a..d8f9268f 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/TypedActionBuilder/Flows/TypedActionBuilderControlFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/TypedActionBuilder/Flows/TypedActionBuilderControlFlowsTypedExtensions.cs @@ -12,12 +12,12 @@ public static ITypedActionBuilder AddControlFlow(this ITypedActionB [DebuggerHidden] public static ITypedActionBuilder AddControlFlow(this ITypedActionBuilder builder, string targetNodeName) - where TControlFlow : class, IBaseControlFlow + where TControlFlow : class, IControlFlow => (builder as IActionBuilder).AddControlFlow(targetNodeName) as ITypedActionBuilder; [DebuggerHidden] public static ITypedActionBuilder AddControlFlow(this ITypedActionBuilder builder) - where TControlFlow : class, IBaseControlFlow + where TControlFlow : class, IControlFlow where TTargetNode : class, IActivityNode => builder.AddControlFlow(ActivityNode.Name); } diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/TypedActionBuilder/Flows/TypedActionBuilderFlowsTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/TypedActionBuilder/Flows/TypedActionBuilderFlowsTypedExtensions.cs index c4316281..fbe6ce82 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/TypedActionBuilder/Flows/TypedActionBuilderFlowsTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/TypedActionBuilder/Flows/TypedActionBuilderFlowsTypedExtensions.cs @@ -12,12 +12,12 @@ public static ITypedActionBuilder AddFlow(this ITypedAction [DebuggerHidden] public static ITypedActionBuilder AddFlow(this ITypedActionBuilder builder, string targetNodeName) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow => (builder as IActionBuilder).AddFlow(targetNodeName) as ITypedActionBuilder; [DebuggerHidden] public static ITypedActionBuilder AddFlow(this ITypedActionBuilder builder) - where TFlow : class, IBaseFlow + where TFlow : class, IFlow where TTargetNode : class, IActivityNode => builder.AddFlow(ActivityNode.Name); diff --git a/Core/Stateflows/Activities/Registration/Interfaces/IActivityBuilder.cs b/Core/Stateflows/Activities/Registration/Interfaces/IActivityBuilder.cs index 1293d5cf..2e3bf4c9 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/IActivityBuilder.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/IActivityBuilder.cs @@ -1,6 +1,6 @@ using Stateflows.Activities.Registration.Interfaces.Base; -namespace Stateflows.Activities.Registration.Interfaces +namespace Stateflows.Activities { public interface IActivityBuilder : IActivityUtils, diff --git a/Core/Stateflows/Activities/StateMachines/Classes/BaseActivityBuilder.cs b/Core/Stateflows/Activities/StateMachines/Classes/BaseActivityBuilder.cs new file mode 100644 index 00000000..47a0a701 --- /dev/null +++ b/Core/Stateflows/Activities/StateMachines/Classes/BaseActivityBuilder.cs @@ -0,0 +1,30 @@ +using System; +using System.Linq; +using System.Collections.Generic; +using Stateflows.Common; + +namespace Stateflows.Activities.StateMachines.Interfaces +{ + internal class BaseActivityBuilder + { + public List Notifications { get; } = new List(); + + public SubscriptionRequest GetSubscriptionRequest(BehaviorId behaviorId) + => new SubscriptionRequest() + { + NotificationNames = Notifications + .Select(notificationType => notificationType.GetEventName()) + .ToList(), + BehaviorId = behaviorId + }; + + public UnsubscriptionRequest GetUnsubscriptionRequest(BehaviorId behaviorId) + => new UnsubscriptionRequest() + { + NotificationNames = Notifications + .Select(notificationType => notificationType.GetEventName()) + .ToList(), + BehaviorId = behaviorId + }; + } +} diff --git a/Core/Stateflows/Activities/StateMachines/Classes/IntegratedActivityBuilder.cs b/Core/Stateflows/Activities/StateMachines/Classes/IntegratedActivityBuilder.cs deleted file mode 100644 index ab29b3d0..00000000 --- a/Core/Stateflows/Activities/StateMachines/Classes/IntegratedActivityBuilder.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Stateflows.Activities.Extensions; -using Stateflows.Common; - -namespace Stateflows.Activities.StateMachines.Interfaces -{ - internal class IntegratedActivityBuilder : IIntegratedActivityBuilder - { - public List Notifications { get; } = new List(); - - public IntegratedActivityBuilder(IntegratedActivityBuildAction buildAction) - { - buildAction?.Invoke(this); - } - - public SubscriptionRequest GetSubscriptionRequest() - => new SubscriptionRequest() - { - NotificationNames = Notifications - .Select(notificationType => notificationType.GetEventName()) - .ToList() - }; - - public UnsubscriptionRequest GetUnsubscriptionRequest() - => new UnsubscriptionRequest() - { - NotificationNames = Notifications - .Select(notificationType => notificationType.GetEventName()) - .ToList() - }; - - public Task SubscribeAsync(IBehavior behavior) - => Notifications.Any() - ? behavior.RequestAsync(GetSubscriptionRequest()) - : Task.CompletedTask; - - public Task UnsubscribeAsync(IBehavior behavior) - => Notifications.Any() - ? behavior.RequestAsync(GetUnsubscriptionRequest()) - : Task.CompletedTask; - - public IIntegratedActivityBuilder AddSubscription() - where TNotification : Notification, new() - { - Notifications.Add(typeof(TNotification)); - - return this; - } - } -} diff --git a/Core/Stateflows/Activities/StateMachines/Classes/StateActionActivityBuilder.cs b/Core/Stateflows/Activities/StateMachines/Classes/StateActionActivityBuilder.cs new file mode 100644 index 00000000..015edfff --- /dev/null +++ b/Core/Stateflows/Activities/StateMachines/Classes/StateActionActivityBuilder.cs @@ -0,0 +1,42 @@ +using Stateflows.Common; +using Stateflows.Activities.Extensions; + +namespace Stateflows.Activities.StateMachines.Interfaces +{ + internal class StateActionActivityBuilder : + BaseActivityBuilder, + IStateActionActivityBuilder, + IInitializedStateActionActivityBuilder + { + public StateActionActivityInitializationBuilderAsync InitializationBuilder { get; private set; } = null; + + public StateActionActivityBuilder(StateActionActivityBuildAction buildAction) + { + buildAction?.Invoke(this); + } + + IInitializedStateActionActivityBuilder IStateActionInitialization.InitializeWith(StateActionActivityInitializationBuilderAsync builderAsync) + { + if (builderAsync != null) + { + InitializationBuilder = async c => await builderAsync(c); + } + + return this; + } + + public StateActionActivityBuilder AddSubscription() + where TNotification : Notification, new() + { + Notifications.Add(typeof(TNotification)); + + return this; + } + + IStateActionActivityBuilder ISubscription.AddSubscription() + => AddSubscription(); + + IInitializedStateActionActivityBuilder ISubscription.AddSubscription() + => AddSubscription(); + } +} diff --git a/Core/Stateflows/Activities/StateMachines/Classes/TransitionActivityBuilder.cs b/Core/Stateflows/Activities/StateMachines/Classes/TransitionActivityBuilder.cs new file mode 100644 index 00000000..8f38068b --- /dev/null +++ b/Core/Stateflows/Activities/StateMachines/Classes/TransitionActivityBuilder.cs @@ -0,0 +1,43 @@ +using Stateflows.Common; +using Stateflows.Activities.Extensions; + +namespace Stateflows.Activities.StateMachines.Interfaces +{ + internal class TransitionActivityBuilder : + BaseActivityBuilder, + ITransitionActivityBuilder, + IInitializedTransitionActivityBuilder + where TEvent : Event, new() + { + public TransitionActivityInitializationBuilderAsync InitializationBuilder { get; private set; } = null; + + public TransitionActivityBuilder(TransitionActivityBuildAction buildAction) + { + buildAction?.Invoke(this); + } + + IInitializedTransitionActivityBuilder ITransitionInitialization>.InitializeWith(TransitionActivityInitializationBuilderAsync builderAsync) + { + if (builderAsync != null) + { + InitializationBuilder = async c => await builderAsync(c); + } + + return this; + } + + public TransitionActivityBuilder AddSubscription() + where TNotification : Notification, new() + { + Notifications.Add(typeof(TNotification)); + + return this; + } + + ITransitionActivityBuilder ISubscription>.AddSubscription() + => AddSubscription(); + + IInitializedTransitionActivityBuilder ISubscription>.AddSubscription() + => AddSubscription(); + } +} diff --git a/Core/Stateflows/Activities/StateMachines/Extensions/CompositeStateBuilderExtensions.cs b/Core/Stateflows/Activities/StateMachines/Extensions/CompositeStateBuilderExtensions.cs index 51761704..ef31a53c 100644 --- a/Core/Stateflows/Activities/StateMachines/Extensions/CompositeStateBuilderExtensions.cs +++ b/Core/Stateflows/Activities/StateMachines/Extensions/CompositeStateBuilderExtensions.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using Stateflows.Common; +using Stateflows.Common.Classes; using Stateflows.StateMachines.Sync; using Stateflows.Activities.Events; using Stateflows.Activities.Extensions; @@ -11,56 +12,60 @@ namespace Stateflows.Activities { public static class CompositeStateBuilderExtensions { - public static ICompositeStateBuilder AddOnEntryActivity(this ICompositeStateBuilder builder, string activityName, StateActionActivityInitializationBuilder initializationBuilder = null, IntegratedActivityBuildAction buildAction = null) + public static ICompositeStateBuilder AddOnEntryActivity(this ICompositeStateBuilder builder, string activityName, StateActionActivityBuildAction buildAction = null) => builder .AddOnEntry( c => { - if (c.TryLocateActivity(activityName, Constants.Entry, out var a)) + if (c.TryLocateActivity(activityName, $"{c.StateMachine.Id.Instance}.{c.CurrentState.Name}.{Constants.Entry}.{c.ExecutionTrigger.Id}", out var a)) { - Event initializationEvent = initializationBuilder?.Invoke(c) ?? new Initialize(); - Task.Run(() => + Task.Run(async () => { - var integratedActivityBuilder = new IntegratedActivityBuilder(buildAction); + var integratedActivityBuilder = new StateActionActivityBuilder(buildAction); + Event initializationEvent = (integratedActivityBuilder.InitializationBuilder != null) + ? await integratedActivityBuilder.InitializationBuilder(c) + : new Initialize(); return a.SendCompoundAsync( - integratedActivityBuilder.GetSubscriptionRequest(), - new ResetRequest() { Mode = ResetMode.KeepVersionAndSubscriptions }, + integratedActivityBuilder.GetSubscriptionRequest(c.StateMachine.Id), + new SetGlobalValues() { Values = (c.StateMachine.Values as ContextValuesCollection).Values }, new ExecutionRequest() { InitializationEvent = initializationEvent }, - integratedActivityBuilder.GetUnsubscriptionRequest() + integratedActivityBuilder.GetUnsubscriptionRequest(c.StateMachine.Id) ); }); } } ); - public static ICompositeStateBuilder AddOnEntryActivity(this ICompositeStateBuilder builder, StateActionActivityInitializationBuilder initializationBuilder = null, IntegratedActivityBuildAction buildAction = null) + public static ICompositeStateBuilder AddOnEntryActivity(this ICompositeStateBuilder builder, StateActionActivityBuildAction buildAction = null) where TActivity : class, IActivity - => AddOnEntryActivity(builder, Activity.Name, initializationBuilder, buildAction); + => AddOnEntryActivity(builder, Activity.Name, buildAction); - public static ICompositeStateBuilder AddOnExitActivity(this ICompositeStateBuilder builder, string activityName, StateActionActivityInitializationBuilder initializationBuilder = null, IntegratedActivityBuildAction buildAction = null) + public static ICompositeStateBuilder AddOnExitActivity(this ICompositeStateBuilder builder, string activityName, StateActionActivityBuildAction buildAction = null) => builder .AddOnExit( c => { - if (c.TryLocateActivity(activityName, Constants.Exit, out var a)) + if (c.TryLocateActivity(activityName, $"{c.StateMachine.Id.Instance}.{c.CurrentState.Name}.{Constants.Exit}.{c.ExecutionTrigger.Id}", out var a)) { - Event initializationEvent = initializationBuilder?.Invoke(c) ?? new Initialize(); - Task.Run(() => + Task.Run(async () => { - var integratedActivityBuilder = new IntegratedActivityBuilder(buildAction); + var integratedActivityBuilder = new StateActionActivityBuilder(buildAction); + Event initializationEvent = (integratedActivityBuilder.InitializationBuilder != null) + ? await integratedActivityBuilder.InitializationBuilder(c) + : new Initialize(); return a.SendCompoundAsync( - integratedActivityBuilder.GetSubscriptionRequest(), - new ResetRequest() { Mode = ResetMode.KeepVersionAndSubscriptions }, + integratedActivityBuilder.GetSubscriptionRequest(c.StateMachine.Id), + new SetGlobalValues() { Values = (c.StateMachine.Values as ContextValuesCollection).Values }, new ExecutionRequest() { InitializationEvent = initializationEvent }, - integratedActivityBuilder.GetUnsubscriptionRequest() + integratedActivityBuilder.GetUnsubscriptionRequest(c.StateMachine.Id) ); }); } } ); - public static ICompositeStateBuilder AddOnExitActivity(this ICompositeStateBuilder builder, StateActionActivityInitializationBuilder initializationBuilder = null, IntegratedActivityBuildAction buildAction = null) + public static ICompositeStateBuilder AddOnExitActivity(this ICompositeStateBuilder builder, StateActionActivityBuildAction buildAction = null) where TActivity : class, IActivity - => AddOnExitActivity(builder, Activity.Name, initializationBuilder, buildAction); + => AddOnExitActivity(builder, Activity.Name, buildAction); } } diff --git a/Core/Stateflows/Activities/StateMachines/Extensions/DefaultTransitionBuilderExtensions.cs b/Core/Stateflows/Activities/StateMachines/Extensions/DefaultTransitionBuilderExtensions.cs new file mode 100644 index 00000000..e2889a18 --- /dev/null +++ b/Core/Stateflows/Activities/StateMachines/Extensions/DefaultTransitionBuilderExtensions.cs @@ -0,0 +1,99 @@ +using System.Linq; +using System.Diagnostics; +using System.Threading.Tasks; +using Stateflows.Common; +using Stateflows.Common.Classes; +using Stateflows.Activities.Events; +using Stateflows.Activities.Extensions; +using Stateflows.Activities.StateMachines.Interfaces; +using Stateflows.StateMachines.Events; +using Stateflows.StateMachines.Registration; +using Stateflows.StateMachines.Registration.Interfaces; +using Stateflows.Common.Utilities; + +namespace Stateflows.Activities +{ + public static class DefaultTransitionBuilderExtensions + { + #region AddGuardActivity + [DebuggerHidden] + public static IDefaultTransitionBuilder AddGuardActivity(this IDefaultTransitionBuilder builder, string activityName, TransitionActivityBuildAction buildAction = null) + => builder.AddGuard( + async c => + { + var result = false; + if (c.TryLocateActivity(activityName, $"{c.StateMachine.Id.Instance}.{c.SourceState.Name}.{Constants.Guard}.{c.Event.Id}", out var a)) + { + var ev = StateflowsJsonConverter.Clone(c.Event); + await Task.Run(async () => + { + var integratedActivityBuilder = new TransitionActivityBuilder(buildAction); + Event initializationEvent = (integratedActivityBuilder.InitializationBuilder != null) + ? await integratedActivityBuilder.InitializationBuilder(c) + : new Initialize(); + var executionRequest = new ExecutionRequest() { InitializationEvent = initializationEvent }; + executionRequest.AddInputToken(ev); + + var sendResult = await a.SendCompoundAsync( + integratedActivityBuilder.GetSubscriptionRequest(c.StateMachine.Id), + new SetGlobalValues() { Values = (c.StateMachine.Values as ContextValuesCollection).Values }, + executionRequest, + integratedActivityBuilder.GetUnsubscriptionRequest(c.StateMachine.Id) + ); + + result = (sendResult.Response.Results.Skip(2).Take(1).First().Response as ExecutionResponse).OutputTokens.OfType>().FirstOrDefault()?.Payload ?? false; + }); + } + + return result; + } + ); + + [DebuggerHidden] + public static IDefaultTransitionBuilder AddGuardActivity(this IDefaultTransitionBuilder builder, TransitionActivityBuildAction buildAction = null) + where TActivity : class, IActivity + => builder.AddGuardActivity(Activity.Name, buildAction); + #endregion + + #region AddEffectActivity + [DebuggerHidden] + public static IDefaultTransitionBuilder AddEffectActivity(this IDefaultTransitionBuilder builder, string activityName, TransitionActivityBuildAction buildAction = null) + => builder.AddEffect( + c => + { + if (c.TryLocateActivity(activityName, $"{c.StateMachine.Id.Instance}.{c.SourceState.Name}.{Constants.Effect}.{c.Event.Id}", out var a)) + { + var ev = StateflowsJsonConverter.Clone(c.Event); + Task.Run(async () => + { + var integratedActivityBuilder = new TransitionActivityBuilder(buildAction); + Event initializationEvent = (integratedActivityBuilder.InitializationBuilder != null) + ? await integratedActivityBuilder.InitializationBuilder(c) + : new Initialize(); + var executionRequest = new ExecutionRequest() { InitializationEvent = initializationEvent }; + executionRequest.AddInputToken(ev); + + return a.SendCompoundAsync( + integratedActivityBuilder.GetSubscriptionRequest(c.StateMachine.Id), + new SetGlobalValues() { Values = (c.StateMachine.Values as ContextValuesCollection).Values }, + executionRequest, + integratedActivityBuilder.GetUnsubscriptionRequest(c.StateMachine.Id) + ); + }); + + return Task.CompletedTask; + } + else + { + return Task.CompletedTask; + } + } + ); + + [DebuggerHidden] + public static IDefaultTransitionBuilder AddEffectActivity(this IDefaultTransitionBuilder builder, TransitionActivityBuildAction buildAction = null) + where TActivity : class, IActivity + => builder.AddEffectActivity(Activity.Name, buildAction); + #endregion + } +} \ No newline at end of file diff --git a/Core/Stateflows/Activities/StateMachines/Extensions/Delegates.cs b/Core/Stateflows/Activities/StateMachines/Extensions/Delegates.cs index a3412d8d..caabab59 100644 --- a/Core/Stateflows/Activities/StateMachines/Extensions/Delegates.cs +++ b/Core/Stateflows/Activities/StateMachines/Extensions/Delegates.cs @@ -1,16 +1,27 @@ using Stateflows.Common; using Stateflows.StateMachines.Context.Interfaces; using Stateflows.Activities.StateMachines.Interfaces; +using System.Threading.Tasks; namespace Stateflows.Activities.Extensions { public delegate Event StateActionActivityInitializationBuilder(IStateActionContext context); - public delegate Event GuardActivityInitializationBuilder(IGuardContext context) + public delegate Event TransitionActivityInitializationBuilder(ITransitionContext context) where TEvent : Event, new(); - public delegate Event EffectActivityInitializationBuilder(IEventActionContext context) + public delegate void IntegratedActivityBuildAction(IIntegratedActivityBuilder builder); + + + public delegate Task StateActionActivityInitializationBuilderAsync(IStateActionContext context) + where TInitializationEvent : Event, new(); + + public delegate Task TransitionActivityInitializationBuilderAsync(ITransitionContext context) + where TInitializationEvent : Event, new() where TEvent : Event, new(); - public delegate void IntegratedActivityBuildAction(IIntegratedActivityBuilder builder); + public delegate void StateActionActivityBuildAction(IStateActionActivityBuilder builder); + + public delegate void TransitionActivityBuildAction(ITransitionActivityBuilder builder) + where TEvent : Event, new(); } \ No newline at end of file diff --git a/Core/Stateflows/Activities/StateMachines/Extensions/InternalTransitionBuilderExtensions.cs b/Core/Stateflows/Activities/StateMachines/Extensions/InternalTransitionBuilderExtensions.cs new file mode 100644 index 00000000..90c5068c --- /dev/null +++ b/Core/Stateflows/Activities/StateMachines/Extensions/InternalTransitionBuilderExtensions.cs @@ -0,0 +1,98 @@ +using System.Linq; +using System.Diagnostics; +using System.Threading.Tasks; +using Stateflows.Common; +using Stateflows.Common.Classes; +using Stateflows.Activities.Extensions; +using Stateflows.StateMachines.Registration; +using Stateflows.StateMachines.Registration.Interfaces; +using Stateflows.Activities.Events; +using Stateflows.Activities.StateMachines.Interfaces; +using Stateflows.Common.Utilities; + +namespace Stateflows.Activities +{ + public static class InternalTransitionBuilderExtensions + { + #region AddGuardActivity + [DebuggerHidden] + public static IInternalTransitionBuilder AddGuardActivity(this IInternalTransitionBuilder builder, string activityName, TransitionActivityBuildAction buildAction = null) + where TEvent : Event, new() + => builder.AddGuard( + async c => + { + var result = false; + if (c.TryLocateActivity(activityName, $"{c.StateMachine.Id.Instance}.{c.SourceState.Name}.{EventInfo.Name}.{Constants.Guard}.{c.Event.Id}", out var a)) + { + var ev = StateflowsJsonConverter.Clone(c.Event); + await Task.Run(async () => + { + var integratedActivityBuilder = new TransitionActivityBuilder(buildAction); + Event initializationEvent = (integratedActivityBuilder.InitializationBuilder != null) + ? await integratedActivityBuilder.InitializationBuilder(c) + : new Initialize(); + var executionRequest = new ExecutionRequest() { InitializationEvent = initializationEvent }; + executionRequest.AddInputToken(ev); + + var sendResult = await a.SendCompoundAsync( + integratedActivityBuilder.GetSubscriptionRequest(c.StateMachine.Id), + new SetGlobalValues() { Values = (c.StateMachine.Values as ContextValuesCollection).Values }, + executionRequest, + integratedActivityBuilder.GetUnsubscriptionRequest(c.StateMachine.Id) + ); + + result = (sendResult.Response.Results.Skip(2).Take(1).First().Response as ExecutionResponse).OutputTokens.OfType>().FirstOrDefault()?.Payload ?? false; + }); + } + + return result; + } + ); + + [DebuggerHidden] + public static IInternalTransitionBuilder AddGuardActivity(this IInternalTransitionBuilder builder, TransitionActivityBuildAction buildAction = null) + where TEvent : Event, new() + where TActivity : class, IActivity + => builder.AddGuardActivity(Activity.Name, buildAction); + #endregion + + #region AddEffectActivity + [DebuggerHidden] + public static IInternalTransitionBuilder AddEffectActivity(this IInternalTransitionBuilder builder, string activityName, TransitionActivityBuildAction buildAction = null) + where TEvent : Event, new() + => builder.AddEffect( + c => + { + if (c.TryLocateActivity(activityName, $"{c.StateMachine.Id.Instance}.{c.SourceState.Name}.{EventInfo.Name}.{Constants.Effect}.{c.Event.Id}", out var a)) + { + var ev = StateflowsJsonConverter.Clone(c.Event); + Task.Run(async () => + { + var integratedActivityBuilder = new TransitionActivityBuilder(buildAction); + Event initializationEvent = (integratedActivityBuilder.InitializationBuilder != null) + ? await integratedActivityBuilder.InitializationBuilder(c) + : new Initialize(); + var executionRequest = new ExecutionRequest() { InitializationEvent = initializationEvent }; + executionRequest.AddInputToken(ev); + + return a.SendCompoundAsync( + integratedActivityBuilder.GetSubscriptionRequest(c.StateMachine.Id), + new SetGlobalValues() { Values = (c.StateMachine.Values as ContextValuesCollection).Values }, + executionRequest, + integratedActivityBuilder.GetUnsubscriptionRequest(c.StateMachine.Id) + ); + }); + } + + return Task.CompletedTask; + } + ); + + [DebuggerHidden] + public static IInternalTransitionBuilder AddEffectActivity(this IInternalTransitionBuilder builder, TransitionActivityBuildAction buildAction = null) + where TEvent : Event, new() + where TActivity : class, IActivity + => builder.AddEffectActivity(Activity.Name, buildAction); + #endregion + } +} \ No newline at end of file diff --git a/Core/Stateflows/Activities/StateMachines/Extensions/StateBuilderExtensions.cs b/Core/Stateflows/Activities/StateMachines/Extensions/StateBuilderExtensions.cs index 2f2f8608..21c637db 100644 --- a/Core/Stateflows/Activities/StateMachines/Extensions/StateBuilderExtensions.cs +++ b/Core/Stateflows/Activities/StateMachines/Extensions/StateBuilderExtensions.cs @@ -1,6 +1,7 @@ using System.Threading.Tasks; using System.Collections.Generic; using Stateflows.Common; +using Stateflows.Common.Classes; using Stateflows.StateMachines.Sync; using Stateflows.Activities.Events; using Stateflows.Activities.Extensions; @@ -14,58 +15,60 @@ public static class StateBuilderExtensions { internal static readonly List DoActivites = new List(); - public static IStateBuilder AddOnEntryActivity(this IStateBuilder builder, string activityName, StateActionActivityInitializationBuilder initializationBuilder = null, IntegratedActivityBuildAction buildAction = null) + public static IStateBuilder AddOnEntryActivity(this IStateBuilder builder, string activityName, StateActionActivityBuildAction buildAction = null) => builder .AddOnEntry( c => { - if (c.TryLocateActivity(activityName, Constants.Entry, out var a)) + if (c.TryLocateActivity(activityName, $"{c.StateMachine.Id.Instance}.{c.CurrentState.Name}.{Constants.Entry}.{c.ExecutionTrigger.Id}", out var a)) { - Event initializationEvent = initializationBuilder?.Invoke(c) ?? new Initialize(); - Task.Run(() => + Task.Run(async () => { - var integratedActivityBuilder = new IntegratedActivityBuilder(buildAction); - + var integratedActivityBuilder = new StateActionActivityBuilder(buildAction); + Event initializationEvent = (integratedActivityBuilder.InitializationBuilder != null) + ? await integratedActivityBuilder.InitializationBuilder(c) + : new Initialize(); return a.SendCompoundAsync( - integratedActivityBuilder.GetSubscriptionRequest(), - new ResetRequest() { Mode = ResetMode.KeepVersionAndSubscriptions }, + integratedActivityBuilder.GetSubscriptionRequest(c.StateMachine.Id), + new SetGlobalValues() { Values = (c.StateMachine.Values as ContextValuesCollection).Values }, new ExecutionRequest() { InitializationEvent = initializationEvent }, - integratedActivityBuilder.GetUnsubscriptionRequest() + integratedActivityBuilder.GetUnsubscriptionRequest(c.StateMachine.Id) ); }); } } ); - public static IStateBuilder AddOnEntryActivity(this IStateBuilder builder, StateActionActivityInitializationBuilder initializationBuilder = null, IntegratedActivityBuildAction buildAction = null) + public static IStateBuilder AddOnEntryActivity(this IStateBuilder builder, StateActionActivityBuildAction buildAction = null) where TActivity : class, IActivity - => AddOnEntryActivity(builder, Activity.Name, initializationBuilder, buildAction); + => AddOnEntryActivity(builder, Activity.Name, buildAction); - public static IStateBuilder AddOnExitActivity(this IStateBuilder builder, string activityName, StateActionActivityInitializationBuilder initializationBuilder = null, IntegratedActivityBuildAction buildAction = null) + public static IStateBuilder AddOnExitActivity(this IStateBuilder builder, string activityName, StateActionActivityBuildAction buildAction = null) => builder .AddOnExit( c => { - if (c.TryLocateActivity(activityName, Constants.Exit, out var a)) + if (c.TryLocateActivity(activityName, $"{c.StateMachine.Id.Instance}.{c.CurrentState.Name}.{Constants.Exit}.{c.ExecutionTrigger.Id}", out var a)) { - Event initializationEvent = initializationBuilder?.Invoke(c) ?? new Initialize(); - Task.Run(() => + Task.Run(async () => { - var integratedActivityBuilder = new IntegratedActivityBuilder(buildAction); - + var integratedActivityBuilder = new StateActionActivityBuilder(buildAction); + Event initializationEvent = (integratedActivityBuilder.InitializationBuilder != null) + ? await integratedActivityBuilder.InitializationBuilder(c) + : new Initialize(); return a.SendCompoundAsync( - integratedActivityBuilder.GetSubscriptionRequest(), - new ResetRequest() { Mode = ResetMode.KeepVersionAndSubscriptions }, + integratedActivityBuilder.GetSubscriptionRequest(c.StateMachine.Id), + new SetGlobalValues() { Values = (c.StateMachine.Values as ContextValuesCollection).Values }, new ExecutionRequest() { InitializationEvent = initializationEvent }, - integratedActivityBuilder.GetUnsubscriptionRequest() + integratedActivityBuilder.GetUnsubscriptionRequest(c.StateMachine.Id) ); }); } } ); - public static IStateBuilder AddOnExitActivity(this IStateBuilder builder, StateActionActivityInitializationBuilder initializationBuilder = null, IntegratedActivityBuildAction buildAction = null) + public static IStateBuilder AddOnExitActivity(this IStateBuilder builder, StateActionActivityBuildAction buildAction = null) where TActivity : class, IActivity - => AddOnExitActivity(builder, Activity.Name, initializationBuilder, buildAction); + => AddOnExitActivity(builder, Activity.Name, buildAction); } } diff --git a/Core/Stateflows/Activities/StateMachines/Extensions/TransitionBuilderExtensions.cs b/Core/Stateflows/Activities/StateMachines/Extensions/TransitionBuilderExtensions.cs index 7b5c72f5..9b21a4b2 100644 --- a/Core/Stateflows/Activities/StateMachines/Extensions/TransitionBuilderExtensions.cs +++ b/Core/Stateflows/Activities/StateMachines/Extensions/TransitionBuilderExtensions.cs @@ -2,11 +2,13 @@ using System.Diagnostics; using System.Threading.Tasks; using Stateflows.Common; -using Stateflows.Activities.Extensions; +using Stateflows.Common.Classes; using Stateflows.StateMachines.Registration; using Stateflows.StateMachines.Registration.Interfaces; -using Stateflows.Activities.StateMachines.Interfaces; using Stateflows.Activities.Events; +using Stateflows.Activities.Extensions; +using Stateflows.Activities.StateMachines.Interfaces; +using Stateflows.Common.Utilities; namespace Stateflows.Activities { @@ -14,73 +16,83 @@ public static class TransitionBuilderExtensions { #region AddGuardActivity [DebuggerHidden] - public static ITransitionBuilder AddGuardActivity(this ITransitionBuilder builder, string activityName, GuardActivityInitializationBuilder initializationBuilder = null, IntegratedActivityBuildAction buildAction = null) + public static ITransitionBuilder AddGuardActivity(this ITransitionBuilder builder, string activityName, TransitionActivityBuildAction buildAction = null) where TEvent : Event, new() => builder.AddGuard( - async c => + async c => + { + var result = false; + if (c.TryLocateActivity(activityName, $"{c.StateMachine.Id.Instance}.{c.SourceState.Name}.{EventInfo.Name}.{Constants.Guard}.{c.Event.Id}", out var a)) { - var result = false; - if (c.TryLocateActivity(activityName, Constants.Entry, out var a)) + var ev = StateflowsJsonConverter.Clone(c.Event); + await Task.Run(async () => { - Event initializationEvent = initializationBuilder?.Invoke(c) ?? new Initialize(); - await Task.Run(async () => - { - var integratedActivityBuilder = new IntegratedActivityBuilder(buildAction); - var sendResult = await a.SendCompoundAsync( - integratedActivityBuilder.GetSubscriptionRequest(), - new ResetRequest() { Mode = ResetMode.KeepVersionAndSubscriptions }, - new ExecutionRequest() { InitializationEvent = initializationEvent }, - integratedActivityBuilder.GetUnsubscriptionRequest() - ); + var integratedActivityBuilder = new TransitionActivityBuilder(buildAction); + Event initializationEvent = (integratedActivityBuilder.InitializationBuilder != null) + ? await integratedActivityBuilder.InitializationBuilder(c) + : new Initialize(); + var executionRequest = new ExecutionRequest() { InitializationEvent = initializationEvent }; + executionRequest.AddInputToken(ev); - result = (sendResult.Response.Results.Skip(2).Take(1).First().Response as ExecutionResponse).OutputTokens.OfType>().FirstOrDefault()?.Payload ?? false; - }); - } + var sendResult = await a.SendCompoundAsync( + integratedActivityBuilder.GetSubscriptionRequest(c.StateMachine.Id), + new SetGlobalValues() { Values = (c.StateMachine.Values as ContextValuesCollection).Values }, + executionRequest, + integratedActivityBuilder.GetUnsubscriptionRequest(c.StateMachine.Id) + ); - return result; + result = (sendResult.Response.Results.Skip(2).Take(1).First()?.Response as ExecutionResponse)?.OutputTokens?.OfType>()?.FirstOrDefault()?.Payload ?? false; + }); } + + return result; + } ); [DebuggerHidden] - public static ITransitionBuilder AddGuardActivity(this ITransitionBuilder builder, GuardActivityInitializationBuilder initializationBuilder = null, IntegratedActivityBuildAction buildAction = null) + public static ITransitionBuilder AddGuardActivity(this ITransitionBuilder builder, TransitionActivityBuildAction buildAction = null) where TEvent : Event, new() where TActivity : class, IActivity - => builder.AddGuardActivity(Activity.Name, initializationBuilder); + => builder.AddGuardActivity(Activity.Name, buildAction); #endregion #region AddEffectActivity [DebuggerHidden] - public static ITransitionBuilder AddEffectActivity(this ITransitionBuilder builder, string activityName, EffectActivityInitializationBuilder initializationBuilder = null, IntegratedActivityBuildAction buildAction = null) + public static ITransitionBuilder AddEffectActivity(this ITransitionBuilder builder, string activityName, TransitionActivityBuildAction buildAction = null) where TEvent : Event, new() => builder.AddEffect( c => { - if (c.TryLocateActivity(activityName, Constants.Entry, out var a)) + if (c.TryLocateActivity(activityName, $"{c.StateMachine.Id.Instance}.{c.SourceState.Name}.{EventInfo.Name}.{Constants.Effect}.{c.Event.Id}", out var a)) { - Event initializationEvent = initializationBuilder?.Invoke(c) ?? new Initialize(); - return Task.Run(() => + var ev = StateflowsJsonConverter.Clone(c.Event); + Task.Run(async () => { - var integratedActivityBuilder = new IntegratedActivityBuilder(buildAction); + var integratedActivityBuilder = new TransitionActivityBuilder(buildAction); + Event initializationEvent = (integratedActivityBuilder.InitializationBuilder != null) + ? await integratedActivityBuilder.InitializationBuilder(c) + : new Initialize(); + var executionRequest = new ExecutionRequest() { InitializationEvent = initializationEvent }; + executionRequest.AddInputToken(ev); + return a.SendCompoundAsync( - integratedActivityBuilder.GetSubscriptionRequest(), - new ResetRequest() { Mode = ResetMode.KeepVersionAndSubscriptions }, - new ExecutionRequest() { InitializationEvent = initializationEvent }, - integratedActivityBuilder.GetUnsubscriptionRequest() + integratedActivityBuilder.GetSubscriptionRequest(c.StateMachine.Id), + new SetGlobalValues() { Values = (c.StateMachine.Values as ContextValuesCollection).Values }, + executionRequest, + integratedActivityBuilder.GetUnsubscriptionRequest(c.StateMachine.Id) ); }); } - else - { - return Task.CompletedTask; - } + + return Task.CompletedTask; } ); [DebuggerHidden] - public static ITransitionBuilder AddEffectActivity(this ITransitionBuilder builder, EffectActivityInitializationBuilder initializationBuilder = null, IntegratedActivityBuildAction buildAction = null) + public static ITransitionBuilder AddEffectActivity(this ITransitionBuilder builder, TransitionActivityBuildAction buildAction = null) where TEvent : Event, new() where TActivity : class, IActivity - => builder.AddEffectActivity(Activity.Name, initializationBuilder); + => builder.AddEffectActivity(Activity.Name, buildAction); #endregion } } \ No newline at end of file diff --git a/Core/Stateflows/Activities/StateMachines/Extensions/TypedCompositeStateBuilderExtensions.cs b/Core/Stateflows/Activities/StateMachines/Extensions/TypedCompositeStateBuilderExtensions.cs index fb32036c..8ffb18e1 100644 --- a/Core/Stateflows/Activities/StateMachines/Extensions/TypedCompositeStateBuilderExtensions.cs +++ b/Core/Stateflows/Activities/StateMachines/Extensions/TypedCompositeStateBuilderExtensions.cs @@ -5,18 +5,18 @@ namespace Stateflows.Activities { public static class TypedCompositeStateBuilderExtensions { - public static ITypedCompositeStateBuilder AddOnEntryActivity(this ITypedCompositeStateBuilder builder, string activityName, StateActionActivityInitializationBuilder parametersBuilder = null, IntegratedActivityBuildAction buildAction = null) - => (builder as ICompositeStateBuilder).AddOnEntryActivity(activityName, parametersBuilder, buildAction) as ITypedCompositeStateBuilder; + public static ITypedCompositeStateBuilder AddOnEntryActivity(this ITypedCompositeStateBuilder builder, string activityName, StateActionActivityBuildAction buildAction = null) + => (builder as ICompositeStateBuilder).AddOnEntryActivity(activityName, buildAction) as ITypedCompositeStateBuilder; - public static ITypedCompositeStateBuilder AddOnEntryActivity(this ITypedCompositeStateBuilder builder, StateActionActivityInitializationBuilder parametersBuilder = null, IntegratedActivityBuildAction buildAction = null) + public static ITypedCompositeStateBuilder AddOnEntryActivity(this ITypedCompositeStateBuilder builder, StateActionActivityBuildAction buildAction = null) where TActivity : class, IActivity - => (builder as ICompositeStateBuilder).AddOnEntryActivity(parametersBuilder, buildAction) as ITypedCompositeStateBuilder; + => (builder as ICompositeStateBuilder).AddOnEntryActivity(buildAction) as ITypedCompositeStateBuilder; - public static ITypedCompositeStateBuilder AddOnExitActivity(this ITypedCompositeStateBuilder builder, string activityName, StateActionActivityInitializationBuilder parametersBuilder = null, IntegratedActivityBuildAction buildAction = null) - => (builder as ICompositeStateBuilder).AddOnExitActivity(activityName, parametersBuilder, buildAction) as ITypedCompositeStateBuilder; + public static ITypedCompositeStateBuilder AddOnExitActivity(this ITypedCompositeStateBuilder builder, string activityName, StateActionActivityBuildAction buildAction = null) + => (builder as ICompositeStateBuilder).AddOnExitActivity(activityName, buildAction) as ITypedCompositeStateBuilder; - public static ITypedCompositeStateBuilder AddOnExitActivity(this ITypedCompositeStateBuilder builder, StateActionActivityInitializationBuilder parametersBuilder = null, IntegratedActivityBuildAction buildAction = null) + public static ITypedCompositeStateBuilder AddOnExitActivity(this ITypedCompositeStateBuilder builder, StateActionActivityBuildAction buildAction = null) where TActivity : class, IActivity - => (builder as ICompositeStateBuilder).AddOnExitActivity(parametersBuilder, buildAction) as ITypedCompositeStateBuilder; + => (builder as ICompositeStateBuilder).AddOnExitActivity(buildAction) as ITypedCompositeStateBuilder; } } diff --git a/Core/Stateflows/Activities/StateMachines/Extensions/TypedStateBuilderExtensions.cs b/Core/Stateflows/Activities/StateMachines/Extensions/TypedStateBuilderExtensions.cs index b57e71fa..c5597a87 100644 --- a/Core/Stateflows/Activities/StateMachines/Extensions/TypedStateBuilderExtensions.cs +++ b/Core/Stateflows/Activities/StateMachines/Extensions/TypedStateBuilderExtensions.cs @@ -5,18 +5,18 @@ namespace Stateflows.Activities { public static class TypedStateBuilderExtensions { - public static ITypedStateBuilder AddOnEntryActivity(this ITypedStateBuilder builder, string activityName, StateActionActivityInitializationBuilder parametersBuilder = null, IntegratedActivityBuildAction buildAction = null) - => (builder as IStateBuilder).AddOnEntryActivity(activityName, parametersBuilder, buildAction) as ITypedStateBuilder; + public static ITypedStateBuilder AddOnEntryActivity(this ITypedStateBuilder builder, string activityName, StateActionActivityBuildAction buildAction = null) + => (builder as IStateBuilder).AddOnEntryActivity(activityName, buildAction) as ITypedStateBuilder; - public static ITypedStateBuilder AddOnEntryActivity(this ITypedStateBuilder builder, StateActionActivityInitializationBuilder parametersBuilder = null, IntegratedActivityBuildAction buildAction = null) + public static ITypedStateBuilder AddOnEntryActivity(this ITypedStateBuilder builder, StateActionActivityBuildAction buildAction = null) where TActivity : class, IActivity - => (builder as IStateBuilder).AddOnEntryActivity(parametersBuilder, buildAction) as ITypedStateBuilder; + => (builder as IStateBuilder).AddOnEntryActivity(buildAction) as ITypedStateBuilder; - public static ITypedStateBuilder AddOnExitActivity(this ITypedStateBuilder builder, string activityName, StateActionActivityInitializationBuilder parametersBuilder = null, IntegratedActivityBuildAction buildAction = null) - => (builder as IStateBuilder).AddOnExitActivity(activityName, parametersBuilder, buildAction) as ITypedStateBuilder; + public static ITypedStateBuilder AddOnExitActivity(this ITypedStateBuilder builder, string activityName, StateActionActivityBuildAction buildAction = null) + => (builder as IStateBuilder).AddOnExitActivity(activityName, buildAction) as ITypedStateBuilder; - public static ITypedStateBuilder AddOnExitActivity(this ITypedStateBuilder builder, StateActionActivityInitializationBuilder parametersBuilder = null, IntegratedActivityBuildAction buildAction = null) + public static ITypedStateBuilder AddOnExitActivity(this ITypedStateBuilder builder, StateActionActivityBuildAction buildAction = null) where TActivity : class, IActivity - => (builder as IStateBuilder).AddOnExitActivity(parametersBuilder, buildAction) as ITypedStateBuilder; + => (builder as IStateBuilder).AddOnExitActivity(buildAction) as ITypedStateBuilder; } } diff --git a/Core/Stateflows/Activities/StateMachines/Interfaces/Base/IStateActionInitialization.cs b/Core/Stateflows/Activities/StateMachines/Interfaces/Base/IStateActionInitialization.cs new file mode 100644 index 00000000..c864b731 --- /dev/null +++ b/Core/Stateflows/Activities/StateMachines/Interfaces/Base/IStateActionInitialization.cs @@ -0,0 +1,11 @@ +using Stateflows.Common; +using Stateflows.Activities.Extensions; + +namespace Stateflows.Activities.StateMachines.Interfaces +{ + public interface IStateActionInitialization + { + TReturn InitializeWith(StateActionActivityInitializationBuilderAsync builderAsync) + where TInitializationEvent : Event, new(); + } +} diff --git a/Core/Stateflows/Activities/StateMachines/Interfaces/Base/ISubscription.cs b/Core/Stateflows/Activities/StateMachines/Interfaces/Base/ISubscription.cs new file mode 100644 index 00000000..87293ea8 --- /dev/null +++ b/Core/Stateflows/Activities/StateMachines/Interfaces/Base/ISubscription.cs @@ -0,0 +1,10 @@ +using Stateflows.Common; + +namespace Stateflows.Activities.StateMachines.Interfaces +{ + public interface ISubscription + { + TReturn AddSubscription() + where TNotification : Notification, new(); + } +} diff --git a/Core/Stateflows/Activities/StateMachines/Interfaces/Base/ITransitionInitialization.cs b/Core/Stateflows/Activities/StateMachines/Interfaces/Base/ITransitionInitialization.cs new file mode 100644 index 00000000..65f22a36 --- /dev/null +++ b/Core/Stateflows/Activities/StateMachines/Interfaces/Base/ITransitionInitialization.cs @@ -0,0 +1,12 @@ +using Stateflows.Common; +using Stateflows.Activities.Extensions; + +namespace Stateflows.Activities.StateMachines.Interfaces +{ + public interface ITransitionInitialization + where TEvent : Event, new() + { + TReturn InitializeWith(TransitionActivityInitializationBuilderAsync builderAsync) + where TInitializationEvent : Event, new(); + } +} diff --git a/Core/Stateflows/Activities/StateMachines/Interfaces/IStateActionActivityBuilder.cs b/Core/Stateflows/Activities/StateMachines/Interfaces/IStateActionActivityBuilder.cs new file mode 100644 index 00000000..07809581 --- /dev/null +++ b/Core/Stateflows/Activities/StateMachines/Interfaces/IStateActionActivityBuilder.cs @@ -0,0 +1,11 @@ +namespace Stateflows.Activities.StateMachines.Interfaces +{ + public interface IStateActionActivityBuilder : + IStateActionInitialization, + ISubscription + { } + + public interface IInitializedStateActionActivityBuilder : + ISubscription + { } +} diff --git a/Core/Stateflows/Activities/StateMachines/Interfaces/ITransitionActivityBuilder.cs b/Core/Stateflows/Activities/StateMachines/Interfaces/ITransitionActivityBuilder.cs new file mode 100644 index 00000000..454fe4ba --- /dev/null +++ b/Core/Stateflows/Activities/StateMachines/Interfaces/ITransitionActivityBuilder.cs @@ -0,0 +1,15 @@ +using Stateflows.Common; + +namespace Stateflows.Activities.StateMachines.Interfaces +{ + public interface ITransitionActivityBuilder : + ITransitionInitialization>, + ISubscription> + where TEvent : Event, new() + { } + + public interface IInitializedTransitionActivityBuilder : + ISubscription> + where TEvent : Event, new() + { } +} diff --git a/Core/Stateflows/Activities/Utils/ObjectExtensions.cs b/Core/Stateflows/Activities/Utils/ObjectExtensions.cs index da42ad21..e2746f76 100644 --- a/Core/Stateflows/Activities/Utils/ObjectExtensions.cs +++ b/Core/Stateflows/Activities/Utils/ObjectExtensions.cs @@ -1,5 +1,8 @@ using System; +using System.Linq; +using System.Collections.Generic; using Stateflows.Activities; +using Stateflows.Activities.Events; namespace Stateflows.Utils { @@ -30,5 +33,11 @@ internal static TokenHolder ToExceptionHolder(this T payload, Type exceptionT return holder; } + + public static void AddInputToken(this ExecutionRequest executionRequest, TToken token) + => executionRequest.InputTokens.Add(token.ToTokenHolder()); + + public static void AddInputTokens(this ExecutionRequest executionRequest, IEnumerable tokens) + => executionRequest.InputTokens.AddRange(tokens.Select(token => token.ToTokenHolder())); } } diff --git a/Core/Stateflows/Common/Classes/BaseValueAccessor.cs b/Core/Stateflows/Common/Classes/BaseValueAccessor.cs index f979695d..554eea41 100644 --- a/Core/Stateflows/Common/Classes/BaseValueAccessor.cs +++ b/Core/Stateflows/Common/Classes/BaseValueAccessor.cs @@ -24,7 +24,7 @@ public bool IsSet public bool TryGet(out T value) => valueSet.TryGet(valueName, out value); - public T GetOrDefault(T defaultValue) + public T GetOrDefault(T defaultValue = default) => valueSet.GetOrDefault(valueName, defaultValue); public void Remove() diff --git a/Core/Stateflows/Common/Classes/ContextValuesCollection.cs b/Core/Stateflows/Common/Classes/ContextValuesCollection.cs index 445328ce..a6dadc6a 100644 --- a/Core/Stateflows/Common/Classes/ContextValuesCollection.cs +++ b/Core/Stateflows/Common/Classes/ContextValuesCollection.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json.Linq; -using Stateflows.Common.Interfaces; using Stateflows.Common.Utilities; +using Stateflows.Common.Interfaces; using System.Collections.Generic; namespace Stateflows.Common.Classes diff --git a/Core/Stateflows/Common/Engine/StateflowsEngine.cs b/Core/Stateflows/Common/Engine/StateflowsEngine.cs index 99047bb2..e3ecfcda 100644 --- a/Core/Stateflows/Common/Engine/StateflowsEngine.cs +++ b/Core/Stateflows/Common/Engine/StateflowsEngine.cs @@ -22,7 +22,6 @@ internal class StateflowsEngine : /*BackgroundService, */IHostedService private readonly IStateflowsExecutionInterceptor Interceptor; private readonly IStateflowsTenantProvider TenantProvider; private readonly ITenantAccessor TenantAccessor; - private readonly ILogger Logger; private Dictionary processors; private Dictionary Processors => processors ??= ServiceProvider.GetRequiredService>().ToDictionary(p => p.BehaviorType, p => p); @@ -38,7 +37,6 @@ public StateflowsEngine(IServiceProvider serviceProvider) Interceptor = ServiceProvider.GetRequiredService(); TenantAccessor = ServiceProvider.GetRequiredService(); TenantProvider = ServiceProvider.GetRequiredService(); - Logger = ServiceProvider.GetRequiredService>(); } public EventHolder EnqueueEvent(BehaviorId id, Event @event, IServiceProvider serviceProvider) @@ -107,41 +105,38 @@ public Task StartAsync(CancellationToken cancellationToken) return Task.CompletedTask; } - //[DebuggerHidden] + [DebuggerHidden] public async Task ProcessEventAsync(BehaviorId id, TEvent @event, IServiceProvider serviceProvider, List exceptions) where TEvent : Event, new() { var result = EventStatus.Undelivered; - if (Processors.TryGetValue(id.Type, out var processor)) + if (Processors.TryGetValue(id.Type, out var processor) && Interceptor.BeforeExecute(@event)) { - if (Interceptor.BeforeExecute(@event)) - { - TenantAccessor.CurrentTenantId = await TenantProvider.GetCurrentTenantIdAsync(); + TenantAccessor.CurrentTenantId = await TenantProvider.GetCurrentTenantIdAsync(); - await using var lockHandle = await Lock.AquireLockAsync(id); + await using var lockHandle = await Lock.AquireLockAsync(id); + try + { try { - try - { - result = await processor.ProcessEventAsync(id, @event, serviceProvider, exceptions); - } - finally - { - var response = @event.GetResponse(); - if (response != null) - { - response.SenderId = id; - response.SentAt = DateTime.Now; - } - } + result = await processor.ProcessEventAsync(id, @event, serviceProvider, exceptions); } finally { - Interceptor.AfterExecute(@event); + var response = @event.GetResponse(); + if (response != null) + { + response.SenderId = id; + response.SentAt = DateTime.Now; + } } } + finally + { + Interceptor.AfterExecute(@event); + } } return result; diff --git a/Core/Stateflows/Common/Events/SetGlobalValues.cs b/Core/Stateflows/Common/Events/SetGlobalValues.cs new file mode 100644 index 00000000..3ae897ef --- /dev/null +++ b/Core/Stateflows/Common/Events/SetGlobalValues.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace Stateflows.Common +{ + [NoImplicitInitialization] + internal class SetGlobalValues : Event + { + public Dictionary Values { get; set; } + } +} diff --git a/Core/Stateflows/Activities/Context/Interfaces/IExecutionContext.cs b/Core/Stateflows/Common/Interfaces/Context/IExecutionContext.cs similarity index 53% rename from Core/Stateflows/Activities/Context/Interfaces/IExecutionContext.cs rename to Core/Stateflows/Common/Interfaces/Context/IExecutionContext.cs index 02ea5e45..af9f68b5 100644 --- a/Core/Stateflows/Activities/Context/Interfaces/IExecutionContext.cs +++ b/Core/Stateflows/Common/Interfaces/Context/IExecutionContext.cs @@ -1,8 +1,5 @@ -using Stateflows.Common; - -namespace Stateflows.Activities.Context.Interfaces +namespace Stateflows.Common { - public interface IExecutionContext { Event ExecutionTrigger { get; } diff --git a/Core/Stateflows/Common/Interfaces/IContextValues.cs b/Core/Stateflows/Common/Interfaces/IContextValues.cs index fb0cbdca..2c7d837b 100644 --- a/Core/Stateflows/Common/Interfaces/IContextValues.cs +++ b/Core/Stateflows/Common/Interfaces/IContextValues.cs @@ -1,4 +1,6 @@ -namespace Stateflows.Common.Interfaces +using System.Collections.Generic; + +namespace Stateflows.Common.Interfaces { public interface IContextValues { @@ -8,7 +10,7 @@ public interface IContextValues bool TryGet(string key, out T value); - T GetOrDefault(string key, T defaultValue); + T GetOrDefault(string key, T defaultValue = default); void Remove(string key); diff --git a/Core/Stateflows/StateMachines/Interfaces/Model/IFinalizer.cs b/Core/Stateflows/Common/Interfaces/Model/IFinalizer.cs similarity index 76% rename from Core/Stateflows/StateMachines/Interfaces/Model/IFinalizer.cs rename to Core/Stateflows/Common/Interfaces/Model/IFinalizer.cs index 9430cf30..8cd7f38d 100644 --- a/Core/Stateflows/StateMachines/Interfaces/Model/IFinalizer.cs +++ b/Core/Stateflows/Common/Interfaces/Model/IFinalizer.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace Stateflows.StateMachines +namespace Stateflows.Common { public interface IFinalizer { diff --git a/Core/Stateflows/StateMachines/Interfaces/Model/IInitializer.cs b/Core/Stateflows/Common/Interfaces/Model/IInitializer.cs similarity index 76% rename from Core/Stateflows/StateMachines/Interfaces/Model/IInitializer.cs rename to Core/Stateflows/Common/Interfaces/Model/IInitializer.cs index 364cd1e9..8409cc5e 100644 --- a/Core/Stateflows/StateMachines/Interfaces/Model/IInitializer.cs +++ b/Core/Stateflows/Common/Interfaces/Model/IInitializer.cs @@ -1,7 +1,6 @@ -using Stateflows.Common; -using System.Threading.Tasks; +using System.Threading.Tasks; -namespace Stateflows.StateMachines +namespace Stateflows.Common { public interface IInitializer where TInitializationEvent : Event, new() diff --git a/Core/Stateflows/Common/Scheduler/ThreadScheduler.cs b/Core/Stateflows/Common/Scheduler/ThreadScheduler.cs index 2c0b60fb..e0af578b 100644 --- a/Core/Stateflows/Common/Scheduler/ThreadScheduler.cs +++ b/Core/Stateflows/Common/Scheduler/ThreadScheduler.cs @@ -28,7 +28,7 @@ public Task StartAsync(CancellationToken cancellationToken) { _ = Task.Run(async () => { - await HandleStartupEvents(); + await Executor.ExecuteByTenantsAsync(() => HandleStartupEvents()); await TimingLoop(CancellationTokenSource.Token); }); diff --git a/Core/Stateflows/DependencyInjection.cs b/Core/Stateflows/DependencyInjection.cs index 1ba3fc9e..fed884e0 100644 --- a/Core/Stateflows/DependencyInjection.cs +++ b/Core/Stateflows/DependencyInjection.cs @@ -13,7 +13,6 @@ using Stateflows.Common.Subscription; using Stateflows.Common.Registration.Builders; using Stateflows.Common.Registration.Interfaces; -using Stateflows.StateMachines; namespace Stateflows { diff --git a/Core/Stateflows/StateMachines/Context/ContextHolder.cs b/Core/Stateflows/StateMachines/Context/ContextHolder.cs index f770fd75..a2df1c47 100644 --- a/Core/Stateflows/StateMachines/Context/ContextHolder.cs +++ b/Core/Stateflows/StateMachines/Context/ContextHolder.cs @@ -1,5 +1,5 @@ using System.Threading; -using Stateflows.StateMachines.Context.Interfaces; +using Stateflows.Common; namespace Stateflows.StateMachines.Context { diff --git a/Core/Stateflows/StateMachines/Context/Interfaces/IGuardContext.cs b/Core/Stateflows/StateMachines/Context/Interfaces/IGuardContext.cs deleted file mode 100644 index 9c62ddfc..00000000 --- a/Core/Stateflows/StateMachines/Context/Interfaces/IGuardContext.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Stateflows.Common; - -namespace Stateflows.StateMachines.Context.Interfaces -{ - public interface IGuardContext : ITransitionContext - where TEvent : Event, new() - { } -} diff --git a/Core/Stateflows/StateMachines/Context/Interfaces/IStateMachineActionContext.cs b/Core/Stateflows/StateMachines/Context/Interfaces/IStateMachineActionContext.cs index 3981a41f..e5736a68 100644 --- a/Core/Stateflows/StateMachines/Context/Interfaces/IStateMachineActionContext.cs +++ b/Core/Stateflows/StateMachines/Context/Interfaces/IStateMachineActionContext.cs @@ -2,11 +2,6 @@ namespace Stateflows.StateMachines.Context.Interfaces { - public interface IExecutionContext - { - Event ExecutionTrigger { get; } - } - public interface IInitializationContext { Event InitializationEvent { get; } diff --git a/Core/Stateflows/StateMachines/Context/Interfaces/ITransitionContext.cs b/Core/Stateflows/StateMachines/Context/Interfaces/ITransitionContext.cs index a07c7442..c064dfa9 100644 --- a/Core/Stateflows/StateMachines/Context/Interfaces/ITransitionContext.cs +++ b/Core/Stateflows/StateMachines/Context/Interfaces/ITransitionContext.cs @@ -2,13 +2,6 @@ namespace Stateflows.StateMachines.Context.Interfaces { - public interface ITransitionContext - { - IStateContext SourceState { get; } - - IStateContext TargetState { get; } - } - public interface ITransitionContext : IEventActionContext, ITransitionContext where TEvent : Event, new() { } diff --git a/Core/Stateflows/StateMachines/Engine/Executor.cs b/Core/Stateflows/StateMachines/Engine/Executor.cs index cc541275..24cacfc0 100644 --- a/Core/Stateflows/StateMachines/Engine/Executor.cs +++ b/Core/Stateflows/StateMachines/Engine/Executor.cs @@ -713,7 +713,7 @@ public TFinalizer GetFinalizer(IStateMachineActionContext context) } public TState GetState(IStateActionContext context) - where TState : class, IBaseState + where TState : class, IState { ContextValues.GlobalValuesHolder.Value = context.StateMachine.Values; ContextValues.StateValuesHolder.Value = context.CurrentState.Values; @@ -731,7 +731,7 @@ public TState GetState(IStateActionContext context) } public TTransition GetTransition(ITransitionContext context) - where TTransition : class, IBaseTransition + where TTransition : class, ITransition where TEvent : Event, new() { ContextValues.GlobalValuesHolder.Value = context.StateMachine.Values; @@ -750,7 +750,7 @@ public TTransition GetTransition(ITransitionContext } public TDefaultTransition GetDefaultTransition(ITransitionContext context) - where TDefaultTransition : class, IBaseDefaultTransition + where TDefaultTransition : class, IDefaultTransition { ContextValues.GlobalValuesHolder.Value = context.StateMachine.Values; ContextValues.StateValuesHolder.Value = null; diff --git a/Core/Stateflows/StateMachines/Engine/Plugins/Notifications.cs b/Core/Stateflows/StateMachines/Engine/Plugins/Notifications.cs index 2c4a08d8..e01613b6 100644 --- a/Core/Stateflows/StateMachines/Engine/Plugins/Notifications.cs +++ b/Core/Stateflows/StateMachines/Engine/Plugins/Notifications.cs @@ -68,7 +68,7 @@ public Task AfterStateMachineFinalizeAsync(IStateMachineActionContext context) public Task AfterTransitionEffectAsync(ITransitionContext context) => Task.CompletedTask; - public Task AfterTransitionGuardAsync(IGuardContext context, bool guardResult) + public Task AfterTransitionGuardAsync(ITransitionContext context, bool guardResult) { if (guardResult) { @@ -137,7 +137,7 @@ public Task OnStateMachineFinalizationExceptionAsync(IStateMachineActionContext return Task.CompletedTask; } - public Task OnTransitionGuardExceptionAsync(IGuardContext context, Exception exception) + public Task OnTransitionGuardExceptionAsync(ITransitionContext context, Exception exception) { Trace.WriteLine($"⦗→s⦘ State Machine '{context.StateMachine.Id.Name}:{context.StateMachine.Id.Instance}': unhandled exception '{exception.GetType().Name}' with message '{exception.Message}' on transition guard"); diff --git a/Core/Stateflows/StateMachines/Engine/Plugins/TimeEvents.cs b/Core/Stateflows/StateMachines/Engine/Plugins/TimeEvents.cs index d33562ee..74fbd82d 100644 --- a/Core/Stateflows/StateMachines/Engine/Plugins/TimeEvents.cs +++ b/Core/Stateflows/StateMachines/Engine/Plugins/TimeEvents.cs @@ -114,7 +114,7 @@ public Task AfterProcessEventAsync(IEventActionContext context) return Task.CompletedTask; } - public Task BeforeTransitionGuardAsync(IGuardContext context) + public Task BeforeTransitionGuardAsync(ITransitionContext context) { if (ConsumedInTransition == null && (context as IEdgeContext).Edge.Trigger == context.ExecutionTrigger.Name) { diff --git a/Core/Stateflows/StateMachines/Extensions/BuilderExtensions.cs b/Core/Stateflows/StateMachines/Extensions/BuilderExtensions.cs index 5baf982d..7a38dbae 100644 --- a/Core/Stateflows/StateMachines/Extensions/BuilderExtensions.cs +++ b/Core/Stateflows/StateMachines/Extensions/BuilderExtensions.cs @@ -8,7 +8,7 @@ namespace Stateflows.StateMachines.Extensions internal static class BuilderExtensions { public static void AddStateEvents(this IStateEvents builder) - where TState : class, IBaseState + where TState : class, IState { if (typeof(IStateEntry).IsAssignableFrom(typeof(TState))) { @@ -22,7 +22,7 @@ public static void AddStateEvents(this IStateEvents bu } public static void AddCompositeStateEvents(this ICompositeStateEvents builder) - where TCompositeState : class, IBaseCompositeState + where TCompositeState : class, ICompositeState { if (typeof(ICompositeStateInitialization).IsAssignableFrom(typeof(TCompositeState))) { @@ -46,7 +46,7 @@ public static void AddElseTransitionEvents(this IElseTr } public static void AddTransitionEvents(this ITransitionBuilder builder) - where TTransition : class, IBaseTransition + where TTransition : class, ITransition where TEvent : Event, new() { if (typeof(ITransitionGuard).IsAssignableFrom(typeof(TTransition))) @@ -61,7 +61,7 @@ public static void AddTransitionEvents(this ITransitionBuil } public static void AddDefaultTransitionEvents(this IDefaultTransitionBuilder builder) - where TTransition : class, IBaseDefaultTransition + where TTransition : class, IDefaultTransition { if (typeof(IDefaultTransitionGuard).IsAssignableFrom(typeof(TTransition))) { diff --git a/Core/Stateflows/StateMachines/Helpers/TransitionGuard.cs b/Core/Stateflows/StateMachines/Helpers/TransitionGuard.cs index cfea5749..05c38894 100644 --- a/Core/Stateflows/StateMachines/Helpers/TransitionGuard.cs +++ b/Core/Stateflows/StateMachines/Helpers/TransitionGuard.cs @@ -7,15 +7,15 @@ namespace Stateflows.StateMachines { public static class TransitionGuard { - public static Task Empty(IGuardContext context) + public static Task Empty(ITransitionContext context) where TEvent : Event, new() => Allow(context); - public static Task Allow(IGuardContext _) + public static Task Allow(ITransitionContext _) where TEvent : Event, new() => Task.FromResult(true); - public static Func, Task> ToAsync(this Func, bool> guard) + public static Func, Task> ToAsync(this Func, bool> guard) where TEvent : Event, new() => c => Task.FromResult(guard(c)); } diff --git a/Core/Stateflows/StateMachines/Inspection/Interfaces/IGuardInspectionContext.cs b/Core/Stateflows/StateMachines/Inspection/Interfaces/IGuardInspectionContext.cs index 72746636..bf4c8092 100644 --- a/Core/Stateflows/StateMachines/Inspection/Interfaces/IGuardInspectionContext.cs +++ b/Core/Stateflows/StateMachines/Inspection/Interfaces/IGuardInspectionContext.cs @@ -3,7 +3,7 @@ namespace Stateflows.StateMachines.Inspection.Interfaces { - public interface IGuardInspectionContext : IGuardContext + public interface IGuardInspectionContext : ITransitionContext where TEvent : Event, new() { new IStateMachineInspectionContext StateMachine { get; } diff --git a/Core/Stateflows/StateMachines/Context/Interfaces/IStateContext.cs b/Core/Stateflows/StateMachines/Interfaces/Context/IStateContext.cs similarity index 81% rename from Core/Stateflows/StateMachines/Context/Interfaces/IStateContext.cs rename to Core/Stateflows/StateMachines/Interfaces/Context/IStateContext.cs index 1deafa4a..3deef5c8 100644 --- a/Core/Stateflows/StateMachines/Context/Interfaces/IStateContext.cs +++ b/Core/Stateflows/StateMachines/Interfaces/Context/IStateContext.cs @@ -1,6 +1,6 @@ using Stateflows.Common.Interfaces; -namespace Stateflows.StateMachines.Context.Interfaces +namespace Stateflows.StateMachines { public interface IStateContext { diff --git a/Core/Stateflows/StateMachines/Context/Interfaces/IStateMachineContext.cs b/Core/Stateflows/StateMachines/Interfaces/Context/IStateMachineContext.cs similarity index 75% rename from Core/Stateflows/StateMachines/Context/Interfaces/IStateMachineContext.cs rename to Core/Stateflows/StateMachines/Interfaces/Context/IStateMachineContext.cs index f8f907b9..ed821189 100644 --- a/Core/Stateflows/StateMachines/Context/Interfaces/IStateMachineContext.cs +++ b/Core/Stateflows/StateMachines/Interfaces/Context/IStateMachineContext.cs @@ -1,6 +1,6 @@ using Stateflows.Common.Context.Interfaces; -namespace Stateflows.StateMachines.Context.Interfaces +namespace Stateflows.StateMachines { public interface IStateMachineContext : IBehaviorContext { diff --git a/Core/Stateflows/StateMachines/Interfaces/Context/ITransitionContext.cs b/Core/Stateflows/StateMachines/Interfaces/Context/ITransitionContext.cs new file mode 100644 index 00000000..48776184 --- /dev/null +++ b/Core/Stateflows/StateMachines/Interfaces/Context/ITransitionContext.cs @@ -0,0 +1,9 @@ +namespace Stateflows.StateMachines +{ + public interface ITransitionContext + { + IStateContext SourceState { get; } + + IStateContext TargetState { get; } + } +} diff --git a/Core/Stateflows/StateMachines/Interfaces/IStateMachineExceptionHandler.cs b/Core/Stateflows/StateMachines/Interfaces/IStateMachineExceptionHandler.cs index 2f50d968..db223b28 100644 --- a/Core/Stateflows/StateMachines/Interfaces/IStateMachineExceptionHandler.cs +++ b/Core/Stateflows/StateMachines/Interfaces/IStateMachineExceptionHandler.cs @@ -13,7 +13,7 @@ Task OnStateMachineInitializationExceptionAsync(IStateMachineInitializatio Task OnStateMachineFinalizationExceptionAsync(IStateMachineActionContext context, Exception exception) => Task.FromResult(false); - Task OnTransitionGuardExceptionAsync(IGuardContext context, Exception exception) + Task OnTransitionGuardExceptionAsync(ITransitionContext context, Exception exception) => Task.FromResult(false); Task OnTransitionEffectExceptionAsync(ITransitionContext context, Exception exception) diff --git a/Core/Stateflows/StateMachines/Interfaces/IStateMachineObserver.cs b/Core/Stateflows/StateMachines/Interfaces/IStateMachineObserver.cs index c5a4dde8..7a31dc91 100644 --- a/Core/Stateflows/StateMachines/Interfaces/IStateMachineObserver.cs +++ b/Core/Stateflows/StateMachines/Interfaces/IStateMachineObserver.cs @@ -42,10 +42,10 @@ Task BeforeStateExitAsync(IStateActionContext context) Task AfterStateExitAsync(IStateActionContext context) => Task.CompletedTask; - Task BeforeTransitionGuardAsync(IGuardContext context) + Task BeforeTransitionGuardAsync(ITransitionContext context) => Task.CompletedTask; - Task AfterTransitionGuardAsync(IGuardContext context, bool guardResult) + Task AfterTransitionGuardAsync(ITransitionContext context, bool guardResult) => Task.CompletedTask; Task BeforeTransitionEffectAsync(ITransitionContext context) diff --git a/Core/Stateflows/StateMachines/Interfaces/Model/ICompositeState.cs b/Core/Stateflows/StateMachines/Interfaces/Model/ICompositeState.cs index 024412cf..c46729fa 100644 --- a/Core/Stateflows/StateMachines/Interfaces/Model/ICompositeState.cs +++ b/Core/Stateflows/StateMachines/Interfaces/Model/ICompositeState.cs @@ -2,25 +2,25 @@ namespace Stateflows.StateMachines { - public interface IBaseCompositeState : IBaseState + public interface ICompositeState : IState { } - public interface ICompositeStateEntry : IBaseCompositeState + public interface ICompositeStateEntry : ICompositeState { Task OnEntryAsync(); } - public interface ICompositeStateExit : IBaseCompositeState + public interface ICompositeStateExit : ICompositeState { Task OnExitAsync(); } - public interface ICompositeStateInitialization : IBaseCompositeState + public interface ICompositeStateInitialization : ICompositeState { Task OnInitializeAsync(); } - public interface ICompositeStateFinalization : IBaseCompositeState + public interface ICompositeStateFinalization : ICompositeState { Task OnFinalizeAsync(); } diff --git a/Core/Stateflows/StateMachines/Interfaces/Model/IDefaultTransition.cs b/Core/Stateflows/StateMachines/Interfaces/Model/IDefaultTransition.cs new file mode 100644 index 00000000..780dc539 --- /dev/null +++ b/Core/Stateflows/StateMachines/Interfaces/Model/IDefaultTransition.cs @@ -0,0 +1,17 @@ +using System.Threading.Tasks; + +namespace Stateflows.StateMachines +{ + public interface IDefaultTransition + { } + + public interface IDefaultTransitionEffect : IDefaultTransition + { + Task EffectAsync(); + } + + public interface IDefaultTransitionGuard : IDefaultTransition + { + Task GuardAsync(); + } +} diff --git a/Core/Stateflows/StateMachines/Interfaces/Model/IState.cs b/Core/Stateflows/StateMachines/Interfaces/Model/IState.cs index 8d7e9422..615e1a99 100644 --- a/Core/Stateflows/StateMachines/Interfaces/Model/IState.cs +++ b/Core/Stateflows/StateMachines/Interfaces/Model/IState.cs @@ -5,15 +5,15 @@ namespace Stateflows.StateMachines public interface IVertex { } - public interface IBaseState : IVertex + public interface IState : IVertex { } - public interface IStateEntry : IBaseState + public interface IStateEntry : IState { Task OnEntryAsync(); } - public interface IStateExit : IBaseState + public interface IStateExit : IState { Task OnExitAsync(); } diff --git a/Core/Stateflows/StateMachines/Interfaces/Model/ITransition.cs b/Core/Stateflows/StateMachines/Interfaces/Model/ITransition.cs index c60f57d5..cd156956 100644 --- a/Core/Stateflows/StateMachines/Interfaces/Model/ITransition.cs +++ b/Core/Stateflows/StateMachines/Interfaces/Model/ITransition.cs @@ -3,32 +3,19 @@ namespace Stateflows.StateMachines { - public interface IBaseTransition + public interface ITransition where TEvent : Event, new() { } - public interface ITransitionEffect : IBaseTransition + public interface ITransitionEffect : ITransition where TEvent : Event, new() { Task EffectAsync(TEvent @event); } - public interface ITransitionGuard : IBaseTransition + public interface ITransitionGuard : ITransition where TEvent : Event, new() { Task GuardAsync(TEvent @event); } - - public interface IBaseDefaultTransition - { } - - public interface IDefaultTransitionEffect : IBaseDefaultTransition - { - Task EffectAsync(); - } - - public interface IDefaultTransitionGuard : IBaseDefaultTransition - { - Task GuardAsync(); - } } diff --git a/Core/Stateflows/StateMachines/Registration/Builders/TransitionBuilder.cs b/Core/Stateflows/StateMachines/Registration/Builders/TransitionBuilder.cs index ac88c0fe..fbe38f15 100644 --- a/Core/Stateflows/StateMachines/Registration/Builders/TransitionBuilder.cs +++ b/Core/Stateflows/StateMachines/Registration/Builders/TransitionBuilder.cs @@ -35,7 +35,7 @@ public TransitionBuilder(Edge edge) Edge = edge; } - public ITransitionBuilder AddGuard(Func, Task> guardAsync) + public ITransitionBuilder AddGuard(Func, Task> guardAsync) { guardAsync.ThrowIfNull(nameof(guardAsync)); @@ -115,7 +115,7 @@ public ITransitionBuilder AddEffect(Func, Tas IInternalTransitionBuilder IEffect>.AddEffect(Func, Task> effectAsync) => AddEffect(effectAsync) as IInternalTransitionBuilder; - IInternalTransitionBuilder IGuard>.AddGuard(Func, Task> guardAsync) + IInternalTransitionBuilder IGuard>.AddGuard(Func, Task> guardAsync) => AddGuard(guardAsync) as IInternalTransitionBuilder; IElseTransitionBuilder IEffect>.AddEffect(Func, Task> effectAsync) @@ -127,13 +127,13 @@ IElseInternalTransitionBuilder IEffect.AddEffect(Func, Task> effectAsync) => AddEffect(c => effectAsync(c as ITransitionContext)) as IDefaultTransitionBuilder; - IDefaultTransitionBuilder IGuard.AddGuard(Func, Task> guardAsync) - => AddGuard(c => guardAsync(c as IGuardContext)) as IDefaultTransitionBuilder; + IDefaultTransitionBuilder IGuard.AddGuard(Func, Task> guardAsync) + => AddGuard(c => guardAsync(c as ITransitionContext)) as IDefaultTransitionBuilder; IElseDefaultTransitionBuilder IEffect.AddEffect(Func, Task> effectAsync) => AddEffect(c => effectAsync(c as ITransitionContext)) as IElseDefaultTransitionBuilder; - IForwardedEventBuilder IGuard>.AddGuard(Func, Task> guardAsync) + IForwardedEventBuilder IGuard>.AddGuard(Func, Task> guardAsync) => AddGuard(guardAsync) as IForwardedEventBuilder; } } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Base/IGuard.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Base/IGuard.cs index 914c478b..d89fea70 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Base/IGuard.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Base/IGuard.cs @@ -8,6 +8,6 @@ namespace Stateflows.StateMachines.Registration.Interfaces.Base public interface IGuard where TEvent : Event, new() { - TReturn AddGuard(Func, Task> guardAsync); + TReturn AddGuard(Func, Task> guardAsync); } } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorStateBuilder/Transitions/BehaviorStateBuilderDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorStateBuilder/Transitions/BehaviorStateBuilderDefaultTransitionTypedExtensions.cs index c111f872..45b615a8 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorStateBuilder/Transitions/BehaviorStateBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorStateBuilder/Transitions/BehaviorStateBuilderDefaultTransitionTypedExtensions.cs @@ -40,7 +40,7 @@ public static class BehaviorStateBuilderDefaultTransitionTypedExtensions /// [DebuggerHidden] public static IBehaviorStateBuilder AddDefaultTransition(this IBehaviorStateBuilder builder) - where TTransition : class, IBaseDefaultTransition + where TTransition : class, IDefaultTransition where TTargetState : class, IVertex => builder.AddDefaultTransition(State.Name); @@ -67,7 +67,7 @@ public static IBehaviorStateBuilder AddDefaultTransitionTarget state name [DebuggerHidden] public static IBehaviorStateBuilder AddDefaultTransition(this IBehaviorStateBuilder builder, string targetStateName) - where TTransition : class, IBaseDefaultTransition + where TTransition : class, IDefaultTransition { (builder as IInternal).Services.AddServiceType(); diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorStateBuilder/Transitions/BehaviorStateBuilderInternalTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorStateBuilder/Transitions/BehaviorStateBuilderInternalTransitionTypedExtensions.cs index ab573587..63cb906e 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorStateBuilder/Transitions/BehaviorStateBuilderInternalTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorStateBuilder/Transitions/BehaviorStateBuilderInternalTransitionTypedExtensions.cs @@ -31,7 +31,7 @@ public static class BehaviorStateBuilderInternalTransitionTypedExtensions [DebuggerHidden] public static IBehaviorStateBuilder AddInternalTransition(this IBehaviorStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition => builder.AddTransition(Constants.DefaultTransitionTarget); } } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorStateBuilder/Transitions/BehaviorStateBuilderTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorStateBuilder/Transitions/BehaviorStateBuilderTransitionTypedExtensions.cs index 2ea423f1..c678e4ab 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorStateBuilder/Transitions/BehaviorStateBuilderTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorStateBuilder/Transitions/BehaviorStateBuilderTransitionTypedExtensions.cs @@ -47,7 +47,7 @@ public static class BehaviorStateBuilderTransitionTypedExtensions [DebuggerHidden] public static IBehaviorStateBuilder AddTransition(this IBehaviorStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition where TTargetState : class, IVertex => AddTransition(builder, State.Name); @@ -80,7 +80,7 @@ public static IBehaviorStateBuilder AddTransition(this IBehaviorStateBuilder builder, string targetStateName) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition { (builder as IInternal).Services.AddServiceType(); diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorTypedStateBuilder/Transitions/BehaviorTypedStateBuilderDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorTypedStateBuilder/Transitions/BehaviorTypedStateBuilderDefaultTransitionTypedExtensions.cs index 5ece8b25..9e93df82 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorTypedStateBuilder/Transitions/BehaviorTypedStateBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorTypedStateBuilder/Transitions/BehaviorTypedStateBuilderDefaultTransitionTypedExtensions.cs @@ -40,7 +40,7 @@ public static class BehaviorTypedStateBuilderDefaultTransitionTypedExtensions /// [DebuggerHidden] public static IBehaviorTypedStateBuilder AddDefaultTransition(this IBehaviorTypedStateBuilder builder) - where TTransition : class, IBaseDefaultTransition + where TTransition : class, IDefaultTransition where TTargetState : class, IVertex => builder.AddDefaultTransition(State.Name); @@ -67,7 +67,7 @@ public static IBehaviorTypedStateBuilder AddDefaultTransitionTarget state name [DebuggerHidden] public static IBehaviorTypedStateBuilder AddDefaultTransition(this IBehaviorTypedStateBuilder builder, string targetStateName) - where TTransition : class, IBaseDefaultTransition + where TTransition : class, IDefaultTransition { (builder as IInternal).Services.AddServiceType(); diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorTypedStateBuilder/Transitions/BehaviorTypedStateBuilderInternalTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorTypedStateBuilder/Transitions/BehaviorTypedStateBuilderInternalTransitionTypedExtensions.cs index 4027945c..9fcf839b 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorTypedStateBuilder/Transitions/BehaviorTypedStateBuilderInternalTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorTypedStateBuilder/Transitions/BehaviorTypedStateBuilderInternalTransitionTypedExtensions.cs @@ -31,7 +31,7 @@ public static class BehaviorTypedStateBuilderInternalTransitionTypedExtensions [DebuggerHidden] public static IBehaviorTypedStateBuilder AddInternalTransition(this IBehaviorTypedStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition => builder.AddTransition(Constants.DefaultTransitionTarget); } } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorTypedStateBuilder/Transitions/BehaviorTypedStateBuilderTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorTypedStateBuilder/Transitions/BehaviorTypedStateBuilderTransitionTypedExtensions.cs index d413824c..22fe20b3 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorTypedStateBuilder/Transitions/BehaviorTypedStateBuilderTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/BehaviorTypedStateBuilder/Transitions/BehaviorTypedStateBuilderTransitionTypedExtensions.cs @@ -47,7 +47,7 @@ public static class BehaviorTypedStateBuilderTransitionTypedExtensions [DebuggerHidden] public static IBehaviorTypedStateBuilder AddTransition(this IBehaviorTypedStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition where TTargetState : class, IVertex => AddTransition(builder, State.Name); @@ -80,7 +80,7 @@ public static IBehaviorTypedStateBuilder AddTransition(this IBehaviorTypedStateBuilder builder, string targetStateName) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition { (builder as IInternal).Services.AddServiceType(); diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/StateMachine/CompositeStateBuilderTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/StateMachine/CompositeStateBuilderTypedExtensions.cs index a48a033f..9aeef842 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/StateMachine/CompositeStateBuilderTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/StateMachine/CompositeStateBuilderTypedExtensions.cs @@ -16,7 +16,7 @@ public static class CompositeStateBuilderTypedExtensions /// State build action [DebuggerHidden] public static IInitializedCompositeStateBuilder AddInitialState(this ICompositeStateBuilder builder, StateTransitionsBuildAction stateBuildAction = null) - where TState : class, IBaseState + where TState : class, IState => builder.AddInitialState(State.Name, stateBuildAction); /// @@ -27,7 +27,7 @@ public static IInitializedCompositeStateBuilder AddInitialState(this ICo /// State build action [DebuggerHidden] public static IInitializedCompositeStateBuilder AddInitialState(this ICompositeStateBuilder builder, string stateName, StateTransitionsBuildAction stateBuildAction = null) - where TState : class, IBaseState + where TState : class, IState { (builder as IInternal).Services.AddServiceType(); @@ -51,7 +51,7 @@ public static IInitializedCompositeStateBuilder AddInitialState(this ICo /// Composite state build action [DebuggerHidden] public static IInitializedCompositeStateBuilder AddInitialCompositeState(this ICompositeStateBuilder builder, CompositeStateTransitionsBuildAction compositeStateBuildAction) - where TCompositeState : class, IBaseCompositeState + where TCompositeState : class, ICompositeState => builder.AddInitialCompositeState(State.Name, compositeStateBuildAction); /// @@ -62,7 +62,7 @@ public static IInitializedCompositeStateBuilder AddInitialCompositeStateComposite state build action [DebuggerHidden] public static IInitializedCompositeStateBuilder AddInitialCompositeState(this ICompositeStateBuilder builder, string compositeStateName, CompositeStateTransitionsBuildAction compositeStateBuildAction) - where TCompositeState : class, IBaseCompositeState + where TCompositeState : class, ICompositeState { (builder as IInternal).Services.AddServiceType(); diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/StateMachine/InitializedCompositeStateBuilderTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/StateMachine/InitializedCompositeStateBuilderTypedExtensions.cs index 9427bad9..8f9b7435 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/StateMachine/InitializedCompositeStateBuilderTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/StateMachine/InitializedCompositeStateBuilderTypedExtensions.cs @@ -28,7 +28,7 @@ public static IFinalizedCompositeStateBuilder AddState(this IInitia /// State build action [DebuggerHidden] public static IInitializedCompositeStateBuilder AddState(this IInitializedCompositeStateBuilder builder, StateTransitionsBuildAction stateBuildAction = null) - where TState : class, IBaseState + where TState : class, IState => builder.AddState(State.Name, stateBuildAction); /// @@ -40,7 +40,7 @@ public static IInitializedCompositeStateBuilder AddState(this IInitializ /// [DebuggerHidden] public static IInitializedCompositeStateBuilder AddState(this IInitializedCompositeStateBuilder builder, string stateName, StateTransitionsBuildAction stateBuildAction = null) - where TState : class, IBaseState + where TState : class, IState { (builder as IInternal).Services.AddServiceType(); @@ -64,7 +64,7 @@ public static IInitializedCompositeStateBuilder AddState(this IInitializ /// Composite state build action [DebuggerHidden] public static IInitializedCompositeStateBuilder AddCompositeState(this IInitializedCompositeStateBuilder builder, CompositeStateTransitionsBuildAction compositeStateBuildAction) - where TCompositeState : class, IBaseCompositeState + where TCompositeState : class, ICompositeState => builder.AddCompositeState(State.Name, compositeStateBuildAction); /// @@ -75,7 +75,7 @@ public static IInitializedCompositeStateBuilder AddCompositeStateComposite state build action [DebuggerHidden] public static IInitializedCompositeStateBuilder AddCompositeState(this IInitializedCompositeStateBuilder builder, string compositeStateName, CompositeStateTransitionsBuildAction compositeStateBuildAction) - where TCompositeState : class, IBaseCompositeState + where TCompositeState : class, ICompositeState { (builder as IInternal).Services.AddServiceType(); diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/CompositeStateBuilderDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/CompositeStateBuilderDefaultTransitionTypedExtensions.cs index c6f496af..c8b45b9d 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/CompositeStateBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/CompositeStateBuilderDefaultTransitionTypedExtensions.cs @@ -37,7 +37,7 @@ public static class CompositeStateBuilderDefaultTransitionTypedExtensions /// [DebuggerHidden] public static ICompositeStateBuilder AddDefaultTransition(this ICompositeStateBuilder builder) - where TDefaultTransition : class, IBaseDefaultTransition + where TDefaultTransition : class, IDefaultTransition where TTargetState : class, IVertex => builder.AddDefaultTransition(State.Name); @@ -64,8 +64,8 @@ public static ICompositeStateBuilder AddDefaultTransitionTarget state name [DebuggerHidden] public static ICompositeStateBuilder AddDefaultTransition(this ICompositeStateBuilder builder, string targetStateName) - where TDefaultTransition : class, IBaseDefaultTransition - => (builder as IStateBuilder).AddDefaultTransition(targetStateName) as ICompositeStateBuilder; + where TDefaultTransition : class, IDefaultTransition + => builder.AddDefaultTransition(targetStateName); /// /// Adds default transition coming from current state.
diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/CompositeStateBuilderInternalTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/CompositeStateBuilderInternalTransitionTypedExtensions.cs index 438117bd..365740b7 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/CompositeStateBuilderInternalTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/CompositeStateBuilderInternalTransitionTypedExtensions.cs @@ -31,7 +31,7 @@ public static class CompositeStateBuilderInternalTransitionTypedExtensions [DebuggerHidden] public static ICompositeStateBuilder AddInternalTransition(this ICompositeStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition => builder.AddTransition(Constants.DefaultTransitionTarget); } } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/CompositeStateBuilderTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/CompositeStateBuilderTransitionTypedExtensions.cs index 7830d33b..1368dffe 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/CompositeStateBuilderTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/CompositeStateBuilderTransitionTypedExtensions.cs @@ -1,6 +1,9 @@ using System.Diagnostics; using Stateflows.Common; +using Stateflows.Common.Extensions; +using Stateflows.StateMachines.Extensions; using Stateflows.StateMachines.Registration.Interfaces; +using Stateflows.StateMachines.Registration.Interfaces.Internal; namespace Stateflows.StateMachines.Typed { @@ -44,7 +47,7 @@ public static class CompositeStateBuilderTransitionTypedExtensions [DebuggerHidden] public static ICompositeStateBuilder AddTransition(this ICompositeStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition where TTargetState : class, IVertex => AddTransition(builder, State.Name); @@ -77,8 +80,15 @@ public static ICompositeStateBuilder AddTransition(this ICompositeStateBuilder builder, string targetStateName) where TEvent : Event, new() - where TTransition : class, IBaseTransition - => (builder as IStateBuilder).AddTransition(targetStateName) as ICompositeStateBuilder; + where TTransition : class, ITransition + { + (builder as IInternal).Services.AddServiceType(); + + return builder.AddTransition( + targetStateName, + t => t.AddTransitionEvents() + ); + } /// /// Adds transition triggered by coming from current state.
diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/FinalizedCompositeStateBuilderDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/FinalizedCompositeStateBuilderDefaultTransitionTypedExtensions.cs index 2e665e5d..43b45fe8 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/FinalizedCompositeStateBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/FinalizedCompositeStateBuilderDefaultTransitionTypedExtensions.cs @@ -37,7 +37,7 @@ public static class FinalizedCompositeStateBuilderDefaultTransitionTypedExtensio /// [DebuggerHidden] public static IFinalizedCompositeStateBuilder AddDefaultTransition(this IFinalizedCompositeStateBuilder builder) - where TDefaultTransition : class, IBaseDefaultTransition + where TDefaultTransition : class, IDefaultTransition where TTargetState : class, IVertex => builder.AddDefaultTransition(State.Name); @@ -64,8 +64,8 @@ public static IFinalizedCompositeStateBuilder AddDefaultTransitionTarget state name [DebuggerHidden] public static IFinalizedCompositeStateBuilder AddDefaultTransition(this IFinalizedCompositeStateBuilder builder, string targetStateName) - where TDefaultTransition : class, IBaseDefaultTransition - => (builder as IStateBuilder).AddDefaultTransition(targetStateName) as IFinalizedCompositeStateBuilder; + where TDefaultTransition : class, IDefaultTransition + => (builder as ICompositeStateBuilder).AddDefaultTransition(targetStateName) as IFinalizedCompositeStateBuilder; /// /// Adds default transition coming from current state.
diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/FinalizedCompositeStateBuilderInternalTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/FinalizedCompositeStateBuilderInternalTransitionTypedExtensions.cs index 4ddbd2a4..dd5eaf44 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/FinalizedCompositeStateBuilderInternalTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/FinalizedCompositeStateBuilderInternalTransitionTypedExtensions.cs @@ -31,7 +31,7 @@ public static class FinalizedCompositeStateBuilderInternalTransitionTypedExtensi [DebuggerHidden] public static IFinalizedCompositeStateBuilder AddInternalTransition(this IFinalizedCompositeStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition => builder.AddTransition(Constants.DefaultTransitionTarget); } } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/FinalizedCompositeStateBuilderTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/FinalizedCompositeStateBuilderTransitionTypedExtensions.cs index 3a5be877..eb7833b3 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/FinalizedCompositeStateBuilderTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/FinalizedCompositeStateBuilderTransitionTypedExtensions.cs @@ -44,7 +44,7 @@ public static class FinalizedCompositeStateBuilderTransitionTypedExtensions [DebuggerHidden] public static IFinalizedCompositeStateBuilder AddTransition(this IFinalizedCompositeStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition where TTargetState : class, IVertex => AddTransition(builder, State.Name); @@ -77,8 +77,8 @@ public static IFinalizedCompositeStateBuilder AddTransition(this IFinalizedCompositeStateBuilder builder, string targetStateName) where TEvent : Event, new() - where TTransition : class, IBaseTransition - => (builder as IStateBuilder).AddTransition(targetStateName) as IFinalizedCompositeStateBuilder; + where TTransition : class, ITransition + => (builder as ICompositeStateBuilder).AddTransition(targetStateName) as IFinalizedCompositeStateBuilder; /// /// Adds transition triggered by coming from current state.
diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/InitializedCompositeStateBuilderDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/InitializedCompositeStateBuilderDefaultTransitionTypedExtensions.cs index 7a551ae6..45faa6ac 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/InitializedCompositeStateBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/InitializedCompositeStateBuilderDefaultTransitionTypedExtensions.cs @@ -37,7 +37,7 @@ public static class InitializedCompositeStateBuilderDefaultTransitionTypedExtens /// [DebuggerHidden] public static IInitializedCompositeStateBuilder AddDefaultTransition(this IInitializedCompositeStateBuilder builder) - where TDefaultTransition : class, IBaseDefaultTransition + where TDefaultTransition : class, IDefaultTransition where TTargetState : class, IVertex => builder.AddDefaultTransition(State.Name); @@ -64,8 +64,8 @@ public static IInitializedCompositeStateBuilder AddDefaultTransitionTarget state name [DebuggerHidden] public static IInitializedCompositeStateBuilder AddDefaultTransition(this IInitializedCompositeStateBuilder builder, string targetStateName) - where TDefaultTransition : class, IBaseDefaultTransition - => (builder as IStateBuilder).AddDefaultTransition(targetStateName) as IInitializedCompositeStateBuilder; + where TDefaultTransition : class, IDefaultTransition + => (builder as ICompositeStateBuilder).AddDefaultTransition(targetStateName) as IInitializedCompositeStateBuilder; /// /// Adds default transition coming from current state.
diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/InitializedCompositeStateBuilderInternalTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/InitializedCompositeStateBuilderInternalTransitionTypedExtensions.cs index 94a96f46..a8f4bffd 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/InitializedCompositeStateBuilderInternalTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/InitializedCompositeStateBuilderInternalTransitionTypedExtensions.cs @@ -31,7 +31,7 @@ public static class InitializedCompositeStateBuilderInternalTransitionTypedExten [DebuggerHidden] public static IInitializedCompositeStateBuilder AddInternalTransition(this IInitializedCompositeStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition => builder.AddTransition(Constants.DefaultTransitionTarget); } } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/InitializedCompositeStateBuilderTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/InitializedCompositeStateBuilderTransitionTypedExtensions.cs index 7f70fd1d..973c5b07 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/InitializedCompositeStateBuilderTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/InitializedCompositeStateBuilderTransitionTypedExtensions.cs @@ -44,7 +44,7 @@ public static class InitializedCompositeStateBuilderTransitionTypedExtensions [DebuggerHidden] public static IInitializedCompositeStateBuilder AddTransition(this IInitializedCompositeStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition where TTargetState : class, IVertex => AddTransition(builder, State.Name); @@ -77,8 +77,8 @@ public static IInitializedCompositeStateBuilder AddTransition(this IInitializedCompositeStateBuilder builder, string targetStateName) where TEvent : Event, new() - where TTransition : class, IBaseTransition - => (builder as IStateBuilder).AddTransition(targetStateName) as IInitializedCompositeStateBuilder; + where TTransition : class, ITransition + => (builder as ICompositeStateBuilder).AddTransition(targetStateName) as IInitializedCompositeStateBuilder; /// /// Adds transition triggered by coming from current state.
diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/Transitions/StateBuilderDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/Transitions/StateBuilderDefaultTransitionTypedExtensions.cs index 36c68147..49e8b545 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/Transitions/StateBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/Transitions/StateBuilderDefaultTransitionTypedExtensions.cs @@ -40,7 +40,7 @@ public static class StateBuilderDefaultTransitionTypedExtensions /// [DebuggerHidden] public static IStateBuilder AddDefaultTransition(this IStateBuilder builder) - where TTransition : class, IBaseDefaultTransition + where TTransition : class, IDefaultTransition where TTargetState : class, IVertex => builder.AddDefaultTransition(State.Name); @@ -67,7 +67,7 @@ public static IStateBuilder AddDefaultTransition(this /// Target state name [DebuggerHidden] public static IStateBuilder AddDefaultTransition(this IStateBuilder builder, string targetStateName) - where TTransition : class, IBaseDefaultTransition + where TTransition : class, IDefaultTransition { (builder as IInternal).Services.AddServiceType(); diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/Transitions/StateBuilderInternalTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/Transitions/StateBuilderInternalTransitionTypedExtensions.cs index 63c197b2..f51992d2 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/Transitions/StateBuilderInternalTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/Transitions/StateBuilderInternalTransitionTypedExtensions.cs @@ -31,7 +31,7 @@ public static class StateBuilderInternalTransitionTypedExtensions [DebuggerHidden] public static IStateBuilder AddInternalTransition(this IStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition => builder.AddTransition(Constants.DefaultTransitionTarget); } } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/Transitions/StateBuilderTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/Transitions/StateBuilderTransitionTypedExtensions.cs index db8609c6..4a344cbc 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/Transitions/StateBuilderTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/Transitions/StateBuilderTransitionTypedExtensions.cs @@ -47,7 +47,7 @@ public static class StateBuilderTransitionTypedExtensions [DebuggerHidden] public static IStateBuilder AddTransition(this IStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition where TTargetState : class, IVertex => AddTransition(builder, State.Name); @@ -80,7 +80,7 @@ public static IStateBuilder AddTransition(thi [DebuggerHidden] public static IStateBuilder AddTransition(this IStateBuilder builder, string targetStateName) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition { (builder as IInternal).Services.AddServiceType(); diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/FinalizedStateMachineBuilderEventsSyncExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/FinalizedStateMachineBuilderEventsSyncExtensions.cs deleted file mode 100644 index aac4c6eb..00000000 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/FinalizedStateMachineBuilderEventsSyncExtensions.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Diagnostics; -using Stateflows.Common; -using Stateflows.StateMachines.Context.Interfaces; -using Stateflows.StateMachines.Registration.Builders; -using Stateflows.StateMachines.Registration.Extensions; - -namespace Stateflows.StateMachines.Sync -{ - public static class FinalizedStateMachineBuilderEventsSyncExtensions - { - [DebuggerHidden] - public static IFinalizedStateMachineBuilder AddDefaultInitializer(this IFinalizedStateMachineBuilder builder, Func stateMachineAction) - => builder.AddDefaultInitializer(stateMachineAction - .AddStateMachineInvocationContext((builder as StateMachineBuilder).Result) - .ToAsync() - ); - - [DebuggerHidden] - public static IFinalizedStateMachineBuilder AddInitializer(this IFinalizedStateMachineBuilder builder, Func, bool> stateMachineAction) - where TInitializationEvent : Event, new() - => builder.AddInitializer(stateMachineAction - .AddStateMachineInvocationContext((builder as StateMachineBuilder).Result) - .ToAsync() - ); - - [DebuggerHidden] - public static IFinalizedStateMachineBuilder AddFinalizer(this IFinalizedStateMachineBuilder builder, Action stateMachineAction) - => builder.AddFinalizer(stateMachineAction - .AddStateMachineInvocationContext((builder as StateMachineBuilder).Result) - .ToAsync() - ); - } -} diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/FinalizedStateMachineBuilderEventsTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/FinalizedStateMachineBuilderEventsTypedExtensions.cs new file mode 100644 index 00000000..8399c0c5 --- /dev/null +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/FinalizedStateMachineBuilderEventsTypedExtensions.cs @@ -0,0 +1,39 @@ +using Stateflows.Common; +using System.Diagnostics; +using Stateflows.Common.Extensions; +using Stateflows.StateMachines.Context.Classes; +using Stateflows.StateMachines.Registration.Interfaces.Internal; + +namespace Stateflows.StateMachines.Typed +{ + public static class FinalizedStateMachineBuilderEventsTypedExtensions + { + [DebuggerHidden] + public static IFinalizedStateMachineBuilder AddDefaultInitializer(this IFinalizedStateMachineBuilder builder) + where TInitializer : class, IDefaultInitializer + { + (builder as IInternal).Services.AddServiceType(); + + return builder.AddDefaultInitializer(c => (c as BaseContext).Context.Executor.GetDefaultInitializer(c)?.OnInitializeAsync()); + } + + [DebuggerHidden] + public static IFinalizedStateMachineBuilder AddInitializer(this IFinalizedStateMachineBuilder builder) + where TInitializationEvent : Event, new() + where TInitializer : class, IInitializer + { + (builder as IInternal).Services.AddServiceType(); + + return builder.AddInitializer(c => (c as BaseContext).Context.Executor.GetInitializer(c)?.OnInitializeAsync(c.InitializationEvent)); + } + + [DebuggerHidden] + public static IFinalizedStateMachineBuilder AddFinalizer(this IFinalizedStateMachineBuilder builder) + where TFinalizer : class, IFinalizer + { + (builder as IInternal).Services.AddServiceType(); + + return builder.AddFinalizer(c => (c as BaseContext).Context.Executor.GetFinalizer(c)?.OnFinalizeAsync()); + } + } +} diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/InitializedStateMachineBuilderEventsSyncExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/InitializedStateMachineBuilderEventsSyncExtensions.cs deleted file mode 100644 index ffa4c7ca..00000000 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/InitializedStateMachineBuilderEventsSyncExtensions.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Diagnostics; -using Stateflows.Common; -using Stateflows.StateMachines.Context.Interfaces; -using Stateflows.StateMachines.Registration.Builders; -using Stateflows.StateMachines.Registration.Extensions; - -namespace Stateflows.StateMachines.Sync -{ - public static class InitializedStateMachineBuilderEventsSyncExtensions - { - [DebuggerHidden] - public static IInitializedStateMachineBuilder AddDefaultInitializer(this IInitializedStateMachineBuilder builder, Func stateMachineAction) - => builder.AddDefaultInitializer(stateMachineAction - .AddStateMachineInvocationContext((builder as StateMachineBuilder).Result) - .ToAsync() - ); - - [DebuggerHidden] - public static IInitializedStateMachineBuilder AddInitializer(this IInitializedStateMachineBuilder builder, Func, bool> stateMachineAction) - where TInitializationEvent : Event, new() - => builder.AddInitializer(stateMachineAction - .AddStateMachineInvocationContext((builder as StateMachineBuilder).Result) - .ToAsync() - ); - - [DebuggerHidden] - public static IInitializedStateMachineBuilder AddFinalizer(this IInitializedStateMachineBuilder builder, Action stateMachineAction) - => builder.AddFinalizer(stateMachineAction - .AddStateMachineInvocationContext((builder as StateMachineBuilder).Result) - .ToAsync() - ); - } -} diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/InitializedStateMachineBuilderEventsTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/InitializedStateMachineBuilderEventsTypedExtensions.cs new file mode 100644 index 00000000..81165fd1 --- /dev/null +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/InitializedStateMachineBuilderEventsTypedExtensions.cs @@ -0,0 +1,39 @@ +using Stateflows.Common; +using System.Diagnostics; +using Stateflows.Common.Extensions; +using Stateflows.StateMachines.Context.Classes; +using Stateflows.StateMachines.Registration.Interfaces.Internal; + +namespace Stateflows.StateMachines.Typed +{ + public static class InitializedStateMachineBuilderEventsTypedExtensions + { + [DebuggerHidden] + public static IInitializedStateMachineBuilder AddDefaultInitializer(this IInitializedStateMachineBuilder builder) + where TInitializer : class, IDefaultInitializer + { + (builder as IInternal).Services.AddServiceType(); + + return builder.AddDefaultInitializer(c => (c as BaseContext).Context.Executor.GetDefaultInitializer(c)?.OnInitializeAsync()); + } + + [DebuggerHidden] + public static IInitializedStateMachineBuilder AddInitializer(this IInitializedStateMachineBuilder builder) + where TInitializationEvent : Event, new() + where TInitializer : class, IInitializer + { + (builder as IInternal).Services.AddServiceType(); + + return builder.AddInitializer(c => (c as BaseContext).Context.Executor.GetInitializer(c)?.OnInitializeAsync(c.InitializationEvent)); + } + + [DebuggerHidden] + public static IInitializedStateMachineBuilder AddFinalizer(this IInitializedStateMachineBuilder builder) + where TFinalizer : class, IFinalizer + { + (builder as IInternal).Services.AddServiceType(); + + return builder.AddFinalizer(c => (c as BaseContext).Context.Executor.GetFinalizer(c)?.OnFinalizeAsync()); + } + } +} diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/StateMachineBuilderEventsSyncExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/StateMachineBuilderEventsSyncExtensions.cs deleted file mode 100644 index c65ac18d..00000000 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/StateMachineBuilderEventsSyncExtensions.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Diagnostics; -using Stateflows.Common; -using Stateflows.StateMachines.Context.Interfaces; -using Stateflows.StateMachines.Registration.Builders; -using Stateflows.StateMachines.Registration.Extensions; - -namespace Stateflows.StateMachines.Sync -{ - public static class StateMachineBuilderEventsSyncExtensions - { - [DebuggerHidden] - public static IStateMachineBuilder AddDefaultInitializer(this IStateMachineBuilder builder, Func stateMachineAction) - => builder.AddDefaultInitializer(stateMachineAction - .AddStateMachineInvocationContext((builder as StateMachineBuilder).Result) - .ToAsync() - ); - - [DebuggerHidden] - public static IStateMachineBuilder AddInitializer(this IStateMachineBuilder builder, Func, bool> stateMachineAction) - where TInitializationEvent : Event, new() - => builder.AddInitializer(stateMachineAction - .AddStateMachineInvocationContext((builder as StateMachineBuilder).Result) - .ToAsync() - ); - - [DebuggerHidden] - public static IStateMachineBuilder AddFinalizer(this IStateMachineBuilder builder, Action stateMachineAction) - => builder.AddFinalizer(stateMachineAction - .AddStateMachineInvocationContext((builder as StateMachineBuilder).Result) - .ToAsync() - ); - } -} diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/StateMachineBuilderEventsTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/StateMachineBuilderEventsTypedExtensions.cs index 59976435..b54a3062 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/StateMachineBuilderEventsTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/Events/StateMachineBuilderEventsTypedExtensions.cs @@ -1,9 +1,8 @@ using Stateflows.Common; using System.Diagnostics; -using Stateflows.StateMachines.Extensions; +using Stateflows.Common.Extensions; using Stateflows.StateMachines.Context.Classes; using Stateflows.StateMachines.Registration.Interfaces.Internal; -using Stateflows.Common.Extensions; namespace Stateflows.StateMachines.Typed { diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/StateMachine/InitializedStateMachineBuilderTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/StateMachine/InitializedStateMachineBuilderTypedExtensions.cs index 6126db60..99965c2f 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/StateMachine/InitializedStateMachineBuilderTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/StateMachine/InitializedStateMachineBuilderTypedExtensions.cs @@ -18,12 +18,12 @@ public static IFinalizedStateMachineBuilder AddState(this IInitiali #region AddState [DebuggerHidden] public static IInitializedStateMachineBuilder AddState(this IInitializedStateMachineBuilder builder, StateTransitionsBuildAction stateBuildAction = null) - where TState : class, IBaseState + where TState : class, IState => builder.AddState(State.Name, stateBuildAction); [DebuggerHidden] public static IInitializedStateMachineBuilder AddState(this IInitializedStateMachineBuilder builder, string stateName, StateTransitionsBuildAction stateBuildAction = null) - where TState : class, IBaseState + where TState : class, IState { (builder as IInternal).Services.AddServiceType(); @@ -42,12 +42,12 @@ public static IInitializedStateMachineBuilder AddState(this IInitialized #region AddCompositeState [DebuggerHidden] public static IInitializedStateMachineBuilder AddCompositeState(this IInitializedStateMachineBuilder builder, CompositeStateTransitionsBuildAction compositeStateBuildAction) - where TCompositeState : class, IBaseCompositeState + where TCompositeState : class, ICompositeState => builder.AddCompositeState(State.Name, compositeStateBuildAction); [DebuggerHidden] public static IInitializedStateMachineBuilder AddCompositeState(this IInitializedStateMachineBuilder builder, string stateName, CompositeStateTransitionsBuildAction compositeStateBuildAction) - where TCompositeState : class, IBaseCompositeState + where TCompositeState : class, ICompositeState { (builder as IInternal).Services.AddServiceType(); diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/StateMachine/StateMachineBuilderTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/StateMachine/StateMachineBuilderTypedExtensions.cs index b9f11261..d353e830 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/StateMachine/StateMachineBuilderTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateMachineBuilder/StateMachine/StateMachineBuilderTypedExtensions.cs @@ -11,12 +11,12 @@ public static class StateMachineBuilderTypedExtensions #region AddInitialState [DebuggerHidden] public static IInitializedStateMachineBuilder AddInitialState(this IStateMachineBuilder builder, StateTransitionsBuildAction stateBuildAction = null) - where TState : class, IBaseState + where TState : class, IState => builder.AddInitialState(State.Name, stateBuildAction); [DebuggerHidden] public static IInitializedStateMachineBuilder AddInitialState(this IStateMachineBuilder builder, string stateName, StateTransitionsBuildAction stateBuildAction = null) - where TState : class, IBaseState + where TState : class, IState { (builder as IInternal).Services.AddServiceType(); @@ -35,12 +35,12 @@ public static IInitializedStateMachineBuilder AddInitialState(this IStat #region AddInitialCompositeState [DebuggerHidden] public static IInitializedStateMachineBuilder AddInitialCompositeState(this IStateMachineBuilder builder, CompositeStateTransitionsBuildAction compositeStateBuildAction) - where TState : class, IBaseCompositeState + where TState : class, ICompositeState => builder.AddInitialCompositeState(State.Name, compositeStateBuildAction); [DebuggerHidden] public static IInitializedStateMachineBuilder AddInitialCompositeState(this IStateMachineBuilder builder, string stateName, CompositeStateTransitionsBuildAction compositeStateBuildAction) - where TState : class, IBaseCompositeState + where TState : class, ICompositeState { (builder as IInternal).Services.AddServiceType(); diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TransitionBuilder/TransitionBuilderSyncExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TransitionBuilder/TransitionBuilderSyncExtensions.cs index c1b176fe..14eb1cfd 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TransitionBuilder/TransitionBuilderSyncExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TransitionBuilder/TransitionBuilderSyncExtensions.cs @@ -12,7 +12,7 @@ namespace Stateflows.StateMachines.Sync public static class TransitionBuilderSyncExtensions { [DebuggerHidden] - public static ITransitionBuilder AddGuard(this ITransitionBuilder builder, Func, bool> guard) + public static ITransitionBuilder AddGuard(this ITransitionBuilder builder, Func, bool> guard) where TEvent : Event, new() => builder.AddGuard(guard .AddStateMachineInvocationContext((builder as TransitionBuilder).Edge.Graph) @@ -20,7 +20,7 @@ public static ITransitionBuilder AddGuard(this ITransitionBuilde ); [DebuggerHidden] - public static IInternalTransitionBuilder AddGuard(this IInternalTransitionBuilder builder, Func, bool> guard) + public static IInternalTransitionBuilder AddGuard(this IInternalTransitionBuilder builder, Func, bool> guard) where TEvent : Event, new() => builder.AddGuard(guard .AddStateMachineInvocationContext((builder as TransitionBuilder).Edge.Graph) @@ -28,7 +28,7 @@ public static IInternalTransitionBuilder AddGuard(this IInternal ); [DebuggerHidden] - public static IDefaultTransitionBuilder AddGuard(this IDefaultTransitionBuilder builder, Func, bool> guard) + public static IDefaultTransitionBuilder AddGuard(this IDefaultTransitionBuilder builder, Func, bool> guard) => builder.AddGuard(guard .AddStateMachineInvocationContext((builder as TransitionBuilder).Edge.Graph) .ToAsync() diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/StateMachine/TypedCompositeStateBuilderTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/StateMachine/TypedCompositeStateBuilderTypedExtensions.cs index f1025399..31298ee4 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/StateMachine/TypedCompositeStateBuilderTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/StateMachine/TypedCompositeStateBuilderTypedExtensions.cs @@ -11,12 +11,12 @@ public static class TypedCompositeStateBuilderTypedExtensions #region AddInitialState [DebuggerHidden] public static ITypedInitializedCompositeStateBuilder AddInitialState(this ITypedCompositeStateBuilder builder, StateTransitionsBuildAction stateBuildAction = null) - where TState : class, IBaseState + where TState : class, IState => builder.AddInitialState(State.Name, stateBuildAction); [DebuggerHidden] public static ITypedInitializedCompositeStateBuilder AddInitialState(this ITypedCompositeStateBuilder builder, string stateName, StateTransitionsBuildAction stateBuildAction = null) - where TState : class, IBaseState + where TState : class, IState { (builder as IInternal).Services.AddServiceType(); @@ -35,12 +35,12 @@ public static ITypedInitializedCompositeStateBuilder AddInitialState(thi #region AddInitialCompositeState [DebuggerHidden] public static ITypedInitializedCompositeStateBuilder AddInitialCompositeState(this ITypedCompositeStateBuilder builder, CompositeStateTransitionsBuildAction compositeStateBuildAction) - where TState : class, IBaseState + where TState : class, IState => builder.AddInitialCompositeState(State.Name, compositeStateBuildAction); [DebuggerHidden] public static ITypedInitializedCompositeStateBuilder AddInitialCompositeState(this ITypedCompositeStateBuilder builder, string stateName, CompositeStateTransitionsBuildAction compositeStateBuildAction) - where TState : class, IBaseState + where TState : class, IState { (builder as IInternal).Services.AddServiceType(); diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/StateMachine/TypedInitializedCompositeStateBuilderTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/StateMachine/TypedInitializedCompositeStateBuilderTypedExtensions.cs index 19855517..e04b3343 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/StateMachine/TypedInitializedCompositeStateBuilderTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/StateMachine/TypedInitializedCompositeStateBuilderTypedExtensions.cs @@ -18,12 +18,12 @@ public static ITypedFinalizedCompositeStateBuilder AddState(this IT #region AddState [DebuggerHidden] public static ITypedInitializedCompositeStateBuilder AddState(this ITypedInitializedCompositeStateBuilder builder, StateTransitionsBuildAction stateBuildAction = null) - where TState : class, IBaseState + where TState : class, IState => builder.AddState(State.Name, stateBuildAction); [DebuggerHidden] public static ITypedInitializedCompositeStateBuilder AddState(this ITypedInitializedCompositeStateBuilder builder, string stateName, StateTransitionsBuildAction stateBuildAction = null) - where TState : class, IBaseState + where TState : class, IState { (builder as IInternal).Services.AddServiceType(); @@ -42,12 +42,12 @@ public static ITypedInitializedCompositeStateBuilder AddState(this IType #region AddCompositeState [DebuggerHidden] public static ITypedInitializedCompositeStateBuilder AddCompositeState(this ITypedInitializedCompositeStateBuilder builder, CompositeStateTransitionsBuildAction compositeStateBuildAction) - where TCompositeState : class, IBaseCompositeState + where TCompositeState : class, ICompositeState => builder.AddCompositeState(State.Name, compositeStateBuildAction); [DebuggerHidden] public static ITypedInitializedCompositeStateBuilder AddCompositeState(this ITypedInitializedCompositeStateBuilder builder, string stateName, CompositeStateTransitionsBuildAction compositeStateBuildAction) - where TCompositeState : class, IBaseCompositeState + where TCompositeState : class, ICompositeState { (builder as IInternal).Services.AddServiceType(); diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateBuilderDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateBuilderDefaultTransitionTypedExtensions.cs index f84fdcf5..07671ea5 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateBuilderDefaultTransitionTypedExtensions.cs @@ -37,7 +37,7 @@ public static class TypedCompositeStateBuilderDefaultTransitionTypedExtensions /// [DebuggerHidden] public static ITypedCompositeStateBuilder AddDefaultTransition(this ITypedCompositeStateBuilder builder) - where TDefaultTransition : class, IBaseDefaultTransition + where TDefaultTransition : class, IDefaultTransition where TTargetState : class, IVertex => builder.AddDefaultTransition(State.Name); @@ -64,8 +64,8 @@ public static ITypedCompositeStateBuilder AddDefaultTransitionTarget state name [DebuggerHidden] public static ITypedCompositeStateBuilder AddDefaultTransition(this ITypedCompositeStateBuilder builder, string targetStateName) - where TDefaultTransition : class, IBaseDefaultTransition - => (builder as IStateBuilder).AddDefaultTransition(targetStateName) as ITypedCompositeStateBuilder; + where TDefaultTransition : class, IDefaultTransition + => (builder as ICompositeStateBuilder).AddDefaultTransition(targetStateName) as ITypedCompositeStateBuilder; /// /// Adds default transition coming from current state.
diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateBuilderInternalTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateBuilderInternalTransitionTypedExtensions.cs index 3ba34657..870daaef 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateBuilderInternalTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateBuilderInternalTransitionTypedExtensions.cs @@ -31,7 +31,7 @@ public static class TypedCompositeStateBuilderInternalTransitionTypedExtensions [DebuggerHidden] public static ITypedCompositeStateBuilder AddInternalTransition(this ITypedCompositeStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition => builder.AddTransition(Constants.DefaultTransitionTarget); } } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateBuilderTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateBuilderTransitionTypedExtensions.cs index 9b1ddb1c..971dcc60 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateBuilderTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateBuilderTransitionTypedExtensions.cs @@ -44,7 +44,7 @@ public static class TypedCompositeStateBuilderTransitionTypedExtensions [DebuggerHidden] public static ITypedCompositeStateBuilder AddTransition(this ITypedCompositeStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition where TTargetState : class, IVertex => AddTransition(builder, State.Name); @@ -77,8 +77,8 @@ public static ITypedCompositeStateBuilder AddTransition(this ITypedCompositeStateBuilder builder, string targetStateName) where TEvent : Event, new() - where TTransition : class, IBaseTransition - => (builder as IStateBuilder).AddTransition(targetStateName) as ITypedCompositeStateBuilder; + where TTransition : class, ITransition + => (builder as ICompositeStateBuilder).AddTransition(targetStateName) as ITypedCompositeStateBuilder; /// /// Adds transition triggered by coming from current state.
diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedFinalizedCompositeStateBuilderDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedFinalizedCompositeStateBuilderDefaultTransitionTypedExtensions.cs index 3b6b012c..97066c44 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedFinalizedCompositeStateBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedFinalizedCompositeStateBuilderDefaultTransitionTypedExtensions.cs @@ -37,7 +37,7 @@ public static class TypedFinalizedCompositeStateBuilderDefaultTransitionTypedExt /// [DebuggerHidden] public static ITypedFinalizedCompositeStateBuilder AddDefaultTransition(this ITypedFinalizedCompositeStateBuilder builder) - where TDefaultTransition : class, IBaseDefaultTransition + where TDefaultTransition : class, IDefaultTransition where TTargetState : class, IVertex => builder.AddDefaultTransition(State.Name); @@ -64,8 +64,8 @@ public static ITypedFinalizedCompositeStateBuilder AddDefaultTransitionTarget state name [DebuggerHidden] public static ITypedFinalizedCompositeStateBuilder AddDefaultTransition(this ITypedFinalizedCompositeStateBuilder builder, string targetStateName) - where TDefaultTransition : class, IBaseDefaultTransition - => (builder as IStateBuilder).AddDefaultTransition(targetStateName) as ITypedFinalizedCompositeStateBuilder; + where TDefaultTransition : class, IDefaultTransition + => (builder as ICompositeStateBuilder).AddDefaultTransition(targetStateName) as ITypedFinalizedCompositeStateBuilder; /// /// Adds default transition coming from current state.
diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedFinalizedCompositeStateBuilderInternalTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedFinalizedCompositeStateBuilderInternalTransitionTypedExtensions.cs index ef86c0b2..393344e9 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedFinalizedCompositeStateBuilderInternalTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedFinalizedCompositeStateBuilderInternalTransitionTypedExtensions.cs @@ -1,7 +1,7 @@ -using Stateflows.Common; +using System.Diagnostics; +using Stateflows.Common; using Stateflows.StateMachines.Registration; using Stateflows.StateMachines.Registration.Interfaces; -using System.Diagnostics; namespace Stateflows.StateMachines.Typed { @@ -31,7 +31,7 @@ public static class TypedFinalizedCompositeStateBuilderInternalTransitionTypedEx [DebuggerHidden] public static ITypedFinalizedCompositeStateBuilder AddInternalTransition(this ITypedFinalizedCompositeStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition => builder.AddTransition(Constants.DefaultTransitionTarget); } } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedFinalizedCompositeStateBuilderTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedFinalizedCompositeStateBuilderTransitionTypedExtensions.cs index 458125a7..21004379 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedFinalizedCompositeStateBuilderTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedFinalizedCompositeStateBuilderTransitionTypedExtensions.cs @@ -44,7 +44,7 @@ public static class TypedFinalizedCompositeStateBuilderTransitionTypedExtensions [DebuggerHidden] public static ITypedFinalizedCompositeStateBuilder AddTransition(this ITypedFinalizedCompositeStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition where TTargetState : class, IVertex => AddTransition(builder, State.Name); @@ -77,8 +77,8 @@ public static ITypedFinalizedCompositeStateBuilder AddTransition(this ITypedFinalizedCompositeStateBuilder builder, string targetStateName) where TEvent : Event, new() - where TTransition : class, IBaseTransition - => (builder as IStateBuilder).AddTransition(targetStateName) as ITypedFinalizedCompositeStateBuilder; + where TTransition : class, ITransition + => (builder as ICompositeStateBuilder).AddTransition(targetStateName) as ITypedFinalizedCompositeStateBuilder; /// /// Adds transition triggered by coming from current state.
diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedInitializedCompositeStateBuilderDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedInitializedCompositeStateBuilderDefaultTransitionTypedExtensions.cs index 56c511a7..c76af5e8 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedInitializedCompositeStateBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedInitializedCompositeStateBuilderDefaultTransitionTypedExtensions.cs @@ -37,7 +37,7 @@ public static class TypedInitializedCompositeStateBuilderDefaultTransitionTypedE /// [DebuggerHidden] public static ITypedInitializedCompositeStateBuilder AddDefaultTransition(this ITypedInitializedCompositeStateBuilder builder) - where TDefaultTransition : class, IBaseDefaultTransition + where TDefaultTransition : class, IDefaultTransition where TTargetState : class, IVertex => builder.AddDefaultTransition(State.Name); @@ -64,8 +64,8 @@ public static ITypedInitializedCompositeStateBuilder AddDefaultTransitionTarget state name [DebuggerHidden] public static ITypedInitializedCompositeStateBuilder AddDefaultTransition(this ITypedInitializedCompositeStateBuilder builder, string targetStateName) - where TDefaultTransition : class, IBaseDefaultTransition - => (builder as IStateBuilder).AddDefaultTransition(targetStateName) as ITypedInitializedCompositeStateBuilder; + where TDefaultTransition : class, IDefaultTransition + => (builder as ICompositeStateBuilder).AddDefaultTransition(targetStateName) as ITypedInitializedCompositeStateBuilder; /// /// Adds default transition coming from current state.
diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedInitializedCompositeStateBuilderInternalTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedInitializedCompositeStateBuilderInternalTransitionTypedExtensions.cs index ff979b02..c5b08674 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedInitializedCompositeStateBuilderInternalTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedInitializedCompositeStateBuilderInternalTransitionTypedExtensions.cs @@ -31,7 +31,7 @@ public static class TypedInitializedCompositeStateBuilderInternalTransitionTyped [DebuggerHidden] public static ITypedInitializedCompositeStateBuilder AddInternalTransition(this ITypedInitializedCompositeStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition => builder.AddTransition(Constants.DefaultTransitionTarget); } } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedInitializedCompositeStateBuilderTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedInitializedCompositeStateBuilderTransitionTypedExtensions.cs index 4f2c4f97..a11d0f67 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedInitializedCompositeStateBuilderTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedInitializedCompositeStateBuilderTransitionTypedExtensions.cs @@ -44,7 +44,7 @@ public static class TypedInitializedCompositeStateBuilderTransitionTypedExtensio [DebuggerHidden] public static ITypedInitializedCompositeStateBuilder AddTransition(this ITypedInitializedCompositeStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition where TTargetState : class, IVertex => AddTransition(builder, State.Name); @@ -77,8 +77,8 @@ public static ITypedInitializedCompositeStateBuilder AddTransition(this ITypedInitializedCompositeStateBuilder builder, string targetStateName) where TEvent : Event, new() - where TTransition : class, IBaseTransition - => (builder as IStateBuilder).AddTransition(targetStateName) as ITypedInitializedCompositeStateBuilder; + where TTransition : class, ITransition + => (builder as ICompositeStateBuilder).AddTransition(targetStateName) as ITypedInitializedCompositeStateBuilder; /// /// Adds transition triggered by coming from current state.
diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/Transitions/TypedStateBuilderDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/Transitions/TypedStateBuilderDefaultTransitionTypedExtensions.cs index d704146f..0cfc3ba9 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/Transitions/TypedStateBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/Transitions/TypedStateBuilderDefaultTransitionTypedExtensions.cs @@ -37,7 +37,7 @@ public static class TypedStateBuilderDefaultTransitionTypedExtensions /// [DebuggerHidden] public static ITypedStateBuilder AddDefaultTransition(this ITypedStateBuilder builder) - where TTransition : class, IBaseDefaultTransition + where TTransition : class, IDefaultTransition where TTargetState : class, IVertex => builder.AddDefaultTransition(State.Name); @@ -64,7 +64,7 @@ public static ITypedStateBuilder AddDefaultTransition /// Target state name [DebuggerHidden] public static ITypedStateBuilder AddDefaultTransition(this ITypedStateBuilder builder, string targetStateName) - where TTransition : class, IBaseDefaultTransition + where TTransition : class, IDefaultTransition => (builder as IStateBuilder).AddDefaultTransition(targetStateName) as ITypedStateBuilder; /// diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/Transitions/TypedStateBuilderInternalTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/Transitions/TypedStateBuilderInternalTransitionTypedExtensions.cs index 11e7ddfb..f9a39cfb 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/Transitions/TypedStateBuilderInternalTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/Transitions/TypedStateBuilderInternalTransitionTypedExtensions.cs @@ -31,7 +31,7 @@ public static class TypedStateBuilderInternalTransitionTypedExtensions [DebuggerHidden] public static ITypedStateBuilder AddInternalTransition(this ITypedStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition => builder.AddTransition(Constants.DefaultTransitionTarget); } } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/Transitions/TypedStateBuilderTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/Transitions/TypedStateBuilderTransitionTypedExtensions.cs index 70971b7e..8905b8d0 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/Transitions/TypedStateBuilderTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/Transitions/TypedStateBuilderTransitionTypedExtensions.cs @@ -44,7 +44,7 @@ public static class TypedStateBuilderTransitionTypedExtensions [DebuggerHidden] public static ITypedStateBuilder AddTransition(this ITypedStateBuilder builder) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition where TTargetState : class, IVertex => AddTransition(builder, State.Name); @@ -77,7 +77,7 @@ public static ITypedStateBuilder AddTransition(this ITypedStateBuilder builder, string targetStateName) where TEvent : Event, new() - where TTransition : class, IBaseTransition + where TTransition : class, ITransition => (builder as IStateBuilder).AddTransition(targetStateName) as ITypedStateBuilder; /// diff --git a/Core/Stateflows/StateMachines/StateMachinesDependencyInjection.cs b/Core/Stateflows/StateMachines/StateMachinesDependencyInjection.cs index 82589517..6e8199e6 100644 --- a/Core/Stateflows/StateMachines/StateMachinesDependencyInjection.cs +++ b/Core/Stateflows/StateMachines/StateMachinesDependencyInjection.cs @@ -2,11 +2,11 @@ using System.Diagnostics; using System.Collections.Generic; using Microsoft.Extensions.DependencyInjection; +using Stateflows.Common; using Stateflows.Common.Interfaces; using Stateflows.Common.Initializer; using Stateflows.Common.Registration.Interfaces; using Stateflows.StateMachines.Context; -using Stateflows.StateMachines.Context.Interfaces; using Stateflows.StateMachines.Engine; using Stateflows.StateMachines.Registration; using Stateflows.StateMachines.EventHandlers; diff --git a/Locks/Stateflows.Locks.DistributedLock/Stateflows.Locks.DistributedLock.csproj b/Locks/Stateflows.Locks.DistributedLock/Stateflows.Locks.DistributedLock.csproj index ab3e9c1b..1e383126 100644 --- a/Locks/Stateflows.Locks.DistributedLock/Stateflows.Locks.DistributedLock.csproj +++ b/Locks/Stateflows.Locks.DistributedLock/Stateflows.Locks.DistributedLock.csproj @@ -36,8 +36,4 @@ - - - - diff --git a/Stateflows.sln b/Stateflows.sln index 63ff772d..1e5e7473 100644 --- a/Stateflows.sln +++ b/Stateflows.sln @@ -92,6 +92,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .editorconfig = .editorconfig EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stateflows.Integrations.Sputnik", "..\Cosmos\Stateflows\src\Stateflows.Integrations.Sputnik\Stateflows.Integrations.Sputnik.csproj", "{11AF9B20-CE14-4AB6-BC2A-E31B923CEF12}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -214,6 +216,10 @@ Global {D6FD721E-4B42-4875-B774-2AD84BE5B3B6}.Debug|Any CPU.Build.0 = Debug|Any CPU {D6FD721E-4B42-4875-B774-2AD84BE5B3B6}.Release|Any CPU.ActiveCfg = Release|Any CPU {D6FD721E-4B42-4875-B774-2AD84BE5B3B6}.Release|Any CPU.Build.0 = Release|Any CPU + {11AF9B20-CE14-4AB6-BC2A-E31B923CEF12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {11AF9B20-CE14-4AB6-BC2A-E31B923CEF12}.Debug|Any CPU.Build.0 = Debug|Any CPU + {11AF9B20-CE14-4AB6-BC2A-E31B923CEF12}.Release|Any CPU.ActiveCfg = Release|Any CPU + {11AF9B20-CE14-4AB6-BC2A-E31B923CEF12}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Storage/Stateflows.Storage.EntityFrameworkCore/Stateflows.Storage.EntityFrameworkCore.csproj b/Storage/Stateflows.Storage.EntityFrameworkCore/Stateflows.Storage.EntityFrameworkCore.csproj index 0e2e2aa9..5ad630f5 100644 --- a/Storage/Stateflows.Storage.EntityFrameworkCore/Stateflows.Storage.EntityFrameworkCore.csproj +++ b/Storage/Stateflows.Storage.EntityFrameworkCore/Stateflows.Storage.EntityFrameworkCore.csproj @@ -47,8 +47,4 @@ - - - - diff --git a/Tests/Activity.IntegrationTests/Tests/Exceptions.cs b/Tests/Activity.IntegrationTests/Tests/Exceptions.cs index 39598934..4687d806 100644 --- a/Tests/Activity.IntegrationTests/Tests/Exceptions.cs +++ b/Tests/Activity.IntegrationTests/Tests/Exceptions.cs @@ -13,7 +13,7 @@ public class OtherException : Exception public OtherException(string? message) : base(message) { } } - public class Main : IBaseStructuredActivityNode + public class Main : IStructuredActivityNode { } diff --git a/Tests/Activity.IntegrationTests/Tests/Execution.cs b/Tests/Activity.IntegrationTests/Tests/Execution.cs index 958c6261..3e88b3fd 100644 --- a/Tests/Activity.IntegrationTests/Tests/Execution.cs +++ b/Tests/Activity.IntegrationTests/Tests/Execution.cs @@ -1,4 +1,5 @@ using Stateflows.Common; +using Stateflows.Utils; using Stateflows.Activities.Typed; using StateMachine.IntegrationTests.Utils; diff --git a/Tests/Activity.IntegrationTests/Tests/Guard.cs b/Tests/Activity.IntegrationTests/Tests/Guard.cs new file mode 100644 index 00000000..f7af9590 --- /dev/null +++ b/Tests/Activity.IntegrationTests/Tests/Guard.cs @@ -0,0 +1,96 @@ +using Stateflows.Activities.Typed; +using Stateflows.Common; +using StateMachine.IntegrationTests.Utils; + +namespace Activity.IntegrationTests.Tests +{ + public class IntHolder + { + public int Value { get; set; } + } + + public class GuardFlow : IFlowGuard + { + public Task GuardAsync(int token) + => Task.FromResult(token % 2 == 0); + } + + [TestClass] + public class Guard : StateflowsTestClass + { + private bool Executed = false; + private int Count = 0; + + [TestInitialize] + public override void Initialize() + => base.Initialize(); + + [TestCleanup] + public override void Cleanup() + => base.Cleanup(); + + protected override void InitializeStateflows(IStateflowsBuilder builder) + { + builder + .AddActivities(b => b + .AddActivity("plain", b => b + .AddInitial(b => b + .AddControlFlow("main") + ) + .AddAction( + "main", + async c => c.OutputRange(Enumerable.Range(0, 100)), + b => b.AddFlow("check", b => b + .AddGuard(async c => c.Token % 2 == 0) + ) + ) + .AddAction("check", async c => + { + Executed = true; + Count = c.GetTokensOfType().Count(); + }) + ) + .AddActivity("typed", b => b + .AddInitial(b => b + .AddControlFlow("main") + ) + .AddAction( + "main", + async c => c.OutputRange(Enumerable.Range(0, 100)), + b => b.AddFlow("check") + ) + .AddAction("check", async c => + { + Executed = true; + Count = c.GetTokensOfType().Count(); + }) + ) + ) + ; + } + + [TestMethod] + public async Task PlainGuard() + { + if (ActivityLocator.TryLocateActivity(new ActivityId("plain", "x"), out var a)) + { + await a.ExecuteAsync(); + } + + Assert.IsTrue(Executed); + Assert.AreEqual(50, Count); + } + + [TestMethod] + public async Task TypedGuard() + { + if (ActivityLocator.TryLocateActivity(new ActivityId("typed", "x"), out var a)) + { + await a.ExecuteAsync(); + } + + Assert.IsTrue(Executed); + Assert.AreEqual(50, Count); + } + } +} \ No newline at end of file diff --git a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/StateMachines/EverythingStateMachine.cs b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/StateMachines/EverythingStateMachine.cs index 4b6d75d0..606ce2bc 100644 --- a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/StateMachines/EverythingStateMachine.cs +++ b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/StateMachines/EverythingStateMachine.cs @@ -3,6 +3,7 @@ using StateMachine.IntegrationTests.Classes.States; using StateMachine.IntegrationTests.Classes.Transitions; using Stateflows.StateMachines.Extensions; +using Stateflows.Common; namespace StateMachine.IntegrationTests.Classes.StateMachines { @@ -36,15 +37,15 @@ public void Build(IStateMachineBuilder builder) { builder .AddInitializer() - .AddInitializer(c => true) + .AddInitializer(async c => true) .AddInitializer(c => Task.FromResult(true)) .AddDefaultInitializer() - .AddDefaultInitializer(c => true) + .AddDefaultInitializer(async c => true) .AddDefaultInitializer(c => Task.FromResult(true)) .AddFinalizer() - .AddFinalizer(c => { }) + .AddFinalizer(async c => { }) .AddFinalizer(c => Task.CompletedTask) .AddInitialState(b => b diff --git a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/StateMachines/StateMachine1.cs b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/StateMachines/StateMachine1.cs index ac9e1469..8892d973 100644 --- a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/StateMachines/StateMachine1.cs +++ b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/StateMachines/StateMachine1.cs @@ -2,6 +2,7 @@ using Stateflows.StateMachines.Attributes; using StateMachine.IntegrationTests.Classes.States; using StateMachine.IntegrationTests.Classes.Transitions; +using Stateflows.Common; namespace StateMachine.IntegrationTests.Classes.StateMachines { diff --git a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/StateMachines/TypedStateMachine.cs b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/StateMachines/TypedStateMachine.cs index c953a796..8fb8624c 100644 --- a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/StateMachines/TypedStateMachine.cs +++ b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/StateMachines/TypedStateMachine.cs @@ -1,6 +1,6 @@ using Stateflows.StateMachines.Typed; using Stateflows.StateMachines.Attributes; -using Stateflows.StateMachines.Context.Interfaces; +using Stateflows.Common; namespace StateMachine.IntegrationTests.Classes.StateMachines { diff --git a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/StateMachines/TypedValue.cs b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/StateMachines/TypedValue.cs index 53be1a53..8d3a360c 100644 --- a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/StateMachines/TypedValue.cs +++ b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/StateMachines/TypedValue.cs @@ -6,7 +6,7 @@ public class TypedValue : IStateMachine { public void Build(IStateMachineBuilder builder) => builder - .AddInitializer(c => + .AddInitializer(async c => { c.StateMachine.Values.Set("foo", c.InitializationEvent.Value); diff --git a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/States/State1.cs b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/States/State1.cs index 6d9cc490..3e6edea9 100644 --- a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/States/State1.cs +++ b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/States/State1.cs @@ -1,4 +1,4 @@ -using Stateflows.StateMachines.Context.Interfaces; +using Stateflows.Common; namespace StateMachine.IntegrationTests.Classes.States { diff --git a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/Transitions/SomeEventTransition.cs b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/Transitions/SomeEventTransition.cs index b9d0b2e4..6fc25022 100644 --- a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/Transitions/SomeEventTransition.cs +++ b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/Transitions/SomeEventTransition.cs @@ -1,4 +1,4 @@ -using Stateflows.StateMachines.Context.Interfaces; +using Stateflows.Common; namespace StateMachine.IntegrationTests.Classes.Transitions { diff --git a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/Transitions/ValueTransition.cs b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/Transitions/ValueTransition.cs index 421d9d11..21b9ccb5 100644 --- a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/Transitions/ValueTransition.cs +++ b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/Transitions/ValueTransition.cs @@ -1,6 +1,6 @@ namespace StateMachine.IntegrationTests.Classes.Transitions { - internal class ValueTransition : IBaseDefaultTransition + internal class ValueTransition : IDefaultTransitionGuard { private readonly SourceStateValue counter = new("counter"); diff --git a/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Activities.cs b/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Activities.cs index b3e248cc..e0ba5664 100644 --- a/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Activities.cs +++ b/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Activities.cs @@ -40,7 +40,7 @@ protected override void InitializeStateflows(IStateflowsBuilder builder) }) .AddInitialState("stateA", b => b .AddTransition("stateB", b => b - .AddGuardActivity("guard", c => new BoolInit() { Value = c.StateMachine.Values.TryGet("value", out var value) && value }) + .AddGuardActivity("guard") .AddEffectActivity("effect") ) ) @@ -52,11 +52,6 @@ protected override void InitializeStateflows(IStateflowsBuilder builder) ) .AddActivities(b => b .AddActivity("guard", b => b - .AddInitializer(async c => - { - c.Activity.Values.Set("value", c.InitializationEvent.Value); - return true; - }) .AddInitial(b => b .AddControlFlow("main") ) @@ -75,8 +70,8 @@ protected override void InitializeStateflows(IStateflowsBuilder builder) .AddOutput() ) .AddActivity("effect", b => b - .AddInitial(b => b - .AddControlFlow("main") + .AddInput(b => b + .AddFlow("main") ) .AddAction("main", async c => { diff --git a/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Behaviors.cs b/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Behaviors.cs index cca6a762..5c0b6b56 100644 --- a/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Behaviors.cs +++ b/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Behaviors.cs @@ -1,5 +1,6 @@ using Stateflows.Common; using Stateflows.Activities; +using Stateflows.Activities.Typed; using StateMachine.IntegrationTests.Utils; namespace StateMachine.IntegrationTests.Tests @@ -55,6 +56,30 @@ protected override void InitializeStateflows(IStateflowsBuilder builder) ) .AddState("state2") ) + + .AddStateMachine("effectActivity", b => b + .AddExecutionSequenceObserver() + .AddInitialState("state1", b => b + .AddInternalTransition(b => b + .AddEffectActivity( + "integrated", + b => b.AddSubscription() + ) + ) + .AddTransition("state2") + ) + .AddState("state2") + ) + + .AddStateMachine("guardActivity", b => b + .AddExecutionSequenceObserver() + .AddInitialState("state1", b => b + .AddTransition("state2", b => b + .AddGuardActivity("guard") + ) + ) + .AddState("state2") + ) ) .AddActivities(b => b .AddActivity("nested", b => b @@ -64,6 +89,34 @@ protected override void InitializeStateflows(IStateflowsBuilder builder) c.Activity.Publish(new SomeNotification()); }) ) + .AddActivity("integrated", b => b + .AddInitial(b => b + .AddControlFlow("effect") + ) + .AddAction( + "effect", + async c => + { + eventConsumed = true; + c.Activity.Publish(new SomeNotification()); + } + ) + ) + .AddActivity("guard", b => b + .AddInput(b => b + .AddFlow("guard") + ) + .AddAction( + "guard", + async c => + { + var t = c.GetTokensOfType().First(); + c.Output(t.TheresSomethingHappeningHere != string.Empty); + }, + b => b.AddFlow() + ) + .AddOutput() + ) ) ; } @@ -120,7 +173,7 @@ public async Task SimpleDoActivity() currentState1 = (await sm.GetCurrentStateAsync()).Response.StatesStack.First(); } - ExecutionSequence.Verify(b => b + ExecutionSequence.Verify(b => b .StateEntry("state1") .StateEntry("state2") ); @@ -129,5 +182,60 @@ public async Task SimpleDoActivity() Assert.AreEqual(true, eventConsumed); Assert.AreEqual("state2", currentState1); } + + [TestMethod] + public async Task SimpleEffectIntegration() + { + var initialized = false; + string currentState1 = ""; + var someStatus1 = EventStatus.Rejected; + + if (StateMachineLocator.TryLocateStateMachine(new StateMachineId("effectActivity", "x"), out var sm)) + { + initialized = (await sm.SendAsync(new Initialize())).Status == EventStatus.Initialized; + + someStatus1 = (await sm.SendAsync(new SomeEvent())).Status; + + await Task.Delay(200); + + currentState1 = (await sm.GetCurrentStateAsync()).Response.StatesStack.First(); + } + + ExecutionSequence.Verify(b => b + .StateEntry("state1") + .StateEntry("state2") + ); + Assert.IsTrue(initialized); + Assert.AreEqual(EventStatus.Consumed, someStatus1); + Assert.AreEqual(true, eventConsumed); + Assert.AreEqual("state2", currentState1); + } + + [TestMethod] + public async Task SimpleGuardIntegration() + { + var initialized = false; + string currentState1 = ""; + var someStatus1 = EventStatus.Rejected; + + if (StateMachineLocator.TryLocateStateMachine(new StateMachineId("guardActivity", "x"), out var sm)) + { + initialized = (await sm.SendAsync(new Initialize())).Status == EventStatus.Initialized; + + someStatus1 = (await sm.SendAsync(new SomeEvent())).Status; + + await Task.Delay(200); + + currentState1 = (await sm.GetCurrentStateAsync()).Response.StatesStack.First(); + } + + ExecutionSequence.Verify(b => b + .StateEntry("state1") + .StateEntry("state2") + ); + Assert.IsTrue(initialized); + Assert.AreEqual(EventStatus.Consumed, someStatus1); + Assert.AreEqual("state2", currentState1); + } } } \ No newline at end of file diff --git a/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Composite.cs b/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Composite.cs index 0c148a74..cdf4d63a 100644 --- a/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Composite.cs +++ b/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Composite.cs @@ -3,11 +3,10 @@ using Stateflows.StateMachines.Events; using StateMachine.IntegrationTests.Utils; using System.Diagnostics; -using Stateflows.StateMachines.Context.Interfaces; namespace StateMachine.IntegrationTests.Tests { - public class StateA : IBaseState + public class StateA : IState { public StateA(IStateMachineContext smContext, ITransitionContext tContext) { @@ -15,7 +14,7 @@ public StateA(IStateMachineContext smContext, ITransitionContext tContext) } } - public class StateB : IBaseState + public class StateB : IState { } [TestClass] @@ -80,7 +79,7 @@ protected override void InitializeStateflows(IStateflowsBuilder builder) .AddStateMachine("exits", b => b .AddExecutionSequenceObserver() - .AddDefaultInitializer(c => + .AddDefaultInitializer(async c => { ParentStateExited = null; ChildStateExited = null; diff --git a/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Initialization.cs b/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Initialization.cs index d3a3d33b..bd5c8e16 100644 --- a/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Initialization.cs +++ b/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Initialization.cs @@ -38,7 +38,7 @@ protected override void InitializeStateflows(IStateflowsBuilder builder) ) .AddStateMachine("explicit", b => b - .AddInitializer(c => + .AddInitializer(async c => { InitializerCalled = true; return c.InitializationEvent.InitializationSuccessful; @@ -49,7 +49,7 @@ protected override void InitializeStateflows(IStateflowsBuilder builder) ) .AddStateMachine("default", b => b - .AddDefaultInitializer(c => + .AddDefaultInitializer(async c => { InitializerCalled = true; return InitializationSuccessful; @@ -60,7 +60,7 @@ protected override void InitializeStateflows(IStateflowsBuilder builder) ) .AddStateMachine("consumption", b => b - .AddInitializer(c => true) + .AddInitializer(async c => true) .AddInitialState("state1", b => b .AddTransition("state2") ) diff --git a/Transport/@stateflows/common/package.json b/Transport/@stateflows/common/package.json index 8afee7cc..6db6ad52 100644 --- a/Transport/@stateflows/common/package.json +++ b/Transport/@stateflows/common/package.json @@ -1,6 +1,6 @@ { "name": "@stateflows/common", - "version": "0.12.0", + "version": "0.13.0", "description": "Common package for Stateflows framework clients", "main": "dist/index.js", "module": "./dist/index.mjs", @@ -23,7 +23,7 @@ "license": "MIT", "homepage": "https://www.stateflows.net", "devDependencies": { - "tsup": "^8.0.1", - "typescript": "^5.3.3" + "tsup": "^8.2.4", + "typescript": "^5.5.4" } } diff --git a/Transport/@stateflows/common/src/behaviors/activity.ts b/Transport/@stateflows/common/src/behaviors/activity.ts index 9f0f50e0..fa5e3cbe 100644 --- a/Transport/@stateflows/common/src/behaviors/activity.ts +++ b/Transport/@stateflows/common/src/behaviors/activity.ts @@ -1,7 +1,7 @@ -import { IActivity } from "../interfaces/activity"; +import { IActivityBehavior } from "../interfaces/activity.behavior"; import { Behavior } from "./behavior"; -export class Activity extends Behavior implements IActivity { +export class Activity extends Behavior implements IActivityBehavior { constructor(behavior: Behavior) { super(behavior, behavior.id); } diff --git a/Transport/@stateflows/common/src/behaviors/state-machine.ts b/Transport/@stateflows/common/src/behaviors/state-machine.ts index 96603422..16353dd8 100644 --- a/Transport/@stateflows/common/src/behaviors/state-machine.ts +++ b/Transport/@stateflows/common/src/behaviors/state-machine.ts @@ -2,11 +2,11 @@ import { RequestResult } from "../classes/request-result"; import { CurrentStateNotification } from "../events/current-state.notification"; import { CurrentStateRequest } from "../events/current-state.request"; import { CurrentStateResponse } from "../events/current-state.response"; -import { IStateMachine } from "../interfaces/state-machine"; +import { IStateMachineBehavior } from "../interfaces/state-machine.behavior"; import { NotificationHandler } from "../utils/notification-handler"; import { Behavior } from "./behavior"; -export class StateMachine extends Behavior implements IStateMachine { +export class StateMachine extends Behavior implements IStateMachineBehavior { constructor(behavior: Behavior) { super(behavior, behavior.id); } diff --git a/Transport/@stateflows/common/src/index.ts b/Transport/@stateflows/common/src/index.ts index d53d88b7..ac40fd63 100644 --- a/Transport/@stateflows/common/src/index.ts +++ b/Transport/@stateflows/common/src/index.ts @@ -10,6 +10,7 @@ export { Request } from "./events/request"; export { Notification } from "./events/notification"; export { CompoundRequest } from "./events/compound.request"; export { CompoundResponse } from "./events/compound.response"; +export { Initialize } from "./events/initialize"; export { FinalizationRequest } from "./events/finalization.request"; export { FinalizationResponse } from "./events/finalization.response"; export { ResetRequest } from "./events/reset.request"; @@ -29,8 +30,8 @@ export { IWatcher } from "./interfaces/watcher"; export { IBehavior } from "./interfaces/behavior"; export { IStateMachineLocator } from "./interfaces/state-machine.locator"; export { IActivityLocator } from "./interfaces/activity.locator"; -export { IStateMachine } from "./interfaces/state-machine"; -export { IActivity } from "./interfaces/activity"; +export { IStateMachineBehavior } from "./interfaces/state-machine.behavior"; +export { IActivityBehavior } from "./interfaces/activity.behavior"; export { EventStatus } from "./enums/event-status"; export { BehaviorStatus } from "./enums/behavior-status"; export { AvailableBehaviorClassesRequest } from "./events/available-behavior-classes.request"; diff --git a/Transport/@stateflows/common/src/interfaces/activity.behavior.ts b/Transport/@stateflows/common/src/interfaces/activity.behavior.ts new file mode 100644 index 00000000..84afe3ca --- /dev/null +++ b/Transport/@stateflows/common/src/interfaces/activity.behavior.ts @@ -0,0 +1,3 @@ +import { IBehavior } from "./behavior"; + +export interface IActivityBehavior extends IBehavior { } \ No newline at end of file diff --git a/Transport/@stateflows/common/src/interfaces/activity.locator.ts b/Transport/@stateflows/common/src/interfaces/activity.locator.ts index ede91113..163b4edb 100644 --- a/Transport/@stateflows/common/src/interfaces/activity.locator.ts +++ b/Transport/@stateflows/common/src/interfaces/activity.locator.ts @@ -1,6 +1,6 @@ import { ActivityId } from "../ids/activity.id"; -import { IActivity } from "./activity"; +import { IActivityBehavior } from "./activity.behavior"; export interface IActivityLocator { - locateActivity(id: ActivityId): Promise; + locateActivity(id: ActivityId): Promise; } \ No newline at end of file diff --git a/Transport/@stateflows/common/src/interfaces/activity.ts b/Transport/@stateflows/common/src/interfaces/activity.ts deleted file mode 100644 index d70c6121..00000000 --- a/Transport/@stateflows/common/src/interfaces/activity.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { IBehavior } from "./behavior"; - -export interface IActivity extends IBehavior { } \ No newline at end of file diff --git a/Transport/@stateflows/common/src/interfaces/state-machine.ts b/Transport/@stateflows/common/src/interfaces/state-machine.behavior.ts similarity index 89% rename from Transport/@stateflows/common/src/interfaces/state-machine.ts rename to Transport/@stateflows/common/src/interfaces/state-machine.behavior.ts index fd8ab6f8..8d1c0143 100644 --- a/Transport/@stateflows/common/src/interfaces/state-machine.ts +++ b/Transport/@stateflows/common/src/interfaces/state-machine.behavior.ts @@ -4,7 +4,7 @@ import { CurrentStateResponse } from "../events/current-state.response"; import { NotificationHandler } from "../utils/notification-handler"; import { IBehavior } from "./behavior"; -export interface IStateMachine extends IBehavior { +export interface IStateMachineBehavior extends IBehavior { getCurrentState(): Promise>; watchCurrentState(handler: NotificationHandler): Promise; unwatchCurrentState(): Promise; diff --git a/Transport/@stateflows/common/src/interfaces/state-machine.locator.ts b/Transport/@stateflows/common/src/interfaces/state-machine.locator.ts index 1707a818..922fbebc 100644 --- a/Transport/@stateflows/common/src/interfaces/state-machine.locator.ts +++ b/Transport/@stateflows/common/src/interfaces/state-machine.locator.ts @@ -1,6 +1,6 @@ import { StateMachineId } from "../ids/state-machine.id"; -import { IStateMachine } from "./state-machine"; +import { IStateMachineBehavior } from "./state-machine.behavior"; export interface IStateMachineLocator { - locateStateMachine(id: StateMachineId): Promise; + locateStateMachine(id: StateMachineId): Promise; } \ No newline at end of file diff --git a/Transport/@stateflows/http-client/package.json b/Transport/@stateflows/http-client/package.json index 894a0b43..26c08acd 100644 --- a/Transport/@stateflows/http-client/package.json +++ b/Transport/@stateflows/http-client/package.json @@ -1,6 +1,6 @@ { "name": "@stateflows/http-client", - "version": "0.12.0", + "version": "0.13.0", "description": "HTTP-based client for Stateflows framework", "main": "dist/index.js", "module": "./dist/index.mjs", @@ -23,10 +23,10 @@ "license": "MIT", "homepage": "https://www.stateflows.net", "devDependencies": { - "tsup": "^8.0.1", - "typescript": "^5.3.3" + "tsup": "^8.2.4", + "typescript": "^5.5.4" }, "dependencies": { - "@stateflows/common": "^0.12.0" + "@stateflows/common": "^0.13.0" } } diff --git a/Transport/@stateflows/signalr-client/package.json b/Transport/@stateflows/signalr-client/package.json index 7a5414ef..072ce6c9 100644 --- a/Transport/@stateflows/signalr-client/package.json +++ b/Transport/@stateflows/signalr-client/package.json @@ -1,6 +1,6 @@ { "name": "@stateflows/signalr-client", - "version": "0.12.0", + "version": "0.13.0", "description": "SignalR-based client for Stateflows framework", "main": "dist/index.js", "module": "./dist/index.mjs", @@ -26,10 +26,10 @@ "homepage": "https://www.stateflows.net", "dependencies": { "@microsoft/signalr": "^8.0.0", - "@stateflows/common": "^0.12.0" + "@stateflows/common": "^0.13.0" }, "devDependencies": { - "tsup": "^8.0.1", - "typescript": "^5.3.3" + "tsup": "^8.2.4", + "typescript": "^5.5.4" } } diff --git a/Transport/Stateflows.Transport.Http/Stateflows.Transport.Http.csproj b/Transport/Stateflows.Transport.Http/Stateflows.Transport.Http.csproj index 2165dc4b..88f37d81 100644 --- a/Transport/Stateflows.Transport.Http/Stateflows.Transport.Http.csproj +++ b/Transport/Stateflows.Transport.Http/Stateflows.Transport.Http.csproj @@ -36,9 +36,4 @@ \ - - - - -