From d1bcbe92cc701331cb6176244a6a67c5b866d716 Mon Sep 17 00:00:00 2001 From: mikolaj-milewski Date: Mon, 12 Feb 2024 14:53:09 +0100 Subject: [PATCH 1/2] Create dotnet-test.yml --- .github/workflows/dotnet-test.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/dotnet-test.yml diff --git a/.github/workflows/dotnet-test.yml b/.github/workflows/dotnet-test.yml new file mode 100644 index 00000000..d23825f4 --- /dev/null +++ b/.github/workflows/dotnet-test.yml @@ -0,0 +1,29 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: .NET test + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 6.0.x + - name: Restore dependencies + working-directory: ./Tests/StateMachine/StateMachine.IntegrationTests + run: dotnet restore + - name: Build + run: dotnet build --no-restore + - name: Test + run: dotnet test --no-build --verbosity normal From 267fd41a4378184c50e2039415f10fde4d10e701 Mon Sep 17 00:00:00 2001 From: mikolaj-milewski Date: Mon, 12 Feb 2024 16:14:56 +0100 Subject: [PATCH 2/2] 0.9.1-alpha (#22) * Http transport * 0.8.1-alpha * 0.9.1-alpha --- .gitignore | 2 + .../Activities/Classes/ActivityClass.cs | 4 +- .../Activities/Classes/ActivityId.cs | 9 +- .../Activities/Classes/ActivityLocator.cs | 3 +- .../Classes/ActivityClassFactory.cs | 9 - .../Classes/BehaviorClass.cs | 4 +- Core/Stateflows.Common/Classes/BehaviorId.cs | 3 + .../Stateflows.Common/Classes/BehaviorType.cs | 4 +- Core/Stateflows.Common/Classes/SendResult.cs | 6 +- .../Classes/StateMachineClassFactory.cs | 9 - .../Classes/StateMachineClass.cs | 4 +- .../StateMachines/Classes/StateMachineId.cs | 8 + .../Stateflows.Common.csproj | 2 +- Core/Stateflows.Common/Tokens/GroupToken.cs | 2 +- Core/Stateflows.Common/Tokens/Token.cs | 2 +- .../Sequence/ExecutionSequence.cs | 15 +- .../Sequence/IExecutionSequenceBuilder.cs | 4 +- .../Stateflows.Testing.csproj | 2 +- .../Classes/StateflowsRequest.cs | 26 ++ .../Classes/StateflowsResponse.cs | 28 ++ .../Stateflows.Common.Transport.csproj | 2 +- .../Stateflows/Activities/Classes/Activity.cs | 6 + .../Activities/Classes/DecisionNode.cs | 10 + .../Stateflows/Activities/Classes/ForkNode.cs | 7 + .../Classes/IterativeActivityNode.cs | 10 + .../Stateflows/Activities/Classes/JoinNode.cs | 7 + .../Activities/Classes/MergeNode.cs | 7 + .../Classes/ParalellActivityNode.cs | 10 + .../Classes/StructuredActivityNode.cs | 2 +- Core/Stateflows/Activities/Engine/Executor.cs | 13 +- .../Stateflows/Activities/Engine/NodeScope.cs | 182 ++------- .../Builders/ActivitiesBuilder.cs | 2 +- .../ActivityBuilderAnonymousExtensions.cs | 4 +- .../ActivityBuilderSpecialsExtensions.cs | 17 +- .../ActivityBuilderTypedExtensions.cs | 8 +- .../ActivityBuilderTypedPayloadExtensions.cs | 8 +- ...turedActivityBuilderAnonymousExtensions.cs | 4 +- ...cturedActivityBuilderSpecialsExtensions.cs | 16 + ...tructuredActivityBuilderTypedExtensions.cs | 8 +- ...edActivityBuilderTypedPayloadExtensions.cs | 8 +- ...turedActivityBuilderAnonymousExtensions.cs | 4 +- ...cturedActivityBuilderSpecialsExtensions.cs | 17 + ...tructuredActivityBuilderTypedExtensions.cs | 8 +- ...edActivityBuilderTypedPayloadExtensions.cs | 8 +- .../TypedActivityBuilderTypedExtensions.cs | 8 +- ...edActivityBuilderTypedPayloadExtensions.cs | 8 +- .../Activities/Tokens/ParametersToken.cs | 10 - .../Common/Initializer/ThreadInitializer.cs | 2 +- .../StateMachines/Classes/StateMachine.cs | 6 + .../StateMachines/Engine/Executor.cs | 138 +------ .../EventHandlers/CurrentStateHandler.cs | 2 +- .../{Completion.cs => CompletionEvent.cs} | 2 +- .../Builders/CompositeStateBuilder.cs | 28 +- .../Registration/Builders/StateBuilder.cs | 22 +- .../Interfaces/Base/IStateTransitions.cs | 4 +- ...derElseDefaultTransitionTypedExtensions.cs | 8 +- ...derElseDefaultTransitionTypedExtensions.cs | 8 +- ...derElseDefaultTransitionTypedExtensions.cs | 8 +- ...BuilderDefaultTransitionTypedExtensions.cs | 8 +- ...BuilderDefaultTransitionTypedExtensions.cs | 8 +- ...BuilderDefaultTransitionTypedExtensions.cs | 8 +- ...derElseDefaultTransitionTypedExtensions.cs | 8 +- ...BuilderDefaultTransitionTypedExtensions.cs | 8 +- ...derElseDefaultTransitionTypedExtensions.cs | 8 +- ...derElseDefaultTransitionTypedExtensions.cs | 8 +- ...derElseDefaultTransitionTypedExtensions.cs | 8 +- ...BuilderDefaultTransitionTypedExtensions.cs | 8 +- ...BuilderDefaultTransitionTypedExtensions.cs | 8 +- ...BuilderDefaultTransitionTypedExtensions.cs | 8 +- ...derElseDefaultTransitionTypedExtensions.cs | 8 +- ...BuilderDefaultTransitionTypedExtensions.cs | 8 +- Core/Stateflows/Stateflows.csproj | 2 +- .../Server/Blazor.Server/Blazor.Server.csproj | 2 +- .../Blazor/Server/Blazor.Server/Program.cs | 98 +++-- .../Client/Blazor.WebAssembly.Client.csproj | 2 + .../Client/Pages/StateMachines.razor | 2 +- Examples/Blazor/WebAssembly/Client/Program.cs | 3 +- .../Server/Blazor.WebAssembly.Server.csproj | 1 + Examples/Blazor/WebAssembly/Server/Program.cs | 4 +- Examples/Cluster/Cluster.csproj | 1 - .../Examples.Storage/DependencyInjection.cs | 4 +- .../Examples.Storage/Examples.Storage.csproj | 3 +- .../MassTransit.Service1.csproj | 1 - .../MassTransit.Service2.csproj | 1 - .../MassTransit.Service3.csproj | 1 - .../SignalR.Client/ClientApp/package.json | 2 + .../src/app/counter/counter.component.ts | 16 +- Examples/SignalR/SignalR.Client/Program.cs | 5 +- .../SignalR.Client/SignalR.Client.csproj | 1 + .../Classes/ActivityPlantUmlGenerator.cs | 10 +- .../Stateflows.Extensions.PlantUml.csproj | 2 +- .../Stateflows.Locks.DistributedLock.csproj | 2 +- Stateflows.sln | 21 +- .../DependencyInjection.cs | 0 .../Entities/Context_v1.cs | 0 .../EntityFrameworkCore/Entities/Trace_v1.cs | 0 .../IStateflowsDbContext_v1.cs | 0 ...eflows.Storage.EntityFrameworkCore.csproj} | 4 +- .../Stateflows/EntityFrameworkCoreStorage.cs | 0 .../Utils/DbSetExtensions.cs | 0 .../DependencyInjection.cs | 3 +- .../MongoDB/Entities/StateflowsContext_v1.cs | 22 + .../{Context_v1.cs => StateflowsTrace_v1.cs} | 9 +- .../MongoDB/Entities/TimeToken_v1.cs | 18 - .../Stateflows/MongoDBStorage.cs | 130 ++---- .../Utils/CollectionNames.cs | 4 +- .../Utils/MongoDBSetExtension.cs | 60 ++- .../Classes/States/State1.cs | 4 +- .../Classes/States/State2.cs | 4 +- .../Transitions/SomeEventTransition.cs | 4 +- .../Tests/Composite.cs | 10 +- .../Tests/ExternalTransitions.cs | 24 +- Transport/@stateflows/common/dist/index.d.mts | 182 +++++++++ Transport/@stateflows/common/dist/index.d.ts | 182 +++++++++ Transport/@stateflows/common/dist/index.js | 376 ++++++++++++++++++ .../@stateflows/common/dist/index.js.map | 1 + Transport/@stateflows/common/dist/index.mjs | 329 +++++++++++++++ .../@stateflows/common/dist/index.mjs.map | 1 + Transport/@stateflows/common/package.json | 29 ++ .../src/behaviors/activity.ts | 0 .../src/behaviors/behavior.ts | 21 +- .../src/behaviors/state-machine.ts | 0 .../src/behaviors/system.ts | 0 .../src/classes/event-validation.ts | 0 .../src/classes/request-result.ts | 1 + .../src/classes/send-result.ts | 1 + .../src/classes/stateflows-client.ts | 26 +- .../src/classes/validation-result.ts | 0 .../src/enums/behavior-status.ts | 0 .../src/enums/event-status.ts | 0 .../available-behavior-classes.request.ts | 0 .../available-behavior-classes.response.ts | 0 .../src/events/behavior-instances.request.ts | 0 .../src/events/behavior-instances.response.ts | 0 .../src/events/behavior-status.request.ts | 0 .../src/events/behavior-status.response.ts | 0 .../src/events/current-state.request.ts | 0 .../src/events/current-state.response.ts | 0 .../src/events/event.ts | 0 .../src/events/initialization.request.ts | 0 .../src/events/initialization.response.ts | 0 .../src/events/plant-uml.request.ts | 0 .../src/events/plant-uml.response.ts | 0 .../src/events/request.ts | 2 +- .../src/events/response.ts | 0 .../src/ids/activity.id.ts | 0 .../src/ids/behavior.class.ts | 0 .../src/ids/behavior.id.ts | 0 .../src/ids/state-machine.id.ts | 0 Transport/@stateflows/common/src/index.ts | 31 ++ .../src/interfaces/activity.locator.ts | 0 .../src/interfaces/activity.ts | 0 .../src/interfaces/behavior.locator.ts | 0 .../src/interfaces/behavior.ts | 0 .../src/interfaces/state-machine.locator.ts | 0 .../src/interfaces/state-machine.ts | 0 .../stateflows-client-transport-factory.ts | 5 + .../interfaces/stateflows-client-transport.ts | 9 + .../src/interfaces/system.ts | 0 .../src/locators/activity.locator.ts | 0 .../src/locators/behavior.locator.ts | 33 +- .../src/locators/state-machine.locator.ts | 0 Transport/@stateflows/common/tsup.config.ts | 10 + .../@stateflows/http-client/dist/index.d.mts | 5 + .../@stateflows/http-client/dist/index.d.ts | 5 + .../@stateflows/http-client/dist/index.js | 2 + .../@stateflows/http-client/dist/index.js.map | 1 + .../@stateflows/http-client/dist/index.mjs | 2 + .../http-client/dist/index.mjs.map | 1 + .../@stateflows/http-client/package.json | 33 ++ .../src/classes/http-transport-factory.ts | 14 + .../http-client/src/classes/http-transport.ts | 47 +++ .../@stateflows/http-client/src/index.ts | 1 + .../@stateflows/http-client/tsconfig.json | 14 + .../@stateflows/http-client/tsup.config.ts | 11 + .../@stateflows/signalr-client/package.json | 7 +- .../src/classes/signalr-transport-factory.ts | 14 + .../src/classes/signalr-transport.ts | 55 +++ .../@stateflows/signalr-client/src/index.ts | 28 +- .../Behavior.cs | 2 +- .../BehaviorProvider.cs | 2 +- .../DependencyInjection.cs | 2 +- ...Transport.AspNetCore.SignalR.Client.csproj | 2 +- .../DependencyInjection.cs | 2 +- ...eflows.Transport.AspNetCore.SignalR.csproj | 2 +- .../Behavior.cs | 33 ++ .../BehaviorProvider.cs | 37 ++ .../DependencyInjection.cs | 34 ++ .../Stateflows.Transport.Http.Client.csproj | 26 +- .../StateflowsApiClient.cs | 45 +++ .../DependencyInjection.cs | 63 +++ .../Stateflows.Transport.Http.csproj | 44 ++ 192 files changed, 2318 insertions(+), 807 deletions(-) delete mode 100644 Core/Stateflows.Common/Classes/ActivityClassFactory.cs delete mode 100644 Core/Stateflows.Common/Classes/StateMachineClassFactory.cs create mode 100644 Core/Stateflows.Transport.Common/Classes/StateflowsRequest.cs create mode 100644 Core/Stateflows.Transport.Common/Classes/StateflowsResponse.cs create mode 100644 Core/Stateflows/Activities/Classes/DecisionNode.cs create mode 100644 Core/Stateflows/Activities/Classes/ForkNode.cs create mode 100644 Core/Stateflows/Activities/Classes/IterativeActivityNode.cs create mode 100644 Core/Stateflows/Activities/Classes/JoinNode.cs create mode 100644 Core/Stateflows/Activities/Classes/MergeNode.cs create mode 100644 Core/Stateflows/Activities/Classes/ParalellActivityNode.cs delete mode 100644 Core/Stateflows/Activities/Tokens/ParametersToken.cs rename Core/Stateflows/StateMachines/Events/{Completion.cs => CompletionEvent.cs} (80%) rename Storage/{Stateflows.Storage.EntityFrameworkCore.6.0 => Stateflows.Storage.EntityFrameworkCore}/DependencyInjection.cs (100%) rename Storage/{Stateflows.Storage.EntityFrameworkCore.6.0 => Stateflows.Storage.EntityFrameworkCore}/EntityFrameworkCore/Entities/Context_v1.cs (100%) rename Storage/{Stateflows.Storage.EntityFrameworkCore.6.0 => Stateflows.Storage.EntityFrameworkCore}/EntityFrameworkCore/Entities/Trace_v1.cs (100%) rename Storage/{Stateflows.Storage.EntityFrameworkCore.6.0 => Stateflows.Storage.EntityFrameworkCore}/EntityFrameworkCore/IStateflowsDbContext_v1.cs (100%) rename Storage/{Stateflows.Storage.EntityFrameworkCore.6.0/Stateflows.Storage.EntityFrameworkCore.6.0.csproj => Stateflows.Storage.EntityFrameworkCore/Stateflows.Storage.EntityFrameworkCore.csproj} (94%) rename Storage/{Stateflows.Storage.EntityFrameworkCore.6.0 => Stateflows.Storage.EntityFrameworkCore}/Stateflows/EntityFrameworkCoreStorage.cs (100%) rename Storage/{Stateflows.Storage.EntityFrameworkCore.6.0 => Stateflows.Storage.EntityFrameworkCore}/Utils/DbSetExtensions.cs (100%) create mode 100644 Storage/Stateflows.Storage.MongoDb/MongoDB/Entities/StateflowsContext_v1.cs rename Storage/Stateflows.Storage.MongoDb/MongoDB/Entities/{Context_v1.cs => StateflowsTrace_v1.cs} (56%) delete mode 100644 Storage/Stateflows.Storage.MongoDb/MongoDB/Entities/TimeToken_v1.cs create mode 100644 Transport/@stateflows/common/dist/index.d.mts create mode 100644 Transport/@stateflows/common/dist/index.d.ts create mode 100644 Transport/@stateflows/common/dist/index.js create mode 100644 Transport/@stateflows/common/dist/index.js.map create mode 100644 Transport/@stateflows/common/dist/index.mjs create mode 100644 Transport/@stateflows/common/dist/index.mjs.map create mode 100644 Transport/@stateflows/common/package.json rename Transport/@stateflows/{signalr-client => common}/src/behaviors/activity.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/behaviors/behavior.ts (68%) rename Transport/@stateflows/{signalr-client => common}/src/behaviors/state-machine.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/behaviors/system.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/classes/event-validation.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/classes/request-result.ts (90%) rename Transport/@stateflows/{signalr-client => common}/src/classes/send-result.ts (86%) rename Transport/@stateflows/{signalr-client => common}/src/classes/stateflows-client.ts (71%) rename Transport/@stateflows/{signalr-client => common}/src/classes/validation-result.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/enums/behavior-status.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/enums/event-status.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/events/available-behavior-classes.request.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/events/available-behavior-classes.response.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/events/behavior-instances.request.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/events/behavior-instances.response.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/events/behavior-status.request.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/events/behavior-status.response.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/events/current-state.request.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/events/current-state.response.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/events/event.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/events/initialization.request.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/events/initialization.response.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/events/plant-uml.request.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/events/plant-uml.response.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/events/request.ts (81%) rename Transport/@stateflows/{signalr-client => common}/src/events/response.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/ids/activity.id.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/ids/behavior.class.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/ids/behavior.id.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/ids/state-machine.id.ts (100%) create mode 100644 Transport/@stateflows/common/src/index.ts rename Transport/@stateflows/{signalr-client => common}/src/interfaces/activity.locator.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/interfaces/activity.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/interfaces/behavior.locator.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/interfaces/behavior.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/interfaces/state-machine.locator.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/interfaces/state-machine.ts (100%) create mode 100644 Transport/@stateflows/common/src/interfaces/stateflows-client-transport-factory.ts create mode 100644 Transport/@stateflows/common/src/interfaces/stateflows-client-transport.ts rename Transport/@stateflows/{signalr-client => common}/src/interfaces/system.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/locators/activity.locator.ts (100%) rename Transport/@stateflows/{signalr-client => common}/src/locators/behavior.locator.ts (53%) rename Transport/@stateflows/{signalr-client => common}/src/locators/state-machine.locator.ts (100%) create mode 100644 Transport/@stateflows/common/tsup.config.ts create mode 100644 Transport/@stateflows/http-client/dist/index.d.mts create mode 100644 Transport/@stateflows/http-client/dist/index.d.ts create mode 100644 Transport/@stateflows/http-client/dist/index.js create mode 100644 Transport/@stateflows/http-client/dist/index.js.map create mode 100644 Transport/@stateflows/http-client/dist/index.mjs create mode 100644 Transport/@stateflows/http-client/dist/index.mjs.map create mode 100644 Transport/@stateflows/http-client/package.json create mode 100644 Transport/@stateflows/http-client/src/classes/http-transport-factory.ts create mode 100644 Transport/@stateflows/http-client/src/classes/http-transport.ts create mode 100644 Transport/@stateflows/http-client/src/index.ts create mode 100644 Transport/@stateflows/http-client/tsconfig.json create mode 100644 Transport/@stateflows/http-client/tsup.config.ts create mode 100644 Transport/@stateflows/signalr-client/src/classes/signalr-transport-factory.ts create mode 100644 Transport/@stateflows/signalr-client/src/classes/signalr-transport.ts create mode 100644 Transport/Stateflows.Transport.Http.Client/Behavior.cs create mode 100644 Transport/Stateflows.Transport.Http.Client/BehaviorProvider.cs create mode 100644 Transport/Stateflows.Transport.Http.Client/DependencyInjection.cs rename Storage/Stateflows.Storage.EntityFrameworkCore.6.0/Stateflows - Backup.Storage.EntityFrameworkCore.6.0.csproj => Transport/Stateflows.Transport.Http.Client/Stateflows.Transport.Http.Client.csproj (58%) create mode 100644 Transport/Stateflows.Transport.Http.Client/StateflowsApiClient.cs create mode 100644 Transport/Stateflows.Transport.Http/DependencyInjection.cs create mode 100644 Transport/Stateflows.Transport.Http/Stateflows.Transport.Http.csproj diff --git a/.gitignore b/.gitignore index 74f13f81..b9156053 100644 --- a/.gitignore +++ b/.gitignore @@ -493,3 +493,5 @@ $RECYCLE.BIN/ .angular Transport/@stateflows/signalr-client/dist/ Examples/SignalR/SignalR.Client/ClientApp/.angular/ +*.txt +Publish.ps1 diff --git a/Core/Stateflows.Common/Activities/Classes/ActivityClass.cs b/Core/Stateflows.Common/Activities/Classes/ActivityClass.cs index 31e73a23..48cbcc12 100644 --- a/Core/Stateflows.Common/Activities/Classes/ActivityClass.cs +++ b/Core/Stateflows.Common/Activities/Classes/ActivityClass.cs @@ -53,7 +53,7 @@ public readonly override int GetHashCode() public readonly override string ToString() => StateflowsJsonConverter.SerializeObject(this); - public readonly StateMachineId ToId(string instance) - => new StateMachineId(Name, instance); + public static implicit operator string(ActivityClass activityClass) + => StateflowsJsonConverter.SerializeObject(activityClass); } } diff --git a/Core/Stateflows.Common/Activities/Classes/ActivityId.cs b/Core/Stateflows.Common/Activities/Classes/ActivityId.cs index 56f374bd..363c05e2 100644 --- a/Core/Stateflows.Common/Activities/Classes/ActivityId.cs +++ b/Core/Stateflows.Common/Activities/Classes/ActivityId.cs @@ -1,5 +1,6 @@ using System; using Stateflows.Common.Exceptions; +using Stateflows.Common.Utilities; namespace Stateflows.Activities { @@ -26,7 +27,7 @@ public ActivityId(BehaviorId id) public string Instance { get; set; } - public readonly BehaviorId BehaviorId => BehaviorType.Activity.ToClass(Name).ToId(Instance); + public readonly BehaviorId BehaviorId => new BehaviorId(BehaviorType.Activity, Name, Instance); public static bool operator ==(ActivityId id1, ActivityId id2) => id1.Equals(id2); @@ -54,5 +55,11 @@ obj is ActivityId id && public readonly override int GetHashCode() => Tuple.Create(Name, Instance).GetHashCode(); + + public readonly override string ToString() + => StateflowsJsonConverter.SerializeObject(this); + + public static implicit operator string(ActivityId activityId) + => StateflowsJsonConverter.SerializeObject(activityId); } } diff --git a/Core/Stateflows.Common/Activities/Classes/ActivityLocator.cs b/Core/Stateflows.Common/Activities/Classes/ActivityLocator.cs index 66a18fc5..36411008 100644 --- a/Core/Stateflows.Common/Activities/Classes/ActivityLocator.cs +++ b/Core/Stateflows.Common/Activities/Classes/ActivityLocator.cs @@ -1,5 +1,4 @@ -using Stateflows.Common; -using Stateflows.Activities; +using Stateflows.Activities; namespace Stateflows.Common.Activities.Classes { diff --git a/Core/Stateflows.Common/Classes/ActivityClassFactory.cs b/Core/Stateflows.Common/Classes/ActivityClassFactory.cs deleted file mode 100644 index ab593706..00000000 --- a/Core/Stateflows.Common/Classes/ActivityClassFactory.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Stateflows -{ - public struct ActivityClassFactory - { - public readonly ActivityClass ToClass(string name) => new ActivityClass(name); - - public static implicit operator string(ActivityClassFactory _) => "Activity"; - } -} diff --git a/Core/Stateflows.Common/Classes/BehaviorClass.cs b/Core/Stateflows.Common/Classes/BehaviorClass.cs index efb5794c..f4851302 100644 --- a/Core/Stateflows.Common/Classes/BehaviorClass.cs +++ b/Core/Stateflows.Common/Classes/BehaviorClass.cs @@ -44,7 +44,7 @@ public readonly override int GetHashCode() public readonly override string ToString() => StateflowsJsonConverter.SerializeObject(this); - public readonly BehaviorId ToId(string instance) - => new BehaviorId(this, instance); + public static implicit operator string(BehaviorClass behaviorClass) + => StateflowsJsonConverter.SerializeObject(behaviorClass); } } diff --git a/Core/Stateflows.Common/Classes/BehaviorId.cs b/Core/Stateflows.Common/Classes/BehaviorId.cs index ffd889ea..c652f079 100644 --- a/Core/Stateflows.Common/Classes/BehaviorId.cs +++ b/Core/Stateflows.Common/Classes/BehaviorId.cs @@ -31,6 +31,9 @@ public BehaviorId(string type, string name, string instance) public readonly override string ToString() => StateflowsJsonConverter.SerializeObject(this); + public static implicit operator string(BehaviorId behaviorId) + => StateflowsJsonConverter.SerializeObject(behaviorId); + public static bool operator ==(BehaviorId id1, BehaviorId id2) => id1.Equals(id2); diff --git a/Core/Stateflows.Common/Classes/BehaviorType.cs b/Core/Stateflows.Common/Classes/BehaviorType.cs index 2e143099..09c97845 100644 --- a/Core/Stateflows.Common/Classes/BehaviorType.cs +++ b/Core/Stateflows.Common/Classes/BehaviorType.cs @@ -2,7 +2,7 @@ { public static class BehaviorType { - public static readonly ActivityClassFactory Activity; - public static readonly StateMachineClassFactory StateMachine; + public static readonly string Activity = nameof(Activity); + public static readonly string StateMachine = nameof(StateMachine); } } diff --git a/Core/Stateflows.Common/Classes/SendResult.cs b/Core/Stateflows.Common/Classes/SendResult.cs index 655a2834..6b87eb07 100644 --- a/Core/Stateflows.Common/Classes/SendResult.cs +++ b/Core/Stateflows.Common/Classes/SendResult.cs @@ -1,4 +1,6 @@ using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations; +using System; namespace Stateflows.Common { @@ -7,11 +9,11 @@ public class SendResult [JsonConstructor] protected SendResult() { } - public SendResult(Event @event, EventStatus status, EventValidation validation) + public SendResult(Event @event, EventStatus status, EventValidation validation = null) { Event = @event; Status = status; - Validation = validation; + Validation = validation ?? new EventValidation(true, Array.Empty()); } public Event Event { get; set; } diff --git a/Core/Stateflows.Common/Classes/StateMachineClassFactory.cs b/Core/Stateflows.Common/Classes/StateMachineClassFactory.cs deleted file mode 100644 index 77948bce..00000000 --- a/Core/Stateflows.Common/Classes/StateMachineClassFactory.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Stateflows -{ - public struct StateMachineClassFactory - { - public readonly StateMachineClass ToClass(string name) => new StateMachineClass(name); - - public static implicit operator string(StateMachineClassFactory _) => "StateMachine"; - } -} diff --git a/Core/Stateflows.Common/StateMachines/Classes/StateMachineClass.cs b/Core/Stateflows.Common/StateMachines/Classes/StateMachineClass.cs index 50a2da48..8335aa2d 100644 --- a/Core/Stateflows.Common/StateMachines/Classes/StateMachineClass.cs +++ b/Core/Stateflows.Common/StateMachines/Classes/StateMachineClass.cs @@ -53,7 +53,7 @@ public readonly override int GetHashCode() public readonly override string ToString() => StateflowsJsonConverter.SerializeObject(this); - public readonly StateMachineId ToId(string instance) - => new StateMachineId(Name, instance); + public static implicit operator string(StateMachineClass stateMachineClass) + => StateflowsJsonConverter.SerializeObject(stateMachineClass); } } diff --git a/Core/Stateflows.Common/StateMachines/Classes/StateMachineId.cs b/Core/Stateflows.Common/StateMachines/Classes/StateMachineId.cs index 6736063d..26b40639 100644 --- a/Core/Stateflows.Common/StateMachines/Classes/StateMachineId.cs +++ b/Core/Stateflows.Common/StateMachines/Classes/StateMachineId.cs @@ -1,6 +1,8 @@ using System; using Newtonsoft.Json; +using Stateflows.Activities; using Stateflows.Common.Exceptions; +using Stateflows.Common.Utilities; namespace Stateflows.StateMachines { @@ -65,5 +67,11 @@ obj is StateMachineId id && public readonly override int GetHashCode() => Tuple.Create(Name, Instance).GetHashCode(); + + public readonly override string ToString() + => StateflowsJsonConverter.SerializeObject(this); + + public static implicit operator string(StateMachineId stateMachineId) + => StateflowsJsonConverter.SerializeObject(stateMachineId); } } diff --git a/Core/Stateflows.Common/Stateflows.Common.csproj b/Core/Stateflows.Common/Stateflows.Common.csproj index 3cc659c0..60674532 100644 --- a/Core/Stateflows.Common/Stateflows.Common.csproj +++ b/Core/Stateflows.Common/Stateflows.Common.csproj @@ -12,7 +12,7 @@ Stateflows;state-machine;activity;workflow - 0.8.0-alpha + $(STATEFLOWS_VERSION) README.md LICENSE ..\..\NuGet diff --git a/Core/Stateflows.Common/Tokens/GroupToken.cs b/Core/Stateflows.Common/Tokens/GroupToken.cs index b52fb4b5..246147e8 100644 --- a/Core/Stateflows.Common/Tokens/GroupToken.cs +++ b/Core/Stateflows.Common/Tokens/GroupToken.cs @@ -9,7 +9,7 @@ public GroupToken() { } public override string Name - => $"Stateflows.Activities.GroupToken<{TokenInfo.TokenName}>"; + => $"Stateflows.Activities.GroupToken<{TokenInfo.Name}>"; public List Tokens { get; set; } = new List(); } diff --git a/Core/Stateflows.Common/Tokens/Token.cs b/Core/Stateflows.Common/Tokens/Token.cs index 56392380..0ae19097 100644 --- a/Core/Stateflows.Common/Tokens/Token.cs +++ b/Core/Stateflows.Common/Tokens/Token.cs @@ -41,7 +41,7 @@ public static IEnumerable CloneTokens(this IEnumerable t public static class TokenInfo where TToken : Token, new() { - public static string TokenName => TokenInfo.GetName(typeof(TToken)); + public static string Name => TokenInfo.GetName(typeof(TToken)); } public static class TokenInfo diff --git a/Core/Stateflows.Testing/StateMachines/Sequence/ExecutionSequence.cs b/Core/Stateflows.Testing/StateMachines/Sequence/ExecutionSequence.cs index 93508906..a74ef90e 100644 --- a/Core/Stateflows.Testing/StateMachines/Sequence/ExecutionSequence.cs +++ b/Core/Stateflows.Testing/StateMachines/Sequence/ExecutionSequence.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using Stateflows.Common; +using Stateflows.Common.Exceptions; using Stateflows.StateMachines.Events; +#nullable enable namespace Stateflows.Testing.StateMachines.Sequence { @@ -11,7 +13,12 @@ internal class ExecutionSequence : IExecutionSequenceBuilder public void ValidateWith(IExecutionSequenceBuilder sequenceBuilder) { - var actualSequence = (sequenceBuilder as ExecutionSequence).Sequence; + if (!(sequenceBuilder is ExecutionSequence executionSequence)) + { + return; + } + + var actualSequence = executionSequence.Sequence; int index = 0; for (int x = 0; x < Sequence.Count; x++) @@ -31,16 +38,16 @@ public void ValidateWith(IExecutionSequenceBuilder sequenceBuilder) if (!found) { - throw new Exception($"Expected execution step \"{entry}\" not found"); + throw new StateflowsException($"Expected execution step \"{entry}\" not found"); } } } public IExecutionSequenceBuilder DefaultTransitionEffect(string sourceStateName, string targetVertexName) - => TransitionEffect(EventInfo.Name, sourceStateName, targetVertexName); + => TransitionEffect(EventInfo.Name, sourceStateName, targetVertexName); public IExecutionSequenceBuilder DefaultTransitionGuard(string sourceStateName, string targetVertexName) - => TransitionGuard(EventInfo.Name, sourceStateName, targetVertexName); + => TransitionGuard(EventInfo.Name, sourceStateName, targetVertexName); public IExecutionSequenceBuilder InternalTransitionEffect(string eventName, string sourceStateName) => TransitionEffect(eventName, sourceStateName, ""); diff --git a/Core/Stateflows.Testing/StateMachines/Sequence/IExecutionSequenceBuilder.cs b/Core/Stateflows.Testing/StateMachines/Sequence/IExecutionSequenceBuilder.cs index 9adca2fa..ec670bae 100644 --- a/Core/Stateflows.Testing/StateMachines/Sequence/IExecutionSequenceBuilder.cs +++ b/Core/Stateflows.Testing/StateMachines/Sequence/IExecutionSequenceBuilder.cs @@ -1,4 +1,6 @@ -namespace Stateflows.Testing.StateMachines.Sequence +#nullable enable + +namespace Stateflows.Testing.StateMachines.Sequence { public interface IExecutionSequenceBuilder { diff --git a/Core/Stateflows.Testing/Stateflows.Testing.csproj b/Core/Stateflows.Testing/Stateflows.Testing.csproj index ea15e73f..8ffc2b2c 100644 --- a/Core/Stateflows.Testing/Stateflows.Testing.csproj +++ b/Core/Stateflows.Testing/Stateflows.Testing.csproj @@ -2,7 +2,7 @@ netstandard2.1 - 0.8.0-alpha + $(STATEFLOWS_VERSION) Stateflows framework testing utilities Stateflows True diff --git a/Core/Stateflows.Transport.Common/Classes/StateflowsRequest.cs b/Core/Stateflows.Transport.Common/Classes/StateflowsRequest.cs new file mode 100644 index 00000000..2a808335 --- /dev/null +++ b/Core/Stateflows.Transport.Common/Classes/StateflowsRequest.cs @@ -0,0 +1,26 @@ +using Stateflows.Common.Utilities; +using System.Text.Json.Serialization; + +namespace Stateflows.Common.Transport.Classes +{ + public class StateflowsRequest + { + public string EventString { get; set; } + + [JsonIgnore] + public Event Event + { + get => StateflowsJsonConverter.DeserializeObject(EventString); + set => EventString = StateflowsJsonConverter.SerializePolymorphicObject(value); + } + + public string BehaviorIdString { get; set; } + + [JsonIgnore] + public BehaviorId BehaviorId + { + get => StateflowsJsonConverter.DeserializeObject(BehaviorIdString); + set => BehaviorIdString = StateflowsJsonConverter.SerializePolymorphicObject(value); + } + } +} diff --git a/Core/Stateflows.Transport.Common/Classes/StateflowsResponse.cs b/Core/Stateflows.Transport.Common/Classes/StateflowsResponse.cs new file mode 100644 index 00000000..7a54aaad --- /dev/null +++ b/Core/Stateflows.Transport.Common/Classes/StateflowsResponse.cs @@ -0,0 +1,28 @@ +using Stateflows.Common.Utilities; +using System.Text.Json.Serialization; + +namespace Stateflows.Common.Transport.Classes +{ + public class StateflowsResponse + { + public EventStatus EventStatus { get; set; } + + public string ValidationString { get; set; } + + [JsonIgnore] + public EventValidation Validation + { + get => StateflowsJsonConverter.DeserializeObject(ValidationString); + set => ValidationString = StateflowsJsonConverter.SerializePolymorphicObject(value); + } + + public string ResponseString { get; set; } + + [JsonIgnore] + public Response Response + { + get => StateflowsJsonConverter.DeserializeObject(ResponseString); + set => ResponseString = StateflowsJsonConverter.SerializePolymorphicObject(value); + } + } +} diff --git a/Core/Stateflows.Transport.Common/Stateflows.Common.Transport.csproj b/Core/Stateflows.Transport.Common/Stateflows.Common.Transport.csproj index 9812a82d..bb2faf7a 100644 --- a/Core/Stateflows.Transport.Common/Stateflows.Common.Transport.csproj +++ b/Core/Stateflows.Transport.Common/Stateflows.Common.Transport.csproj @@ -3,7 +3,7 @@ netstandard2.1 Stateflows framework transport abstractions - 0.8.0-alpha + $(STATEFLOWS_VERSION) Stateflows https://www.stateflows.net stateflows-logo-1024.png diff --git a/Core/Stateflows/Activities/Classes/Activity.cs b/Core/Stateflows/Activities/Classes/Activity.cs index 1b764c49..310cc40d 100644 --- a/Core/Stateflows/Activities/Classes/Activity.cs +++ b/Core/Stateflows/Activities/Classes/Activity.cs @@ -55,5 +55,11 @@ public static string Name : stateMachineType.FullName; } } + + public static BehaviorClass ToClass() + => new BehaviorClass(BehaviorType.Activity, Name); + + public static BehaviorId ToId(string instance) + => new BehaviorId(ToClass(), instance); } } diff --git a/Core/Stateflows/Activities/Classes/DecisionNode.cs b/Core/Stateflows/Activities/Classes/DecisionNode.cs new file mode 100644 index 00000000..6bc6573a --- /dev/null +++ b/Core/Stateflows/Activities/Classes/DecisionNode.cs @@ -0,0 +1,10 @@ +using Stateflows.Common; + +namespace Stateflows.Activities +{ + public sealed class DecisionNode : ActivityNode + where TToken : Token, new() + { + public string Name => $"Stateflows.Activities.DecisionNode<{TokenInfo.Name}>"; + } +} diff --git a/Core/Stateflows/Activities/Classes/ForkNode.cs b/Core/Stateflows/Activities/Classes/ForkNode.cs new file mode 100644 index 00000000..06ac7e39 --- /dev/null +++ b/Core/Stateflows/Activities/Classes/ForkNode.cs @@ -0,0 +1,7 @@ +namespace Stateflows.Activities +{ + public sealed class ForkNode : ActivityNode + { + public const string Name = "Stateflows.Activities.ForkNode"; + } +} diff --git a/Core/Stateflows/Activities/Classes/IterativeActivityNode.cs b/Core/Stateflows/Activities/Classes/IterativeActivityNode.cs new file mode 100644 index 00000000..0d5a0549 --- /dev/null +++ b/Core/Stateflows/Activities/Classes/IterativeActivityNode.cs @@ -0,0 +1,10 @@ +using Stateflows.Common; + +namespace Stateflows.Activities +{ + public abstract class IterativeActivityNode : StructuredActivityNode + where TToken : Token, new() + { + public string Name => $"Stateflows.Activities.IterativeActivityNode<{TokenInfo.Name}>"; + } +} diff --git a/Core/Stateflows/Activities/Classes/JoinNode.cs b/Core/Stateflows/Activities/Classes/JoinNode.cs new file mode 100644 index 00000000..17de7919 --- /dev/null +++ b/Core/Stateflows/Activities/Classes/JoinNode.cs @@ -0,0 +1,7 @@ +namespace Stateflows.Activities +{ + public sealed class JoinNode : ActivityNode + { + public const string Name = "Stateflows.Activities.JoinNode"; + } +} diff --git a/Core/Stateflows/Activities/Classes/MergeNode.cs b/Core/Stateflows/Activities/Classes/MergeNode.cs new file mode 100644 index 00000000..a22ebdc0 --- /dev/null +++ b/Core/Stateflows/Activities/Classes/MergeNode.cs @@ -0,0 +1,7 @@ +namespace Stateflows.Activities +{ + public sealed class MergeNode : ActivityNode + { + public const string Name = "Stateflows.Activities.MergeNode"; + } +} diff --git a/Core/Stateflows/Activities/Classes/ParalellActivityNode.cs b/Core/Stateflows/Activities/Classes/ParalellActivityNode.cs new file mode 100644 index 00000000..ab8bce4b --- /dev/null +++ b/Core/Stateflows/Activities/Classes/ParalellActivityNode.cs @@ -0,0 +1,10 @@ +using Stateflows.Common; + +namespace Stateflows.Activities +{ + public abstract class ParallelActivityNode : StructuredActivityNode + where TToken : Token, new() + { + public string Name => $"Stateflows.Activities.ParallelActivityNode<{TokenInfo.Name}>"; + } +} diff --git a/Core/Stateflows/Activities/Classes/StructuredActivityNode.cs b/Core/Stateflows/Activities/Classes/StructuredActivityNode.cs index 1b9a7856..aa4f4bdf 100644 --- a/Core/Stateflows/Activities/Classes/StructuredActivityNode.cs +++ b/Core/Stateflows/Activities/Classes/StructuredActivityNode.cs @@ -13,7 +13,7 @@ public virtual Task OnFinalizeAsync() => Task.CompletedTask; } - public abstract class StructuredActivity : StructuredActivityNode + public abstract class StructuredActivityNode : StructuredActivityNode where TToken : Token, new() { public new IActionContext Context => base.Context as IActionContext; diff --git a/Core/Stateflows/Activities/Engine/Executor.cs b/Core/Stateflows/Activities/Engine/Executor.cs index dd15a42e..2af1e634 100644 --- a/Core/Stateflows/Activities/Engine/Executor.cs +++ b/Core/Stateflows/Activities/Engine/Executor.cs @@ -48,7 +48,7 @@ internal class Executor : IDisposable public Executor(ActivitiesRegister register, Graph graph, IServiceProvider serviceProvider) { Register = register; - NodeScope = new NodeScope(serviceProvider, Guid.NewGuid()); + NodeScope = new NodeScope(serviceProvider, graph, Guid.NewGuid()); Graph = graph; Logger = serviceProvider.GetService>(); @@ -306,7 +306,7 @@ await Task.WhenAll(parallelInput await DoExecuteNodeStructureAsync( context.Node, - context.NodeScope, + context.NodeScope.CreateChildScope(context.Node, threadId), restOfInput.Concat(new Token[] { token }).ToArray(), token ); @@ -354,7 +354,7 @@ public async Task> DoExecuteIterativeNodeAsync(Action { await DoExecuteNodeStructureAsync( context.Node, - context.NodeScope, + context.NodeScope.CreateChildScope(context.Node, threadId), restOfInput.Concat(new Token[] { token }), token ); @@ -485,6 +485,7 @@ public async Task DoHandleNodeAsync(Node node, NodeScope nodeScope, IEnumerable< var inputTokens = input ?? streams.SelectMany(stream => stream.Tokens).ToArray(); + nodeScope = nodeScope.CreateChildScope(node); lock (node.Graph) { Debug.WriteLine($">>> Executing node {node.Name}, threadId: {nodeScope.ThreadId}"); @@ -500,11 +501,11 @@ public async Task DoHandleNodeAsync(Node node, NodeScope nodeScope, IEnumerable< Context.ClearEvent(); - if (@event is RecurringEvent) + if (@event is TimeEvent) { Inspector.AcceptEventsPlugin.UnregisterAcceptEventNode(node); - if (!node.IncomingEdges.Any() && Context.NodesToExecute.Contains(node)) + if (@event is RecurringEvent && !node.IncomingEdges.Any() && Context.NodesToExecute.Contains(node)) { Inspector.AcceptEventsPlugin.RegisterAcceptEventNode(node, nodeScope.ThreadId); } @@ -608,7 +609,7 @@ private async Task DoHandleEdgeAsync(Edge edge, ActionContext context) { var stream = Context.GetStream(edge.Identifier, context.NodeScope.ThreadId); - if (edgeTokenName != TokenInfo.TokenName) + if (edgeTokenName != TokenInfo.Name) { processedTokens.Add(new ControlToken()); } diff --git a/Core/Stateflows/Activities/Engine/NodeScope.cs b/Core/Stateflows/Activities/Engine/NodeScope.cs index a51650ad..acf2645a 100644 --- a/Core/Stateflows/Activities/Engine/NodeScope.cs +++ b/Core/Stateflows/Activities/Engine/NodeScope.cs @@ -1,10 +1,9 @@ using System; using System.Threading; -using System.Collections.Generic; using Microsoft.Extensions.DependencyInjection; using Stateflows.Common; using Stateflows.Activities.Context.Interfaces; - +using Stateflows.Activities.Models; namespace Stateflows.Activities.Engine { @@ -36,208 +35,113 @@ public CancellationToken CancellationToken public bool IsTerminated { get; private set; } + public Node Node { get; private set; } + public void Terminate() { CancellationTokenSource.Cancel(); - IsTerminated = true; + var currentScope = this; + do + { + currentScope.IsTerminated = true; + currentScope = currentScope.BaseNodeScope; + if (currentScope.Node == Node.Parent) + { + break; + } + } while (currentScope != null); } - public NodeScope(IServiceProvider serviceProvider, Guid threadId) + public NodeScope(IServiceProvider serviceProvider, Node node, Guid threadId) { baseServiceProvider = serviceProvider; + Node = node; ThreadId = threadId; } - public NodeScope(NodeScope nodeScope, Guid threadId) + private NodeScope(NodeScope nodeScope, Node node, Guid threadId) { BaseNodeScope = nodeScope; + Node = node; ThreadId = threadId; } public NodeScope ChildScope { get; private set; } - public NodeScope CreateChildScope(Guid? threadId = null) - => ChildScope = new NodeScope(this, threadId ?? ThreadId); - - private readonly IDictionary Actions = new Dictionary(); + public NodeScope CreateChildScope(Node node = null, Guid? threadId = null) + => ChildScope = new NodeScope(this, node ?? Node, threadId ?? ThreadId); public TAction GetAction(IActionContext context) where TAction : ActionNode { - lock (Actions) - { - if (!Actions.TryGetValue(typeof(TAction), out var action)) - { - action = ServiceProvider.GetService(); + var action = ServiceProvider.GetService(); + action.Context = context; - Actions.Add(typeof(TAction), action); - } - - action.Context = context; - - return action as TAction; - } + return action; } - private readonly IDictionary AcceptEventActions = new Dictionary(); - public TAcceptEventAction GetAcceptEventAction(IAcceptEventActionContext context) where TEvent : Event, new() where TAcceptEventAction : AcceptEventActionNode { - lock (AcceptEventActions) - { - if (!AcceptEventActions.TryGetValue(typeof(TAcceptEventAction), out var action)) - { - action = ServiceProvider.GetService(); - - AcceptEventActions.Add(typeof(TAcceptEventAction), action); - } + var acceptEventAction = ServiceProvider.GetService(); + acceptEventAction.Context = context; - var acceptEventAction = action as TAcceptEventAction; - - acceptEventAction.Context = context; - - return acceptEventAction; - } + return acceptEventAction; } - private readonly IDictionary SendEventActions = new Dictionary(); - public TSendEventAction GetSendEventAction(IActionContext context) where TEvent : Event, new() where TSendEventAction : SendEventActionNode { - lock (SendEventActions) - { - if (!SendEventActions.TryGetValue(typeof(TSendEventAction), out var action)) - { - action = ServiceProvider.GetService(); - - SendEventActions.Add(typeof(TSendEventAction), action); - } - - var acceptEventAction = action as TSendEventAction; + var acceptEventAction = ServiceProvider.GetService(); + acceptEventAction.Context = context; - acceptEventAction.Context = context; - - return acceptEventAction; - } + return acceptEventAction; } - private readonly IDictionary StructuredActivities = new Dictionary(); - public TStructuredActivity GetStructuredActivity(IActionContext context) where TStructuredActivity : StructuredActivityNode { - if (!StructuredActivities.TryGetValue(typeof(TStructuredActivity), out var structuredActivity)) - { - structuredActivity = ServiceProvider.GetService(); - - StructuredActivities.Add(typeof(TStructuredActivity), structuredActivity); - } - + var structuredActivity = ServiceProvider.GetService(); structuredActivity.Context = context; - return structuredActivity as TStructuredActivity; + return structuredActivity; } - private readonly IDictionary ExceptionHandlers = new Dictionary(); - public TExceptionHandler GetExceptionHandler(IExceptionHandlerContext context) where TException : Exception where TExceptionHandler : ExceptionHandlerNode { - if (!ExceptionHandlers.TryGetValue(typeof(TExceptionHandler), out var exceptionHandlerNode)) - { - var exceptionHandler = ServiceProvider.GetService(); - - exceptionHandler.Context = context; + var exceptionHandler = ServiceProvider.GetService(); + exceptionHandler.Context = context; - ExceptionHandlers.Add(typeof(TExceptionHandler), exceptionHandler); - - return exceptionHandler; - } - else - { - if (exceptionHandlerNode is TExceptionHandler exceptionHandler) - { - exceptionHandler.Context = context; + return exceptionHandler; + } - return exceptionHandler; - } - } + public TFlow GetFlow(IFlowContext context) + where TFlow : BaseControlFlow + { + var flow = ServiceProvider.GetService(); + flow.Context = context; - return null; + return flow; } - private readonly IDictionary Flows = new Dictionary(); - public TControlFlow GetControlFlow(IFlowContext context) where TControlFlow : ControlFlow - { - if (!Flows.TryGetValue(typeof(TControlFlow), out var flowObj)) - { - var flow = ServiceProvider.GetService(); - - flow.Context = context; - - Flows.Add(typeof(TControlFlow), flow); - - return flow; - } - else - { - (flowObj as TControlFlow).Context = context; - - return flowObj as TControlFlow; - } - } + => GetFlow(context); public TFlow GetObjectFlow(IFlowContext context) where TFlow : TokenFlow where TToken : Token, new() - { - if (!Flows.TryGetValue(typeof(TFlow), out var flowObj)) - { - var flow = ServiceProvider.GetService(); - - flow.Context = context; - - Flows.Add(typeof(TFlow), flow); - - return flow; - } - else - { - (flowObj as TFlow).Context = context; - - return flowObj as TFlow; - } - } + => GetFlow(context); public TFlow GetObjectTransformationFlow(IFlowContext context) where TFlow : TokenTransformationFlow where TToken : Token, new() where TTransformedToken : Token, new() - { - if (!Flows.TryGetValue(typeof(TFlow), out var flowObj)) - { - var flow = ServiceProvider.GetService(); - - flow.Context = context; - - Flows.Add(typeof(TFlow), flow); - - return flow; - } - else - { - (flowObj as TFlow).Context = context; - - return flowObj as TFlow; - } - } + => GetFlow(context); public void Dispose() { diff --git a/Core/Stateflows/Activities/Registration/Builders/ActivitiesBuilder.cs b/Core/Stateflows/Activities/Registration/Builders/ActivitiesBuilder.cs index d167b6d1..c5c77fa2 100644 --- a/Core/Stateflows/Activities/Registration/Builders/ActivitiesBuilder.cs +++ b/Core/Stateflows/Activities/Registration/Builders/ActivitiesBuilder.cs @@ -53,7 +53,7 @@ public IActivitiesBuilder AddFromLoadedAssemblies() public IActivitiesBuilder AddActivity(string activityName, ReactiveActivityBuildAction buildAction) => AddActivity(activityName, 1, buildAction); - [DebuggerHidden] + //[DebuggerHidden] public IActivitiesBuilder AddActivity(string activityName, int version, ReactiveActivityBuildAction buildAction) { Register.AddActivity(activityName, version, buildAction); diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderAnonymousExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderAnonymousExtensions.cs index f145e9e7..960b72b3 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderAnonymousExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderAnonymousExtensions.cs @@ -10,10 +10,10 @@ public static IActivityBuilder AddStructuredActivity(this IActivityBuilder build public static IActivityBuilder AddParallelActivity(this IActivityBuilder builder, ParallelActivityBuildAction buildAction) where TParallelizationToken : Token, new() - => builder.AddParallelActivity(ActivityNodeInfo>.Name, buildAction); + => builder.AddParallelActivity(ActivityNodeInfo>.Name, buildAction); public static IActivityBuilder AddIterativeActivity(this IActivityBuilder builder, IterativeActivityBuildAction buildAction) where TIterationToken : Token, new() - => builder.AddIterativeActivity(ActivityNodeInfo>.Name, buildAction); + => builder.AddIterativeActivity(ActivityNodeInfo>.Name, buildAction); } } diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderSpecialsExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderSpecialsExtensions.cs index e8be1dfb..4ece3c00 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderSpecialsExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderSpecialsExtensions.cs @@ -3,7 +3,6 @@ using Stateflows.Activities.Registration; using Stateflows.Activities.Registration.Builders; using Stateflows.Activities.Registration.Interfaces; -using Stateflows.StateMachines.Engine; namespace Stateflows.Activities { @@ -22,6 +21,9 @@ public static IActivityBuilder AddJoin(this IActivityBuilder builder, string joi b => joinBuildAction(b) ) as IActivityBuilder; + public static IActivityBuilder AddJoin(this IActivityBuilder builder, JoinBuildAction joinBuildAction) + => builder.AddJoin(ActivityNodeInfo.Name, joinBuildAction); + public static IActivityBuilder AddFork(this IActivityBuilder builder, string forkNodeName, ForkBuildAction forkBuildAction) => (builder as BaseActivityBuilder) .AddNode( @@ -35,6 +37,9 @@ public static IActivityBuilder AddFork(this IActivityBuilder builder, string for b => forkBuildAction(b) ) as IActivityBuilder; + public static IActivityBuilder AddFork(this IActivityBuilder builder, ForkBuildAction forkBuildAction) + => builder.AddFork(ActivityNodeInfo.Name, forkBuildAction); + public static IActivityBuilder AddMerge(this IActivityBuilder builder, string mergeNodeName, MergeBuildAction mergeBuildAction) => (builder as BaseActivityBuilder) .AddNode( @@ -48,6 +53,9 @@ public static IActivityBuilder AddMerge(this IActivityBuilder builder, string me b => mergeBuildAction(b.SetOptions(NodeOptions.None) as IMergeBuilder) ) as IActivityBuilder; + public static IActivityBuilder AddMerge(this IActivityBuilder builder, MergeBuildAction mergeBuildAction) + => builder.AddMerge(ActivityNodeInfo.Name, mergeBuildAction); + public static IActivityBuilder AddControlDecision(this IActivityBuilder builder, string decisionNodeName, DecisionBuildAction decisionBuildAction) => (builder as BaseActivityBuilder) .AddNode( @@ -61,6 +69,9 @@ public static IActivityBuilder AddControlDecision(this IActivityBuilder builder, b => decisionBuildAction(b.SetOptions(NodeOptions.DecisionDefault) as IDecisionBuilder) ) as IActivityBuilder; + public static IActivityBuilder AddControlDecision(this IActivityBuilder builder, DecisionBuildAction decisionBuildAction) + => builder.AddControlDecision(ActivityNodeInfo>.Name, decisionBuildAction); + public static IActivityBuilder AddTokenDecision(this IActivityBuilder builder, string decisionNodeName, DecisionBuildAction decisionBuildAction) where TToken : Token, new() => (builder as BaseActivityBuilder) @@ -75,6 +86,10 @@ public static IActivityBuilder AddTokenDecision(this IActivityBuilder bu b => decisionBuildAction(new DecisionBuilder(b.SetOptions(NodeOptions.DecisionDefault) as NodeBuilder)) ) as IActivityBuilder; + public static IActivityBuilder AddTokenDecision(this IActivityBuilder builder, DecisionBuildAction decisionBuildAction) + where TToken : Token, new() + => builder.AddTokenDecision(ActivityNodeInfo>.Name, decisionBuildAction); + public static IActivityBuilder AddDataStore(this IActivityBuilder builder, string dataStoreNodeName, DataStoreBuildAction decisionBuildAction) => (builder as BaseActivityBuilder) .AddNode( diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderTypedExtensions.cs index 4a3679a1..4581f33e 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderTypedExtensions.cs @@ -139,12 +139,12 @@ public static IActivityBuilder AddStructuredActivity(this I #region AddParallelActivity public static IActivityBuilder AddParallelActivity(this IActivityBuilder builder, ParallelActivityBuildAction buildAction = null) where TParallelizationToken : Token, new() - where TStructuredActivity : StructuredActivity + where TStructuredActivity : ParallelActivityNode => AddParallelActivity(builder, ActivityNodeInfo.Name, buildAction); public static IActivityBuilder AddParallelActivity(this IActivityBuilder builder, string structuredActivityName, ParallelActivityBuildAction buildAction = null) where TParallelizationToken : Token, new() - where TStructuredActivity : StructuredActivity + where TStructuredActivity : ParallelActivityNode { (builder as IInternal).Services.RegisterStructuredActivity(); @@ -164,12 +164,12 @@ public static IActivityBuilder AddParallelActivity(this IActivityBuilder builder, IterativeActivityBuildAction buildAction = null) where TIterationToken : Token, new() - where TStructuredActivity : StructuredActivity + where TStructuredActivity : IterativeActivityNode => AddIterativeActivity(builder, ActivityNodeInfo.Name, buildAction); public static IActivityBuilder AddIterativeActivity(this IActivityBuilder builder, string structuredActivityName, IterativeActivityBuildAction buildAction = null) where TIterationToken : Token, new() - where TStructuredActivity : StructuredActivity + where TStructuredActivity : IterativeActivityNode { (builder as IInternal).Services.RegisterStructuredActivity(); return builder.AddIterativeActivity( diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderTypedPayloadExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderTypedPayloadExtensions.cs index 8099478f..f9ed6c83 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderTypedPayloadExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ActivityBuilder/ActivityBuilderTypedPayloadExtensions.cs @@ -27,21 +27,21 @@ public static IActivityBuilder AddSendEventAction(this IActivityBuilder builder, ParallelActivityBuildAction buildAction = null) - where TStructuredActivity : StructuredActivity> + where TStructuredActivity : ParallelActivityNode> => builder.AddParallelActivity(ActivityNodeInfo.Name, buildAction); public static IActivityBuilder AddParallelActivity(this IActivityBuilder builder, string structuredActivityName, ParallelActivityBuildAction buildAction = null) - where TStructuredActivity : StructuredActivity> + where TStructuredActivity : ParallelActivityNode> => builder.AddParallelActivity, TStructuredActivity>(structuredActivityName, buildAction); #endregion #region AddIterativeActivity public static IActivityBuilder AddIterativeActivity(this IActivityBuilder builder, IterativeActivityBuildAction buildAction = null) - where TStructuredActivity : StructuredActivity> + where TStructuredActivity : IterativeActivityNode> => builder.AddIterativeActivity(ActivityNodeInfo.Name, buildAction); public static IActivityBuilder AddIterativeActivity(this IActivityBuilder builder, string structuredActivityName, IterativeActivityBuildAction buildAction = null) - where TStructuredActivity : StructuredActivity> + where TStructuredActivity : IterativeActivityNode> => builder.AddIterativeActivity, TStructuredActivity>(structuredActivityName, buildAction); #endregion } diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderAnonymousExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderAnonymousExtensions.cs index a309533b..54ef5a24 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderAnonymousExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderAnonymousExtensions.cs @@ -10,10 +10,10 @@ public static IReactiveStructuredActivityBuilder AddStructuredActivity(this IRea public static IReactiveStructuredActivityBuilder AddParallelActivity(this IReactiveStructuredActivityBuilder builder, ParallelActivityBuildAction buildAction) where TParallelizationToken : Token, new() - => builder.AddParallelActivity(ActivityNodeInfo>.Name, buildAction); + => builder.AddParallelActivity(ActivityNodeInfo>.Name, buildAction); public static IReactiveStructuredActivityBuilder AddIterativeActivity(this IReactiveStructuredActivityBuilder builder, IterativeActivityBuildAction buildAction) where TIterationToken : Token, new() - => builder.AddIterativeActivity(ActivityNodeInfo>.Name, buildAction); + => builder.AddIterativeActivity(ActivityNodeInfo>.Name, buildAction); } } diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderSpecialsExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderSpecialsExtensions.cs index d4451a30..e625bc04 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderSpecialsExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderSpecialsExtensions.cs @@ -21,6 +21,9 @@ public static IReactiveStructuredActivityBuilder AddJoin(this IReactiveStructure b => buildAction(b) ) as IReactiveStructuredActivityBuilder; + public static IReactiveStructuredActivityBuilder AddJoin(this IReactiveStructuredActivityBuilder builder, JoinBuildAction joinBuildAction) + => builder.AddJoin(ActivityNodeInfo.Name, joinBuildAction); + public static IReactiveStructuredActivityBuilder AddFork(this IReactiveStructuredActivityBuilder builder, string forkNodeName, ForkBuildAction buildAction) => (builder as BaseActivityBuilder) .AddNode( @@ -34,6 +37,9 @@ public static IReactiveStructuredActivityBuilder AddFork(this IReactiveStructure b => buildAction(b) ) as IReactiveStructuredActivityBuilder; + public static IReactiveStructuredActivityBuilder AddFork(this IReactiveStructuredActivityBuilder builder, ForkBuildAction forkBuildAction) + => builder.AddFork(ActivityNodeInfo.Name, forkBuildAction); + public static IReactiveStructuredActivityBuilder AddMerge(this IReactiveStructuredActivityBuilder builder, string mergeNodeName, MergeBuildAction buildAction) => (builder as BaseActivityBuilder) .AddNode( @@ -47,6 +53,9 @@ public static IReactiveStructuredActivityBuilder AddMerge(this IReactiveStructur b => buildAction(b.SetOptions(NodeOptions.None) as IMergeBuilder) ) as IReactiveStructuredActivityBuilder; + public static IReactiveStructuredActivityBuilder AddMerge(this IReactiveStructuredActivityBuilder builder, MergeBuildAction mergeBuildAction) + => builder.AddMerge(ActivityNodeInfo.Name, mergeBuildAction); + public static IReactiveStructuredActivityBuilder AddControlDecision(this IReactiveStructuredActivityBuilder builder, string decisionNodeName, DecisionBuildAction buildAction) => (builder as BaseActivityBuilder) .AddNode( @@ -60,6 +69,9 @@ public static IReactiveStructuredActivityBuilder AddControlDecision(this IReacti b => buildAction(b.SetOptions(NodeOptions.DecisionDefault) as IDecisionBuilder) ) as IReactiveStructuredActivityBuilder; + public static IReactiveStructuredActivityBuilder AddControlDecision(this IReactiveStructuredActivityBuilder builder, DecisionBuildAction decisionBuildAction) + => builder.AddControlDecision(ActivityNodeInfo>.Name, decisionBuildAction); + public static IReactiveStructuredActivityBuilder AddTokenDecision(this IReactiveStructuredActivityBuilder builder, string decisionNodeName, DecisionBuildAction buildAction) where TToken : Token, new() => (builder as BaseActivityBuilder) @@ -74,6 +86,10 @@ public static IReactiveStructuredActivityBuilder AddTokenDecision(this I b => buildAction(new DecisionBuilder(b.SetOptions(NodeOptions.DecisionDefault) as NodeBuilder)) ) as IReactiveStructuredActivityBuilder; + public static IReactiveStructuredActivityBuilder AddTokenDecision(this IReactiveStructuredActivityBuilder builder, DecisionBuildAction decisionBuildAction) + where TToken : Token, new() + => builder.AddTokenDecision(ActivityNodeInfo>.Name, decisionBuildAction); + public static IReactiveStructuredActivityBuilder AddDataStore(this IReactiveStructuredActivityBuilder builder, string dataStoreNodeName, DataStoreBuildAction buildAction) => (builder as BaseActivityBuilder) .AddNode( diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderTypedExtensions.cs index 1da34964..0e6027d6 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderTypedExtensions.cs @@ -139,12 +139,12 @@ public static IReactiveStructuredActivityBuilder AddStructuredActivity(this IReactiveStructuredActivityBuilder builder, ParallelActivityBuildAction buildAction = null) where TToken : Token, new() - where TStructuredActivity : StructuredActivity + where TStructuredActivity : ParallelActivityNode => AddParallelActivity(builder, ActivityNodeInfo.Name, buildAction); public static IReactiveStructuredActivityBuilder AddParallelActivity(this IReactiveStructuredActivityBuilder builder, string structuredActivityName, ParallelActivityBuildAction buildAction = null) where TParallelizationToken : Token, new() - where TStructuredActivity : StructuredActivity + where TStructuredActivity : ParallelActivityNode { (builder as IInternal).Services.RegisterStructuredActivity(); @@ -164,12 +164,12 @@ public static IReactiveStructuredActivityBuilder AddParallelActivity(this IReactiveStructuredActivityBuilder builder, IterativeActivityBuildAction buildAction = null) where TIterationToken : Token, new() - where TStructuredActivity : StructuredActivity + where TStructuredActivity : IterativeActivityNode => AddIterativeActivity(builder, ActivityNodeInfo.Name, buildAction); public static IReactiveStructuredActivityBuilder AddIterativeActivity(this IReactiveStructuredActivityBuilder builder, string structuredActivityName, IterativeActivityBuildAction buildAction = null) where TIterationToken : Token, new() - where TStructuredActivity : StructuredActivity + where TStructuredActivity : IterativeActivityNode { (builder as IInternal).Services.RegisterStructuredActivity(); return builder.AddIterativeActivity( diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderTypedPayloadExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderTypedPayloadExtensions.cs index 16b8367d..25329527 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderTypedPayloadExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/ReactiveStructuredActivityBuilder/ReactiveStructuredActivityBuilderTypedPayloadExtensions.cs @@ -27,21 +27,21 @@ public static IReactiveStructuredActivityBuilder AddSendEventAction(this IReactiveStructuredActivityBuilder builder, ParallelActivityBuildAction buildAction = null) - where TStructuredActivity : StructuredActivity> + where TStructuredActivity : ParallelActivityNode> => builder.AddParallelActivity(ActivityNodeInfo.Name, buildAction); public static IReactiveStructuredActivityBuilder AddParallelActivity(this IReactiveStructuredActivityBuilder builder, string structuredActivityName, ParallelActivityBuildAction buildAction = null) - where TStructuredActivity : StructuredActivity> + where TStructuredActivity : ParallelActivityNode> => builder.AddParallelActivity, TStructuredActivity>(structuredActivityName, buildAction); #endregion #region AddIterativeActivity public static IReactiveStructuredActivityBuilder AddIterativeActivity(this IReactiveStructuredActivityBuilder builder, IterativeActivityBuildAction buildAction = null) - where TStructuredActivity : StructuredActivity> + where TStructuredActivity : IterativeActivityNode> => builder.AddIterativeActivity(ActivityNodeInfo.Name, buildAction); public static IReactiveStructuredActivityBuilder AddIterativeActivity(this IReactiveStructuredActivityBuilder builder, string structuredActivityName, IterativeActivityBuildAction buildAction = null) - where TStructuredActivity : StructuredActivity> + where TStructuredActivity : IterativeActivityNode> => builder.AddIterativeActivity, TStructuredActivity>(structuredActivityName, buildAction); #endregion } diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderAnonymousExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderAnonymousExtensions.cs index 3023c4d3..82068789 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderAnonymousExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderAnonymousExtensions.cs @@ -10,10 +10,10 @@ public static IStructuredActivityBuilder AddStructuredActivity(this IStructuredA public static IStructuredActivityBuilder AddParallelActivity(this IStructuredActivityBuilder builder, ParallelActivityBuildAction buildAction) where TParallelizationToken : Token, new() - => builder.AddParallelActivity(ActivityNodeInfo>.Name, buildAction); + => builder.AddParallelActivity(ActivityNodeInfo>.Name, buildAction); public static IStructuredActivityBuilder AddIterativeActivity(this IStructuredActivityBuilder builder, IterativeActivityBuildAction buildAction) where TIterationToken : Token, new() - => builder.AddIterativeActivity(ActivityNodeInfo>.Name, buildAction); + => builder.AddIterativeActivity(ActivityNodeInfo>.Name, buildAction); } } diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderSpecialsExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderSpecialsExtensions.cs index a650ebe9..15a8e958 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderSpecialsExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderSpecialsExtensions.cs @@ -3,6 +3,7 @@ using Stateflows.Activities.Registration; using Stateflows.Activities.Registration.Builders; using Stateflows.Activities.Registration.Interfaces; +using Stateflows.Common.Classes; namespace Stateflows.Activities { @@ -21,6 +22,9 @@ public static IStructuredActivityBuilder AddJoin(this IStructuredActivityBuilder b => joinBuildAction(b) ) as IStructuredActivityBuilder; + public static IStructuredActivityBuilder AddJoin(this IStructuredActivityBuilder builder, JoinBuildAction joinBuildAction) + => builder.AddJoin(ActivityNodeInfo.Name, joinBuildAction); + public static IStructuredActivityBuilder AddFork(this IStructuredActivityBuilder builder, string forkNodeName, ForkBuildAction forkBuildAction) => (builder as BaseActivityBuilder) .AddNode( @@ -34,6 +38,9 @@ public static IStructuredActivityBuilder AddFork(this IStructuredActivityBuilder b => forkBuildAction(b) ) as IStructuredActivityBuilder; + public static IStructuredActivityBuilder AddFork(this IStructuredActivityBuilder builder, ForkBuildAction forkBuildAction) + => builder.AddFork(ActivityNodeInfo.Name, forkBuildAction); + public static IStructuredActivityBuilder AddMerge(this IStructuredActivityBuilder builder, string mergeNodeName, MergeBuildAction mergeBuildAction) => (builder as BaseActivityBuilder) .AddNode( @@ -47,6 +54,9 @@ public static IStructuredActivityBuilder AddMerge(this IStructuredActivityBuilde b => mergeBuildAction(b.SetOptions(NodeOptions.None) as IMergeBuilder) ) as IStructuredActivityBuilder; + public static IStructuredActivityBuilder AddMerge(this IStructuredActivityBuilder builder, MergeBuildAction mergeBuildAction) + => builder.AddMerge(ActivityNodeInfo.Name, mergeBuildAction); + public static IStructuredActivityBuilder AddControlDecision(this IStructuredActivityBuilder builder, string decisionNodeName, DecisionBuildAction decisionBuildAction) => (builder as BaseActivityBuilder) .AddNode( @@ -60,6 +70,9 @@ public static IStructuredActivityBuilder AddControlDecision(this IStructuredActi b => decisionBuildAction(b.SetOptions(NodeOptions.DecisionDefault) as IDecisionBuilder) ) as IStructuredActivityBuilder; + public static IStructuredActivityBuilder AddControlDecision(this IStructuredActivityBuilder builder, DecisionBuildAction decisionBuildAction) + => builder.AddControlDecision(ActivityNodeInfo>.Name, decisionBuildAction); + public static IStructuredActivityBuilder AddTokenDecision(this IStructuredActivityBuilder builder, string decisionNodeName, DecisionBuildAction decisionBuildAction) where TToken : Token, new() => (builder as BaseActivityBuilder) @@ -74,6 +87,10 @@ public static IStructuredActivityBuilder AddTokenDecision(this IStructur b => decisionBuildAction(new DecisionBuilder(b.SetOptions(NodeOptions.DecisionDefault) as NodeBuilder)) ) as IStructuredActivityBuilder; + public static IStructuredActivityBuilder AddTokenDecision(this IStructuredActivityBuilder builder, DecisionBuildAction decisionBuildAction) + where TToken : Token, new() + => builder.AddTokenDecision(ActivityNodeInfo>.Name, decisionBuildAction); + public static IStructuredActivityBuilder AddDataStore(this IStructuredActivityBuilder builder, string dataStoreNodeName, DataStoreBuildAction decisionBuildAction) => (builder as BaseActivityBuilder) .AddNode( diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderTypedExtensions.cs index 74ee71ce..4f3dedfa 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderTypedExtensions.cs @@ -124,12 +124,12 @@ public static IStructuredActivityBuilder AddStructuredActivity(this IStructuredActivityBuilder builder, ParallelActivityBuildAction buildAction = null) where TParallelizationToken : Token, new() - where TStructuredActivity : StructuredActivity + where TStructuredActivity : ParallelActivityNode => AddParallelActivity(builder, ActivityNodeInfo.Name, buildAction); public static IStructuredActivityBuilder AddParallelActivity(this IStructuredActivityBuilder builder, string structuredActivityName, ParallelActivityBuildAction buildAction = null) where TParallelizationToken : Token, new() - where TStructuredActivity : StructuredActivity + where TStructuredActivity : ParallelActivityNode { (builder as IInternal).Services.RegisterStructuredActivity(); @@ -149,12 +149,12 @@ public static IStructuredActivityBuilder AddParallelActivity(this IStructuredActivityBuilder builder, IterativeActivityBuildAction buildAction = null) where TIterationToken : Token, new() - where TStructuredActivity : StructuredActivity + where TStructuredActivity : IterativeActivityNode => AddIterativeActivity(builder, ActivityNodeInfo.Name, buildAction); public static IStructuredActivityBuilder AddIterativeActivity(this IStructuredActivityBuilder builder, string structuredActivityName, IterativeActivityBuildAction buildAction = null) where TIterationToken : Token, new() - where TStructuredActivity : StructuredActivity + where TStructuredActivity : IterativeActivityNode { (builder as IInternal).Services.RegisterStructuredActivity(); return builder.AddIterativeActivity( diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderTypedPayloadExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderTypedPayloadExtensions.cs index f81ceece..1450f89b 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderTypedPayloadExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/StructuredActivityBuilder/StructuredActivityBuilderTypedPayloadExtensions.cs @@ -17,21 +17,21 @@ public static IStructuredActivityBuilder AddSendEventAction(this IStructuredActivityBuilder builder, ParallelActivityBuildAction buildAction = null) - where TStructuredActivity : StructuredActivity> + where TStructuredActivity : ParallelActivityNode> => builder.AddParallelActivity(ActivityNodeInfo.Name, buildAction); public static IStructuredActivityBuilder AddParallelActivity(this IStructuredActivityBuilder builder, string structuredActivityName, ParallelActivityBuildAction buildAction = null) - where TStructuredActivity : StructuredActivity> + where TStructuredActivity : ParallelActivityNode> => builder.AddParallelActivity, TStructuredActivity>(structuredActivityName, buildAction); #endregion #region AddIterativeActivity public static IStructuredActivityBuilder AddIterativeActivity(this IStructuredActivityBuilder builder, IterativeActivityBuildAction buildAction = null) - where TStructuredActivity : StructuredActivity> + where TStructuredActivity : IterativeActivityNode> => builder.AddIterativeActivity(ActivityNodeInfo.Name, buildAction); public static IStructuredActivityBuilder AddIterativeActivity(this IStructuredActivityBuilder builder, string structuredActivityName, IterativeActivityBuildAction buildAction = null) - where TStructuredActivity : StructuredActivity> + where TStructuredActivity : IterativeActivityNode> => builder.AddIterativeActivity, TStructuredActivity>(structuredActivityName, buildAction); #endregion } diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/TypedActivityBuilder/TypedActivityBuilderTypedExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/TypedActivityBuilder/TypedActivityBuilderTypedExtensions.cs index 1e3be45c..353969bb 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/TypedActivityBuilder/TypedActivityBuilderTypedExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/TypedActivityBuilder/TypedActivityBuilderTypedExtensions.cs @@ -127,12 +127,12 @@ public static ITypedActivityBuilder AddStructuredActivity(t #region AddParallelActivity public static ITypedActivityBuilder AddParallelActivity(this ITypedActivityBuilder builder, ParallelActivityBuildAction buildAction = null) where TParallelizationToken : Token, new() - where TStructuredActivity : StructuredActivity + where TStructuredActivity : StructuredActivityNode => AddParallelActivity(builder, ActivityNodeInfo.Name, buildAction); public static ITypedActivityBuilder AddParallelActivity(this ITypedActivityBuilder builder, string structuredActivityName, ParallelActivityBuildAction buildAction = null) where TParallelizationToken : Token, new() - where TStructuredActivity : StructuredActivity + where TStructuredActivity : StructuredActivityNode { (builder as IInternal).Services.RegisterStructuredActivity(); @@ -152,12 +152,12 @@ public static ITypedActivityBuilder AddParallelActivity(this ITypedActivityBuilder builder, IterativeActivityBuildAction buildAction = null) where TIterationToken : Token, new() - where TStructuredActivity : StructuredActivity + where TStructuredActivity : StructuredActivityNode => AddIterativeActivity(builder, ActivityNodeInfo.Name, buildAction); public static ITypedActivityBuilder AddIterativeActivity(this ITypedActivityBuilder builder, string structuredActivityName, IterativeActivityBuildAction buildAction = null) where TIterationToken : Token, new() - where TStructuredActivity : StructuredActivity + where TStructuredActivity : StructuredActivityNode { (builder as IInternal).Services.RegisterStructuredActivity(); return builder.AddIterativeActivity( diff --git a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/TypedActivityBuilder/TypedActivityBuilderTypedPayloadExtensions.cs b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/TypedActivityBuilder/TypedActivityBuilderTypedPayloadExtensions.cs index 2a07484b..7e73100a 100644 --- a/Core/Stateflows/Activities/Registration/Interfaces/Extensions/TypedActivityBuilder/TypedActivityBuilderTypedPayloadExtensions.cs +++ b/Core/Stateflows/Activities/Registration/Interfaces/Extensions/TypedActivityBuilder/TypedActivityBuilderTypedPayloadExtensions.cs @@ -27,21 +27,21 @@ public static ITypedActivityBuilder AddSendEventAction(this ITypedActivityBuilder builder, ParallelActivityBuildAction buildAction = null) - where TStructuredActivity : StructuredActivity> + where TStructuredActivity : StructuredActivityNode> => builder.AddParallelActivity(ActivityNodeInfo.Name, buildAction); public static ITypedActivityBuilder AddParallelActivity(this ITypedActivityBuilder builder, string structuredActivityName, ParallelActivityBuildAction buildAction = null) - where TStructuredActivity : StructuredActivity> + where TStructuredActivity : StructuredActivityNode> => builder.AddParallelActivity, TStructuredActivity>(structuredActivityName, buildAction); #endregion #region AddIterativeActivity public static ITypedActivityBuilder AddIterativeActivity(this ITypedActivityBuilder builder, IterativeActivityBuildAction buildAction = null) - where TStructuredActivity : StructuredActivity> + where TStructuredActivity : StructuredActivityNode> => builder.AddIterativeActivity(ActivityNodeInfo.Name, buildAction); public static ITypedActivityBuilder AddIterativeActivity(this ITypedActivityBuilder builder, string structuredActivityName, IterativeActivityBuildAction buildAction = null) - where TStructuredActivity : StructuredActivity> + where TStructuredActivity : StructuredActivityNode> => builder.AddIterativeActivity, TStructuredActivity>(structuredActivityName, buildAction); #endregion } diff --git a/Core/Stateflows/Activities/Tokens/ParametersToken.cs b/Core/Stateflows/Activities/Tokens/ParametersToken.cs deleted file mode 100644 index 3b800218..00000000 --- a/Core/Stateflows/Activities/Tokens/ParametersToken.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; -using Stateflows.Common; - -namespace Stateflows.Activities -{ - public class ParametersToken : Token - { - public Dictionary Parameters { get; set; } = new Dictionary(); - } -} diff --git a/Core/Stateflows/Common/Initializer/ThreadInitializer.cs b/Core/Stateflows/Common/Initializer/ThreadInitializer.cs index a1e73aa6..ae0e051c 100644 --- a/Core/Stateflows/Common/Initializer/ThreadInitializer.cs +++ b/Core/Stateflows/Common/Initializer/ThreadInitializer.cs @@ -50,7 +50,7 @@ await Task.WhenAll( { token.RefreshEnvironment(); - if (Locator.TryLocateBehavior(token.BehaviorClass.ToId(string.Empty), out var behavior)) + if (Locator.TryLocateBehavior(new BehaviorId(token.BehaviorClass, string.Empty), out var behavior)) { await behavior.InitializeAsync(await token.InitializationRequestFactory(ServiceProvider, token.BehaviorClass)); } diff --git a/Core/Stateflows/StateMachines/Classes/StateMachine.cs b/Core/Stateflows/StateMachines/Classes/StateMachine.cs index 9f67089e..d097a439 100644 --- a/Core/Stateflows/StateMachines/Classes/StateMachine.cs +++ b/Core/Stateflows/StateMachines/Classes/StateMachine.cs @@ -54,5 +54,11 @@ public static string Name : stateMachineType.FullName; } } + + public static BehaviorClass ToClass() + => new BehaviorClass(BehaviorType.StateMachine, Name); + + public static BehaviorId ToId(string instance) + => new BehaviorId(ToClass(), instance); } } diff --git a/Core/Stateflows/StateMachines/Engine/Executor.cs b/Core/Stateflows/StateMachines/Engine/Executor.cs index bb50fd72..75da58c2 100644 --- a/Core/Stateflows/StateMachines/Engine/Executor.cs +++ b/Core/Stateflows/StateMachines/Engine/Executor.cs @@ -479,75 +479,11 @@ private async Task DoConsumeAsync(Edge edge) } } } - - //var nextVertex = edge.Target; - //if (nextVertex != null) - //{ - // Context.StatesStack.Reverse(); - // foreach (var state in Context.StatesStack) - // { - // if (Graph.AllVertices.TryGetValue(state, out var vertex)) - // { - // if (vertex == nextVertex.Parent) - // { - // break; - // } - - // await DoExitAsync(vertex); - // } - // } - //} - - //await DoEffectAsync(edge); - - //if (nextVertex != null) - //{ - // var previousNextVertex = nextVertex; - - // Context.StatesStack.Clear(); - - // while (nextVertex != null) - // { - // if (nextVertex.Parent != null && nextVertex.Parent.InitialVertex == nextVertex) - // { - // await DoInitializeStateAsync(nextVertex.Parent); - // } - - // if (nextVertex.Type == VertexType.FinalState) - // { - // if (nextVertex.Parent is null) - // { - // await DoFinalizeStateMachineAsync(); - // } - // else - // { - // await DoFinalizeStateAsync(nextVertex.Parent); - // } - - // nextVertex = null; - // } - // else - // { - // await DoEntryAsync(nextVertex); - - // previousNextVertex = nextVertex; - // nextVertex = nextVertex.InitialVertex; - // } - // } - - // nextVertex = previousNextVertex; - // while (nextVertex != null) - // { - // Context.StatesStack.Add(nextVertex.Identifier); - // nextVertex = nextVertex.Parent; - // } - // Context.StatesStack.Reverse(); - //} } private async Task DoCompletion() { - Context.SetEvent(new Completion()); + Context.SetEvent(new CompletionEvent()); RebuildVerticesStack(); @@ -556,85 +492,41 @@ private async Task DoCompletion() Context.ClearEvent(); } - private readonly IDictionary StateMachines = new Dictionary(); - public StateMachine GetStateMachine(Type stateMachineType, RootContext context) { - lock (StateMachines) - { - if (!StateMachines.TryGetValue(stateMachineType, out var stateMachine)) - { - stateMachine = ServiceProvider.GetService(stateMachineType) as StateMachine; - stateMachine.Context = new StateMachineActionContext(context); + var stateMachine = ServiceProvider.GetService(stateMachineType) as StateMachine; + stateMachine.Context = new StateMachineActionContext(context); - StateMachines.Add(stateMachineType, stateMachine); - } - - return stateMachine; - } + return stateMachine; } - private readonly IDictionary States = new Dictionary(); - public TState GetState(IStateActionContext context) where TState : BaseState { - if (!States.TryGetValue(typeof(TState), out var state)) - { - state = ServiceProvider.GetService(); - - States.Add(typeof(TState), state); - } - + var state = ServiceProvider.GetService(); state.Context = context; - - return state as TState; + + return state; } - private readonly IDictionary Transitions = new Dictionary(); - public TTransition GetTransition(ITransitionContext context) where TTransition : Transition where TEvent : Event, new() { - if (!Transitions.TryGetValue(typeof(TTransition), out var transitionObj)) - { - var transition = ServiceProvider.GetService(); - - transition.Context = context; - - Transitions.Add(typeof(TTransition), transition); - - return transition; - } - else - { - (transitionObj as TTransition).Context = context; - - return transitionObj as TTransition; - } + var transition = ServiceProvider.GetService(); + transition.Context = context; + + return transition; } public TElseTransition GetElseTransition(ITransitionContext context) where TElseTransition : ElseTransition where TEvent : Event, new() { - if (!Transitions.TryGetValue(typeof(TElseTransition), out var transitionObj)) - { - var transition = ServiceProvider.GetService(); - - transition.Context = context; - - Transitions.Add(typeof(TElseTransition), transition); - - return transition; - } - else - { - (transitionObj as TElseTransition).Context = context; - - return transitionObj as TElseTransition; - } + var elseTransition = ServiceProvider.GetService(); + elseTransition.Context = context; + + return elseTransition; } } } diff --git a/Core/Stateflows/StateMachines/EventHandlers/CurrentStateHandler.cs b/Core/Stateflows/StateMachines/EventHandlers/CurrentStateHandler.cs index ecdb286f..f0559c9b 100644 --- a/Core/Stateflows/StateMachines/EventHandlers/CurrentStateHandler.cs +++ b/Core/Stateflows/StateMachines/EventHandlers/CurrentStateHandler.cs @@ -24,7 +24,7 @@ public Task TryHandleEventAsync(IEventInspectionContext !type.IsSubclassOf(typeof(TimeEvent))) - .Where(type => type != typeof(Completion)) + .Where(type => type != typeof(CompletionEvent)) .Select(type => type.GetEventName()) .ToArray(), BehaviorStatus = executor.BehaviorStatus diff --git a/Core/Stateflows/StateMachines/Events/Completion.cs b/Core/Stateflows/StateMachines/Events/CompletionEvent.cs similarity index 80% rename from Core/Stateflows/StateMachines/Events/Completion.cs rename to Core/Stateflows/StateMachines/Events/CompletionEvent.cs index 104592af..9aa72914 100644 --- a/Core/Stateflows/StateMachines/Events/Completion.cs +++ b/Core/Stateflows/StateMachines/Events/CompletionEvent.cs @@ -3,7 +3,7 @@ namespace Stateflows.StateMachines.Events { - public sealed class Completion : Event + public sealed class CompletionEvent : Event { public override string Name => Constants.CompletionEvent; } diff --git a/Core/Stateflows/StateMachines/Registration/Builders/CompositeStateBuilder.cs b/Core/Stateflows/StateMachines/Registration/Builders/CompositeStateBuilder.cs index 015ef34d..ca3dbf54 100644 --- a/Core/Stateflows/StateMachines/Registration/Builders/CompositeStateBuilder.cs +++ b/Core/Stateflows/StateMachines/Registration/Builders/CompositeStateBuilder.cs @@ -127,12 +127,12 @@ public IInitializedCompositeStateBuilder AddElseTransition(string target } [DebuggerHidden] - public IInitializedCompositeStateBuilder AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction = null) - => AddTransition(targetVertexName, transitionBuildAction); + public IInitializedCompositeStateBuilder AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction = null) + => AddTransition(targetVertexName, transitionBuildAction); [DebuggerHidden] - public IInitializedCompositeStateBuilder AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction = null) - => AddElseTransition(targetVertexName, transitionBuildAction); + public IInitializedCompositeStateBuilder AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction = null) + => AddElseTransition(targetVertexName, transitionBuildAction); [DebuggerHidden] public IInitializedCompositeStateBuilder AddInternalTransition(TransitionBuildAction transitionBuildAction = null) @@ -153,11 +153,11 @@ ITypedInitializedCompositeStateBuilder IStateTransitions AddElseTransition(targetVertexName, transitionBuildAction) as ITypedInitializedCompositeStateBuilder; [DebuggerHidden] - ITypedInitializedCompositeStateBuilder IStateTransitions.AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction) + ITypedInitializedCompositeStateBuilder IStateTransitions.AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction) => AddDefaultTransition(targetVertexName, transitionBuildAction) as ITypedInitializedCompositeStateBuilder; [DebuggerHidden] - ITypedInitializedCompositeStateBuilder IStateTransitions.AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction) + ITypedInitializedCompositeStateBuilder IStateTransitions.AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction) => AddElseDefaultTransition(targetVertexName, transitionBuildAction) as ITypedInitializedCompositeStateBuilder; [DebuggerHidden] @@ -254,11 +254,11 @@ ICompositeStateBuilder IStateTransitions.AddElseTransiti => AddElseTransition(targetVertexName, transitionBuildAction) as ICompositeStateBuilder; [DebuggerHidden] - ICompositeStateBuilder IStateTransitions.AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction) + ICompositeStateBuilder IStateTransitions.AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction) => AddDefaultTransition(targetVertexName, transitionBuildAction) as ICompositeStateBuilder; [DebuggerHidden] - ICompositeStateBuilder IStateTransitions.AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction) + ICompositeStateBuilder IStateTransitions.AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction) => AddElseDefaultTransition(targetVertexName, transitionBuildAction) as ICompositeStateBuilder; [DebuggerHidden] @@ -290,11 +290,11 @@ ITypedCompositeStateBuilder IStateTransitions.AddEl => AddElseTransition(targetVertexName, transitionBuildAction) as ITypedCompositeStateBuilder; [DebuggerHidden] - ITypedCompositeStateBuilder IStateTransitions.AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction) + ITypedCompositeStateBuilder IStateTransitions.AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction) => AddDefaultTransition(targetVertexName, transitionBuildAction) as ITypedCompositeStateBuilder; [DebuggerHidden] - ITypedCompositeStateBuilder IStateTransitions.AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction) + ITypedCompositeStateBuilder IStateTransitions.AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction) => AddElseDefaultTransition(targetVertexName, transitionBuildAction) as ITypedCompositeStateBuilder; [DebuggerHidden] @@ -326,11 +326,11 @@ IFinalizedCompositeStateBuilder IStateTransitions AddElseTransition(targetVertexName, transitionBuildAction) as IFinalizedCompositeStateBuilder; [DebuggerHidden] - IFinalizedCompositeStateBuilder IStateTransitions.AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction) + IFinalizedCompositeStateBuilder IStateTransitions.AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction) => AddDefaultTransition(targetVertexName, transitionBuildAction) as IFinalizedCompositeStateBuilder; [DebuggerHidden] - IFinalizedCompositeStateBuilder IStateTransitions.AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction) + IFinalizedCompositeStateBuilder IStateTransitions.AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction) => AddElseDefaultTransition(targetVertexName, transitionBuildAction) as IFinalizedCompositeStateBuilder; [DebuggerHidden] @@ -354,11 +354,11 @@ ITypedFinalizedCompositeStateBuilder IStateTransitions AddElseTransition(targetVertexName, transitionBuildAction) as ITypedFinalizedCompositeStateBuilder; [DebuggerHidden] - ITypedFinalizedCompositeStateBuilder IStateTransitions.AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction) + ITypedFinalizedCompositeStateBuilder IStateTransitions.AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction) => AddDefaultTransition(targetVertexName, transitionBuildAction) as ITypedFinalizedCompositeStateBuilder; [DebuggerHidden] - ITypedFinalizedCompositeStateBuilder IStateTransitions.AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction) + ITypedFinalizedCompositeStateBuilder IStateTransitions.AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction) => AddElseDefaultTransition(targetVertexName, transitionBuildAction) as ITypedFinalizedCompositeStateBuilder; [DebuggerHidden] diff --git a/Core/Stateflows/StateMachines/Registration/Builders/StateBuilder.cs b/Core/Stateflows/StateMachines/Registration/Builders/StateBuilder.cs index e0834a07..fa4ad7be 100644 --- a/Core/Stateflows/StateMachines/Registration/Builders/StateBuilder.cs +++ b/Core/Stateflows/StateMachines/Registration/Builders/StateBuilder.cs @@ -141,7 +141,7 @@ public IStateBuilder AddOnExit(Func actionAsync) [DebuggerHidden] public IStateBuilder AddDeferredEvent() where TEvent : Event, new() { - if (typeof(TEvent) == typeof(Completion)) + if (typeof(TEvent) == typeof(CompletionEvent)) throw new DeferralDefinitionException(EventInfo.Name, "Completion event cannot be deferred.", Vertex.Graph.Class); if (typeof(TEvent) == typeof(Exit)) @@ -207,12 +207,12 @@ public IStateBuilder AddElseTransition(string targetVertexName, ElseTran => AddTransitionInternal(targetVertexName, true, builder => transitionBuildAction?.Invoke(builder)); [DebuggerHidden] - public IStateBuilder AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction = null) - => AddTransition(targetVertexName, transitionBuildAction); + public IStateBuilder AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction = null) + => AddTransition(targetVertexName, transitionBuildAction); [DebuggerHidden] - public IStateBuilder AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction = null) - => AddElseTransition(targetVertexName, transitionBuildAction); + public IStateBuilder AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction = null) + => AddElseTransition(targetVertexName, transitionBuildAction); [DebuggerHidden] public IStateBuilder AddInternalTransition(TransitionBuildAction transitionBuildAction = null) @@ -233,11 +233,11 @@ ITypedStateBuilder IStateTransitions.AddElseTransition AddElseTransition(targetVertexName, transitionBuildAction) as ITypedStateBuilder; [DebuggerHidden] - ITypedStateBuilder IStateTransitions.AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction) + ITypedStateBuilder IStateTransitions.AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction) => AddDefaultTransition(targetVertexName, transitionBuildAction) as ITypedStateBuilder; [DebuggerHidden] - ITypedStateBuilder IStateTransitions.AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction) + ITypedStateBuilder IStateTransitions.AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction) => AddElseDefaultTransition(targetVertexName, transitionBuildAction) as ITypedStateBuilder; [DebuggerHidden] @@ -288,11 +288,11 @@ ISubmachineStateBuilder IStateTransitions.AddElseTransi => AddElseTransition(targetVertexName, transitionBuildAction) as ISubmachineStateBuilder; [DebuggerHidden] - ISubmachineStateBuilder IStateTransitions.AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction) + ISubmachineStateBuilder IStateTransitions.AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction) => AddDefaultTransition(targetVertexName, transitionBuildAction) as ISubmachineStateBuilder; [DebuggerHidden] - ISubmachineStateBuilder IStateTransitions.AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction) + ISubmachineStateBuilder IStateTransitions.AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction) => AddElseDefaultTransition(targetVertexName, transitionBuildAction) as ISubmachineStateBuilder; [DebuggerHidden] @@ -316,11 +316,11 @@ ISubmachineTypedStateBuilder IStateTransitions.Add => AddElseTransition(targetVertexName, transitionBuildAction) as ISubmachineTypedStateBuilder; [DebuggerHidden] - ISubmachineTypedStateBuilder IStateTransitions.AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction) + ISubmachineTypedStateBuilder IStateTransitions.AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction) => AddDefaultTransition(targetVertexName, transitionBuildAction) as ISubmachineTypedStateBuilder; [DebuggerHidden] - ISubmachineTypedStateBuilder IStateTransitions.AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction) + ISubmachineTypedStateBuilder IStateTransitions.AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction) => AddElseDefaultTransition(targetVertexName, transitionBuildAction) as ISubmachineTypedStateBuilder; [DebuggerHidden] diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Base/IStateTransitions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Base/IStateTransitions.cs index 36253e17..fa7511ec 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Base/IStateTransitions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Base/IStateTransitions.cs @@ -9,7 +9,7 @@ public interface IStateTransitions TReturn AddTransition(string targetVertexName, TransitionBuildAction transitionBuildAction = null) where TEvent : Event, new(); - TReturn AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction = null); + TReturn AddDefaultTransition(string targetVertexName, TransitionBuildAction transitionBuildAction = null); TReturn AddInternalTransition(TransitionBuildAction transitionBuildAction = null) where TEvent : Event, new(); @@ -19,7 +19,7 @@ TReturn AddInternalTransition(TransitionBuildAction transitionBu TReturn AddElseTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction = null) where TEvent : Event, new(); - TReturn AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction = null); + TReturn AddElseDefaultTransition(string targetVertexName, ElseTransitionBuildAction transitionBuildAction = null); TReturn AddElseInternalTransition(ElseTransitionBuildAction transitionBuildAction = null) where TEvent : Event, new(); diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/ElseTransitions/CompositeStateBuilderElseDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/ElseTransitions/CompositeStateBuilderElseDefaultTransitionTypedExtensions.cs index 559c8fd3..2222b1ef 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/ElseTransitions/CompositeStateBuilderElseDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/ElseTransitions/CompositeStateBuilderElseDefaultTransitionTypedExtensions.cs @@ -6,15 +6,15 @@ namespace Stateflows.StateMachines.Typed public static class CompositeStateBuilderElseDefaultTransitionTypedExtensions { public static ICompositeStateBuilder AddElseDefaultTransition(this ICompositeStateBuilder builder) - where TElseTransition : ElseTransition + where TElseTransition : ElseTransition where TTargetState : BaseState => builder.AddElseDefaultTransition(StateInfo.Name); public static ICompositeStateBuilder AddElseDefaultTransition(this ICompositeStateBuilder builder, string targetVertexName) - where TElseTransition : ElseTransition - => builder.AddElseTransition(targetVertexName); + where TElseTransition : ElseTransition + => builder.AddElseTransition(targetVertexName); - public static ICompositeStateBuilder AddElseDefaultTransition(this ICompositeStateBuilder builder, ElseTransitionBuildAction transitionBuildAction = null) + public static ICompositeStateBuilder AddElseDefaultTransition(this ICompositeStateBuilder builder, ElseTransitionBuildAction transitionBuildAction = null) where TTargetState : BaseState => builder.AddElseDefaultTransition(StateInfo.Name, transitionBuildAction); } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/ElseTransitions/FinalizedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/ElseTransitions/FinalizedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs index 7cec3788..fd7c615d 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/ElseTransitions/FinalizedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/ElseTransitions/FinalizedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs @@ -6,15 +6,15 @@ namespace Stateflows.StateMachines.Typed public static class FinalizedCompositeStateBuilderElseDefaultTransitionTypedExtensions { public static IFinalizedCompositeStateBuilder AddElseDefaultTransition(this IFinalizedCompositeStateBuilder builder) - where TElseTransition : ElseTransition + where TElseTransition : ElseTransition where TTargetState : BaseState => builder.AddElseDefaultTransition(StateInfo.Name); public static IFinalizedCompositeStateBuilder AddElseDefaultTransition(this IFinalizedCompositeStateBuilder builder, string targetVertexName) - where TElseTransition : ElseTransition - => builder.AddElseTransition(targetVertexName); + where TElseTransition : ElseTransition + => builder.AddElseTransition(targetVertexName); - public static IFinalizedCompositeStateBuilder AddElseDefaultTransition(this IFinalizedCompositeStateBuilder builder, ElseTransitionBuildAction transitionBuildAction = null) + public static IFinalizedCompositeStateBuilder AddElseDefaultTransition(this IFinalizedCompositeStateBuilder builder, ElseTransitionBuildAction transitionBuildAction = null) where TTargetState : BaseState => builder.AddElseDefaultTransition(StateInfo.Name, transitionBuildAction); } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/ElseTransitions/InitializedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/ElseTransitions/InitializedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs index 641f9dbe..e837659a 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/ElseTransitions/InitializedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/ElseTransitions/InitializedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs @@ -6,15 +6,15 @@ namespace Stateflows.StateMachines.Typed public static class InitializedCompositeStateBuilderElseDefaultTransitionTypedExtensions { public static IInitializedCompositeStateBuilder AddElseDefaultTransition(this IInitializedCompositeStateBuilder builder) - where TElseTransition : ElseTransition + where TElseTransition : ElseTransition where TTargetState : BaseState => builder.AddElseDefaultTransition(StateInfo.Name); public static IInitializedCompositeStateBuilder AddElseDefaultTransition(this IInitializedCompositeStateBuilder builder, string targetVertexName) - where TElseTransition : ElseTransition - => builder.AddElseTransition(targetVertexName); + where TElseTransition : ElseTransition + => builder.AddElseTransition(targetVertexName); - public static IInitializedCompositeStateBuilder AddElseDefaultTransition(this IInitializedCompositeStateBuilder builder, ElseTransitionBuildAction transitionBuildAction = null) + public static IInitializedCompositeStateBuilder AddElseDefaultTransition(this IInitializedCompositeStateBuilder builder, ElseTransitionBuildAction transitionBuildAction = null) where TTargetState : BaseState => builder.AddElseDefaultTransition(StateInfo.Name, transitionBuildAction); } 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 24dab4e9..dc656623 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/CompositeStateBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/CompositeStateBuilderDefaultTransitionTypedExtensions.cs @@ -6,15 +6,15 @@ namespace Stateflows.StateMachines.Typed public static class CompositeStateBuilderDefaultTransitionTypedExtensions { public static ICompositeStateBuilder AddDefaultTransition(this ICompositeStateBuilder builder) - where TTransition : Transition + where TTransition : Transition where TTargetState : BaseState => builder.AddDefaultTransition(StateInfo.Name); public static ICompositeStateBuilder AddDefaultTransition(this ICompositeStateBuilder builder, string targetVertexName) - where TTransition : Transition - => builder.AddTransition(targetVertexName); + where TTransition : Transition + => builder.AddTransition(targetVertexName); - public static ICompositeStateBuilder AddDefaultTransition(this ICompositeStateBuilder builder, TransitionBuildAction transitionBuildAction = null) + public static ICompositeStateBuilder AddDefaultTransition(this ICompositeStateBuilder builder, TransitionBuildAction transitionBuildAction = null) where TTargetState : BaseState => builder.AddDefaultTransition(StateInfo.Name, transitionBuildAction); } 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 4a1a92e1..ad449e8f 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/FinalizedCompositeStateBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/FinalizedCompositeStateBuilderDefaultTransitionTypedExtensions.cs @@ -6,15 +6,15 @@ namespace Stateflows.StateMachines.Typed public static class FinalizedCompositeStateBuilderDefaultTransitionTypedExtensions { public static IFinalizedCompositeStateBuilder AddDefaultTransition(this IFinalizedCompositeStateBuilder builder) - where TTransition : Transition + where TTransition : Transition where TTargetState : BaseState => builder.AddDefaultTransition(StateInfo.Name); public static IFinalizedCompositeStateBuilder AddDefaultTransition(this IFinalizedCompositeStateBuilder builder, string targetVertexName) - where TTransition : Transition - => builder.AddTransition(targetVertexName); + where TTransition : Transition + => builder.AddTransition(targetVertexName); - public static IFinalizedCompositeStateBuilder AddDefaultTransition(this IFinalizedCompositeStateBuilder builder, TransitionBuildAction transitionBuildAction = null) + public static IFinalizedCompositeStateBuilder AddDefaultTransition(this IFinalizedCompositeStateBuilder builder, TransitionBuildAction transitionBuildAction = null) where TTargetState : BaseState => builder.AddDefaultTransition(StateInfo.Name, transitionBuildAction); } 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 1d44bdcd..1a02296a 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/InitializedCompositeStateBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/CompositeStateBuilder/Transitions/InitializedCompositeStateBuilderDefaultTransitionTypedExtensions.cs @@ -6,15 +6,15 @@ namespace Stateflows.StateMachines.Typed public static class InitializedCompositeStateBuilderDefaultTransitionTypedExtensions { public static IInitializedCompositeStateBuilder AddDefaultTransition(this IInitializedCompositeStateBuilder builder) - where TTransition : Transition + where TTransition : Transition where TTargetState : BaseState => builder.AddDefaultTransition(StateInfo.Name); public static IInitializedCompositeStateBuilder AddDefaultTransition(this IInitializedCompositeStateBuilder builder, string targetVertexName) - where TTransition : Transition - => builder.AddTransition(targetVertexName); + where TTransition : Transition + => builder.AddTransition(targetVertexName); - public static IInitializedCompositeStateBuilder AddDefaultTransition(this IInitializedCompositeStateBuilder builder, TransitionBuildAction transitionBuildAction = null) + public static IInitializedCompositeStateBuilder AddDefaultTransition(this IInitializedCompositeStateBuilder builder, TransitionBuildAction transitionBuildAction = null) where TTargetState : BaseState => builder.AddDefaultTransition(StateInfo.Name, transitionBuildAction); } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/ElseTransitions/StateBuilderElseDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/ElseTransitions/StateBuilderElseDefaultTransitionTypedExtensions.cs index 55593312..755d0df0 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/ElseTransitions/StateBuilderElseDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/ElseTransitions/StateBuilderElseDefaultTransitionTypedExtensions.cs @@ -6,15 +6,15 @@ namespace Stateflows.StateMachines.Typed public static class StateBuilderElseDefaultTransitionTypedExtensions { public static IStateBuilder AddElseDefaultTransition(this IStateBuilder builder) - where TElseTransition : ElseTransition + where TElseTransition : ElseTransition where TTargetState : BaseState => builder.AddElseDefaultTransition(StateInfo.Name); public static IStateBuilder AddElseDefaultTransition(this IStateBuilder builder, string targetVertexName) - where TElseTransition : ElseTransition - => builder.AddElseTransition(targetVertexName); + where TElseTransition : ElseTransition + => builder.AddElseTransition(targetVertexName); - public static IStateBuilder AddElseDefaultTransition(this IStateBuilder builder, ElseTransitionBuildAction transitionBuildAction = null) + public static IStateBuilder AddElseDefaultTransition(this IStateBuilder builder, ElseTransitionBuildAction transitionBuildAction = null) where TTargetState : BaseState => builder.AddElseDefaultTransition(StateInfo.Name, transitionBuildAction); } 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 32617e59..9ef1a040 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/Transitions/StateBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/StateBuilder/Transitions/StateBuilderDefaultTransitionTypedExtensions.cs @@ -6,15 +6,15 @@ namespace Stateflows.StateMachines.Typed public static class StateBuilderDefaultTransitionTypedExtensions { public static IStateBuilder AddDefaultTransition(this IStateBuilder builder) - where TTransition : Transition + where TTransition : Transition where TTargetState : BaseState => builder.AddDefaultTransition(StateInfo.Name); public static IStateBuilder AddDefaultTransition(this IStateBuilder builder, string targetVertexName) - where TTransition : Transition - => builder.AddTransition(targetVertexName); + where TTransition : Transition + => builder.AddTransition(targetVertexName); - public static IStateBuilder AddDefaultTransition(this IStateBuilder builder, TransitionBuildAction transitionBuildAction = null) + public static IStateBuilder AddDefaultTransition(this IStateBuilder builder, TransitionBuildAction transitionBuildAction = null) where TTargetState : BaseState => builder.AddDefaultTransition(StateInfo.Name, transitionBuildAction); } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/ElseTransitions/TypedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/ElseTransitions/TypedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs index 1901d72f..fb22f7cf 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/ElseTransitions/TypedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/ElseTransitions/TypedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs @@ -6,15 +6,15 @@ namespace Stateflows.StateMachines.Typed public static class TypedCompositeStateBuilderElseDefaultTransitionTypedExtensions { public static ITypedCompositeStateBuilder AddElseDefaultTransition(this ITypedCompositeStateBuilder builder) - where TElseTransition : ElseTransition + where TElseTransition : ElseTransition where TTargetState : BaseState => builder.AddElseDefaultTransition(StateInfo.Name); public static ITypedCompositeStateBuilder AddElseDefaultTransition(this ITypedCompositeStateBuilder builder, string targetVertexName) - where TElseTransition : ElseTransition - => builder.AddElseTransition(targetVertexName); + where TElseTransition : ElseTransition + => builder.AddElseTransition(targetVertexName); - public static ITypedCompositeStateBuilder AddElseDefaultTransition(this ITypedCompositeStateBuilder builder, ElseTransitionBuildAction transitionBuildAction = null) + public static ITypedCompositeStateBuilder AddElseDefaultTransition(this ITypedCompositeStateBuilder builder, ElseTransitionBuildAction transitionBuildAction = null) where TTargetState : BaseState => builder.AddElseDefaultTransition(StateInfo.Name, transitionBuildAction); } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/ElseTransitions/TypedFinalizedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/ElseTransitions/TypedFinalizedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs index 4691134a..c6c9ac84 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/ElseTransitions/TypedFinalizedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/ElseTransitions/TypedFinalizedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs @@ -6,15 +6,15 @@ namespace Stateflows.StateMachines.Typed public static class TypedFinalizedCompositeStateBuilderElseDefaultTransitionTypedExtensions { public static ITypedFinalizedCompositeStateBuilder AddElseDefaultTransition(this ITypedFinalizedCompositeStateBuilder builder) - where TElseTransition : ElseTransition + where TElseTransition : ElseTransition where TTargetState : BaseState => builder.AddElseDefaultTransition(StateInfo.Name); public static ITypedFinalizedCompositeStateBuilder AddElseDefaultTransition(this ITypedFinalizedCompositeStateBuilder builder, string targetVertexName) - where TElseTransition : ElseTransition - => builder.AddElseTransition(targetVertexName); + where TElseTransition : ElseTransition + => builder.AddElseTransition(targetVertexName); - public static ITypedFinalizedCompositeStateBuilder AddElseDefaultTransition(this ITypedFinalizedCompositeStateBuilder builder, ElseTransitionBuildAction transitionBuildAction = null) + public static ITypedFinalizedCompositeStateBuilder AddElseDefaultTransition(this ITypedFinalizedCompositeStateBuilder builder, ElseTransitionBuildAction transitionBuildAction = null) where TTargetState : BaseState => builder.AddElseDefaultTransition(StateInfo.Name, transitionBuildAction); } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/ElseTransitions/TypedInitializedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/ElseTransitions/TypedInitializedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs index 6fb4f9d6..3dd2c292 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/ElseTransitions/TypedInitializedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/ElseTransitions/TypedInitializedCompositeStateBuilderElseDefaultTransitionTypedExtensions.cs @@ -6,15 +6,15 @@ namespace Stateflows.StateMachines.Typed public static class TypedInitializedCompositeStateBuilderElseDefaultTransitionTypedExtensions { public static ITypedInitializedCompositeStateBuilder AddElseDefaultTransition(this ITypedInitializedCompositeStateBuilder builder) - where TElseTransition : ElseTransition + where TElseTransition : ElseTransition where TTargetState : BaseState => builder.AddElseDefaultTransition(StateInfo.Name); public static ITypedInitializedCompositeStateBuilder AddElseDefaultTransition(this ITypedInitializedCompositeStateBuilder builder, string targetVertexName) - where TElseTransition : ElseTransition - => builder.AddElseTransition(targetVertexName); + where TElseTransition : ElseTransition + => builder.AddElseTransition(targetVertexName); - public static ITypedInitializedCompositeStateBuilder AddElseDefaultTransition(this ITypedInitializedCompositeStateBuilder builder, ElseTransitionBuildAction transitionBuildAction = null) + public static ITypedInitializedCompositeStateBuilder AddElseDefaultTransition(this ITypedInitializedCompositeStateBuilder builder, ElseTransitionBuildAction transitionBuildAction = null) where TTargetState : BaseState => builder.AddElseDefaultTransition(StateInfo.Name, transitionBuildAction); } 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 669058cc..0d5a9b4a 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateBuilderDefaultTransitionTypedExtensions.cs @@ -6,15 +6,15 @@ namespace Stateflows.StateMachines.Typed public static class TypedCompositeStateBuilderDefaultTransitionTypedExtensions { public static ITypedInitializedCompositeStateBuilder AddDefaultTransition(this ITypedInitializedCompositeStateBuilder builder) - where TTransition : Transition + where TTransition : Transition where TTargetState : BaseState => builder.AddDefaultTransition(StateInfo.Name); public static ITypedInitializedCompositeStateBuilder AddDefaultTransition(this ITypedInitializedCompositeStateBuilder builder, string targetVertexName) - where TTransition : Transition - => builder.AddTransition(targetVertexName); + where TTransition : Transition + => builder.AddTransition(targetVertexName); - public static ITypedInitializedCompositeStateBuilder AddDefaultTransition(this ITypedInitializedCompositeStateBuilder builder, TransitionBuildAction transitionBuildAction = null) + public static ITypedInitializedCompositeStateBuilder AddDefaultTransition(this ITypedInitializedCompositeStateBuilder builder, TransitionBuildAction transitionBuildAction = null) where TTargetState : BaseState => builder.AddDefaultTransition(StateInfo.Name, transitionBuildAction); } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateInitialBuilderDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateInitialBuilderDefaultTransitionTypedExtensions.cs index 6898b173..be5ff189 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateInitialBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedCompositeStateInitialBuilderDefaultTransitionTypedExtensions.cs @@ -6,15 +6,15 @@ namespace Stateflows.StateMachines.Typed public static class TypedCompositeStateInitialBuilderDefaultTransitionTypedExtensions { public static ITypedCompositeStateBuilder AddDefaultTransition(this ITypedCompositeStateBuilder builder) - where TTransition : Transition + where TTransition : Transition where TTargetState : BaseState => builder.AddDefaultTransition(StateInfo.Name); public static ITypedCompositeStateBuilder AddDefaultTransition(this ITypedCompositeStateBuilder builder, string targetVertexName) - where TTransition : Transition - => builder.AddTransition(targetVertexName); + where TTransition : Transition + => builder.AddTransition(targetVertexName); - public static ITypedCompositeStateBuilder AddDefaultTransition(this ITypedCompositeStateBuilder builder, TransitionBuildAction transitionBuildAction = null) + public static ITypedCompositeStateBuilder AddDefaultTransition(this ITypedCompositeStateBuilder builder, TransitionBuildAction transitionBuildAction = null) where TTargetState : BaseState => builder.AddDefaultTransition(StateInfo.Name, transitionBuildAction); } 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 a3bd0677..550e4f49 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedFinalizedCompositeStateBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedCompositeStateBuilder/Transitions/TypedFinalizedCompositeStateBuilderDefaultTransitionTypedExtensions.cs @@ -6,15 +6,15 @@ namespace Stateflows.StateMachines.Typed public static class TypedFinalizedCompositeStateBuilderDefaultTransitionTypedExtensions { public static ITypedFinalizedCompositeStateBuilder AddDefaultTransition(this ITypedFinalizedCompositeStateBuilder builder) - where TTransition : Transition + where TTransition : Transition where TTargetState : BaseState => builder.AddDefaultTransition(StateInfo.Name); public static ITypedFinalizedCompositeStateBuilder AddDefaultTransition(this ITypedFinalizedCompositeStateBuilder builder, string targetVertexName) - where TTransition : Transition - => builder.AddTransition(targetVertexName); + where TTransition : Transition + => builder.AddTransition(targetVertexName); - public static ITypedFinalizedCompositeStateBuilder AddDefaultTransition(this ITypedFinalizedCompositeStateBuilder builder, TransitionBuildAction transitionBuildAction = null) + public static ITypedFinalizedCompositeStateBuilder AddDefaultTransition(this ITypedFinalizedCompositeStateBuilder builder, TransitionBuildAction transitionBuildAction = null) where TTargetState : BaseState => builder.AddDefaultTransition(StateInfo.Name, transitionBuildAction); } diff --git a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/ElseTransitions/TypedStateBuilderElseDefaultTransitionTypedExtensions.cs b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/ElseTransitions/TypedStateBuilderElseDefaultTransitionTypedExtensions.cs index 6db9e9d1..0dd260e4 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/ElseTransitions/TypedStateBuilderElseDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/ElseTransitions/TypedStateBuilderElseDefaultTransitionTypedExtensions.cs @@ -6,15 +6,15 @@ namespace Stateflows.StateMachines.Typed public static class TypedStateBuilderElseDefaultTransitionTypedExtensions { public static ITypedStateBuilder AddElseDefaultTransition(this ITypedStateBuilder builder) - where TElseTransition : ElseTransition + where TElseTransition : ElseTransition where TTargetState : BaseState => builder.AddElseDefaultTransition(StateInfo.Name); public static ITypedStateBuilder AddElseDefaultTransition(this ITypedStateBuilder builder, string targetVertexName) - where TElseTransition : ElseTransition - => builder.AddElseTransition(targetVertexName); + where TElseTransition : ElseTransition + => builder.AddElseTransition(targetVertexName); - public static ITypedStateBuilder AddElseDefaultTransition(this ITypedStateBuilder builder, ElseTransitionBuildAction transitionBuildAction = null) + public static ITypedStateBuilder AddElseDefaultTransition(this ITypedStateBuilder builder, ElseTransitionBuildAction transitionBuildAction = null) where TTargetState : BaseState => builder.AddElseDefaultTransition(StateInfo.Name, transitionBuildAction); } 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 5292019c..9f5e409d 100644 --- a/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/Transitions/TypedStateBuilderDefaultTransitionTypedExtensions.cs +++ b/Core/Stateflows/StateMachines/Registration/Interfaces/Extensions/TypedStateBuilder/Transitions/TypedStateBuilderDefaultTransitionTypedExtensions.cs @@ -6,15 +6,15 @@ namespace Stateflows.StateMachines.Typed public static class TypedStateBuilderDefaultTransitionTypedExtensions { public static ITypedStateBuilder AddDefaultTransition(this ITypedStateBuilder builder) - where TTransition : Transition + where TTransition : Transition where TTargetState : BaseState => builder.AddDefaultTransition(StateInfo.Name); public static ITypedStateBuilder AddDefaultTransition(this ITypedStateBuilder builder, string targetVertexName) - where TTransition : Transition - => builder.AddTransition(targetVertexName); + where TTransition : Transition + => builder.AddTransition(targetVertexName); - public static ITypedStateBuilder AddDefaultTransition(this ITypedStateBuilder builder, TransitionBuildAction transitionBuildAction = null) + public static ITypedStateBuilder AddDefaultTransition(this ITypedStateBuilder builder, TransitionBuildAction transitionBuildAction = null) where TTargetState : BaseState => builder.AddDefaultTransition(StateInfo.Name, transitionBuildAction); } diff --git a/Core/Stateflows/Stateflows.csproj b/Core/Stateflows/Stateflows.csproj index d45d2337..2581e294 100644 --- a/Core/Stateflows/Stateflows.csproj +++ b/Core/Stateflows/Stateflows.csproj @@ -3,7 +3,7 @@ netstandard2.1 Stateflows framework core - 0.8.0-alpha + $(STATEFLOWS_VERSION) Stateflows https://www.stateflows.net stateflows-logo-1024.png diff --git a/Examples/Blazor/Server/Blazor.Server/Blazor.Server.csproj b/Examples/Blazor/Server/Blazor.Server/Blazor.Server.csproj index 2feaa83a..12088dec 100644 --- a/Examples/Blazor/Server/Blazor.Server/Blazor.Server.csproj +++ b/Examples/Blazor/Server/Blazor.Server/Blazor.Server.csproj @@ -1,4 +1,4 @@ - + net6.0 diff --git a/Examples/Blazor/Server/Blazor.Server/Program.cs b/Examples/Blazor/Server/Blazor.Server/Program.cs index 9d57d10d..dd729024 100644 --- a/Examples/Blazor/Server/Blazor.Server/Program.cs +++ b/Examples/Blazor/Server/Blazor.Server/Program.cs @@ -5,6 +5,7 @@ using Stateflows.Common; using Stateflows.Common.Data; using Stateflows.StateMachines; +using Stateflows.StateMachines.Typed; using Stateflows.StateMachines.Data; using Stateflows.StateMachines.Sync; using Stateflows.Activities; @@ -14,6 +15,7 @@ using Stateflows.Activities.Registration.Interfaces; using Stateflows.StateMachines.Attributes; using Examples.Storage; +using TestNamespace; var builder = WebApplication.CreateBuilder(args); @@ -58,11 +60,11 @@ ) ) - .AddDefaultInstance(BehaviorType.Activity.ToClass("sync0")) + .AddDefaultInstance(new ActivityClass("sync0")) .AddStorage() - //.AddTracing() + .AddTracing() .AddActivities(b => b .AddActivity("activity1", b => b @@ -166,44 +168,43 @@ ) ) - .AddTracer("W:\\traces") - .AddStateMachines(b => b - .AddStateMachine("stateMachine1", b => b - .AddInitialState("state1", b => b - .AddTransition("state3", b => { } - //.AddEffect(c => Console.Write(c.Event.Payload.Prop)) - ) - .AddTransition("state2") - .AddTransition("state2", b => b - .AddGuard(c => false) - ) - //.AddElseTransition("state2") - .AddTransition("state2", b => b - .AddEffect(c => throw new Exception("test")) - ) - .AddInternalTransition(b => b - .AddEffect(c => - { - c.Event.Respond(new ExampleResponse()); - c.StateMachine.Send(new TestNamespace.MyClass().ToEvent()); - }) - ) - ) - .AddState("state2", b => b - .AddTransition("state3") - .AddOnDoActivity("activity1") - ) - .AddState("state3", b => b - .AddTransition("state1", b => b - .AddGuard(c => Random.Shared.Next(1, 10) % 2 == 0) - //.AddEffect(c => Debug.WriteLine("Even, going to state1")) - ) - .AddElseTransition("state2", b => { } - //.AddEffect(c => Debug.WriteLine("Odd, going to state2")) - ) - ) - ) + .AddStateMachine() + //.AddStateMachine("stateMachine1", b => b + // .AddInitialState("state1", b => b + // .AddTransition("state3", b => { } + // //.AddEffect(c => Console.Write(c.Event.Payload.Prop)) + // ) + // .AddTransition("state2") + // .AddTransition("state2", b => b + // .AddGuard(c => false) + // ) + // //.AddElseTransition("state2") + // .AddTransition("state2", b => b + // .AddEffect(c => throw new Exception("test")) + // ) + // .AddInternalTransition(b => b + // .AddEffect(c => + // { + // c.Event.Respond(new ExampleResponse()); + // c.StateMachine.Send(new TestNamespace.MyClass().ToEvent()); + // }) + // ) + // ) + // .AddState("state2", b => b + // .AddTransition("state3") + // .AddOnDoActivity("activity1") + // ) + // .AddState("state3", b => b + // .AddTransition("state1", b => b + // .AddGuard(c => Random.Shared.Next(1, 10) % 2 == 0) + // //.AddEffect(c => Debug.WriteLine("Even, going to state1")) + // ) + // .AddElseTransition("state2", b => { } + // //.AddEffect(c => Debug.WriteLine("Odd, going to state2")) + // ) + // ) + //) ) .SetEnvironment( @@ -215,8 +216,7 @@ var app = builder.Build(); -app.MapStateflowsTransportHub(); -app.MapStateflowsEndpoints(); +app.MapStateflowsSignalRTransport(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) @@ -291,21 +291,31 @@ public override void Build(ITypedActivityBuilder builder) } } - [StateMachineBehavior] + [StateMachineBehavior(nameof(StateMachine1))] public class StateMachine1 : Stateflows.StateMachines.StateMachine { public override void Build(ITypedStateMachineBuilder builder) { builder .AddInitialState("1", b => b - .AddDefaultTransition("2") + .AddDefaultTransition() ) - .AddState("2") + .AddState() ; } } } +public class StateX : State +{ + public override Task OnEntryAsync() + { + Debug.WriteLine(Context.StateMachine.Id.Instance); + + return Task.CompletedTask; + } +} + public class SynchronizeDatabase : ActionNode { public override Task ExecuteAsync() diff --git a/Examples/Blazor/WebAssembly/Client/Blazor.WebAssembly.Client.csproj b/Examples/Blazor/WebAssembly/Client/Blazor.WebAssembly.Client.csproj index e7a724d9..6684759b 100644 --- a/Examples/Blazor/WebAssembly/Client/Blazor.WebAssembly.Client.csproj +++ b/Examples/Blazor/WebAssembly/Client/Blazor.WebAssembly.Client.csproj @@ -9,12 +9,14 @@ + + diff --git a/Examples/Blazor/WebAssembly/Client/Pages/StateMachines.razor b/Examples/Blazor/WebAssembly/Client/Pages/StateMachines.razor index 23c1dd8b..df56faf9 100644 --- a/Examples/Blazor/WebAssembly/Client/Pages/StateMachines.razor +++ b/Examples/Blazor/WebAssembly/Client/Pages/StateMachines.razor @@ -93,7 +93,7 @@ if (locator.TryLocateStateMachine(GetCurrentId(), out var stateMachine)) { var result = await stateMachine.InitializeAsync(); - message = result.Response.InitializationSuccessful + message = result.Response?.InitializationSuccessful ?? false ? "State Machine located and initialized" : "State Machine located, it's already initialized"; diff --git a/Examples/Blazor/WebAssembly/Client/Program.cs b/Examples/Blazor/WebAssembly/Client/Program.cs index 0ffa0656..520c40b4 100644 --- a/Examples/Blazor/WebAssembly/Client/Program.cs +++ b/Examples/Blazor/WebAssembly/Client/Program.cs @@ -11,7 +11,8 @@ builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); builder.Services.AddStateflowsClient(b => b - .AddSignalRTransport(provider => provider.GetRequiredService().BaseUri) + .AddHttpTransport(provider => new Uri(provider.GetRequiredService().BaseUri)) + //.AddSignalRTransport(provider => provider.GetRequiredService().BaseUri) ); await builder.Build().RunAsync(); diff --git a/Examples/Blazor/WebAssembly/Server/Blazor.WebAssembly.Server.csproj b/Examples/Blazor/WebAssembly/Server/Blazor.WebAssembly.Server.csproj index 9ab1b508..afcd9ee9 100644 --- a/Examples/Blazor/WebAssembly/Server/Blazor.WebAssembly.Server.csproj +++ b/Examples/Blazor/WebAssembly/Server/Blazor.WebAssembly.Server.csproj @@ -14,6 +14,7 @@ + diff --git a/Examples/Blazor/WebAssembly/Server/Program.cs b/Examples/Blazor/WebAssembly/Server/Program.cs index e4536f2e..42ee06aa 100644 --- a/Examples/Blazor/WebAssembly/Server/Program.cs +++ b/Examples/Blazor/WebAssembly/Server/Program.cs @@ -4,6 +4,7 @@ using Stateflows.Common; using Stateflows.StateMachines; using Stateflows.StateMachines.Sync; +using Stateflows.Transport.Http; var builder = WebApplication.CreateBuilder(args); @@ -64,7 +65,8 @@ var app = builder.Build(); -app.MapStateflowsTransportHub(); +app.MapStateflowsSignalRTransport(); +app.MapStateflowsHttpTransport(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) diff --git a/Examples/Cluster/Cluster.csproj b/Examples/Cluster/Cluster.csproj index de41fb65..543bfce6 100644 --- a/Examples/Cluster/Cluster.csproj +++ b/Examples/Cluster/Cluster.csproj @@ -12,7 +12,6 @@ - diff --git a/Examples/Examples.Storage/DependencyInjection.cs b/Examples/Examples.Storage/DependencyInjection.cs index 602142cb..caad99b4 100644 --- a/Examples/Examples.Storage/DependencyInjection.cs +++ b/Examples/Examples.Storage/DependencyInjection.cs @@ -1,5 +1,6 @@ using Stateflows; using Stateflows.Common.Registration.Interfaces; +using Stateflows.Storage.MongoDB.Utils; namespace Examples.Storage { @@ -8,7 +9,8 @@ public static class DependencyInjection public static IStateflowsBuilder AddStorage(this IStateflowsBuilder builder) { return builder - .AddEntityFrameworkCoreStorage() + //.AddEntityFrameworkCoreStorage() + .AddMongoDBStorage(provider => new MongoDatabaseConfiguration("localhost", 27017, "local")) ; } } diff --git a/Examples/Examples.Storage/Examples.Storage.csproj b/Examples/Examples.Storage/Examples.Storage.csproj index e47df074..c61461ed 100644 --- a/Examples/Examples.Storage/Examples.Storage.csproj +++ b/Examples/Examples.Storage/Examples.Storage.csproj @@ -18,7 +18,8 @@ - + + diff --git a/Examples/MassTransit/MassTransit.Service1/MassTransit.Service1.csproj b/Examples/MassTransit/MassTransit.Service1/MassTransit.Service1.csproj index 854ac508..c5898cad 100644 --- a/Examples/MassTransit/MassTransit.Service1/MassTransit.Service1.csproj +++ b/Examples/MassTransit/MassTransit.Service1/MassTransit.Service1.csproj @@ -8,7 +8,6 @@ - diff --git a/Examples/MassTransit/MassTransit.Service2/MassTransit.Service2.csproj b/Examples/MassTransit/MassTransit.Service2/MassTransit.Service2.csproj index 854ac508..c5898cad 100644 --- a/Examples/MassTransit/MassTransit.Service2/MassTransit.Service2.csproj +++ b/Examples/MassTransit/MassTransit.Service2/MassTransit.Service2.csproj @@ -8,7 +8,6 @@ - diff --git a/Examples/MassTransit/MassTransit.Service3/MassTransit.Service3.csproj b/Examples/MassTransit/MassTransit.Service3/MassTransit.Service3.csproj index 854ac508..c5898cad 100644 --- a/Examples/MassTransit/MassTransit.Service3/MassTransit.Service3.csproj +++ b/Examples/MassTransit/MassTransit.Service3/MassTransit.Service3.csproj @@ -8,7 +8,6 @@ - diff --git a/Examples/SignalR/SignalR.Client/ClientApp/package.json b/Examples/SignalR/SignalR.Client/ClientApp/package.json index 782e6841..14ebecc1 100644 --- a/Examples/SignalR/SignalR.Client/ClientApp/package.json +++ b/Examples/SignalR/SignalR.Client/ClientApp/package.json @@ -23,6 +23,8 @@ "@angular/platform-browser-dynamic": "^15.2.8", "@angular/platform-server": "^15.2.10", "@angular/router": "^15.2.10", + "@stateflows/client-abstractions": "file:../../../../Transport/@stateflows/client-abstractions", + "@stateflows/http-client": "file:../../../../Transport/@stateflows/http-client", "@stateflows/signalr-client": "file:../../../../Transport/@stateflows/signalr-client", "bootstrap": "^5.3.2", "jquery": "^3.7.1", diff --git a/Examples/SignalR/SignalR.Client/ClientApp/src/app/counter/counter.component.ts b/Examples/SignalR/SignalR.Client/ClientApp/src/app/counter/counter.component.ts index af7637e0..f4fb628e 100644 --- a/Examples/SignalR/SignalR.Client/ClientApp/src/app/counter/counter.component.ts +++ b/Examples/SignalR/SignalR.Client/ClientApp/src/app/counter/counter.component.ts @@ -1,10 +1,8 @@ import { HttpClient } from '@angular/common/http'; import { Component } from '@angular/core'; -import { BehaviorClass } from '@stateflows/signalr-client'; -import { BehaviorId } from '@stateflows/signalr-client'; -import { ActivityId } from '@stateflows/signalr-client'; -import { BehaviorStatus, Event, EventStatus, PlantUmlRequest, PlantUmlResponse, StateMachineId, StateflowsClient, AvailableBehaviorClassesRequest, AvailableBehaviorClassesResponse } from '@stateflows/signalr-client'; import * as plantUmlEncoder from 'plantuml-encoder'; +import { StateflowsClient, StateMachineId, BehaviorStatus, EventStatus, PlantUmlRequest, PlantUmlResponse, Event } from '@stateflows/client-abstractions'; +import { UseHttp } from '@stateflows/http-client'; class OtherEvent extends Event { public $type: string = "Examples.Common.OtherEvent, Examples.Common"; @@ -17,7 +15,7 @@ class OtherEvent extends Event { }) export class CounterComponent { public currentCount = 0; - private stateflows: StateflowsClient = new StateflowsClient("https://localhost:7067/"); + private stateflows: StateflowsClient = new StateflowsClient(UseHttp("https://localhost:7067/")); public url: string | null = null; constructor(private http: HttpClient) { } @@ -37,8 +35,10 @@ export class CounterComponent { } public async incrementCounter() { - let sm = await this.stateflows.stateMachineLocator.locateStateMachine(new StateMachineId("stateMachine1", "x")); - if ((await sm.getStatus()).Response.BehaviorStatus == BehaviorStatus.NotInitialized) { + let sm = await this.stateflows.stateMachineLocator.locateStateMachine(new StateMachineId("stateMachine1", "xx")); + let x = await sm.getStatus(); + console.log(x); + if (x.Response.BehaviorStatus == BehaviorStatus.NotInitialized) { await sm.initialize(); } @@ -49,8 +49,6 @@ export class CounterComponent { } let system = await this.stateflows.system; - // let result = await system.getAvailableBehaviorClasses(); - // console.log(await system.getBehaviorInstances()); this.currentCount++; } diff --git a/Examples/SignalR/SignalR.Client/Program.cs b/Examples/SignalR/SignalR.Client/Program.cs index b84ffd4e..10e4e887 100644 --- a/Examples/SignalR/SignalR.Client/Program.cs +++ b/Examples/SignalR/SignalR.Client/Program.cs @@ -5,6 +5,7 @@ using Stateflows.StateMachines; using Stateflows.StateMachines.Sync; using Stateflows.StateMachines.Typed; +using Stateflows.Transport.Http; var builder = WebApplication.CreateBuilder(args); @@ -50,8 +51,8 @@ app.UseStaticFiles(); app.UseRouting(); -app.MapStateflowsTransportHub(); -app.MapStateflowsEndpoints(); +app.MapStateflowsSignalRTransport(); +app.MapStateflowsHttpTransport(); app.UseCors(builder => builder .AllowAnyHeader() diff --git a/Examples/SignalR/SignalR.Client/SignalR.Client.csproj b/Examples/SignalR/SignalR.Client/SignalR.Client.csproj index 6dca245f..b8f8d980 100644 --- a/Examples/SignalR/SignalR.Client/SignalR.Client.csproj +++ b/Examples/SignalR/SignalR.Client/SignalR.Client.csproj @@ -26,6 +26,7 @@ + diff --git a/Extensions/Stateflows.Extensions.PlantUml/Classes/ActivityPlantUmlGenerator.cs b/Extensions/Stateflows.Extensions.PlantUml/Classes/ActivityPlantUmlGenerator.cs index 4b07d387..857c2b76 100644 --- a/Extensions/Stateflows.Extensions.PlantUml/Classes/ActivityPlantUmlGenerator.cs +++ b/Extensions/Stateflows.Extensions.PlantUml/Classes/ActivityPlantUmlGenerator.cs @@ -61,20 +61,12 @@ private static void GetPlantUml(int indentCount, INodeInspection node, StringBui var source = GetNodeName(transition.Source, parentName); var target = GetNodeName(transition.Target, parentName); - if (transition.TokenName == TokenInfo.TokenName) + if (transition.TokenName == TokenInfo.Name) { builder.AppendLine($"{indent}{source} --> {target}"); } else { - //var tokenName = transition.TokenName.Split('`').First().Split('.').Last(); - - //if (tokenName == "ValueToken" || tokenName == "ExceptionToken") - //{ - // var typeName = transition.TokenName.Split('`').Last().Trim('1', '[', ']').Split(',').First().Split('.').Last(); - // tokenName = $"{tokenName}<{typeName}>"; - //} - builder.AppendLine($"{indent}{source} -->[{transition.TokenName}] {target}"); } } diff --git a/Extensions/Stateflows.Extensions.PlantUml/Stateflows.Extensions.PlantUml.csproj b/Extensions/Stateflows.Extensions.PlantUml/Stateflows.Extensions.PlantUml.csproj index 1b870403..654b7c81 100644 --- a/Extensions/Stateflows.Extensions.PlantUml/Stateflows.Extensions.PlantUml.csproj +++ b/Extensions/Stateflows.Extensions.PlantUml/Stateflows.Extensions.PlantUml.csproj @@ -3,7 +3,7 @@ netstandard2.1 PlantUML extension for Stateflows framework - 0.8.0-alpha + $(STATEFLOWS_VERSION) Stateflows https://www.stateflows.net stateflows-logo-1024.png diff --git a/Locks/Stateflows.Locks.DistributedLock/Stateflows.Locks.DistributedLock.csproj b/Locks/Stateflows.Locks.DistributedLock/Stateflows.Locks.DistributedLock.csproj index 25c2b9a8..ab3e9c1b 100644 --- a/Locks/Stateflows.Locks.DistributedLock/Stateflows.Locks.DistributedLock.csproj +++ b/Locks/Stateflows.Locks.DistributedLock/Stateflows.Locks.DistributedLock.csproj @@ -4,7 +4,7 @@ netstandard2.1 enable DistributedLock locking for Stateflows framework - 0.8.0-alpha + $(STATEFLOWS_VERSION) Stateflows https://www.stateflows.net stateflows-logo-1024.png diff --git a/Stateflows.sln b/Stateflows.sln index 4744bdcb..bf34f416 100644 --- a/Stateflows.sln +++ b/Stateflows.sln @@ -11,8 +11,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stateflows.Common", "Core\S EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Transport", "Transport", "{D789B3ED-A0A0-40B3-A746-337C7EF71B9D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stateflows.Transport.AspNetCore.WebApi", "Transport\Stateflows.Transport.AspNetCore.WebApi\Stateflows.Transport.AspNetCore.WebApi.csproj", "{C7824EBF-62A7-4B8C-8FB4-3146C4435618}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stateflows.Transport.MassTransit", "Transport\Stateflows.Transport.MassTransit\Stateflows.Transport.MassTransit.csproj", "{9A9239D6-4E00-4ACF-9AAD-9F9B9A6792A7}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Storage", "Storage", "{82B8FBE5-CA6A-4BB0-BB42-D0F0BDEFEDD4}" @@ -83,6 +81,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MinimalAPI", "Examples\Mini EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stateflows.Extensions.MinimalApi", "Extensions\Stateflows.Extensions.MinimalAPI\Stateflows.Extensions.MinimalApi.csproj", "{8AD6B55A-4307-45A0-8C70-D64B7CE46313}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stateflows.Transport.Http", "Transport\Stateflows.Transport.Http\Stateflows.Transport.Http.csproj", "{8C6BEB59-8CCB-4BB9-950D-08D95FDE2BC8}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stateflows.Transport.Http.Client", "Transport\Stateflows.Transport.Http.Client\Stateflows.Transport.Http.Client.csproj", "{37C61B16-A27E-487B-AEBC-126E7FDD8443}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -97,10 +99,6 @@ Global {FD59CE94-009E-47D5-B5FC-9F17B385B114}.Debug|Any CPU.Build.0 = Debug|Any CPU {FD59CE94-009E-47D5-B5FC-9F17B385B114}.Release|Any CPU.ActiveCfg = Release|Any CPU {FD59CE94-009E-47D5-B5FC-9F17B385B114}.Release|Any CPU.Build.0 = Release|Any CPU - {C7824EBF-62A7-4B8C-8FB4-3146C4435618}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C7824EBF-62A7-4B8C-8FB4-3146C4435618}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C7824EBF-62A7-4B8C-8FB4-3146C4435618}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C7824EBF-62A7-4B8C-8FB4-3146C4435618}.Release|Any CPU.Build.0 = Release|Any CPU {9A9239D6-4E00-4ACF-9AAD-9F9B9A6792A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9A9239D6-4E00-4ACF-9AAD-9F9B9A6792A7}.Debug|Any CPU.Build.0 = Debug|Any CPU {9A9239D6-4E00-4ACF-9AAD-9F9B9A6792A7}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -197,6 +195,14 @@ Global {8AD6B55A-4307-45A0-8C70-D64B7CE46313}.Debug|Any CPU.Build.0 = Debug|Any CPU {8AD6B55A-4307-45A0-8C70-D64B7CE46313}.Release|Any CPU.ActiveCfg = Release|Any CPU {8AD6B55A-4307-45A0-8C70-D64B7CE46313}.Release|Any CPU.Build.0 = Release|Any CPU + {8C6BEB59-8CCB-4BB9-950D-08D95FDE2BC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8C6BEB59-8CCB-4BB9-950D-08D95FDE2BC8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8C6BEB59-8CCB-4BB9-950D-08D95FDE2BC8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8C6BEB59-8CCB-4BB9-950D-08D95FDE2BC8}.Release|Any CPU.Build.0 = Release|Any CPU + {37C61B16-A27E-487B-AEBC-126E7FDD8443}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {37C61B16-A27E-487B-AEBC-126E7FDD8443}.Debug|Any CPU.Build.0 = Debug|Any CPU + {37C61B16-A27E-487B-AEBC-126E7FDD8443}.Release|Any CPU.ActiveCfg = Release|Any CPU + {37C61B16-A27E-487B-AEBC-126E7FDD8443}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -204,7 +210,6 @@ Global GlobalSection(NestedProjects) = preSolution {EF688ED7-689D-401D-9D68-5385B7B1A7DC} = {835D16B4-CF1C-491C-8FB7-F33A3D64EC69} {FD59CE94-009E-47D5-B5FC-9F17B385B114} = {835D16B4-CF1C-491C-8FB7-F33A3D64EC69} - {C7824EBF-62A7-4B8C-8FB4-3146C4435618} = {D789B3ED-A0A0-40B3-A746-337C7EF71B9D} {9A9239D6-4E00-4ACF-9AAD-9F9B9A6792A7} = {D789B3ED-A0A0-40B3-A746-337C7EF71B9D} {06AD764B-5355-4C18-8D6F-B326567B1BE3} = {D789B3ED-A0A0-40B3-A746-337C7EF71B9D} {47C05CF4-4154-4959-B0EE-E196E6E834B0} = {D02BCCCA-7A8D-4AB8-AF36-020DCF92E17C} @@ -235,6 +240,8 @@ Global {74AD1209-0A74-4E81-850A-5C3C775A8CB4} = {82B8FBE5-CA6A-4BB0-BB42-D0F0BDEFEDD4} {09631A73-6BE3-4895-9D75-722F24AF161D} = {D02BCCCA-7A8D-4AB8-AF36-020DCF92E17C} {8AD6B55A-4307-45A0-8C70-D64B7CE46313} = {580A6B03-79AD-430C-AEF6-80EC6A02FA61} + {8C6BEB59-8CCB-4BB9-950D-08D95FDE2BC8} = {D789B3ED-A0A0-40B3-A746-337C7EF71B9D} + {37C61B16-A27E-487B-AEBC-126E7FDD8443} = {D789B3ED-A0A0-40B3-A746-337C7EF71B9D} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {602A9FD6-5053-42E4-AEAE-2813DF169A3C} diff --git a/Storage/Stateflows.Storage.EntityFrameworkCore.6.0/DependencyInjection.cs b/Storage/Stateflows.Storage.EntityFrameworkCore/DependencyInjection.cs similarity index 100% rename from Storage/Stateflows.Storage.EntityFrameworkCore.6.0/DependencyInjection.cs rename to Storage/Stateflows.Storage.EntityFrameworkCore/DependencyInjection.cs diff --git a/Storage/Stateflows.Storage.EntityFrameworkCore.6.0/EntityFrameworkCore/Entities/Context_v1.cs b/Storage/Stateflows.Storage.EntityFrameworkCore/EntityFrameworkCore/Entities/Context_v1.cs similarity index 100% rename from Storage/Stateflows.Storage.EntityFrameworkCore.6.0/EntityFrameworkCore/Entities/Context_v1.cs rename to Storage/Stateflows.Storage.EntityFrameworkCore/EntityFrameworkCore/Entities/Context_v1.cs diff --git a/Storage/Stateflows.Storage.EntityFrameworkCore.6.0/EntityFrameworkCore/Entities/Trace_v1.cs b/Storage/Stateflows.Storage.EntityFrameworkCore/EntityFrameworkCore/Entities/Trace_v1.cs similarity index 100% rename from Storage/Stateflows.Storage.EntityFrameworkCore.6.0/EntityFrameworkCore/Entities/Trace_v1.cs rename to Storage/Stateflows.Storage.EntityFrameworkCore/EntityFrameworkCore/Entities/Trace_v1.cs diff --git a/Storage/Stateflows.Storage.EntityFrameworkCore.6.0/EntityFrameworkCore/IStateflowsDbContext_v1.cs b/Storage/Stateflows.Storage.EntityFrameworkCore/EntityFrameworkCore/IStateflowsDbContext_v1.cs similarity index 100% rename from Storage/Stateflows.Storage.EntityFrameworkCore.6.0/EntityFrameworkCore/IStateflowsDbContext_v1.cs rename to Storage/Stateflows.Storage.EntityFrameworkCore/EntityFrameworkCore/IStateflowsDbContext_v1.cs diff --git a/Storage/Stateflows.Storage.EntityFrameworkCore.6.0/Stateflows.Storage.EntityFrameworkCore.6.0.csproj b/Storage/Stateflows.Storage.EntityFrameworkCore/Stateflows.Storage.EntityFrameworkCore.csproj similarity index 94% rename from Storage/Stateflows.Storage.EntityFrameworkCore.6.0/Stateflows.Storage.EntityFrameworkCore.6.0.csproj rename to Storage/Stateflows.Storage.EntityFrameworkCore/Stateflows.Storage.EntityFrameworkCore.csproj index c48e2021..0e2e2aa9 100644 --- a/Storage/Stateflows.Storage.EntityFrameworkCore.6.0/Stateflows.Storage.EntityFrameworkCore.6.0.csproj +++ b/Storage/Stateflows.Storage.EntityFrameworkCore/Stateflows.Storage.EntityFrameworkCore.csproj @@ -4,8 +4,8 @@ net6.0 enable enable - Entity Framework Core 6.0 storage for Stateflows framework - 0.7.0-alpha + Entity Framework Core storage for Stateflows framework + $(STATEFLOWS_VERSION) Stateflows https://www.stateflows.net stateflows-logo-1024.png diff --git a/Storage/Stateflows.Storage.EntityFrameworkCore.6.0/Stateflows/EntityFrameworkCoreStorage.cs b/Storage/Stateflows.Storage.EntityFrameworkCore/Stateflows/EntityFrameworkCoreStorage.cs similarity index 100% rename from Storage/Stateflows.Storage.EntityFrameworkCore.6.0/Stateflows/EntityFrameworkCoreStorage.cs rename to Storage/Stateflows.Storage.EntityFrameworkCore/Stateflows/EntityFrameworkCoreStorage.cs diff --git a/Storage/Stateflows.Storage.EntityFrameworkCore.6.0/Utils/DbSetExtensions.cs b/Storage/Stateflows.Storage.EntityFrameworkCore/Utils/DbSetExtensions.cs similarity index 100% rename from Storage/Stateflows.Storage.EntityFrameworkCore.6.0/Utils/DbSetExtensions.cs rename to Storage/Stateflows.Storage.EntityFrameworkCore/Utils/DbSetExtensions.cs diff --git a/Storage/Stateflows.Storage.MongoDb/DependencyInjection.cs b/Storage/Stateflows.Storage.MongoDb/DependencyInjection.cs index 037a5140..ee646aff 100644 --- a/Storage/Stateflows.Storage.MongoDb/DependencyInjection.cs +++ b/Storage/Stateflows.Storage.MongoDb/DependencyInjection.cs @@ -1,6 +1,7 @@ using System; using Microsoft.Extensions.DependencyInjection; using MongoDB.Driver; +using Stateflows.Common.Exceptions; using Stateflows.Common.Interfaces; using Stateflows.Common.Extensions; using Stateflows.Common.Registration.Interfaces; @@ -15,7 +16,7 @@ public static IStateflowsBuilder AddMongoDBStorage(this IStateflowsBuilder build { if (builder.ServiceCollection.IsServiceRegistered()) { - throw new Exception("Another Stateflows storage already registered"); + throw new StateflowsException("Another Stateflows storage already registered"); } builder.ServiceCollection diff --git a/Storage/Stateflows.Storage.MongoDb/MongoDB/Entities/StateflowsContext_v1.cs b/Storage/Stateflows.Storage.MongoDb/MongoDB/Entities/StateflowsContext_v1.cs new file mode 100644 index 00000000..a97cc165 --- /dev/null +++ b/Storage/Stateflows.Storage.MongoDb/MongoDB/Entities/StateflowsContext_v1.cs @@ -0,0 +1,22 @@ +using System; +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; + +namespace Stateflows.Storage.MongoDB.MongoDB.Entities +{ + internal class StateflowsContext_v1 + { + [BsonId] + public ObjectId Id { get; set; } + public string BehaviorId { get; set; } + public string BehaviorClass { get; set; } + public DateTime? TriggerTime { get; set; } + public string Data { get; set; } + public StateflowsContext_v1(BehaviorId behaviorId) + { + BehaviorId = behaviorId; + BehaviorClass = behaviorId.BehaviorClass; + Data = string.Empty; + } + } +} diff --git a/Storage/Stateflows.Storage.MongoDb/MongoDB/Entities/Context_v1.cs b/Storage/Stateflows.Storage.MongoDb/MongoDB/Entities/StateflowsTrace_v1.cs similarity index 56% rename from Storage/Stateflows.Storage.MongoDb/MongoDB/Entities/Context_v1.cs rename to Storage/Stateflows.Storage.MongoDb/MongoDB/Entities/StateflowsTrace_v1.cs index bc33df0b..5911bf0d 100644 --- a/Storage/Stateflows.Storage.MongoDb/MongoDB/Entities/Context_v1.cs +++ b/Storage/Stateflows.Storage.MongoDb/MongoDB/Entities/StateflowsTrace_v1.cs @@ -1,17 +1,20 @@ -using MongoDB.Bson; +using System; +using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; namespace Stateflows.Storage.MongoDB.MongoDB.Entities { - internal class Context_v1 + internal class StateflowsTrace_v1 { [BsonId] public ObjectId Id { get; set; } public string BehaviorId { get; set; } + public DateTime ExecutionTime { get; set; } public string Data { get; set; } - public Context_v1(string behaviorId, string data) + public StateflowsTrace_v1(BehaviorId behaviorId, DateTime executionTime, string data) { BehaviorId = behaviorId; + ExecutionTime = executionTime; Data = data; } } diff --git a/Storage/Stateflows.Storage.MongoDb/MongoDB/Entities/TimeToken_v1.cs b/Storage/Stateflows.Storage.MongoDb/MongoDB/Entities/TimeToken_v1.cs deleted file mode 100644 index db295089..00000000 --- a/Storage/Stateflows.Storage.MongoDb/MongoDB/Entities/TimeToken_v1.cs +++ /dev/null @@ -1,18 +0,0 @@ -using MongoDB.Bson; -using MongoDB.Bson.Serialization.Attributes; - -namespace Stateflows.Storage.MongoDB.MongoDB.Entities -{ - internal class TimeToken_v1 - { - [BsonId] - public ObjectId Id { get; set; } - public string BehaviorClass { get; set; } - public string Data { get; set; } - public TimeToken_v1(string behaviorClass, string data) - { - BehaviorClass = behaviorClass; - Data = data; - } - } -} diff --git a/Storage/Stateflows.Storage.MongoDb/Stateflows/MongoDBStorage.cs b/Storage/Stateflows.Storage.MongoDb/Stateflows/MongoDBStorage.cs index ab510b37..7ef3bb8b 100644 --- a/Storage/Stateflows.Storage.MongoDb/Stateflows/MongoDBStorage.cs +++ b/Storage/Stateflows.Storage.MongoDb/Stateflows/MongoDBStorage.cs @@ -1,16 +1,13 @@ -using MongoDB.Bson; +using System.Linq; +using System.Threading.Tasks; +using System.Collections.Generic; using MongoDB.Driver; using Stateflows.Common.Context; -using Stateflows.Common.Interfaces; using Stateflows.Common.Utilities; -using Stateflows.Storage.MongoDB.MongoDB.Entities; +using Stateflows.Common.Interfaces; +using Stateflows.Common.Trace.Models; using Stateflows.Storage.MongoDB.Utils; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using TimeToken = Stateflows.Common.Classes.TimeToken; -using TimeTokenEntity = Stateflows.Storage.MongoDB.MongoDB.Entities.TimeToken_v1; +using Stateflows.Storage.MongoDB.MongoDB.Entities; namespace Stateflows.Storage.MongoDB.Stateflows { @@ -22,109 +19,42 @@ public MongoDBStorage(IMongoClient mongoDBClient, string databaseName) _mongoDatabase = mongoDBClient.GetDatabase(databaseName); } - public async Task HydrateAsync(BehaviorId id) + public async Task HydrateAsync(BehaviorId behaviorId) { - var context = await MongoDBSetExtension.FindOrCreate(_mongoDatabase, CollectionNames.Context_v1, id); + var context = await MongoDBSetExtension.FindOrCreateContextAsync(_mongoDatabase, behaviorId); StateflowsContext result = StateflowsJsonConverter.DeserializeObject(context?.Data ?? string.Empty) - ?? new StateflowsContext() { Id = id }; + ?? new StateflowsContext() { Id = behaviorId }; return result; } public async Task DehydrateAsync(StateflowsContext context) { - var contextEntity = await _mongoDatabase.FindOrCreate(CollectionNames.Context_v1, context); - contextEntity.Data = StateflowsJsonConverter.SerializeObject(context); - await UpdateOrInsertContextData(contextEntity); - } - - public Task> GetContextsAsync(IEnumerable behaviorClasses) - { - throw new NotImplementedException(); - } - - public async Task AddTimeTokens(TimeToken[] timeTokens) - { - if (!timeTokens.Any()) return; - - var tokens = new Dictionary(); - var collection = _mongoDatabase.GetCollection(CollectionNames.TimeToken_v1); - - foreach (var timeToken in timeTokens) - { - var timeTokenEntity = new TimeTokenEntity( - StateflowsJsonConverter.SerializeObject(timeToken.TargetId.BehaviorClass), - StateflowsJsonConverter.SerializeObject(timeToken) - ); - tokens.Add(timeToken, timeTokenEntity); - } - - await collection.InsertManyAsync(tokens.Values); - UpdateIdsForInsertedTimeTokens(tokens, timeTokens); - } - - public async Task ClearTimeTokens(BehaviorId behaviorId, IEnumerable ids) - { - var collection = _mongoDatabase.GetCollection(CollectionNames.TimeToken_v1); - var objectIds = ids.Select(id => ObjectId.Parse(id)).ToList(); - - var filter = Builders.Filter.In("_id", objectIds); - - await collection.DeleteManyAsync(filter); - } - - public async Task> GetTimeTokens(IEnumerable behaviorClasses) - { - var collection = _mongoDatabase.GetCollection(CollectionNames.TimeToken_v1); - var behaviorClassStrings = behaviorClasses.Select(bc => bc.ToString()); - - return (await collection.Find(p => behaviorClassStrings.Contains(p.BehaviorClass)).ToListAsync()) - .Select(e => - { - var result = StateflowsJsonConverter.DeserializeObject(e.Data); - if (result != null) - { - result.Id = e.Id.ToString(); - } - else - { - result = new TimeToken(); - } - - return result; - }) - .Where(e => e.Id != null) - .ToArray(); + var contextEntity = await _mongoDatabase.FindOrCreateContextAsync(context.Id); + contextEntity.Data = StateflowsJsonConverter.SerializePolymorphicObject(context); + contextEntity.TriggerTime = context.TriggerTime; + await _mongoDatabase.UpdateOrInsertContextAsync(contextEntity); } - private async Task UpdateOrInsertContextData(Context_v1 contextEntity) - { - var collection = _mongoDatabase.GetCollection(CollectionNames.Context_v1); - - if (contextEntity.Id == default) - { - await collection.InsertOneAsync(contextEntity); - } - else - { - var filter = Builders.Filter.Where(x => x.Id == contextEntity.Id); - var updateDefBuilder = Builders.Update; - var updateDef = updateDefBuilder.Combine( - updateDefBuilder - .Set(x => x.Data, contextEntity.Data)); + public async Task> GetContextsAsync(IEnumerable behaviorClasses) + => (await _mongoDatabase.FindContextByBehaviorClassAsync(behaviorClasses)) + .Select(e => StateflowsJsonConverter.DeserializeObject(e.Data)); - await collection.UpdateOneAsync(filter, updateDef); - } - } + public async Task> GetContextsToTimeTriggerAsync(IEnumerable behaviorClasses) + => (await _mongoDatabase.FindContextByTimeTriggerAsync(behaviorClasses)) + .Select(e => StateflowsJsonConverter.DeserializeObject(e.Data)); - private static void UpdateIdsForInsertedTimeTokens(Dictionary tokens, TimeToken[] timeTokens) - { - var ids = tokens.Values.Select(_ => _.Id); + public Task SaveTraceAsync(BehaviorTrace behaviorTrace) + => _mongoDatabase.InsertTraceAsync( + new StateflowsTrace_v1( + behaviorTrace.BehaviorId, + behaviorTrace.ExecutedAt, + StateflowsJsonConverter.SerializePolymorphicObject(behaviorTrace) + ) + ); - for (int i = 0; i < timeTokens.Length; i++) - { - timeTokens[i].Id = ids.ElementAt(i).ToString(); - } - } + public async Task> GetTracesAsync(BehaviorId behaviorId) + => (await _mongoDatabase.FindTracesAsync(behaviorId)) + .Select(e => StateflowsJsonConverter.DeserializeObject(e.Data)); } } diff --git a/Storage/Stateflows.Storage.MongoDb/Utils/CollectionNames.cs b/Storage/Stateflows.Storage.MongoDb/Utils/CollectionNames.cs index 159eff96..16d02ac9 100644 --- a/Storage/Stateflows.Storage.MongoDb/Utils/CollectionNames.cs +++ b/Storage/Stateflows.Storage.MongoDb/Utils/CollectionNames.cs @@ -2,7 +2,7 @@ { internal static class CollectionNames { - public const string Context_v1 = "Context_v1"; - public const string TimeToken_v1 = "TimeToken_v1"; + public const string StateflowsContexts_v1 = "StateflowsContexts_v1"; + public const string StateflowsTraces_v1 = "StateflowsTraces_v1"; } } diff --git a/Storage/Stateflows.Storage.MongoDb/Utils/MongoDBSetExtension.cs b/Storage/Stateflows.Storage.MongoDb/Utils/MongoDBSetExtension.cs index 952c32be..83149783 100644 --- a/Storage/Stateflows.Storage.MongoDb/Utils/MongoDBSetExtension.cs +++ b/Storage/Stateflows.Storage.MongoDb/Utils/MongoDBSetExtension.cs @@ -1,22 +1,62 @@ -using MongoDB.Driver; -using Stateflows.Common.Context; -using Stateflows.Storage.MongoDB.MongoDB.Entities; +using System; +using System.Linq; using System.Threading.Tasks; +using System.Collections.Generic; +using MongoDB.Driver; +using Stateflows.Storage.MongoDB.MongoDB.Entities; namespace Stateflows.Storage.MongoDB.Utils { internal static class MongoDBSetExtension { - public static async Task FindOrCreate(this IMongoDatabase mongoDb, string collectionName, StateflowsContext context) - => await FindOrCreate(mongoDb, collectionName, context.Id); + public static async Task> FindContextByTimeTriggerAsync(this IMongoDatabase mongoDb, IEnumerable behaviorClasses) + { + var collection = mongoDb.GetCollection(CollectionNames.StateflowsContexts_v1); + var filter = + Builders.Filter.In(c => c.BehaviorClass, behaviorClasses.Select(c => c.ToString())) & + Builders.Filter.Where(c => c.TriggerTime <= DateTime.Now); + return await collection.Find(filter).ToListAsync(); + } - public static async Task FindOrCreate(this IMongoDatabase mongoDb, string collectionName, BehaviorId id) + public static async Task> FindContextByBehaviorClassAsync(this IMongoDatabase mongoDb, IEnumerable behaviorClasses) { - var collection = mongoDb.GetCollection(collectionName); + var collection = mongoDb.GetCollection(CollectionNames.StateflowsContexts_v1); + var filter = Builders.Filter.In(c => c.BehaviorClass, behaviorClasses.Select(c => c.ToString())); + return await collection.Find(filter).ToListAsync(); + } + + public static async Task FindOrCreateContextAsync(this IMongoDatabase mongoDb, BehaviorId id) + => await mongoDb.GetCollection(CollectionNames.StateflowsContexts_v1) + .Find(c => c.BehaviorId == id) + .FirstOrDefaultAsync() ?? new StateflowsContext_v1(id); - return await collection - .Find(c => c.BehaviorId == id.ToString()) - .FirstOrDefaultAsync() ?? new Context_v1(id.ToString(), string.Empty); + public static async Task UpdateOrInsertContextAsync(this IMongoDatabase mongoDb, StateflowsContext_v1 contextEntity) + { + var collection = mongoDb.GetCollection(CollectionNames.StateflowsContexts_v1); + + if (contextEntity.Id == default) + { + await collection.InsertOneAsync(contextEntity); + } + else + { + var filter = Builders.Filter.Where(x => x.Id == contextEntity.Id); + var updateDefBuilder = Builders.Update; + var updateDef = updateDefBuilder.Combine( + updateDefBuilder + .Set(x => x.Data, contextEntity.Data)) + .Set(x => x.TriggerTime, contextEntity.TriggerTime); + + await collection.UpdateOneAsync(filter, updateDef); + } } + + public static async Task> FindTracesAsync(this IMongoDatabase mongoDb, BehaviorId id) + => await mongoDb.GetCollection(CollectionNames.StateflowsTraces_v1) + .Find(c => c.BehaviorId == id) + .ToListAsync(); + + public static Task InsertTraceAsync(this IMongoDatabase mongoDb, StateflowsTrace_v1 traceEntity) + => mongoDb.GetCollection(CollectionNames.StateflowsTraces_v1).InsertOneAsync(traceEntity); } } diff --git a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/States/State1.cs b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/States/State1.cs index 23543c92..b6e98bc9 100644 --- a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/States/State1.cs +++ b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/States/State1.cs @@ -14,13 +14,13 @@ public static void Reset() public override Task OnEntryAsync() { - EntryFired = true; + EntryFired = Context != null && Context.StateMachine.Id.Instance != null; return Task.CompletedTask; } public override Task OnExitAsync() { - ExitFired = true; + ExitFired = Context != null && Context.StateMachine.Id.Instance != null; return Task.CompletedTask; } } diff --git a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/States/State2.cs b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/States/State2.cs index 944f1401..ba46b592 100644 --- a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/States/State2.cs +++ b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/States/State2.cs @@ -14,13 +14,13 @@ public static void Reset() public override Task OnEntryAsync() { - EntryFired = true; + EntryFired = Context != null && Context.StateMachine.Id.Instance != null; return Task.CompletedTask; } public override Task OnExitAsync() { - ExitFired = true; + ExitFired = Context != null && Context.StateMachine.Id.Instance != null; return Task.CompletedTask; } } diff --git a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/Transitions/SomeEventTransition.cs b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/Transitions/SomeEventTransition.cs index 44626bf5..f435802e 100644 --- a/Tests/StateMachine/StateMachine.IntegrationTests/Classes/Transitions/SomeEventTransition.cs +++ b/Tests/StateMachine/StateMachine.IntegrationTests/Classes/Transitions/SomeEventTransition.cs @@ -14,13 +14,13 @@ public static void Reset() public override Task GuardAsync() { - GuardFired = true; + GuardFired = Context != null && Context.StateMachine.Id.Instance != null; return Task.FromResult(true); } public override Task EffectAsync() { - EffectFired = true; + EffectFired = Context != null && Context.StateMachine.Id.Instance != null; return Task.CompletedTask; } } diff --git a/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Composite.cs b/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Composite.cs index 1f3d3076..ace6b6a5 100644 --- a/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Composite.cs +++ b/Tests/StateMachine/StateMachine.IntegrationTests/Tests/Composite.cs @@ -143,15 +143,15 @@ public async Task DefaultTransition() .StateEntry("state2") .StateInitialize("state2") .StateEntry("state3") - .TransitionGuard(EventInfo.Name, "state3", "state4") + .TransitionGuard(EventInfo.Name, "state3", "state4") .StateExit("state3") - .TransitionEffect(EventInfo.Name, "state3", "state4") + .TransitionEffect(EventInfo.Name, "state3", "state4") .StateEntry("state4") .StateInitialize("state4") .StateEntry("state5") - .TransitionGuard(EventInfo.Name, "state5", "state6") + .TransitionGuard(EventInfo.Name, "state5", "state6") .StateExit("state5") - .TransitionEffect(EventInfo.Name, "state5", "state6") + .TransitionEffect(EventInfo.Name, "state5", "state6") .StateEntry("state6") ); @@ -216,7 +216,7 @@ public async Task SingleInitialization() .StateEntry("state2") .TransitionEffect(EventInfo.Name, "state2", "state3") .StateEntry("state3") - .TransitionEffect(EventInfo.Name, "state3", "state4") + .TransitionEffect(EventInfo.Name, "state3", "state4") .StateEntry("state4") ); diff --git a/Tests/StateMachine/StateMachine.IntegrationTests/Tests/ExternalTransitions.cs b/Tests/StateMachine/StateMachine.IntegrationTests/Tests/ExternalTransitions.cs index d969ff5e..24abbd3b 100644 --- a/Tests/StateMachine/StateMachine.IntegrationTests/Tests/ExternalTransitions.cs +++ b/Tests/StateMachine/StateMachine.IntegrationTests/Tests/ExternalTransitions.cs @@ -105,14 +105,14 @@ public async Task NestedToRootTransition() .StateEntry("state1") .StateInitialize("state1") .StateEntry("state1.1") - .TransitionGuard(EventInfo.Name, "state1.1", "state1.2") + .TransitionGuard(EventInfo.Name, "state1.1", "state1.2") .StateExit("state1.1") - .TransitionEffect(EventInfo.Name, "state1.1", "state1.2") + .TransitionEffect(EventInfo.Name, "state1.1", "state1.2") .StateEntry("state1.2") - .TransitionGuard(EventInfo.Name, "state1.2", "state2") + .TransitionGuard(EventInfo.Name, "state1.2", "state2") .StateExit("state1.2") .StateExit("state1") - .TransitionEffect(EventInfo.Name, "state1.2", "state2") + .TransitionEffect(EventInfo.Name, "state1.2", "state2") .StateEntry("state2") ); @@ -136,9 +136,9 @@ public async Task RootToNestedTransition() ExecutionSequence.Verify(b => b .StateMachineInitialize() .StateEntry("state1") - .TransitionGuard(EventInfo.Name, "state1", "state2.1.2") + .TransitionGuard(EventInfo.Name, "state1", "state2.1.2") .StateExit("state1") - .TransitionEffect(EventInfo.Name, "state1", "state2.1.2") + .TransitionEffect(EventInfo.Name, "state1", "state2.1.2") .StateEntry("state2") .StateEntry("state2.1") .StateEntry("state2.1.2") @@ -166,14 +166,14 @@ public async Task NestedToNestedTransition() .StateEntry("state1") .StateInitialize("state1") .StateEntry("state1.1") - .TransitionGuard(EventInfo.Name, "state1.1", "state1.2") + .TransitionGuard(EventInfo.Name, "state1.1", "state1.2") .StateExit("state1.1") - .TransitionEffect(EventInfo.Name, "state1.1", "state1.2") + .TransitionEffect(EventInfo.Name, "state1.1", "state1.2") .StateEntry("state1.2") - .TransitionGuard(EventInfo.Name, "state1.2", "state2.1") + .TransitionGuard(EventInfo.Name, "state1.2", "state2.1") .StateExit("state1.2") .StateExit("state1") - .TransitionEffect(EventInfo.Name, "state1.2", "state2.1") + .TransitionEffect(EventInfo.Name, "state1.2", "state2.1") .StateEntry("state2") .StateEntry("state2.1") .StateEntry("state2.1.2") @@ -209,10 +209,10 @@ public async Task NestedToParentTransition() .StateExit("state1.1.1") .TransitionEffect(EventInfo.Name, "state1.1.1", "state1.1.2") .StateEntry("state1.1.2") - .TransitionGuard(EventInfo.Name, "state1.1.2", "state1.1") + .TransitionGuard(EventInfo.Name, "state1.1.2", "state1.1") .StateExit("state1.1.2") .StateExit("state1.1") - .TransitionEffect(EventInfo.Name, "state1.1.2", "state1.1") + .TransitionEffect(EventInfo.Name, "state1.1.2", "state1.1") .StateEntry("state1.1") .StateInitialize("state1.1") .StateEntry("state1.1.1") diff --git a/Transport/@stateflows/common/dist/index.d.mts b/Transport/@stateflows/common/dist/index.d.mts new file mode 100644 index 00000000..7157574f --- /dev/null +++ b/Transport/@stateflows/common/dist/index.d.mts @@ -0,0 +1,182 @@ +declare class BehaviorClass { + type: string; + name: string; + constructor(type: string, name: string); + $type: string; +} + +declare class BehaviorId { + behaviorClass: BehaviorClass; + instance: string; + constructor(behaviorClass: BehaviorClass, instance: string); + $type: string; +} + +declare enum EventStatus { + Undelivered = 0, + Rejected = 1, + Invalid = 2, + NotConsumed = 3, + Deferred = 4, + Consumed = 5 +} + +declare class Event { +} + +declare class ValidationResult { + ErrorMessage: string | null; + MemberNames: Array | null; + constructor(ErrorMessage: string | null, MemberNames: Array | null); +} + +declare class EventValidation { + IsValid: boolean; + ValidationResults: Array; + constructor(IsValid: boolean, ValidationResults: Array); +} + +declare class SendResult { + Event: Event; + Status: EventStatus; + Validation: EventValidation; + constructor(Event: Event, Status: EventStatus, Validation: EventValidation); +} + +declare class RequestResult extends SendResult { + Response: TResponse; + constructor(Response: TResponse, event: Event, status: EventStatus, validation: EventValidation); +} + +declare enum BehaviorStatus { + Unknown = 0, + NotInitialized = 1, + Initialized = 2, + Finalized = 3 +} + +declare class Response extends Event { +} + +declare class BehaviorStatusResponse extends Response { + BehaviorStatus: BehaviorStatus; + constructor(BehaviorStatus: BehaviorStatus); +} + +declare class InitializationResponse extends Response { + InitializationSuccessful: boolean; + constructor(InitializationSuccessful: boolean); +} + +declare class Request extends Event { + Response: TResponse; +} + +declare class InitializationRequest extends Request { + $type: string; +} + +interface IBehavior { + send(event: Event): Promise; + request(request: Request): Promise>; + initialize(initializationRequest?: InitializationRequest): Promise>; + getStatus(): Promise>; +} + +interface IBehaviorLocator { + locateBehavior(id: BehaviorId): Promise; +} + +declare class StateMachineId extends BehaviorId { + constructor(name: string, instance: string); +} + +declare class CurrentStateResponse extends Response { + StatesStack: string[]; + ExpectedEvents: string[]; + constructor(StatesStack: string[], ExpectedEvents: string[]); +} + +interface IStateMachine extends IBehavior { + getCurrentState(): Promise>; +} + +interface IStateMachineLocator { + locateStateMachine(id: StateMachineId): Promise; +} + +declare class AvailableBehaviorClassesResponse extends Response { + AvailableBehaviorClasses: BehaviorClass[]; + constructor(AvailableBehaviorClasses: BehaviorClass[]); +} + +declare class BehaviorDescriptor { + Id: BehaviorId; + Status: BehaviorStatus; +} +declare class BehaviorInstancesResponse extends Response { + Behaviors: BehaviorDescriptor[]; + constructor(Behaviors: BehaviorDescriptor[]); +} + +interface ISystem { + getAvailableBehaviorClasses(): Promise>; + getBehaviorInstances(): Promise>; +} + +declare class ActivityId extends BehaviorId { + constructor(name: string, instance: string); +} + +interface IActivity extends IBehavior { +} + +interface IActivityLocator { + locateActivity(id: ActivityId): Promise; +} + +interface IStateflowsClientTransport { + getAvailableClasses(): Promise; + send(behaviorId: BehaviorId, event: Event): Promise; +} + +interface IStateflowsClientTransportFactory { + getTransport(): Promise; +} + +declare class StateflowsClient { + #private; + private transportFactory; + constructor(transportFactory: IStateflowsClientTransportFactory); + get behaviorLocator(): IBehaviorLocator; + get stateMachineLocator(): IStateMachineLocator; + get activityLocator(): IActivityLocator; + get system(): Promise; +} + +declare class BehaviorStatusRequest extends Request { + $type: string; + constructor(); +} + +declare class PlantUmlResponse extends Response { + PlantUml: string; + constructor(PlantUml: string); +} + +declare class PlantUmlRequest extends Request { + $type: string; + constructor(); +} + +declare class AvailableBehaviorClassesRequest extends Request { + $type: string; + constructor(); +} + +declare class BehaviorInstancesRequest extends Request { + $type: string; + constructor(); +} + +export { ActivityId, AvailableBehaviorClassesRequest, AvailableBehaviorClassesResponse, BehaviorClass, BehaviorId, BehaviorInstancesRequest, BehaviorInstancesResponse, BehaviorStatus, BehaviorStatusRequest, BehaviorStatusResponse, Event, EventStatus, type IActivity, type IActivityLocator, type IBehavior, type IBehaviorLocator, type IStateMachine, type IStateMachineLocator, type IStateflowsClientTransport, type IStateflowsClientTransportFactory, type ISystem, InitializationRequest, InitializationResponse, PlantUmlRequest, PlantUmlResponse, Request, RequestResult, Response, SendResult, StateMachineId, StateflowsClient }; diff --git a/Transport/@stateflows/common/dist/index.d.ts b/Transport/@stateflows/common/dist/index.d.ts new file mode 100644 index 00000000..7157574f --- /dev/null +++ b/Transport/@stateflows/common/dist/index.d.ts @@ -0,0 +1,182 @@ +declare class BehaviorClass { + type: string; + name: string; + constructor(type: string, name: string); + $type: string; +} + +declare class BehaviorId { + behaviorClass: BehaviorClass; + instance: string; + constructor(behaviorClass: BehaviorClass, instance: string); + $type: string; +} + +declare enum EventStatus { + Undelivered = 0, + Rejected = 1, + Invalid = 2, + NotConsumed = 3, + Deferred = 4, + Consumed = 5 +} + +declare class Event { +} + +declare class ValidationResult { + ErrorMessage: string | null; + MemberNames: Array | null; + constructor(ErrorMessage: string | null, MemberNames: Array | null); +} + +declare class EventValidation { + IsValid: boolean; + ValidationResults: Array; + constructor(IsValid: boolean, ValidationResults: Array); +} + +declare class SendResult { + Event: Event; + Status: EventStatus; + Validation: EventValidation; + constructor(Event: Event, Status: EventStatus, Validation: EventValidation); +} + +declare class RequestResult extends SendResult { + Response: TResponse; + constructor(Response: TResponse, event: Event, status: EventStatus, validation: EventValidation); +} + +declare enum BehaviorStatus { + Unknown = 0, + NotInitialized = 1, + Initialized = 2, + Finalized = 3 +} + +declare class Response extends Event { +} + +declare class BehaviorStatusResponse extends Response { + BehaviorStatus: BehaviorStatus; + constructor(BehaviorStatus: BehaviorStatus); +} + +declare class InitializationResponse extends Response { + InitializationSuccessful: boolean; + constructor(InitializationSuccessful: boolean); +} + +declare class Request extends Event { + Response: TResponse; +} + +declare class InitializationRequest extends Request { + $type: string; +} + +interface IBehavior { + send(event: Event): Promise; + request(request: Request): Promise>; + initialize(initializationRequest?: InitializationRequest): Promise>; + getStatus(): Promise>; +} + +interface IBehaviorLocator { + locateBehavior(id: BehaviorId): Promise; +} + +declare class StateMachineId extends BehaviorId { + constructor(name: string, instance: string); +} + +declare class CurrentStateResponse extends Response { + StatesStack: string[]; + ExpectedEvents: string[]; + constructor(StatesStack: string[], ExpectedEvents: string[]); +} + +interface IStateMachine extends IBehavior { + getCurrentState(): Promise>; +} + +interface IStateMachineLocator { + locateStateMachine(id: StateMachineId): Promise; +} + +declare class AvailableBehaviorClassesResponse extends Response { + AvailableBehaviorClasses: BehaviorClass[]; + constructor(AvailableBehaviorClasses: BehaviorClass[]); +} + +declare class BehaviorDescriptor { + Id: BehaviorId; + Status: BehaviorStatus; +} +declare class BehaviorInstancesResponse extends Response { + Behaviors: BehaviorDescriptor[]; + constructor(Behaviors: BehaviorDescriptor[]); +} + +interface ISystem { + getAvailableBehaviorClasses(): Promise>; + getBehaviorInstances(): Promise>; +} + +declare class ActivityId extends BehaviorId { + constructor(name: string, instance: string); +} + +interface IActivity extends IBehavior { +} + +interface IActivityLocator { + locateActivity(id: ActivityId): Promise; +} + +interface IStateflowsClientTransport { + getAvailableClasses(): Promise; + send(behaviorId: BehaviorId, event: Event): Promise; +} + +interface IStateflowsClientTransportFactory { + getTransport(): Promise; +} + +declare class StateflowsClient { + #private; + private transportFactory; + constructor(transportFactory: IStateflowsClientTransportFactory); + get behaviorLocator(): IBehaviorLocator; + get stateMachineLocator(): IStateMachineLocator; + get activityLocator(): IActivityLocator; + get system(): Promise; +} + +declare class BehaviorStatusRequest extends Request { + $type: string; + constructor(); +} + +declare class PlantUmlResponse extends Response { + PlantUml: string; + constructor(PlantUml: string); +} + +declare class PlantUmlRequest extends Request { + $type: string; + constructor(); +} + +declare class AvailableBehaviorClassesRequest extends Request { + $type: string; + constructor(); +} + +declare class BehaviorInstancesRequest extends Request { + $type: string; + constructor(); +} + +export { ActivityId, AvailableBehaviorClassesRequest, AvailableBehaviorClassesResponse, BehaviorClass, BehaviorId, BehaviorInstancesRequest, BehaviorInstancesResponse, BehaviorStatus, BehaviorStatusRequest, BehaviorStatusResponse, Event, EventStatus, type IActivity, type IActivityLocator, type IBehavior, type IBehaviorLocator, type IStateMachine, type IStateMachineLocator, type IStateflowsClientTransport, type IStateflowsClientTransportFactory, type ISystem, InitializationRequest, InitializationResponse, PlantUmlRequest, PlantUmlResponse, Request, RequestResult, Response, SendResult, StateMachineId, StateflowsClient }; diff --git a/Transport/@stateflows/common/dist/index.js b/Transport/@stateflows/common/dist/index.js new file mode 100644 index 00000000..3c6db3ee --- /dev/null +++ b/Transport/@stateflows/common/dist/index.js @@ -0,0 +1,376 @@ +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// src/index.ts +var src_exports = {}; +__export(src_exports, { + ActivityId: () => ActivityId, + AvailableBehaviorClassesRequest: () => AvailableBehaviorClassesRequest, + AvailableBehaviorClassesResponse: () => AvailableBehaviorClassesResponse, + BehaviorClass: () => BehaviorClass, + BehaviorId: () => BehaviorId, + BehaviorInstancesRequest: () => BehaviorInstancesRequest, + BehaviorInstancesResponse: () => BehaviorInstancesResponse, + BehaviorStatus: () => BehaviorStatus, + BehaviorStatusRequest: () => BehaviorStatusRequest, + BehaviorStatusResponse: () => BehaviorStatusResponse, + Event: () => Event, + EventStatus: () => EventStatus, + InitializationRequest: () => InitializationRequest, + InitializationResponse: () => InitializationResponse, + PlantUmlRequest: () => PlantUmlRequest, + PlantUmlResponse: () => PlantUmlResponse, + Request: () => Request, + RequestResult: () => RequestResult, + Response: () => Response, + SendResult: () => SendResult, + StateMachineId: () => StateMachineId, + StateflowsClient: () => StateflowsClient +}); +module.exports = __toCommonJS(src_exports); + +// src/classes/send-result.ts +var SendResult = class { + constructor(Event2, Status, Validation) { + this.Event = Event2; + this.Status = Status; + this.Validation = Validation; + } +}; + +// src/classes/request-result.ts +var RequestResult = class extends SendResult { + constructor(Response2, event, status, validation) { + super(event, status, validation); + this.Response = Response2; + } +}; + +// src/events/event.ts +var Event = class { +}; + +// src/events/request.ts +var Request = class extends Event { + Response; +}; + +// src/events/initialization.request.ts +var InitializationRequest = class extends Request { + $type = "Stateflows.Common.InitializationRequest, Stateflows.Common"; +}; + +// src/events/behavior-status.request.ts +var BehaviorStatusRequest = class extends Request { + $type = "Stateflows.Common.BehaviorStatusRequest, Stateflows.Common"; + constructor() { + super(); + } +}; + +// src/behaviors/behavior.ts +var Behavior = class _Behavior { + constructor(transportPromiseOrBehavior, behaviorId) { + this.behaviorId = behaviorId; + this.#transportPromise = transportPromiseOrBehavior instanceof _Behavior ? transportPromiseOrBehavior.#transportPromise : this.#transportPromise = transportPromiseOrBehavior; + } + #transportPromise; + send(event) { + return new Promise(async (resolve, reject) => { + let hub = await this.#transportPromise; + resolve(await hub.send(this.behaviorId, event)); + }); + } + request(request) { + return new Promise(async (resolve, reject) => { + let result = await this.send(request); + resolve(new RequestResult(request.Response, request, result.Status, result.Validation)); + }); + } + initialize(initializationRequest) { + if (typeof initializationRequest === "undefined") { + initializationRequest = new InitializationRequest(); + } + return this.request(initializationRequest); + } + getStatus() { + return this.request(new BehaviorStatusRequest()); + } +}; + +// src/locators/behavior.locator.ts +var BehaviorLocator = class { + behaviorClasses = []; + transportPromise; + constructor(transportPromise) { + this.transportPromise = new Promise((resolve, reject) => { + transportPromise.then((transport) => { + transport.getAvailableClasses().then((result) => { + this.behaviorClasses = result; + resolve(transport); + }); + }).catch((reason) => reject(reason)); + }); + } + locateBehavior(behaviorId) { + return new Promise((resolve, reject) => { + this.transportPromise.then((hub) => { + if (this.behaviorClasses.findIndex( + (behaviorClass) => behaviorClass.type === behaviorId.behaviorClass.type && behaviorClass.name === behaviorId.behaviorClass.name + ) !== -1) { + resolve(new Behavior(this.transportPromise, behaviorId)); + } else { + reject("Behavior not found"); + } + }).catch((reason) => reject(reason)); + }); + } +}; + +// src/events/current-state.request.ts +var CurrentStateRequest = class extends Request { + $type = "Stateflows.StateMachines.Events.CurrentStateRequest, Stateflows.Common"; + constructor() { + super(); + } +}; + +// src/behaviors/state-machine.ts +var StateMachine = class extends Behavior { + constructor(behavior) { + super(behavior, behavior.behaviorId); + } + getCurrentState() { + return this.request(new CurrentStateRequest()); + } +}; + +// src/locators/state-machine.locator.ts +var StateMachineLocator = class { + constructor(behaviorLocator) { + this.behaviorLocator = behaviorLocator; + } + locateStateMachine(id) { + return new Promise((resolve, reject) => { + this.behaviorLocator.locateBehavior(id).then((behavior) => resolve(new StateMachine(behavior))).catch((_) => reject("State Machine not found")); + }); + } +}; + +// src/ids/behavior.id.ts +var BehaviorId = class { + constructor(behaviorClass, instance) { + this.behaviorClass = behaviorClass; + this.instance = instance; + } + $type = "Stateflows.BehaviorId, Stateflows.Common"; +}; + +// src/ids/behavior.class.ts +var BehaviorClass = class { + constructor(type, name) { + this.type = type; + this.name = name; + } + $type = "Stateflows.BehaviorClass, Stateflows.Common"; +}; + +// src/events/available-behavior-classes.request.ts +var AvailableBehaviorClassesRequest = class extends Request { + $type = "Stateflows.System.AvailableBehaviorClassesRequest, Stateflows.Common"; + constructor() { + super(); + } +}; + +// src/events/behavior-instances.request.ts +var BehaviorInstancesRequest = class extends Request { + $type = "Stateflows.System.BehaviorInstancesRequest, Stateflows.Common"; + constructor() { + super(); + } +}; + +// src/behaviors/system.ts +var System = class { + constructor(behavior) { + this.behavior = behavior; + } + getAvailableBehaviorClasses() { + return this.behavior.request(new AvailableBehaviorClassesRequest()); + } + getBehaviorInstances() { + return this.behavior.request(new BehaviorInstancesRequest()); + } +}; + +// src/behaviors/activity.ts +var Activity = class extends Behavior { + constructor(behavior) { + super(behavior, behavior.behaviorId); + } +}; + +// src/locators/activity.locator.ts +var ActivityLocator = class { + constructor(behaviorLocator) { + this.behaviorLocator = behaviorLocator; + } + locateActivity(id) { + return new Promise((resolve, reject) => { + this.behaviorLocator.locateBehavior(id).then((behavior) => resolve(new Activity(behavior))).catch((_) => reject("State Machine not found")); + }); + } +}; + +// src/classes/stateflows-client.ts +var StateflowsClient = class { + constructor(transportFactory) { + this.transportFactory = transportFactory; + } + #behaviorLocator = null; + get behaviorLocator() { + return this.#behaviorLocator ??= new BehaviorLocator(this.transportFactory.getTransport()); + } + #stateMachineLocator = null; + get stateMachineLocator() { + return this.#stateMachineLocator ??= new StateMachineLocator(this.behaviorLocator); + } + #activityLocator = null; + get activityLocator() { + return this.#activityLocator ??= new ActivityLocator(this.behaviorLocator); + } + #systemPromise = null; + get system() { + return this.#systemPromise ??= new Promise((resolve, reject) => { + this.behaviorLocator.locateBehavior(new BehaviorId(new BehaviorClass("System", "Stateflows"), "")).then((behavior) => resolve(new System(behavior))).catch((reason) => reject(reason)); + }); + } +}; + +// src/ids/state-machine.id.ts +var StateMachineId = class extends BehaviorId { + constructor(name, instance) { + super(new BehaviorClass("StateMachine", name), instance); + } +}; + +// src/ids/activity.id.ts +var ActivityId = class extends BehaviorId { + constructor(name, instance) { + super(new BehaviorClass("Activity", name), instance); + } +}; + +// src/events/response.ts +var Response = class extends Event { +}; + +// src/events/initialization.response.ts +var InitializationResponse = class extends Response { + constructor(InitializationSuccessful) { + super(); + this.InitializationSuccessful = InitializationSuccessful; + } +}; + +// src/events/behavior-status.response.ts +var BehaviorStatusResponse = class extends Response { + constructor(BehaviorStatus2) { + super(); + this.BehaviorStatus = BehaviorStatus2; + } +}; + +// src/events/plant-uml.request.ts +var PlantUmlRequest = class extends Request { + $type = "Stateflows.Extensions.PlantUml.Events.PlantUmlRequest, Stateflows.Extensions.PlantUml"; + constructor() { + super(); + } +}; + +// src/events/plant-uml.response.ts +var PlantUmlResponse = class extends Response { + constructor(PlantUml) { + super(); + this.PlantUml = PlantUml; + } +}; + +// src/enums/event-status.ts +var EventStatus = /* @__PURE__ */ ((EventStatus2) => { + EventStatus2[EventStatus2["Undelivered"] = 0] = "Undelivered"; + EventStatus2[EventStatus2["Rejected"] = 1] = "Rejected"; + EventStatus2[EventStatus2["Invalid"] = 2] = "Invalid"; + EventStatus2[EventStatus2["NotConsumed"] = 3] = "NotConsumed"; + EventStatus2[EventStatus2["Deferred"] = 4] = "Deferred"; + EventStatus2[EventStatus2["Consumed"] = 5] = "Consumed"; + return EventStatus2; +})(EventStatus || {}); + +// src/enums/behavior-status.ts +var BehaviorStatus = /* @__PURE__ */ ((BehaviorStatus2) => { + BehaviorStatus2[BehaviorStatus2["Unknown"] = 0] = "Unknown"; + BehaviorStatus2[BehaviorStatus2["NotInitialized"] = 1] = "NotInitialized"; + BehaviorStatus2[BehaviorStatus2["Initialized"] = 2] = "Initialized"; + BehaviorStatus2[BehaviorStatus2["Finalized"] = 3] = "Finalized"; + return BehaviorStatus2; +})(BehaviorStatus || {}); + +// src/events/available-behavior-classes.response.ts +var AvailableBehaviorClassesResponse = class extends Response { + constructor(AvailableBehaviorClasses) { + super(); + this.AvailableBehaviorClasses = AvailableBehaviorClasses; + } +}; + +// src/events/behavior-instances.response.ts +var BehaviorInstancesResponse = class extends Response { + constructor(Behaviors) { + super(); + this.Behaviors = Behaviors; + } +}; +// Annotate the CommonJS export names for ESM import in node: +0 && (module.exports = { + ActivityId, + AvailableBehaviorClassesRequest, + AvailableBehaviorClassesResponse, + BehaviorClass, + BehaviorId, + BehaviorInstancesRequest, + BehaviorInstancesResponse, + BehaviorStatus, + BehaviorStatusRequest, + BehaviorStatusResponse, + Event, + EventStatus, + InitializationRequest, + InitializationResponse, + PlantUmlRequest, + PlantUmlResponse, + Request, + RequestResult, + Response, + SendResult, + StateMachineId, + StateflowsClient +}); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/Transport/@stateflows/common/dist/index.js.map b/Transport/@stateflows/common/dist/index.js.map new file mode 100644 index 00000000..9158a853 --- /dev/null +++ b/Transport/@stateflows/common/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/index.ts","../src/classes/send-result.ts","../src/classes/request-result.ts","../src/events/event.ts","../src/events/request.ts","../src/events/initialization.request.ts","../src/events/behavior-status.request.ts","../src/behaviors/behavior.ts","../src/locators/behavior.locator.ts","../src/events/current-state.request.ts","../src/behaviors/state-machine.ts","../src/locators/state-machine.locator.ts","../src/ids/behavior.id.ts","../src/ids/behavior.class.ts","../src/events/available-behavior-classes.request.ts","../src/events/behavior-instances.request.ts","../src/behaviors/system.ts","../src/behaviors/activity.ts","../src/locators/activity.locator.ts","../src/classes/stateflows-client.ts","../src/ids/state-machine.id.ts","../src/ids/activity.id.ts","../src/events/response.ts","../src/events/initialization.response.ts","../src/events/behavior-status.response.ts","../src/events/plant-uml.request.ts","../src/events/plant-uml.response.ts","../src/enums/event-status.ts","../src/enums/behavior-status.ts","../src/events/available-behavior-classes.response.ts","../src/events/behavior-instances.response.ts"],"sourcesContent":["export { StateflowsClient } from \"./classes/stateflows-client\";\r\nexport { SendResult } from \"./classes/send-result\";\r\nexport { RequestResult } from \"./classes/request-result\";\r\nexport { BehaviorClass } from \"./ids/behavior.class\";\r\nexport { BehaviorId } from \"./ids/behavior.id\";\r\nexport { StateMachineId } from \"./ids/state-machine.id\";\r\nexport { ActivityId } from \"./ids/activity.id\";\r\nexport { Event } from \"./events/event\";\r\nexport { Request } from \"./events/request\";\r\nexport { InitializationRequest } from \"./events/initialization.request\";\r\nexport { InitializationResponse } from \"./events/initialization.response\";\r\nexport { Response } from \"./events/response\";\r\nexport { BehaviorStatusRequest } from \"./events/behavior-status.request\";\r\nexport { BehaviorStatusResponse } from \"./events/behavior-status.response\";\r\nexport { PlantUmlRequest } from \"./events/plant-uml.request\";\r\nexport { PlantUmlResponse } from \"./events/plant-uml.response\";\r\nexport { IBehaviorLocator } from \"./interfaces/behavior.locator\";\r\nexport { IBehavior } from \"./interfaces/behavior\";\r\nexport { ISystem } from \"./interfaces/system\";\r\nexport { IStateMachineLocator } from \"./interfaces/state-machine.locator\";\r\nexport { IActivityLocator } from \"./interfaces/activity.locator\";\r\nexport { IStateMachine } from \"./interfaces/state-machine\";\r\nexport { IActivity } from \"./interfaces/activity\";\r\nexport { EventStatus } from \"./enums/event-status\";\r\nexport { BehaviorStatus } from \"./enums/behavior-status\";\r\nexport { AvailableBehaviorClassesRequest } from \"./events/available-behavior-classes.request\";\r\nexport { AvailableBehaviorClassesResponse } from \"./events/available-behavior-classes.response\";\r\nexport { BehaviorInstancesRequest } from \"./events/behavior-instances.request\";\r\nexport { BehaviorInstancesResponse } from \"./events/behavior-instances.response\";\r\nexport { IStateflowsClientTransport } from \"./interfaces/stateflows-client-transport\";\r\nexport { IStateflowsClientTransportFactory } from \"./interfaces/stateflows-client-transport-factory\";\r\n","import { EventStatus } from \"../enums/event-status\";\r\nimport { Event } from \"../events/event\";\r\nimport { EventValidation } from \"./event-validation\";\r\n\r\nexport class SendResult {\r\n constructor(\r\n public Event: Event,\r\n public Status: EventStatus,\r\n public Validation: EventValidation,\r\n ) {}\r\n}","import { EventStatus } from \"../enums/event-status\";\r\nimport { Event } from \"../events/event\";\r\nimport { EventValidation } from \"./event-validation\";\r\nimport { SendResult } from \"./send-result\";\r\n\r\nexport class RequestResult extends SendResult {\r\n constructor(\r\n public Response: TResponse,\r\n event: Event,\r\n status: EventStatus,\r\n validation: EventValidation,\r\n ) {\r\n super(event, status, validation);\r\n }\r\n}","export class Event {\r\n}","import { Response } from \"./response\";\r\nimport { Event } from \"./event\";\r\n\r\nexport class Request extends Event {\r\n public Response: TResponse;\r\n}","import { Request } from \"./request\";\r\nimport { InitializationResponse } from \"./initialization.response\";\r\n\r\nexport class InitializationRequest extends Request {\r\n public $type = \"Stateflows.Common.InitializationRequest, Stateflows.Common\";\r\n}","import { Request } from \"./request\";\r\nimport { BehaviorStatusResponse } from \"./behavior-status.response\";\r\n\r\nexport class BehaviorStatusRequest extends Request {\r\n public $type = \"Stateflows.Common.BehaviorStatusRequest, Stateflows.Common\";\r\n\r\n constructor() {\r\n super();\r\n }\r\n}","import { Request } from \"../events/request\";\r\nimport { IBehavior } from \"../interfaces/behavior\";\r\nimport { SendResult } from \"../classes/send-result\";\r\nimport { RequestResult } from \"../classes/request-result\";\r\nimport { InitializationResponse } from \"../events/initialization.response\";\r\nimport { BehaviorStatusResponse } from \"../events/behavior-status.response\";\r\nimport { BehaviorId } from \"../ids/behavior.id\";\r\nimport { Response } from \"../events/response\";\r\nimport { InitializationRequest } from \"../events/initialization.request\";\r\nimport { Event } from \"../events/event\";\r\nimport { BehaviorStatusRequest } from \"../events/behavior-status.request\";\r\nimport { IStateflowsClientTransport } from \"../interfaces/stateflows-client-transport\";\r\n\r\nexport class Behavior implements IBehavior {\r\n #transportPromise: Promise\r\n\r\n constructor(transportPromiseOrBehavior: Promise | Behavior, public behaviorId: BehaviorId) {\r\n this.#transportPromise = transportPromiseOrBehavior instanceof Behavior\r\n ? transportPromiseOrBehavior.#transportPromise\r\n : this.#transportPromise = transportPromiseOrBehavior;\r\n }\r\n\r\n send(event: Event): Promise {\r\n return new Promise(async (resolve, reject) => {\r\n let hub = await this.#transportPromise;\r\n resolve(await hub.send(this.behaviorId, event));\r\n });\r\n }\r\n\r\n request(request: Request): Promise> {\r\n return new Promise>(async (resolve, reject) => {\r\n let result = await this.send(request);\r\n resolve(new RequestResult(request.Response as TResponse, request, result.Status, result.Validation));\r\n });\r\n }\r\n\r\n initialize(initializationRequest?: InitializationRequest): Promise> {\r\n if (typeof initializationRequest === \"undefined\") {\r\n initializationRequest = new InitializationRequest();\r\n }\r\n\r\n return this.request(initializationRequest);\r\n }\r\n\r\n getStatus(): Promise> {\r\n return this.request(new BehaviorStatusRequest());\r\n }\r\n}","import { Behavior } from \"../behaviors/behavior\";\r\nimport { BehaviorClass } from \"../ids/behavior.class\";\r\nimport { BehaviorId } from \"../ids/behavior.id\";\r\nimport { IBehavior } from \"../interfaces/behavior\";\r\nimport { IBehaviorLocator } from \"../interfaces/behavior.locator\";\r\nimport { IStateflowsClientTransport } from \"../interfaces/stateflows-client-transport\";\r\n\r\nexport class BehaviorLocator implements IBehaviorLocator {\r\n private behaviorClasses: BehaviorClass[] = [];\r\n\r\n private transportPromise: Promise;\r\n\r\n constructor(transportPromise: Promise) {\r\n this.transportPromise = new Promise((resolve, reject) => {\r\n transportPromise\r\n .then(transport => {\r\n transport.getAvailableClasses().then(result => {\r\n this.behaviorClasses = result;\r\n resolve(transport);\r\n });\r\n })\r\n .catch(reason => reject(reason));\r\n });\r\n }\r\n\r\n locateBehavior(behaviorId: BehaviorId): Promise {\r\n return new Promise((resolve, reject) => {\r\n this.transportPromise\r\n .then(hub => {\r\n if (this.behaviorClasses.findIndex(behaviorClass => \r\n behaviorClass.type === behaviorId.behaviorClass.type &&\r\n behaviorClass.name === behaviorId.behaviorClass.name\r\n ) !== -1) {\r\n resolve(new Behavior(this.transportPromise, behaviorId));\r\n }\r\n else\r\n {\r\n reject(\"Behavior not found\");\r\n }\r\n })\r\n .catch(reason => reject(reason));\r\n });\r\n }\r\n}","import { Request } from \"./request\";\r\nimport { CurrentStateResponse } from \"./current-state.response\";\r\n\r\nexport class CurrentStateRequest extends Request {\r\n public $type = \"Stateflows.StateMachines.Events.CurrentStateRequest, Stateflows.Common\";\r\n\r\n constructor() {\r\n super();\r\n }\r\n}","import { CurrentStateRequest } from \"../events/current-state.request\";\r\nimport { IStateMachine } from \"../interfaces/state-machine\";\r\nimport { Behavior } from \"./behavior\";\r\n\r\nexport class StateMachine extends Behavior implements IStateMachine {\r\n constructor(behavior: Behavior) {\r\n super(behavior, behavior.behaviorId);\r\n }\r\n\r\n getCurrentState(): Promise {\r\n return this.request(new CurrentStateRequest());\r\n }\r\n}","import { Behavior } from \"../behaviors/behavior\";\r\nimport { StateMachine } from \"../behaviors/state-machine\";\r\nimport { StateMachineId } from \"../ids/state-machine.id\";\r\nimport { IBehaviorLocator } from \"../interfaces/behavior.locator\";\r\nimport { IStateMachine } from \"../interfaces/state-machine\";\r\nimport { IStateMachineLocator } from \"../interfaces/state-machine.locator\";\r\n\r\nexport class StateMachineLocator implements IStateMachineLocator {\r\n constructor(private behaviorLocator: IBehaviorLocator) {}\r\n\r\n locateStateMachine(id: StateMachineId): Promise {\r\n return new Promise((resolve, reject) => {\r\n this.behaviorLocator.locateBehavior(id)\r\n .then(behavior => resolve(new StateMachine(behavior as Behavior)))\r\n .catch(_ => reject(\"State Machine not found\"));\r\n });\r\n }\r\n}","import { BehaviorClass } from \"./behavior.class\";\r\n\r\nexport class BehaviorId {\r\n constructor(\r\n public behaviorClass: BehaviorClass,\r\n public instance: string\r\n ) {}\r\n\r\n public $type: string = \"Stateflows.BehaviorId, Stateflows.Common\";\r\n}","export class BehaviorClass {\r\n constructor(\r\n public type: string,\r\n public name: string\r\n ) {}\r\n \r\n public $type: string = \"Stateflows.BehaviorClass, Stateflows.Common\";\r\n}","import { Request } from \"./request\";\r\nimport { AvailableBehaviorClassesResponse } from \"./available-behavior-classes.response\";\r\n\r\nexport class AvailableBehaviorClassesRequest extends Request {\r\n public $type = \"Stateflows.System.AvailableBehaviorClassesRequest, Stateflows.Common\";\r\n\r\n constructor() {\r\n super();\r\n }\r\n}","import { Request } from \"./request\";\r\nimport { BehaviorInstancesResponse } from \"./behavior-instances.response\";\r\n\r\nexport class BehaviorInstancesRequest extends Request {\r\n public $type = \"Stateflows.System.BehaviorInstancesRequest, Stateflows.Common\";\r\n\r\n constructor() {\r\n super();\r\n }\r\n}","import { ISystem } from \"../interfaces/system\";\r\nimport { IBehavior } from \"../interfaces/behavior\";\r\nimport { RequestResult } from \"../classes/request-result\";\r\nimport { AvailableBehaviorClassesRequest } from \"../events/available-behavior-classes.request\";\r\nimport { AvailableBehaviorClassesResponse } from \"../events/available-behavior-classes.response\";\r\nimport { BehaviorInstancesRequest } from \"../events/behavior-instances.request\";\r\nimport { BehaviorInstancesResponse } from \"../events/behavior-instances.response\";\r\n\r\nexport class System implements ISystem {\r\n constructor(private behavior: IBehavior) {}\r\n\r\n getAvailableBehaviorClasses(): Promise> {\r\n return this.behavior.request(new AvailableBehaviorClassesRequest());\r\n }\r\n\r\n getBehaviorInstances(): Promise> {\r\n return this.behavior.request(new BehaviorInstancesRequest());\r\n }\r\n}","import { IActivity } from \"../interfaces/activity\";\r\nimport { Behavior } from \"./behavior\";\r\n\r\nexport class Activity extends Behavior implements IActivity {\r\n constructor(behavior: Behavior) {\r\n super(behavior, behavior.behaviorId);\r\n }\r\n}","import { Activity } from \"../behaviors/activity\";\r\nimport { Behavior } from \"../behaviors/behavior\";\r\nimport { ActivityId } from \"../ids/activity.id\";\r\nimport { IActivity } from \"../interfaces/activity\";\r\nimport { IActivityLocator } from \"../interfaces/activity.locator\";\r\nimport { IBehaviorLocator } from \"../interfaces/behavior.locator\";\r\n\r\nexport class ActivityLocator implements IActivityLocator {\r\n constructor(private behaviorLocator: IBehaviorLocator) {}\r\n\r\n locateActivity(id: ActivityId): Promise {\r\n return new Promise((resolve, reject) => {\r\n this.behaviorLocator.locateBehavior(id)\r\n .then(behavior => resolve(new Activity(behavior as Behavior)))\r\n .catch(_ => reject(\"State Machine not found\"));\r\n });\r\n }\r\n}","import { IBehaviorLocator } from \"../interfaces/behavior.locator\";\r\nimport { IStateMachineLocator } from \"../interfaces/state-machine.locator\";\r\nimport { BehaviorLocator } from \"../locators/behavior.locator\";\r\nimport { StateMachineLocator } from \"../locators/state-machine.locator\";\r\nimport { ISystem } from \"../interfaces/system\";\r\nimport { BehaviorId } from \"../ids/behavior.id\";\r\nimport { BehaviorClass } from \"../ids/behavior.class\";\r\nimport { System } from \"../behaviors/system\";\r\nimport { IActivityLocator } from \"../interfaces/activity.locator\";\r\nimport { ActivityLocator } from \"../locators/activity.locator\";\r\nimport { IStateflowsClientTransportFactory } from \"../interfaces/stateflows-client-transport-factory\";\r\n\r\nexport class StateflowsClient {\r\n constructor(private transportFactory: IStateflowsClientTransportFactory) { }\r\n\r\n #behaviorLocator: IBehaviorLocator | null = null;\r\n\r\n public get behaviorLocator(): IBehaviorLocator {\r\n return this.#behaviorLocator ??= new BehaviorLocator(this.transportFactory.getTransport());\r\n }\r\n\r\n #stateMachineLocator: IStateMachineLocator | null = null;\r\n\r\n public get stateMachineLocator(): IStateMachineLocator {\r\n return this.#stateMachineLocator ??= new StateMachineLocator(this.behaviorLocator);\r\n }\r\n\r\n #activityLocator: IActivityLocator | null = null;\r\n\r\n public get activityLocator(): IActivityLocator {\r\n return this.#activityLocator ??= new ActivityLocator(this.behaviorLocator);\r\n }\r\n\r\n #systemPromise: Promise | null = null;\r\n\r\n public get system(): Promise {\r\n return this.#systemPromise ??= new Promise((resolve, reject) => {\r\n this.behaviorLocator.locateBehavior(new BehaviorId(new BehaviorClass(\"System\", \"Stateflows\"), \"\"))\r\n .then(behavior => resolve(new System(behavior)))\r\n .catch(reason => reject(reason));\r\n })\r\n }\r\n}","import { BehaviorClass } from \"./behavior.class\";\r\nimport { BehaviorId } from \"./behavior.id\";\r\n\r\nexport class StateMachineId extends BehaviorId {\r\n constructor(\r\n name: string,\r\n instance: string\r\n ) {\r\n super(new BehaviorClass(\"StateMachine\", name), instance);\r\n }\r\n}","import { BehaviorClass } from \"./behavior.class\";\r\nimport { BehaviorId } from \"./behavior.id\";\r\n\r\nexport class ActivityId extends BehaviorId {\r\n constructor(\r\n name: string,\r\n instance: string\r\n ) {\r\n super(new BehaviorClass(\"Activity\", name), instance);\r\n }\r\n}","import { Event } from \"./event\";\r\n\r\nexport class Response extends Event {\r\n\r\n}","import { Response } from \"./response\";\r\n\r\nexport class InitializationResponse extends Response {\r\n constructor(\r\n public InitializationSuccessful: boolean,\r\n ) {\r\n super();\r\n }\r\n}","import { BehaviorStatus } from \"../enums/behavior-status\";\r\nimport { Response } from \"./response\";\r\n\r\nexport class BehaviorStatusResponse extends Response {\r\n constructor(\r\n public BehaviorStatus: BehaviorStatus,\r\n ) {\r\n super();\r\n }\r\n}","import { PlantUmlResponse } from \"./plant-uml.response\";\r\nimport { Request } from \"./request\";\r\n\r\nexport class PlantUmlRequest extends Request {\r\n public $type = \"Stateflows.Extensions.PlantUml.Events.PlantUmlRequest, Stateflows.Extensions.PlantUml\";\r\n\r\n constructor() {\r\n super();\r\n }\r\n}","import { Response } from \"./response\";\r\n\r\nexport class PlantUmlResponse extends Response {\r\n constructor(\r\n public PlantUml: string,\r\n ) {\r\n super();\r\n }\r\n}","export enum EventStatus {\r\n Undelivered = 0,\r\n Rejected = 1,\r\n Invalid = 2,\r\n NotConsumed = 3,\r\n Deferred = 4,\r\n Consumed = 5\r\n}","export enum BehaviorStatus {\r\n Unknown = 0,\r\n NotInitialized = 1,\r\n Initialized = 2,\r\n Finalized = 3\r\n}","import { Response } from \"./response\";\r\nimport { BehaviorClass } from \"../ids/behavior.class\";\r\n\r\nexport class AvailableBehaviorClassesResponse extends Response {\r\n constructor(\r\n public AvailableBehaviorClasses: BehaviorClass[],\r\n ) {\r\n super();\r\n }\r\n}","import { Response } from \"./response\";\r\nimport { BehaviorId } from \"../ids/behavior.id\";\r\nimport { BehaviorStatus } from \"../enums/behavior-status\";\r\n\r\nexport class BehaviorDescriptor\r\n{\r\n Id: BehaviorId;\r\n Status: BehaviorStatus;\r\n}\r\n\r\nexport class BehaviorInstancesResponse extends Response {\r\n constructor(\r\n public Behaviors: BehaviorDescriptor[],\r\n ) {\r\n super();\r\n }\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,aAAN,MAAiB;AAAA,EACpB,YACWA,QACA,QACA,YACT;AAHS,iBAAAA;AACA;AACA;AAAA,EACR;AACP;;;ACLO,IAAM,gBAAN,cAAuC,WAAW;AAAA,EACrD,YACWC,WACP,OACA,QACA,YACF;AACE,UAAM,OAAO,QAAQ,UAAU;AALxB,oBAAAA;AAAA,EAMX;AACJ;;;ACdO,IAAM,QAAN,MAAY;AACnB;;;ACEO,IAAM,UAAN,cAAkD,MAAM;AAAA,EACpD;AACX;;;ACFO,IAAM,wBAAN,cAAoC,QAAgC;AAAA,EAChE,QAAQ;AACnB;;;ACFO,IAAM,wBAAN,cAAoC,QAAgC;AAAA,EAChE,QAAQ;AAAA,EAEf,cAAc;AACV,UAAM;AAAA,EACV;AACJ;;;ACIO,IAAM,WAAN,MAAM,UAA8B;AAAA,EAGvC,YAAY,4BAAmF,YAAwB;AAAxB;AAC3F,SAAK,oBAAoB,sCAAsC,YACzD,2BAA2B,oBAC3B,KAAK,oBAAoB;AAAA,EACnC;AAAA,EANA;AAAA,EAQA,KAAK,OAAmC;AACpC,WAAO,IAAI,QAAoB,OAAO,SAAS,WAAW;AACtD,UAAI,MAAM,MAAM,KAAK;AACrB,cAAQ,MAAM,IAAI,KAAK,KAAK,YAAY,KAAK,CAAC;AAAA,IAClD,CAAC;AAAA,EACL;AAAA,EAEA,QAAoC,SAAgE;AAChG,WAAO,IAAI,QAAkC,OAAO,SAAS,WAAW;AACpE,UAAI,SAAS,MAAM,KAAK,KAAK,OAAO;AACpC,cAAQ,IAAI,cAAyB,QAAQ,UAAuB,SAAS,OAAO,QAAQ,OAAO,UAAU,CAAC;AAAA,IAClH,CAAC;AAAA,EACL;AAAA,EAEA,WAAW,uBAA+F;AACtG,QAAI,OAAO,0BAA0B,aAAa;AAC9C,8BAAwB,IAAI,sBAAsB;AAAA,IACtD;AAEA,WAAO,KAAK,QAAQ,qBAAqB;AAAA,EAC7C;AAAA,EAEA,YAA4D;AACxD,WAAO,KAAK,QAAQ,IAAI,sBAAsB,CAAC;AAAA,EACnD;AACJ;;;ACxCO,IAAM,kBAAN,MAAkD;AAAA,EAC7C,kBAAmC,CAAC;AAAA,EAEpC;AAAA,EAER,YAAY,kBAAuD;AAC/D,SAAK,mBAAmB,IAAI,QAAoC,CAAC,SAAS,WAAW;AACjF,uBACK,KAAK,eAAa;AACf,kBAAU,oBAAoB,EAAE,KAAK,YAAU;AAC3C,eAAK,kBAAkB;AACvB,kBAAQ,SAAS;AAAA,QACrB,CAAC;AAAA,MACL,CAAC,EACA,MAAM,YAAU,OAAO,MAAM,CAAC;AAAA,IACvC,CAAC;AAAA,EACL;AAAA,EAEA,eAAe,YAA4C;AACvD,WAAO,IAAI,QAAmB,CAAC,SAAS,WAAW;AAC/C,WAAK,iBACA,KAAK,SAAO;AACT,YAAI,KAAK,gBAAgB;AAAA,UAAU,mBAC/B,cAAc,SAAS,WAAW,cAAc,QAChD,cAAc,SAAS,WAAW,cAAc;AAAA,QACpD,MAAM,IAAI;AACN,kBAAQ,IAAI,SAAS,KAAK,kBAAkB,UAAU,CAAC;AAAA,QAC3D,OAEA;AACI,iBAAO,oBAAoB;AAAA,QAC/B;AAAA,MACJ,CAAC,EACA,MAAM,YAAU,OAAO,MAAM,CAAC;AAAA,IACvC,CAAC;AAAA,EACL;AACJ;;;ACxCO,IAAM,sBAAN,cAAkC,QAA8B;AAAA,EAC5D,QAAQ;AAAA,EAEf,cAAc;AACV,UAAM;AAAA,EACV;AACJ;;;ACLO,IAAM,eAAN,cAA2B,SAAkC;AAAA,EAChE,YAAY,UAAoB;AAC5B,UAAM,UAAU,SAAS,UAAU;AAAA,EACvC;AAAA,EAEA,kBAAgC;AAC5B,WAAO,KAAK,QAAQ,IAAI,oBAAoB,CAAC;AAAA,EACjD;AACJ;;;ACLO,IAAM,sBAAN,MAA0D;AAAA,EAC7D,YAAoB,iBAAmC;AAAnC;AAAA,EAAoC;AAAA,EAExD,mBAAmB,IAA4C;AAC3D,WAAO,IAAI,QAAuB,CAAC,SAAS,WAAW;AACnD,WAAK,gBAAgB,eAAe,EAAE,EACjC,KAAK,cAAY,QAAQ,IAAI,aAAa,QAAoB,CAAC,CAAC,EAChE,MAAM,OAAK,OAAO,yBAAyB,CAAC;AAAA,IACrD,CAAC;AAAA,EACL;AACJ;;;ACfO,IAAM,aAAN,MAAiB;AAAA,EACpB,YACW,eACA,UACT;AAFS;AACA;AAAA,EACR;AAAA,EAEI,QAAgB;AAC3B;;;ACTO,IAAM,gBAAN,MAAoB;AAAA,EACvB,YACW,MACA,MACT;AAFS;AACA;AAAA,EACR;AAAA,EAEI,QAAgB;AAC3B;;;ACJO,IAAM,kCAAN,cAA8C,QAA0C;AAAA,EACpF,QAAQ;AAAA,EAEf,cAAc;AACV,UAAM;AAAA,EACV;AACJ;;;ACNO,IAAM,2BAAN,cAAuC,QAAmC;AAAA,EACtE,QAAQ;AAAA,EAEf,cAAc;AACV,UAAM;AAAA,EACV;AACJ;;;ACDO,IAAM,SAAN,MAAgC;AAAA,EACnC,YAAoB,UAAqB;AAArB;AAAA,EAAsB;AAAA,EAE1C,8BAAwF;AACpF,WAAO,KAAK,SAAS,QAAQ,IAAI,gCAAgC,CAAC;AAAA,EACtE;AAAA,EAEA,uBAA0E;AACtE,WAAO,KAAK,SAAS,QAAQ,IAAI,yBAAyB,CAAC;AAAA,EAC/D;AACJ;;;ACfO,IAAM,WAAN,cAAuB,SAA8B;AAAA,EACxD,YAAY,UAAoB;AAC5B,UAAM,UAAU,SAAS,UAAU;AAAA,EACvC;AACJ;;;ACAO,IAAM,kBAAN,MAAkD;AAAA,EACrD,YAAoB,iBAAmC;AAAnC;AAAA,EAAoC;AAAA,EAExD,eAAe,IAAoC;AAC/C,WAAO,IAAI,QAAmB,CAAC,SAAS,WAAW;AAC/C,WAAK,gBAAgB,eAAe,EAAE,EACjC,KAAK,cAAY,QAAQ,IAAI,SAAS,QAAoB,CAAC,CAAC,EAC5D,MAAM,OAAK,OAAO,yBAAyB,CAAC;AAAA,IACrD,CAAC;AAAA,EACL;AACJ;;;ACLO,IAAM,mBAAN,MAAuB;AAAA,EAC1B,YAAoB,kBAAqD;AAArD;AAAA,EAAuD;AAAA,EAE3E,mBAA4C;AAAA,EAE5C,IAAW,kBAAoC;AAC3C,WAAO,KAAK,qBAAqB,IAAI,gBAAgB,KAAK,iBAAiB,aAAa,CAAC;AAAA,EAC7F;AAAA,EAEA,uBAAoD;AAAA,EAEpD,IAAW,sBAA4C;AACnD,WAAO,KAAK,yBAAyB,IAAI,oBAAoB,KAAK,eAAe;AAAA,EACrF;AAAA,EAEA,mBAA4C;AAAA,EAE5C,IAAW,kBAAoC;AAC3C,WAAO,KAAK,qBAAqB,IAAI,gBAAgB,KAAK,eAAe;AAAA,EAC7E;AAAA,EAEA,iBAA0C;AAAA,EAE1C,IAAW,SAA2B;AAClC,WAAO,KAAK,mBAAmB,IAAI,QAAiB,CAAC,SAAS,WAAW;AACrE,WAAK,gBAAgB,eAAe,IAAI,WAAW,IAAI,cAAc,UAAU,YAAY,GAAG,EAAE,CAAC,EAC5F,KAAK,cAAY,QAAQ,IAAI,OAAO,QAAQ,CAAC,CAAC,EAC9C,MAAM,YAAU,OAAO,MAAM,CAAC;AAAA,IACvC,CAAC;AAAA,EACL;AACJ;;;ACvCO,IAAM,iBAAN,cAA6B,WAAW;AAAA,EAC3C,YACI,MACA,UACF;AACE,UAAM,IAAI,cAAc,gBAAgB,IAAI,GAAG,QAAQ;AAAA,EAC3D;AACJ;;;ACPO,IAAM,aAAN,cAAyB,WAAW;AAAA,EACvC,YACI,MACA,UACF;AACE,UAAM,IAAI,cAAc,YAAY,IAAI,GAAG,QAAQ;AAAA,EACvD;AACJ;;;ACRO,IAAM,WAAN,cAAuB,MAAM;AAEpC;;;ACFO,IAAM,yBAAN,cAAqC,SAAS;AAAA,EACjD,YACW,0BACT;AACE,UAAM;AAFC;AAAA,EAGX;AACJ;;;ACLO,IAAM,yBAAN,cAAqC,SAAS;AAAA,EACjD,YACWC,iBACT;AACE,UAAM;AAFC,0BAAAA;AAAA,EAGX;AACJ;;;ACNO,IAAM,kBAAN,cAA8B,QAA0B;AAAA,EACpD,QAAQ;AAAA,EAEf,cAAc;AACV,UAAM;AAAA,EACV;AACJ;;;ACPO,IAAM,mBAAN,cAA+B,SAAS;AAAA,EAC3C,YACW,UACT;AACE,UAAM;AAFC;AAAA,EAGX;AACJ;;;ACRO,IAAK,cAAL,kBAAKC,iBAAL;AACH,EAAAA,0BAAA,iBAAc,KAAd;AACA,EAAAA,0BAAA,cAAW,KAAX;AACA,EAAAA,0BAAA,aAAU,KAAV;AACA,EAAAA,0BAAA,iBAAc,KAAd;AACA,EAAAA,0BAAA,cAAW,KAAX;AACA,EAAAA,0BAAA,cAAW,KAAX;AANQ,SAAAA;AAAA,GAAA;;;ACAL,IAAK,iBAAL,kBAAKC,oBAAL;AACH,EAAAA,gCAAA,aAAU,KAAV;AACA,EAAAA,gCAAA,oBAAiB,KAAjB;AACA,EAAAA,gCAAA,iBAAc,KAAd;AACA,EAAAA,gCAAA,eAAY,KAAZ;AAJQ,SAAAA;AAAA,GAAA;;;ACGL,IAAM,mCAAN,cAA+C,SAAS;AAAA,EAC3D,YACW,0BACT;AACE,UAAM;AAFC;AAAA,EAGX;AACJ;;;ACCO,IAAM,4BAAN,cAAwC,SAAS;AAAA,EACpD,YACW,WACT;AACE,UAAM;AAFC;AAAA,EAGX;AACJ;","names":["Event","Response","BehaviorStatus","EventStatus","BehaviorStatus"]} \ No newline at end of file diff --git a/Transport/@stateflows/common/dist/index.mjs b/Transport/@stateflows/common/dist/index.mjs new file mode 100644 index 00000000..0093c682 --- /dev/null +++ b/Transport/@stateflows/common/dist/index.mjs @@ -0,0 +1,329 @@ +// src/classes/send-result.ts +var SendResult = class { + constructor(Event2, Status, Validation) { + this.Event = Event2; + this.Status = Status; + this.Validation = Validation; + } +}; + +// src/classes/request-result.ts +var RequestResult = class extends SendResult { + constructor(Response2, event, status, validation) { + super(event, status, validation); + this.Response = Response2; + } +}; + +// src/events/event.ts +var Event = class { +}; + +// src/events/request.ts +var Request = class extends Event { + Response; +}; + +// src/events/initialization.request.ts +var InitializationRequest = class extends Request { + $type = "Stateflows.Common.InitializationRequest, Stateflows.Common"; +}; + +// src/events/behavior-status.request.ts +var BehaviorStatusRequest = class extends Request { + $type = "Stateflows.Common.BehaviorStatusRequest, Stateflows.Common"; + constructor() { + super(); + } +}; + +// src/behaviors/behavior.ts +var Behavior = class _Behavior { + constructor(transportPromiseOrBehavior, behaviorId) { + this.behaviorId = behaviorId; + this.#transportPromise = transportPromiseOrBehavior instanceof _Behavior ? transportPromiseOrBehavior.#transportPromise : this.#transportPromise = transportPromiseOrBehavior; + } + #transportPromise; + send(event) { + return new Promise(async (resolve, reject) => { + let hub = await this.#transportPromise; + resolve(await hub.send(this.behaviorId, event)); + }); + } + request(request) { + return new Promise(async (resolve, reject) => { + let result = await this.send(request); + resolve(new RequestResult(request.Response, request, result.Status, result.Validation)); + }); + } + initialize(initializationRequest) { + if (typeof initializationRequest === "undefined") { + initializationRequest = new InitializationRequest(); + } + return this.request(initializationRequest); + } + getStatus() { + return this.request(new BehaviorStatusRequest()); + } +}; + +// src/locators/behavior.locator.ts +var BehaviorLocator = class { + behaviorClasses = []; + transportPromise; + constructor(transportPromise) { + this.transportPromise = new Promise((resolve, reject) => { + transportPromise.then((transport) => { + transport.getAvailableClasses().then((result) => { + this.behaviorClasses = result; + resolve(transport); + }); + }).catch((reason) => reject(reason)); + }); + } + locateBehavior(behaviorId) { + return new Promise((resolve, reject) => { + this.transportPromise.then((hub) => { + if (this.behaviorClasses.findIndex( + (behaviorClass) => behaviorClass.type === behaviorId.behaviorClass.type && behaviorClass.name === behaviorId.behaviorClass.name + ) !== -1) { + resolve(new Behavior(this.transportPromise, behaviorId)); + } else { + reject("Behavior not found"); + } + }).catch((reason) => reject(reason)); + }); + } +}; + +// src/events/current-state.request.ts +var CurrentStateRequest = class extends Request { + $type = "Stateflows.StateMachines.Events.CurrentStateRequest, Stateflows.Common"; + constructor() { + super(); + } +}; + +// src/behaviors/state-machine.ts +var StateMachine = class extends Behavior { + constructor(behavior) { + super(behavior, behavior.behaviorId); + } + getCurrentState() { + return this.request(new CurrentStateRequest()); + } +}; + +// src/locators/state-machine.locator.ts +var StateMachineLocator = class { + constructor(behaviorLocator) { + this.behaviorLocator = behaviorLocator; + } + locateStateMachine(id) { + return new Promise((resolve, reject) => { + this.behaviorLocator.locateBehavior(id).then((behavior) => resolve(new StateMachine(behavior))).catch((_) => reject("State Machine not found")); + }); + } +}; + +// src/ids/behavior.id.ts +var BehaviorId = class { + constructor(behaviorClass, instance) { + this.behaviorClass = behaviorClass; + this.instance = instance; + } + $type = "Stateflows.BehaviorId, Stateflows.Common"; +}; + +// src/ids/behavior.class.ts +var BehaviorClass = class { + constructor(type, name) { + this.type = type; + this.name = name; + } + $type = "Stateflows.BehaviorClass, Stateflows.Common"; +}; + +// src/events/available-behavior-classes.request.ts +var AvailableBehaviorClassesRequest = class extends Request { + $type = "Stateflows.System.AvailableBehaviorClassesRequest, Stateflows.Common"; + constructor() { + super(); + } +}; + +// src/events/behavior-instances.request.ts +var BehaviorInstancesRequest = class extends Request { + $type = "Stateflows.System.BehaviorInstancesRequest, Stateflows.Common"; + constructor() { + super(); + } +}; + +// src/behaviors/system.ts +var System = class { + constructor(behavior) { + this.behavior = behavior; + } + getAvailableBehaviorClasses() { + return this.behavior.request(new AvailableBehaviorClassesRequest()); + } + getBehaviorInstances() { + return this.behavior.request(new BehaviorInstancesRequest()); + } +}; + +// src/behaviors/activity.ts +var Activity = class extends Behavior { + constructor(behavior) { + super(behavior, behavior.behaviorId); + } +}; + +// src/locators/activity.locator.ts +var ActivityLocator = class { + constructor(behaviorLocator) { + this.behaviorLocator = behaviorLocator; + } + locateActivity(id) { + return new Promise((resolve, reject) => { + this.behaviorLocator.locateBehavior(id).then((behavior) => resolve(new Activity(behavior))).catch((_) => reject("State Machine not found")); + }); + } +}; + +// src/classes/stateflows-client.ts +var StateflowsClient = class { + constructor(transportFactory) { + this.transportFactory = transportFactory; + } + #behaviorLocator = null; + get behaviorLocator() { + return this.#behaviorLocator ??= new BehaviorLocator(this.transportFactory.getTransport()); + } + #stateMachineLocator = null; + get stateMachineLocator() { + return this.#stateMachineLocator ??= new StateMachineLocator(this.behaviorLocator); + } + #activityLocator = null; + get activityLocator() { + return this.#activityLocator ??= new ActivityLocator(this.behaviorLocator); + } + #systemPromise = null; + get system() { + return this.#systemPromise ??= new Promise((resolve, reject) => { + this.behaviorLocator.locateBehavior(new BehaviorId(new BehaviorClass("System", "Stateflows"), "")).then((behavior) => resolve(new System(behavior))).catch((reason) => reject(reason)); + }); + } +}; + +// src/ids/state-machine.id.ts +var StateMachineId = class extends BehaviorId { + constructor(name, instance) { + super(new BehaviorClass("StateMachine", name), instance); + } +}; + +// src/ids/activity.id.ts +var ActivityId = class extends BehaviorId { + constructor(name, instance) { + super(new BehaviorClass("Activity", name), instance); + } +}; + +// src/events/response.ts +var Response = class extends Event { +}; + +// src/events/initialization.response.ts +var InitializationResponse = class extends Response { + constructor(InitializationSuccessful) { + super(); + this.InitializationSuccessful = InitializationSuccessful; + } +}; + +// src/events/behavior-status.response.ts +var BehaviorStatusResponse = class extends Response { + constructor(BehaviorStatus2) { + super(); + this.BehaviorStatus = BehaviorStatus2; + } +}; + +// src/events/plant-uml.request.ts +var PlantUmlRequest = class extends Request { + $type = "Stateflows.Extensions.PlantUml.Events.PlantUmlRequest, Stateflows.Extensions.PlantUml"; + constructor() { + super(); + } +}; + +// src/events/plant-uml.response.ts +var PlantUmlResponse = class extends Response { + constructor(PlantUml) { + super(); + this.PlantUml = PlantUml; + } +}; + +// src/enums/event-status.ts +var EventStatus = /* @__PURE__ */ ((EventStatus2) => { + EventStatus2[EventStatus2["Undelivered"] = 0] = "Undelivered"; + EventStatus2[EventStatus2["Rejected"] = 1] = "Rejected"; + EventStatus2[EventStatus2["Invalid"] = 2] = "Invalid"; + EventStatus2[EventStatus2["NotConsumed"] = 3] = "NotConsumed"; + EventStatus2[EventStatus2["Deferred"] = 4] = "Deferred"; + EventStatus2[EventStatus2["Consumed"] = 5] = "Consumed"; + return EventStatus2; +})(EventStatus || {}); + +// src/enums/behavior-status.ts +var BehaviorStatus = /* @__PURE__ */ ((BehaviorStatus2) => { + BehaviorStatus2[BehaviorStatus2["Unknown"] = 0] = "Unknown"; + BehaviorStatus2[BehaviorStatus2["NotInitialized"] = 1] = "NotInitialized"; + BehaviorStatus2[BehaviorStatus2["Initialized"] = 2] = "Initialized"; + BehaviorStatus2[BehaviorStatus2["Finalized"] = 3] = "Finalized"; + return BehaviorStatus2; +})(BehaviorStatus || {}); + +// src/events/available-behavior-classes.response.ts +var AvailableBehaviorClassesResponse = class extends Response { + constructor(AvailableBehaviorClasses) { + super(); + this.AvailableBehaviorClasses = AvailableBehaviorClasses; + } +}; + +// src/events/behavior-instances.response.ts +var BehaviorInstancesResponse = class extends Response { + constructor(Behaviors) { + super(); + this.Behaviors = Behaviors; + } +}; +export { + ActivityId, + AvailableBehaviorClassesRequest, + AvailableBehaviorClassesResponse, + BehaviorClass, + BehaviorId, + BehaviorInstancesRequest, + BehaviorInstancesResponse, + BehaviorStatus, + BehaviorStatusRequest, + BehaviorStatusResponse, + Event, + EventStatus, + InitializationRequest, + InitializationResponse, + PlantUmlRequest, + PlantUmlResponse, + Request, + RequestResult, + Response, + SendResult, + StateMachineId, + StateflowsClient +}; +//# sourceMappingURL=index.mjs.map \ No newline at end of file diff --git a/Transport/@stateflows/common/dist/index.mjs.map b/Transport/@stateflows/common/dist/index.mjs.map new file mode 100644 index 00000000..b13a42e0 --- /dev/null +++ b/Transport/@stateflows/common/dist/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/classes/send-result.ts","../src/classes/request-result.ts","../src/events/event.ts","../src/events/request.ts","../src/events/initialization.request.ts","../src/events/behavior-status.request.ts","../src/behaviors/behavior.ts","../src/locators/behavior.locator.ts","../src/events/current-state.request.ts","../src/behaviors/state-machine.ts","../src/locators/state-machine.locator.ts","../src/ids/behavior.id.ts","../src/ids/behavior.class.ts","../src/events/available-behavior-classes.request.ts","../src/events/behavior-instances.request.ts","../src/behaviors/system.ts","../src/behaviors/activity.ts","../src/locators/activity.locator.ts","../src/classes/stateflows-client.ts","../src/ids/state-machine.id.ts","../src/ids/activity.id.ts","../src/events/response.ts","../src/events/initialization.response.ts","../src/events/behavior-status.response.ts","../src/events/plant-uml.request.ts","../src/events/plant-uml.response.ts","../src/enums/event-status.ts","../src/enums/behavior-status.ts","../src/events/available-behavior-classes.response.ts","../src/events/behavior-instances.response.ts"],"sourcesContent":["import { EventStatus } from \"../enums/event-status\";\r\nimport { Event } from \"../events/event\";\r\nimport { EventValidation } from \"./event-validation\";\r\n\r\nexport class SendResult {\r\n constructor(\r\n public Event: Event,\r\n public Status: EventStatus,\r\n public Validation: EventValidation,\r\n ) {}\r\n}","import { EventStatus } from \"../enums/event-status\";\r\nimport { Event } from \"../events/event\";\r\nimport { EventValidation } from \"./event-validation\";\r\nimport { SendResult } from \"./send-result\";\r\n\r\nexport class RequestResult extends SendResult {\r\n constructor(\r\n public Response: TResponse,\r\n event: Event,\r\n status: EventStatus,\r\n validation: EventValidation,\r\n ) {\r\n super(event, status, validation);\r\n }\r\n}","export class Event {\r\n}","import { Response } from \"./response\";\r\nimport { Event } from \"./event\";\r\n\r\nexport class Request extends Event {\r\n public Response: TResponse;\r\n}","import { Request } from \"./request\";\r\nimport { InitializationResponse } from \"./initialization.response\";\r\n\r\nexport class InitializationRequest extends Request {\r\n public $type = \"Stateflows.Common.InitializationRequest, Stateflows.Common\";\r\n}","import { Request } from \"./request\";\r\nimport { BehaviorStatusResponse } from \"./behavior-status.response\";\r\n\r\nexport class BehaviorStatusRequest extends Request {\r\n public $type = \"Stateflows.Common.BehaviorStatusRequest, Stateflows.Common\";\r\n\r\n constructor() {\r\n super();\r\n }\r\n}","import { Request } from \"../events/request\";\r\nimport { IBehavior } from \"../interfaces/behavior\";\r\nimport { SendResult } from \"../classes/send-result\";\r\nimport { RequestResult } from \"../classes/request-result\";\r\nimport { InitializationResponse } from \"../events/initialization.response\";\r\nimport { BehaviorStatusResponse } from \"../events/behavior-status.response\";\r\nimport { BehaviorId } from \"../ids/behavior.id\";\r\nimport { Response } from \"../events/response\";\r\nimport { InitializationRequest } from \"../events/initialization.request\";\r\nimport { Event } from \"../events/event\";\r\nimport { BehaviorStatusRequest } from \"../events/behavior-status.request\";\r\nimport { IStateflowsClientTransport } from \"../interfaces/stateflows-client-transport\";\r\n\r\nexport class Behavior implements IBehavior {\r\n #transportPromise: Promise\r\n\r\n constructor(transportPromiseOrBehavior: Promise | Behavior, public behaviorId: BehaviorId) {\r\n this.#transportPromise = transportPromiseOrBehavior instanceof Behavior\r\n ? transportPromiseOrBehavior.#transportPromise\r\n : this.#transportPromise = transportPromiseOrBehavior;\r\n }\r\n\r\n send(event: Event): Promise {\r\n return new Promise(async (resolve, reject) => {\r\n let hub = await this.#transportPromise;\r\n resolve(await hub.send(this.behaviorId, event));\r\n });\r\n }\r\n\r\n request(request: Request): Promise> {\r\n return new Promise>(async (resolve, reject) => {\r\n let result = await this.send(request);\r\n resolve(new RequestResult(request.Response as TResponse, request, result.Status, result.Validation));\r\n });\r\n }\r\n\r\n initialize(initializationRequest?: InitializationRequest): Promise> {\r\n if (typeof initializationRequest === \"undefined\") {\r\n initializationRequest = new InitializationRequest();\r\n }\r\n\r\n return this.request(initializationRequest);\r\n }\r\n\r\n getStatus(): Promise> {\r\n return this.request(new BehaviorStatusRequest());\r\n }\r\n}","import { Behavior } from \"../behaviors/behavior\";\r\nimport { BehaviorClass } from \"../ids/behavior.class\";\r\nimport { BehaviorId } from \"../ids/behavior.id\";\r\nimport { IBehavior } from \"../interfaces/behavior\";\r\nimport { IBehaviorLocator } from \"../interfaces/behavior.locator\";\r\nimport { IStateflowsClientTransport } from \"../interfaces/stateflows-client-transport\";\r\n\r\nexport class BehaviorLocator implements IBehaviorLocator {\r\n private behaviorClasses: BehaviorClass[] = [];\r\n\r\n private transportPromise: Promise;\r\n\r\n constructor(transportPromise: Promise) {\r\n this.transportPromise = new Promise((resolve, reject) => {\r\n transportPromise\r\n .then(transport => {\r\n transport.getAvailableClasses().then(result => {\r\n this.behaviorClasses = result;\r\n resolve(transport);\r\n });\r\n })\r\n .catch(reason => reject(reason));\r\n });\r\n }\r\n\r\n locateBehavior(behaviorId: BehaviorId): Promise {\r\n return new Promise((resolve, reject) => {\r\n this.transportPromise\r\n .then(hub => {\r\n if (this.behaviorClasses.findIndex(behaviorClass => \r\n behaviorClass.type === behaviorId.behaviorClass.type &&\r\n behaviorClass.name === behaviorId.behaviorClass.name\r\n ) !== -1) {\r\n resolve(new Behavior(this.transportPromise, behaviorId));\r\n }\r\n else\r\n {\r\n reject(\"Behavior not found\");\r\n }\r\n })\r\n .catch(reason => reject(reason));\r\n });\r\n }\r\n}","import { Request } from \"./request\";\r\nimport { CurrentStateResponse } from \"./current-state.response\";\r\n\r\nexport class CurrentStateRequest extends Request {\r\n public $type = \"Stateflows.StateMachines.Events.CurrentStateRequest, Stateflows.Common\";\r\n\r\n constructor() {\r\n super();\r\n }\r\n}","import { CurrentStateRequest } from \"../events/current-state.request\";\r\nimport { IStateMachine } from \"../interfaces/state-machine\";\r\nimport { Behavior } from \"./behavior\";\r\n\r\nexport class StateMachine extends Behavior implements IStateMachine {\r\n constructor(behavior: Behavior) {\r\n super(behavior, behavior.behaviorId);\r\n }\r\n\r\n getCurrentState(): Promise {\r\n return this.request(new CurrentStateRequest());\r\n }\r\n}","import { Behavior } from \"../behaviors/behavior\";\r\nimport { StateMachine } from \"../behaviors/state-machine\";\r\nimport { StateMachineId } from \"../ids/state-machine.id\";\r\nimport { IBehaviorLocator } from \"../interfaces/behavior.locator\";\r\nimport { IStateMachine } from \"../interfaces/state-machine\";\r\nimport { IStateMachineLocator } from \"../interfaces/state-machine.locator\";\r\n\r\nexport class StateMachineLocator implements IStateMachineLocator {\r\n constructor(private behaviorLocator: IBehaviorLocator) {}\r\n\r\n locateStateMachine(id: StateMachineId): Promise {\r\n return new Promise((resolve, reject) => {\r\n this.behaviorLocator.locateBehavior(id)\r\n .then(behavior => resolve(new StateMachine(behavior as Behavior)))\r\n .catch(_ => reject(\"State Machine not found\"));\r\n });\r\n }\r\n}","import { BehaviorClass } from \"./behavior.class\";\r\n\r\nexport class BehaviorId {\r\n constructor(\r\n public behaviorClass: BehaviorClass,\r\n public instance: string\r\n ) {}\r\n\r\n public $type: string = \"Stateflows.BehaviorId, Stateflows.Common\";\r\n}","export class BehaviorClass {\r\n constructor(\r\n public type: string,\r\n public name: string\r\n ) {}\r\n \r\n public $type: string = \"Stateflows.BehaviorClass, Stateflows.Common\";\r\n}","import { Request } from \"./request\";\r\nimport { AvailableBehaviorClassesResponse } from \"./available-behavior-classes.response\";\r\n\r\nexport class AvailableBehaviorClassesRequest extends Request {\r\n public $type = \"Stateflows.System.AvailableBehaviorClassesRequest, Stateflows.Common\";\r\n\r\n constructor() {\r\n super();\r\n }\r\n}","import { Request } from \"./request\";\r\nimport { BehaviorInstancesResponse } from \"./behavior-instances.response\";\r\n\r\nexport class BehaviorInstancesRequest extends Request {\r\n public $type = \"Stateflows.System.BehaviorInstancesRequest, Stateflows.Common\";\r\n\r\n constructor() {\r\n super();\r\n }\r\n}","import { ISystem } from \"../interfaces/system\";\r\nimport { IBehavior } from \"../interfaces/behavior\";\r\nimport { RequestResult } from \"../classes/request-result\";\r\nimport { AvailableBehaviorClassesRequest } from \"../events/available-behavior-classes.request\";\r\nimport { AvailableBehaviorClassesResponse } from \"../events/available-behavior-classes.response\";\r\nimport { BehaviorInstancesRequest } from \"../events/behavior-instances.request\";\r\nimport { BehaviorInstancesResponse } from \"../events/behavior-instances.response\";\r\n\r\nexport class System implements ISystem {\r\n constructor(private behavior: IBehavior) {}\r\n\r\n getAvailableBehaviorClasses(): Promise> {\r\n return this.behavior.request(new AvailableBehaviorClassesRequest());\r\n }\r\n\r\n getBehaviorInstances(): Promise> {\r\n return this.behavior.request(new BehaviorInstancesRequest());\r\n }\r\n}","import { IActivity } from \"../interfaces/activity\";\r\nimport { Behavior } from \"./behavior\";\r\n\r\nexport class Activity extends Behavior implements IActivity {\r\n constructor(behavior: Behavior) {\r\n super(behavior, behavior.behaviorId);\r\n }\r\n}","import { Activity } from \"../behaviors/activity\";\r\nimport { Behavior } from \"../behaviors/behavior\";\r\nimport { ActivityId } from \"../ids/activity.id\";\r\nimport { IActivity } from \"../interfaces/activity\";\r\nimport { IActivityLocator } from \"../interfaces/activity.locator\";\r\nimport { IBehaviorLocator } from \"../interfaces/behavior.locator\";\r\n\r\nexport class ActivityLocator implements IActivityLocator {\r\n constructor(private behaviorLocator: IBehaviorLocator) {}\r\n\r\n locateActivity(id: ActivityId): Promise {\r\n return new Promise((resolve, reject) => {\r\n this.behaviorLocator.locateBehavior(id)\r\n .then(behavior => resolve(new Activity(behavior as Behavior)))\r\n .catch(_ => reject(\"State Machine not found\"));\r\n });\r\n }\r\n}","import { IBehaviorLocator } from \"../interfaces/behavior.locator\";\r\nimport { IStateMachineLocator } from \"../interfaces/state-machine.locator\";\r\nimport { BehaviorLocator } from \"../locators/behavior.locator\";\r\nimport { StateMachineLocator } from \"../locators/state-machine.locator\";\r\nimport { ISystem } from \"../interfaces/system\";\r\nimport { BehaviorId } from \"../ids/behavior.id\";\r\nimport { BehaviorClass } from \"../ids/behavior.class\";\r\nimport { System } from \"../behaviors/system\";\r\nimport { IActivityLocator } from \"../interfaces/activity.locator\";\r\nimport { ActivityLocator } from \"../locators/activity.locator\";\r\nimport { IStateflowsClientTransportFactory } from \"../interfaces/stateflows-client-transport-factory\";\r\n\r\nexport class StateflowsClient {\r\n constructor(private transportFactory: IStateflowsClientTransportFactory) { }\r\n\r\n #behaviorLocator: IBehaviorLocator | null = null;\r\n\r\n public get behaviorLocator(): IBehaviorLocator {\r\n return this.#behaviorLocator ??= new BehaviorLocator(this.transportFactory.getTransport());\r\n }\r\n\r\n #stateMachineLocator: IStateMachineLocator | null = null;\r\n\r\n public get stateMachineLocator(): IStateMachineLocator {\r\n return this.#stateMachineLocator ??= new StateMachineLocator(this.behaviorLocator);\r\n }\r\n\r\n #activityLocator: IActivityLocator | null = null;\r\n\r\n public get activityLocator(): IActivityLocator {\r\n return this.#activityLocator ??= new ActivityLocator(this.behaviorLocator);\r\n }\r\n\r\n #systemPromise: Promise | null = null;\r\n\r\n public get system(): Promise {\r\n return this.#systemPromise ??= new Promise((resolve, reject) => {\r\n this.behaviorLocator.locateBehavior(new BehaviorId(new BehaviorClass(\"System\", \"Stateflows\"), \"\"))\r\n .then(behavior => resolve(new System(behavior)))\r\n .catch(reason => reject(reason));\r\n })\r\n }\r\n}","import { BehaviorClass } from \"./behavior.class\";\r\nimport { BehaviorId } from \"./behavior.id\";\r\n\r\nexport class StateMachineId extends BehaviorId {\r\n constructor(\r\n name: string,\r\n instance: string\r\n ) {\r\n super(new BehaviorClass(\"StateMachine\", name), instance);\r\n }\r\n}","import { BehaviorClass } from \"./behavior.class\";\r\nimport { BehaviorId } from \"./behavior.id\";\r\n\r\nexport class ActivityId extends BehaviorId {\r\n constructor(\r\n name: string,\r\n instance: string\r\n ) {\r\n super(new BehaviorClass(\"Activity\", name), instance);\r\n }\r\n}","import { Event } from \"./event\";\r\n\r\nexport class Response extends Event {\r\n\r\n}","import { Response } from \"./response\";\r\n\r\nexport class InitializationResponse extends Response {\r\n constructor(\r\n public InitializationSuccessful: boolean,\r\n ) {\r\n super();\r\n }\r\n}","import { BehaviorStatus } from \"../enums/behavior-status\";\r\nimport { Response } from \"./response\";\r\n\r\nexport class BehaviorStatusResponse extends Response {\r\n constructor(\r\n public BehaviorStatus: BehaviorStatus,\r\n ) {\r\n super();\r\n }\r\n}","import { PlantUmlResponse } from \"./plant-uml.response\";\r\nimport { Request } from \"./request\";\r\n\r\nexport class PlantUmlRequest extends Request {\r\n public $type = \"Stateflows.Extensions.PlantUml.Events.PlantUmlRequest, Stateflows.Extensions.PlantUml\";\r\n\r\n constructor() {\r\n super();\r\n }\r\n}","import { Response } from \"./response\";\r\n\r\nexport class PlantUmlResponse extends Response {\r\n constructor(\r\n public PlantUml: string,\r\n ) {\r\n super();\r\n }\r\n}","export enum EventStatus {\r\n Undelivered = 0,\r\n Rejected = 1,\r\n Invalid = 2,\r\n NotConsumed = 3,\r\n Deferred = 4,\r\n Consumed = 5\r\n}","export enum BehaviorStatus {\r\n Unknown = 0,\r\n NotInitialized = 1,\r\n Initialized = 2,\r\n Finalized = 3\r\n}","import { Response } from \"./response\";\r\nimport { BehaviorClass } from \"../ids/behavior.class\";\r\n\r\nexport class AvailableBehaviorClassesResponse extends Response {\r\n constructor(\r\n public AvailableBehaviorClasses: BehaviorClass[],\r\n ) {\r\n super();\r\n }\r\n}","import { Response } from \"./response\";\r\nimport { BehaviorId } from \"../ids/behavior.id\";\r\nimport { BehaviorStatus } from \"../enums/behavior-status\";\r\n\r\nexport class BehaviorDescriptor\r\n{\r\n Id: BehaviorId;\r\n Status: BehaviorStatus;\r\n}\r\n\r\nexport class BehaviorInstancesResponse extends Response {\r\n constructor(\r\n public Behaviors: BehaviorDescriptor[],\r\n ) {\r\n super();\r\n }\r\n}"],"mappings":";AAIO,IAAM,aAAN,MAAiB;AAAA,EACpB,YACWA,QACA,QACA,YACT;AAHS,iBAAAA;AACA;AACA;AAAA,EACR;AACP;;;ACLO,IAAM,gBAAN,cAAuC,WAAW;AAAA,EACrD,YACWC,WACP,OACA,QACA,YACF;AACE,UAAM,OAAO,QAAQ,UAAU;AALxB,oBAAAA;AAAA,EAMX;AACJ;;;ACdO,IAAM,QAAN,MAAY;AACnB;;;ACEO,IAAM,UAAN,cAAkD,MAAM;AAAA,EACpD;AACX;;;ACFO,IAAM,wBAAN,cAAoC,QAAgC;AAAA,EAChE,QAAQ;AACnB;;;ACFO,IAAM,wBAAN,cAAoC,QAAgC;AAAA,EAChE,QAAQ;AAAA,EAEf,cAAc;AACV,UAAM;AAAA,EACV;AACJ;;;ACIO,IAAM,WAAN,MAAM,UAA8B;AAAA,EAGvC,YAAY,4BAAmF,YAAwB;AAAxB;AAC3F,SAAK,oBAAoB,sCAAsC,YACzD,2BAA2B,oBAC3B,KAAK,oBAAoB;AAAA,EACnC;AAAA,EANA;AAAA,EAQA,KAAK,OAAmC;AACpC,WAAO,IAAI,QAAoB,OAAO,SAAS,WAAW;AACtD,UAAI,MAAM,MAAM,KAAK;AACrB,cAAQ,MAAM,IAAI,KAAK,KAAK,YAAY,KAAK,CAAC;AAAA,IAClD,CAAC;AAAA,EACL;AAAA,EAEA,QAAoC,SAAgE;AAChG,WAAO,IAAI,QAAkC,OAAO,SAAS,WAAW;AACpE,UAAI,SAAS,MAAM,KAAK,KAAK,OAAO;AACpC,cAAQ,IAAI,cAAyB,QAAQ,UAAuB,SAAS,OAAO,QAAQ,OAAO,UAAU,CAAC;AAAA,IAClH,CAAC;AAAA,EACL;AAAA,EAEA,WAAW,uBAA+F;AACtG,QAAI,OAAO,0BAA0B,aAAa;AAC9C,8BAAwB,IAAI,sBAAsB;AAAA,IACtD;AAEA,WAAO,KAAK,QAAQ,qBAAqB;AAAA,EAC7C;AAAA,EAEA,YAA4D;AACxD,WAAO,KAAK,QAAQ,IAAI,sBAAsB,CAAC;AAAA,EACnD;AACJ;;;ACxCO,IAAM,kBAAN,MAAkD;AAAA,EAC7C,kBAAmC,CAAC;AAAA,EAEpC;AAAA,EAER,YAAY,kBAAuD;AAC/D,SAAK,mBAAmB,IAAI,QAAoC,CAAC,SAAS,WAAW;AACjF,uBACK,KAAK,eAAa;AACf,kBAAU,oBAAoB,EAAE,KAAK,YAAU;AAC3C,eAAK,kBAAkB;AACvB,kBAAQ,SAAS;AAAA,QACrB,CAAC;AAAA,MACL,CAAC,EACA,MAAM,YAAU,OAAO,MAAM,CAAC;AAAA,IACvC,CAAC;AAAA,EACL;AAAA,EAEA,eAAe,YAA4C;AACvD,WAAO,IAAI,QAAmB,CAAC,SAAS,WAAW;AAC/C,WAAK,iBACA,KAAK,SAAO;AACT,YAAI,KAAK,gBAAgB;AAAA,UAAU,mBAC/B,cAAc,SAAS,WAAW,cAAc,QAChD,cAAc,SAAS,WAAW,cAAc;AAAA,QACpD,MAAM,IAAI;AACN,kBAAQ,IAAI,SAAS,KAAK,kBAAkB,UAAU,CAAC;AAAA,QAC3D,OAEA;AACI,iBAAO,oBAAoB;AAAA,QAC/B;AAAA,MACJ,CAAC,EACA,MAAM,YAAU,OAAO,MAAM,CAAC;AAAA,IACvC,CAAC;AAAA,EACL;AACJ;;;ACxCO,IAAM,sBAAN,cAAkC,QAA8B;AAAA,EAC5D,QAAQ;AAAA,EAEf,cAAc;AACV,UAAM;AAAA,EACV;AACJ;;;ACLO,IAAM,eAAN,cAA2B,SAAkC;AAAA,EAChE,YAAY,UAAoB;AAC5B,UAAM,UAAU,SAAS,UAAU;AAAA,EACvC;AAAA,EAEA,kBAAgC;AAC5B,WAAO,KAAK,QAAQ,IAAI,oBAAoB,CAAC;AAAA,EACjD;AACJ;;;ACLO,IAAM,sBAAN,MAA0D;AAAA,EAC7D,YAAoB,iBAAmC;AAAnC;AAAA,EAAoC;AAAA,EAExD,mBAAmB,IAA4C;AAC3D,WAAO,IAAI,QAAuB,CAAC,SAAS,WAAW;AACnD,WAAK,gBAAgB,eAAe,EAAE,EACjC,KAAK,cAAY,QAAQ,IAAI,aAAa,QAAoB,CAAC,CAAC,EAChE,MAAM,OAAK,OAAO,yBAAyB,CAAC;AAAA,IACrD,CAAC;AAAA,EACL;AACJ;;;ACfO,IAAM,aAAN,MAAiB;AAAA,EACpB,YACW,eACA,UACT;AAFS;AACA;AAAA,EACR;AAAA,EAEI,QAAgB;AAC3B;;;ACTO,IAAM,gBAAN,MAAoB;AAAA,EACvB,YACW,MACA,MACT;AAFS;AACA;AAAA,EACR;AAAA,EAEI,QAAgB;AAC3B;;;ACJO,IAAM,kCAAN,cAA8C,QAA0C;AAAA,EACpF,QAAQ;AAAA,EAEf,cAAc;AACV,UAAM;AAAA,EACV;AACJ;;;ACNO,IAAM,2BAAN,cAAuC,QAAmC;AAAA,EACtE,QAAQ;AAAA,EAEf,cAAc;AACV,UAAM;AAAA,EACV;AACJ;;;ACDO,IAAM,SAAN,MAAgC;AAAA,EACnC,YAAoB,UAAqB;AAArB;AAAA,EAAsB;AAAA,EAE1C,8BAAwF;AACpF,WAAO,KAAK,SAAS,QAAQ,IAAI,gCAAgC,CAAC;AAAA,EACtE;AAAA,EAEA,uBAA0E;AACtE,WAAO,KAAK,SAAS,QAAQ,IAAI,yBAAyB,CAAC;AAAA,EAC/D;AACJ;;;ACfO,IAAM,WAAN,cAAuB,SAA8B;AAAA,EACxD,YAAY,UAAoB;AAC5B,UAAM,UAAU,SAAS,UAAU;AAAA,EACvC;AACJ;;;ACAO,IAAM,kBAAN,MAAkD;AAAA,EACrD,YAAoB,iBAAmC;AAAnC;AAAA,EAAoC;AAAA,EAExD,eAAe,IAAoC;AAC/C,WAAO,IAAI,QAAmB,CAAC,SAAS,WAAW;AAC/C,WAAK,gBAAgB,eAAe,EAAE,EACjC,KAAK,cAAY,QAAQ,IAAI,SAAS,QAAoB,CAAC,CAAC,EAC5D,MAAM,OAAK,OAAO,yBAAyB,CAAC;AAAA,IACrD,CAAC;AAAA,EACL;AACJ;;;ACLO,IAAM,mBAAN,MAAuB;AAAA,EAC1B,YAAoB,kBAAqD;AAArD;AAAA,EAAuD;AAAA,EAE3E,mBAA4C;AAAA,EAE5C,IAAW,kBAAoC;AAC3C,WAAO,KAAK,qBAAqB,IAAI,gBAAgB,KAAK,iBAAiB,aAAa,CAAC;AAAA,EAC7F;AAAA,EAEA,uBAAoD;AAAA,EAEpD,IAAW,sBAA4C;AACnD,WAAO,KAAK,yBAAyB,IAAI,oBAAoB,KAAK,eAAe;AAAA,EACrF;AAAA,EAEA,mBAA4C;AAAA,EAE5C,IAAW,kBAAoC;AAC3C,WAAO,KAAK,qBAAqB,IAAI,gBAAgB,KAAK,eAAe;AAAA,EAC7E;AAAA,EAEA,iBAA0C;AAAA,EAE1C,IAAW,SAA2B;AAClC,WAAO,KAAK,mBAAmB,IAAI,QAAiB,CAAC,SAAS,WAAW;AACrE,WAAK,gBAAgB,eAAe,IAAI,WAAW,IAAI,cAAc,UAAU,YAAY,GAAG,EAAE,CAAC,EAC5F,KAAK,cAAY,QAAQ,IAAI,OAAO,QAAQ,CAAC,CAAC,EAC9C,MAAM,YAAU,OAAO,MAAM,CAAC;AAAA,IACvC,CAAC;AAAA,EACL;AACJ;;;ACvCO,IAAM,iBAAN,cAA6B,WAAW;AAAA,EAC3C,YACI,MACA,UACF;AACE,UAAM,IAAI,cAAc,gBAAgB,IAAI,GAAG,QAAQ;AAAA,EAC3D;AACJ;;;ACPO,IAAM,aAAN,cAAyB,WAAW;AAAA,EACvC,YACI,MACA,UACF;AACE,UAAM,IAAI,cAAc,YAAY,IAAI,GAAG,QAAQ;AAAA,EACvD;AACJ;;;ACRO,IAAM,WAAN,cAAuB,MAAM;AAEpC;;;ACFO,IAAM,yBAAN,cAAqC,SAAS;AAAA,EACjD,YACW,0BACT;AACE,UAAM;AAFC;AAAA,EAGX;AACJ;;;ACLO,IAAM,yBAAN,cAAqC,SAAS;AAAA,EACjD,YACWC,iBACT;AACE,UAAM;AAFC,0BAAAA;AAAA,EAGX;AACJ;;;ACNO,IAAM,kBAAN,cAA8B,QAA0B;AAAA,EACpD,QAAQ;AAAA,EAEf,cAAc;AACV,UAAM;AAAA,EACV;AACJ;;;ACPO,IAAM,mBAAN,cAA+B,SAAS;AAAA,EAC3C,YACW,UACT;AACE,UAAM;AAFC;AAAA,EAGX;AACJ;;;ACRO,IAAK,cAAL,kBAAKC,iBAAL;AACH,EAAAA,0BAAA,iBAAc,KAAd;AACA,EAAAA,0BAAA,cAAW,KAAX;AACA,EAAAA,0BAAA,aAAU,KAAV;AACA,EAAAA,0BAAA,iBAAc,KAAd;AACA,EAAAA,0BAAA,cAAW,KAAX;AACA,EAAAA,0BAAA,cAAW,KAAX;AANQ,SAAAA;AAAA,GAAA;;;ACAL,IAAK,iBAAL,kBAAKC,oBAAL;AACH,EAAAA,gCAAA,aAAU,KAAV;AACA,EAAAA,gCAAA,oBAAiB,KAAjB;AACA,EAAAA,gCAAA,iBAAc,KAAd;AACA,EAAAA,gCAAA,eAAY,KAAZ;AAJQ,SAAAA;AAAA,GAAA;;;ACGL,IAAM,mCAAN,cAA+C,SAAS;AAAA,EAC3D,YACW,0BACT;AACE,UAAM;AAFC;AAAA,EAGX;AACJ;;;ACCO,IAAM,4BAAN,cAAwC,SAAS;AAAA,EACpD,YACW,WACT;AACE,UAAM;AAFC;AAAA,EAGX;AACJ;","names":["Event","Response","BehaviorStatus","EventStatus","BehaviorStatus"]} \ No newline at end of file diff --git a/Transport/@stateflows/common/package.json b/Transport/@stateflows/common/package.json new file mode 100644 index 00000000..860b20bb --- /dev/null +++ b/Transport/@stateflows/common/package.json @@ -0,0 +1,29 @@ +{ + "name": "@stateflows/common", + "version": "0.9.0", + "description": "Common package for Stateflows framework clients", + "main": "dist/index.js", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "files": [ + "dist" + ], + "scripts": { + "build": "tsup", + "build:dev": "tsup --watch", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "Stateflows", + "state-machine", + "activity", + "workflow" + ], + "author": "Stateflows", + "license": "MIT", + "homepage": "https://www.stateflows.net", + "devDependencies": { + "tsup": "^8.0.1", + "typescript": "^5.3.3" + } +} diff --git a/Transport/@stateflows/signalr-client/src/behaviors/activity.ts b/Transport/@stateflows/common/src/behaviors/activity.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/behaviors/activity.ts rename to Transport/@stateflows/common/src/behaviors/activity.ts diff --git a/Transport/@stateflows/signalr-client/src/behaviors/behavior.ts b/Transport/@stateflows/common/src/behaviors/behavior.ts similarity index 68% rename from Transport/@stateflows/signalr-client/src/behaviors/behavior.ts rename to Transport/@stateflows/common/src/behaviors/behavior.ts index a9057e9d..9176c909 100644 --- a/Transport/@stateflows/signalr-client/src/behaviors/behavior.ts +++ b/Transport/@stateflows/common/src/behaviors/behavior.ts @@ -1,4 +1,3 @@ -import { HubConnection } from "@microsoft/signalr"; import { Request } from "../events/request"; import { IBehavior } from "../interfaces/behavior"; import { SendResult } from "../classes/send-result"; @@ -10,28 +9,28 @@ import { Response } from "../events/response"; import { InitializationRequest } from "../events/initialization.request"; import { Event } from "../events/event"; import { BehaviorStatusRequest } from "../events/behavior-status.request"; +import { IStateflowsClientTransport } from "../interfaces/stateflows-client-transport"; export class Behavior implements IBehavior { - private hubPromise: Promise; - - constructor(hubPromiseOrBehavior: Promise | Behavior, public behaviorId: BehaviorId) { - this.hubPromise = hubPromiseOrBehavior instanceof Behavior - ? hubPromiseOrBehavior.hubPromise - : this.hubPromise = hubPromiseOrBehavior; + #transportPromise: Promise + + constructor(transportPromiseOrBehavior: Promise | Behavior, public behaviorId: BehaviorId) { + this.#transportPromise = transportPromiseOrBehavior instanceof Behavior + ? transportPromiseOrBehavior.#transportPromise + : this.#transportPromise = transportPromiseOrBehavior; } send(event: Event): Promise { return new Promise(async (resolve, reject) => { - let hub = await this.hubPromise; - let result = await hub.invoke("Send", this.behaviorId, JSON.stringify(event)); - resolve(JSON.parse(result)); + let hub = await this.#transportPromise; + resolve(await hub.send(this.behaviorId, event)); }); } request(request: Request): Promise> { return new Promise>(async (resolve, reject) => { let result = await this.send(request); - resolve(new RequestResult((result as any).Response as TResponse, result.Event, result.Status, result.Validation)); + resolve(new RequestResult(request.Response as TResponse, request, result.Status, result.Validation)); }); } diff --git a/Transport/@stateflows/signalr-client/src/behaviors/state-machine.ts b/Transport/@stateflows/common/src/behaviors/state-machine.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/behaviors/state-machine.ts rename to Transport/@stateflows/common/src/behaviors/state-machine.ts diff --git a/Transport/@stateflows/signalr-client/src/behaviors/system.ts b/Transport/@stateflows/common/src/behaviors/system.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/behaviors/system.ts rename to Transport/@stateflows/common/src/behaviors/system.ts diff --git a/Transport/@stateflows/signalr-client/src/classes/event-validation.ts b/Transport/@stateflows/common/src/classes/event-validation.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/classes/event-validation.ts rename to Transport/@stateflows/common/src/classes/event-validation.ts diff --git a/Transport/@stateflows/signalr-client/src/classes/request-result.ts b/Transport/@stateflows/common/src/classes/request-result.ts similarity index 90% rename from Transport/@stateflows/signalr-client/src/classes/request-result.ts rename to Transport/@stateflows/common/src/classes/request-result.ts index 81262499..b76e79c5 100644 --- a/Transport/@stateflows/signalr-client/src/classes/request-result.ts +++ b/Transport/@stateflows/common/src/classes/request-result.ts @@ -1,4 +1,5 @@ import { EventStatus } from "../enums/event-status"; +import { Event } from "../events/event"; import { EventValidation } from "./event-validation"; import { SendResult } from "./send-result"; diff --git a/Transport/@stateflows/signalr-client/src/classes/send-result.ts b/Transport/@stateflows/common/src/classes/send-result.ts similarity index 86% rename from Transport/@stateflows/signalr-client/src/classes/send-result.ts rename to Transport/@stateflows/common/src/classes/send-result.ts index e4784a0f..2bfc12f0 100644 --- a/Transport/@stateflows/signalr-client/src/classes/send-result.ts +++ b/Transport/@stateflows/common/src/classes/send-result.ts @@ -1,4 +1,5 @@ import { EventStatus } from "../enums/event-status"; +import { Event } from "../events/event"; import { EventValidation } from "./event-validation"; export class SendResult { diff --git a/Transport/@stateflows/signalr-client/src/classes/stateflows-client.ts b/Transport/@stateflows/common/src/classes/stateflows-client.ts similarity index 71% rename from Transport/@stateflows/signalr-client/src/classes/stateflows-client.ts rename to Transport/@stateflows/common/src/classes/stateflows-client.ts index 7cf836b2..08b9efe1 100644 --- a/Transport/@stateflows/signalr-client/src/classes/stateflows-client.ts +++ b/Transport/@stateflows/common/src/classes/stateflows-client.ts @@ -1,4 +1,3 @@ -import { HubConnection, HubConnectionBuilder } from "@microsoft/signalr"; import { IBehaviorLocator } from "../interfaces/behavior.locator"; import { IStateMachineLocator } from "../interfaces/state-machine.locator"; import { BehaviorLocator } from "../locators/behavior.locator"; @@ -9,34 +8,15 @@ import { BehaviorClass } from "../ids/behavior.class"; import { System } from "../behaviors/system"; import { IActivityLocator } from "../interfaces/activity.locator"; import { ActivityLocator } from "../locators/activity.locator"; +import { IStateflowsClientTransportFactory } from "../interfaces/stateflows-client-transport-factory"; export class StateflowsClient { - #hub: Promise | null = null; - - private get hub(): Promise { - if (this.#hub == null) { - this.#hub = new Promise((resolve, reject) => { - let hub = new HubConnectionBuilder() - .withUrl(this.url + "stateflows_v1") - .build(); - - hub.start().then(() => resolve(hub)); - }); - } - - return this.#hub; - } - - constructor(private url: string) { - if (url.slice(-1) != '/') { - url = url + '/'; - } - } + constructor(private transportFactory: IStateflowsClientTransportFactory) { } #behaviorLocator: IBehaviorLocator | null = null; public get behaviorLocator(): IBehaviorLocator { - return this.#behaviorLocator ??= new BehaviorLocator(this.hub); + return this.#behaviorLocator ??= new BehaviorLocator(this.transportFactory.getTransport()); } #stateMachineLocator: IStateMachineLocator | null = null; diff --git a/Transport/@stateflows/signalr-client/src/classes/validation-result.ts b/Transport/@stateflows/common/src/classes/validation-result.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/classes/validation-result.ts rename to Transport/@stateflows/common/src/classes/validation-result.ts diff --git a/Transport/@stateflows/signalr-client/src/enums/behavior-status.ts b/Transport/@stateflows/common/src/enums/behavior-status.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/enums/behavior-status.ts rename to Transport/@stateflows/common/src/enums/behavior-status.ts diff --git a/Transport/@stateflows/signalr-client/src/enums/event-status.ts b/Transport/@stateflows/common/src/enums/event-status.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/enums/event-status.ts rename to Transport/@stateflows/common/src/enums/event-status.ts diff --git a/Transport/@stateflows/signalr-client/src/events/available-behavior-classes.request.ts b/Transport/@stateflows/common/src/events/available-behavior-classes.request.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/events/available-behavior-classes.request.ts rename to Transport/@stateflows/common/src/events/available-behavior-classes.request.ts diff --git a/Transport/@stateflows/signalr-client/src/events/available-behavior-classes.response.ts b/Transport/@stateflows/common/src/events/available-behavior-classes.response.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/events/available-behavior-classes.response.ts rename to Transport/@stateflows/common/src/events/available-behavior-classes.response.ts diff --git a/Transport/@stateflows/signalr-client/src/events/behavior-instances.request.ts b/Transport/@stateflows/common/src/events/behavior-instances.request.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/events/behavior-instances.request.ts rename to Transport/@stateflows/common/src/events/behavior-instances.request.ts diff --git a/Transport/@stateflows/signalr-client/src/events/behavior-instances.response.ts b/Transport/@stateflows/common/src/events/behavior-instances.response.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/events/behavior-instances.response.ts rename to Transport/@stateflows/common/src/events/behavior-instances.response.ts diff --git a/Transport/@stateflows/signalr-client/src/events/behavior-status.request.ts b/Transport/@stateflows/common/src/events/behavior-status.request.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/events/behavior-status.request.ts rename to Transport/@stateflows/common/src/events/behavior-status.request.ts diff --git a/Transport/@stateflows/signalr-client/src/events/behavior-status.response.ts b/Transport/@stateflows/common/src/events/behavior-status.response.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/events/behavior-status.response.ts rename to Transport/@stateflows/common/src/events/behavior-status.response.ts diff --git a/Transport/@stateflows/signalr-client/src/events/current-state.request.ts b/Transport/@stateflows/common/src/events/current-state.request.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/events/current-state.request.ts rename to Transport/@stateflows/common/src/events/current-state.request.ts diff --git a/Transport/@stateflows/signalr-client/src/events/current-state.response.ts b/Transport/@stateflows/common/src/events/current-state.response.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/events/current-state.response.ts rename to Transport/@stateflows/common/src/events/current-state.response.ts diff --git a/Transport/@stateflows/signalr-client/src/events/event.ts b/Transport/@stateflows/common/src/events/event.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/events/event.ts rename to Transport/@stateflows/common/src/events/event.ts diff --git a/Transport/@stateflows/signalr-client/src/events/initialization.request.ts b/Transport/@stateflows/common/src/events/initialization.request.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/events/initialization.request.ts rename to Transport/@stateflows/common/src/events/initialization.request.ts diff --git a/Transport/@stateflows/signalr-client/src/events/initialization.response.ts b/Transport/@stateflows/common/src/events/initialization.response.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/events/initialization.response.ts rename to Transport/@stateflows/common/src/events/initialization.response.ts diff --git a/Transport/@stateflows/signalr-client/src/events/plant-uml.request.ts b/Transport/@stateflows/common/src/events/plant-uml.request.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/events/plant-uml.request.ts rename to Transport/@stateflows/common/src/events/plant-uml.request.ts diff --git a/Transport/@stateflows/signalr-client/src/events/plant-uml.response.ts b/Transport/@stateflows/common/src/events/plant-uml.response.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/events/plant-uml.response.ts rename to Transport/@stateflows/common/src/events/plant-uml.response.ts diff --git a/Transport/@stateflows/signalr-client/src/events/request.ts b/Transport/@stateflows/common/src/events/request.ts similarity index 81% rename from Transport/@stateflows/signalr-client/src/events/request.ts rename to Transport/@stateflows/common/src/events/request.ts index 3bb3bb37..061bd99d 100644 --- a/Transport/@stateflows/signalr-client/src/events/request.ts +++ b/Transport/@stateflows/common/src/events/request.ts @@ -2,5 +2,5 @@ import { Response } from "./response"; import { Event } from "./event"; export class Request extends Event { - + public Response: TResponse; } \ No newline at end of file diff --git a/Transport/@stateflows/signalr-client/src/events/response.ts b/Transport/@stateflows/common/src/events/response.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/events/response.ts rename to Transport/@stateflows/common/src/events/response.ts diff --git a/Transport/@stateflows/signalr-client/src/ids/activity.id.ts b/Transport/@stateflows/common/src/ids/activity.id.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/ids/activity.id.ts rename to Transport/@stateflows/common/src/ids/activity.id.ts diff --git a/Transport/@stateflows/signalr-client/src/ids/behavior.class.ts b/Transport/@stateflows/common/src/ids/behavior.class.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/ids/behavior.class.ts rename to Transport/@stateflows/common/src/ids/behavior.class.ts diff --git a/Transport/@stateflows/signalr-client/src/ids/behavior.id.ts b/Transport/@stateflows/common/src/ids/behavior.id.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/ids/behavior.id.ts rename to Transport/@stateflows/common/src/ids/behavior.id.ts diff --git a/Transport/@stateflows/signalr-client/src/ids/state-machine.id.ts b/Transport/@stateflows/common/src/ids/state-machine.id.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/ids/state-machine.id.ts rename to Transport/@stateflows/common/src/ids/state-machine.id.ts diff --git a/Transport/@stateflows/common/src/index.ts b/Transport/@stateflows/common/src/index.ts new file mode 100644 index 00000000..09c916f2 --- /dev/null +++ b/Transport/@stateflows/common/src/index.ts @@ -0,0 +1,31 @@ +export { StateflowsClient } from "./classes/stateflows-client"; +export { SendResult } from "./classes/send-result"; +export { RequestResult } from "./classes/request-result"; +export { BehaviorClass } from "./ids/behavior.class"; +export { BehaviorId } from "./ids/behavior.id"; +export { StateMachineId } from "./ids/state-machine.id"; +export { ActivityId } from "./ids/activity.id"; +export { Event } from "./events/event"; +export { Request } from "./events/request"; +export { InitializationRequest } from "./events/initialization.request"; +export { InitializationResponse } from "./events/initialization.response"; +export { Response } from "./events/response"; +export { BehaviorStatusRequest } from "./events/behavior-status.request"; +export { BehaviorStatusResponse } from "./events/behavior-status.response"; +export { PlantUmlRequest } from "./events/plant-uml.request"; +export { PlantUmlResponse } from "./events/plant-uml.response"; +export { IBehaviorLocator } from "./interfaces/behavior.locator"; +export { IBehavior } from "./interfaces/behavior"; +export { ISystem } from "./interfaces/system"; +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 { EventStatus } from "./enums/event-status"; +export { BehaviorStatus } from "./enums/behavior-status"; +export { AvailableBehaviorClassesRequest } from "./events/available-behavior-classes.request"; +export { AvailableBehaviorClassesResponse } from "./events/available-behavior-classes.response"; +export { BehaviorInstancesRequest } from "./events/behavior-instances.request"; +export { BehaviorInstancesResponse } from "./events/behavior-instances.response"; +export { IStateflowsClientTransport } from "./interfaces/stateflows-client-transport"; +export { IStateflowsClientTransportFactory } from "./interfaces/stateflows-client-transport-factory"; diff --git a/Transport/@stateflows/signalr-client/src/interfaces/activity.locator.ts b/Transport/@stateflows/common/src/interfaces/activity.locator.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/interfaces/activity.locator.ts rename to Transport/@stateflows/common/src/interfaces/activity.locator.ts diff --git a/Transport/@stateflows/signalr-client/src/interfaces/activity.ts b/Transport/@stateflows/common/src/interfaces/activity.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/interfaces/activity.ts rename to Transport/@stateflows/common/src/interfaces/activity.ts diff --git a/Transport/@stateflows/signalr-client/src/interfaces/behavior.locator.ts b/Transport/@stateflows/common/src/interfaces/behavior.locator.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/interfaces/behavior.locator.ts rename to Transport/@stateflows/common/src/interfaces/behavior.locator.ts diff --git a/Transport/@stateflows/signalr-client/src/interfaces/behavior.ts b/Transport/@stateflows/common/src/interfaces/behavior.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/interfaces/behavior.ts rename to Transport/@stateflows/common/src/interfaces/behavior.ts diff --git a/Transport/@stateflows/signalr-client/src/interfaces/state-machine.locator.ts b/Transport/@stateflows/common/src/interfaces/state-machine.locator.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/interfaces/state-machine.locator.ts rename to Transport/@stateflows/common/src/interfaces/state-machine.locator.ts diff --git a/Transport/@stateflows/signalr-client/src/interfaces/state-machine.ts b/Transport/@stateflows/common/src/interfaces/state-machine.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/interfaces/state-machine.ts rename to Transport/@stateflows/common/src/interfaces/state-machine.ts diff --git a/Transport/@stateflows/common/src/interfaces/stateflows-client-transport-factory.ts b/Transport/@stateflows/common/src/interfaces/stateflows-client-transport-factory.ts new file mode 100644 index 00000000..bac47a14 --- /dev/null +++ b/Transport/@stateflows/common/src/interfaces/stateflows-client-transport-factory.ts @@ -0,0 +1,5 @@ +import { IStateflowsClientTransport } from "./stateflows-client-transport"; + +export interface IStateflowsClientTransportFactory { + getTransport(): Promise; +} \ No newline at end of file diff --git a/Transport/@stateflows/common/src/interfaces/stateflows-client-transport.ts b/Transport/@stateflows/common/src/interfaces/stateflows-client-transport.ts new file mode 100644 index 00000000..ca7c1710 --- /dev/null +++ b/Transport/@stateflows/common/src/interfaces/stateflows-client-transport.ts @@ -0,0 +1,9 @@ +import { SendResult } from "../classes/send-result"; +import { Event } from "../events/event"; +import { BehaviorClass } from "../ids/behavior.class"; +import { BehaviorId } from "../ids/behavior.id"; + +export interface IStateflowsClientTransport { + getAvailableClasses(): Promise; + send(behaviorId: BehaviorId, event: Event): Promise; +} \ No newline at end of file diff --git a/Transport/@stateflows/signalr-client/src/interfaces/system.ts b/Transport/@stateflows/common/src/interfaces/system.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/interfaces/system.ts rename to Transport/@stateflows/common/src/interfaces/system.ts diff --git a/Transport/@stateflows/signalr-client/src/locators/activity.locator.ts b/Transport/@stateflows/common/src/locators/activity.locator.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/locators/activity.locator.ts rename to Transport/@stateflows/common/src/locators/activity.locator.ts diff --git a/Transport/@stateflows/signalr-client/src/locators/behavior.locator.ts b/Transport/@stateflows/common/src/locators/behavior.locator.ts similarity index 53% rename from Transport/@stateflows/signalr-client/src/locators/behavior.locator.ts rename to Transport/@stateflows/common/src/locators/behavior.locator.ts index 924120b0..795081c3 100644 --- a/Transport/@stateflows/signalr-client/src/locators/behavior.locator.ts +++ b/Transport/@stateflows/common/src/locators/behavior.locator.ts @@ -1,50 +1,37 @@ -import { HubConnection, HubConnectionState } from "@microsoft/signalr"; import { Behavior } from "../behaviors/behavior"; import { BehaviorClass } from "../ids/behavior.class"; import { BehaviorId } from "../ids/behavior.id"; import { IBehavior } from "../interfaces/behavior"; import { IBehaviorLocator } from "../interfaces/behavior.locator"; +import { IStateflowsClientTransport } from "../interfaces/stateflows-client-transport"; export class BehaviorLocator implements IBehaviorLocator { private behaviorClasses: BehaviorClass[] = []; - private hubPromise: Promise; + private transportPromise: Promise; - constructor(hubPromise: Promise) { - this.hubPromise = new Promise((resolve, reject) => { - hubPromise - .then(hub => { - hub.invoke('GetAvailableClasses').then(result => { + constructor(transportPromise: Promise) { + this.transportPromise = new Promise((resolve, reject) => { + transportPromise + .then(transport => { + transport.getAvailableClasses().then(result => { this.behaviorClasses = result; - console.log(result); - resolve(hub); + resolve(transport); }); }) .catch(reason => reject(reason)); }); } - private getHubReconnectionPromise(hub: HubConnection): Promise { - return new Promise(async (resolve, reject) => { - if (hub.state != HubConnectionState.Connected) { - hub.start() - .then(() => resolve(hub)) - .catch(reason => reject(reason)); - } else { - resolve(hub); - } - }); - } - locateBehavior(behaviorId: BehaviorId): Promise { return new Promise((resolve, reject) => { - this.hubPromise + this.transportPromise .then(hub => { if (this.behaviorClasses.findIndex(behaviorClass => behaviorClass.type === behaviorId.behaviorClass.type && behaviorClass.name === behaviorId.behaviorClass.name ) !== -1) { - resolve(new Behavior(this.getHubReconnectionPromise(hub), behaviorId)); + resolve(new Behavior(this.transportPromise, behaviorId)); } else { diff --git a/Transport/@stateflows/signalr-client/src/locators/state-machine.locator.ts b/Transport/@stateflows/common/src/locators/state-machine.locator.ts similarity index 100% rename from Transport/@stateflows/signalr-client/src/locators/state-machine.locator.ts rename to Transport/@stateflows/common/src/locators/state-machine.locator.ts diff --git a/Transport/@stateflows/common/tsup.config.ts b/Transport/@stateflows/common/tsup.config.ts new file mode 100644 index 00000000..0f43d975 --- /dev/null +++ b/Transport/@stateflows/common/tsup.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from "tsup"; + +export default defineConfig({ + entry: ["src/index.ts"], + format: ["cjs", "esm"], + dts: true, + splitting: false, + sourcemap: true, + clean: true, +}); \ No newline at end of file diff --git a/Transport/@stateflows/http-client/dist/index.d.mts b/Transport/@stateflows/http-client/dist/index.d.mts new file mode 100644 index 00000000..336cbd3b --- /dev/null +++ b/Transport/@stateflows/http-client/dist/index.d.mts @@ -0,0 +1,5 @@ +import { IStateflowsClientTransportFactory } from '@stateflows/common'; + +declare function UseHttp(url: string): IStateflowsClientTransportFactory; + +export { UseHttp }; diff --git a/Transport/@stateflows/http-client/dist/index.d.ts b/Transport/@stateflows/http-client/dist/index.d.ts new file mode 100644 index 00000000..336cbd3b --- /dev/null +++ b/Transport/@stateflows/http-client/dist/index.d.ts @@ -0,0 +1,5 @@ +import { IStateflowsClientTransportFactory } from '@stateflows/common'; + +declare function UseHttp(url: string): IStateflowsClientTransportFactory; + +export { UseHttp }; diff --git a/Transport/@stateflows/http-client/dist/index.js b/Transport/@stateflows/http-client/dist/index.js new file mode 100644 index 00000000..63f53427 --- /dev/null +++ b/Transport/@stateflows/http-client/dist/index.js @@ -0,0 +1,2 @@ +var l=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var u=(e,t)=>{for(var s in t)l(e,s,{get:t[s],enumerable:!0})},C=(e,t,s,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of v(t))!d.call(e,n)&&n!==s&&l(e,n,{get:()=>t[n],enumerable:!(r=w(t,n))||r.enumerable});return e};var g=e=>C(l({},"__esModule",{value:!0}),e);var y={};u(y,{UseHttp:()=>f});module.exports=g(y);var c=require("@stateflows/common"),a=class{constructor(t){this.url=t;t.slice(-1)!="/"&&(t=t+"/")}getAvailableClasses(){return new Promise(async(t,s)=>{fetch(`${this.url}stateflows/availableClasses`).then(async r=>t(await r.json())).catch(r=>s(r))})}send(t,s){return new Promise(async(r,n)=>{fetch(`${this.url}stateflows/send`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({behaviorIdString:JSON.stringify(t),eventString:JSON.stringify(s)})}).then(async o=>{let i=await o.json(),S=JSON.parse(i.responseString),h=JSON.parse(i.validationString);s.Response=S;let m=new c.SendResult(s,i.eventStatus,h);r(m)}).catch(o=>n(o))})}};var p=class{constructor(t){this.url=t}getTransport(){return Promise.resolve(new a(this.url))}};function f(e){return new p(e)}0&&(module.exports={UseHttp}); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/Transport/@stateflows/http-client/dist/index.js.map b/Transport/@stateflows/http-client/dist/index.js.map new file mode 100644 index 00000000..60bb0daf --- /dev/null +++ b/Transport/@stateflows/http-client/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/index.ts","../src/classes/http-transport.ts","../src/classes/http-transport-factory.ts"],"sourcesContent":["export { UseHttp } from \"./classes/http-transport-factory\";","import { Event, BehaviorClass, BehaviorId, IStateflowsClientTransport, SendResult } from \"@stateflows/common\";\r\n\r\nexport class HttpTransport implements IStateflowsClientTransport {\r\n constructor(private url: string) {\r\n if (url.slice(-1) != '/') {\r\n url = url + '/';\r\n }\r\n }\r\n\r\n getAvailableClasses(): Promise {\r\n return new Promise(async (resolve, reject) => {\r\n fetch(`${this.url}stateflows/availableClasses`)\r\n .then(async result => resolve(await result.json() as BehaviorClass[]))\r\n .catch(reason => reject(reason));\r\n });\r\n }\r\n \r\n send(behaviorId: BehaviorId, event: Event): Promise {\r\n return new Promise(async (resolve, reject) => {\r\n fetch(\r\n `${this.url}stateflows/send`,\r\n {\r\n method: \"POST\",\r\n headers: {\r\n 'Accept': 'application/json',\r\n 'Content-Type': 'application/json'\r\n },\r\n body: JSON.stringify({\r\n behaviorIdString: JSON.stringify(behaviorId),\r\n eventString: JSON.stringify(event)\r\n })\r\n }\r\n )\r\n .then(async result => {\r\n let stateflowsResponse = await result.json();\r\n let response = JSON.parse(stateflowsResponse.responseString);\r\n let validation = JSON.parse(stateflowsResponse.validationString);\r\n (event as any).Response = response;\r\n\r\n let sendResult = new SendResult(event, stateflowsResponse.eventStatus, validation);\r\n\r\n resolve(sendResult);\r\n })\r\n .catch(reason => reject(reason));\r\n });\r\n }\r\n}","import { IStateflowsClientTransport, IStateflowsClientTransportFactory } from \"@stateflows/common\";\r\nimport { HttpTransport } from \"./http-transport\";\r\n\r\nexport class HttpTransportFactory implements IStateflowsClientTransportFactory {\r\n constructor(private url: string) {}\r\n\r\n getTransport(): Promise {\r\n return Promise.resolve(new HttpTransport(this.url));\r\n }\r\n}\r\n\r\nexport function UseHttp(url: string): IStateflowsClientTransportFactory {\r\n return new HttpTransportFactory(url);\r\n}"],"mappings":"4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAyF,8BAE5EC,EAAN,KAA0D,CAC7D,YAAoBC,EAAa,CAAb,SAAAA,EACZA,EAAI,MAAM,EAAE,GAAK,MACjBA,EAAMA,EAAM,IAEpB,CAEA,qBAAgD,CAC5C,OAAO,IAAI,QAAyB,MAAOC,EAASC,IAAW,CAC3D,MAAM,GAAG,KAAK,GAAG,6BAA6B,EACzC,KAAK,MAAMC,GAAUF,EAAQ,MAAME,EAAO,KAAK,CAAoB,CAAC,EACpE,MAAMC,GAAUF,EAAOE,CAAM,CAAC,CACvC,CAAC,CACL,CAEA,KAAKC,EAAwBC,EAAmC,CAC5D,OAAO,IAAI,QAAoB,MAAOL,EAASC,IAAW,CACtD,MACI,GAAG,KAAK,GAAG,kBACX,CACI,OAAQ,OACR,QAAS,CACL,OAAU,mBACV,eAAgB,kBACpB,EACA,KAAM,KAAK,UAAU,CACjB,iBAAkB,KAAK,UAAUG,CAAU,EAC3C,YAAa,KAAK,UAAUC,CAAK,CACrC,CAAC,CACL,CACJ,EACK,KAAK,MAAMH,GAAU,CAClB,IAAII,EAAqB,MAAMJ,EAAO,KAAK,EACvCK,EAAW,KAAK,MAAMD,EAAmB,cAAc,EACvDE,EAAa,KAAK,MAAMF,EAAmB,gBAAgB,EAC9DD,EAAc,SAAWE,EAE1B,IAAIE,EAAa,IAAI,aAAWJ,EAAOC,EAAmB,YAAaE,CAAU,EAEjFR,EAAQS,CAAU,CACtB,CAAC,EACA,MAAMN,GAAUF,EAAOE,CAAM,CAAC,CACvC,CAAC,CACL,CACJ,EC3CO,IAAMO,EAAN,KAAwE,CAC3E,YAAoBC,EAAa,CAAb,SAAAA,CAAc,CAElC,cAAoD,CAChD,OAAO,QAAQ,QAAQ,IAAIC,EAAc,KAAK,GAAG,CAAC,CACtD,CACJ,EAEO,SAASC,EAAQF,EAAgD,CACpE,OAAO,IAAID,EAAqBC,CAAG,CACvC","names":["src_exports","__export","UseHttp","__toCommonJS","import_common","HttpTransport","url","resolve","reject","result","reason","behaviorId","event","stateflowsResponse","response","validation","sendResult","HttpTransportFactory","url","HttpTransport","UseHttp"]} \ No newline at end of file diff --git a/Transport/@stateflows/http-client/dist/index.mjs b/Transport/@stateflows/http-client/dist/index.mjs new file mode 100644 index 00000000..b6037a47 --- /dev/null +++ b/Transport/@stateflows/http-client/dist/index.mjs @@ -0,0 +1,2 @@ +import{SendResult as S}from"@stateflows/common";var r=class{constructor(t){this.url=t;t.slice(-1)!="/"&&(t=t+"/")}getAvailableClasses(){return new Promise(async(t,e)=>{fetch(`${this.url}stateflows/availableClasses`).then(async s=>t(await s.json())).catch(s=>e(s))})}send(t,e){return new Promise(async(s,l)=>{fetch(`${this.url}stateflows/send`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({behaviorIdString:JSON.stringify(t),eventString:JSON.stringify(e)})}).then(async a=>{let o=await a.json(),p=JSON.parse(o.responseString),c=JSON.parse(o.validationString);e.Response=p;let f=new S(e,o.eventStatus,c);s(f)}).catch(a=>l(a))})}};var i=class{constructor(t){this.url=t}getTransport(){return Promise.resolve(new r(this.url))}};function h(n){return new i(n)}export{h as UseHttp}; +//# sourceMappingURL=index.mjs.map \ No newline at end of file diff --git a/Transport/@stateflows/http-client/dist/index.mjs.map b/Transport/@stateflows/http-client/dist/index.mjs.map new file mode 100644 index 00000000..4a045ea1 --- /dev/null +++ b/Transport/@stateflows/http-client/dist/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/classes/http-transport.ts","../src/classes/http-transport-factory.ts"],"sourcesContent":["import { Event, BehaviorClass, BehaviorId, IStateflowsClientTransport, SendResult } from \"@stateflows/common\";\r\n\r\nexport class HttpTransport implements IStateflowsClientTransport {\r\n constructor(private url: string) {\r\n if (url.slice(-1) != '/') {\r\n url = url + '/';\r\n }\r\n }\r\n\r\n getAvailableClasses(): Promise {\r\n return new Promise(async (resolve, reject) => {\r\n fetch(`${this.url}stateflows/availableClasses`)\r\n .then(async result => resolve(await result.json() as BehaviorClass[]))\r\n .catch(reason => reject(reason));\r\n });\r\n }\r\n \r\n send(behaviorId: BehaviorId, event: Event): Promise {\r\n return new Promise(async (resolve, reject) => {\r\n fetch(\r\n `${this.url}stateflows/send`,\r\n {\r\n method: \"POST\",\r\n headers: {\r\n 'Accept': 'application/json',\r\n 'Content-Type': 'application/json'\r\n },\r\n body: JSON.stringify({\r\n behaviorIdString: JSON.stringify(behaviorId),\r\n eventString: JSON.stringify(event)\r\n })\r\n }\r\n )\r\n .then(async result => {\r\n let stateflowsResponse = await result.json();\r\n let response = JSON.parse(stateflowsResponse.responseString);\r\n let validation = JSON.parse(stateflowsResponse.validationString);\r\n (event as any).Response = response;\r\n\r\n let sendResult = new SendResult(event, stateflowsResponse.eventStatus, validation);\r\n\r\n resolve(sendResult);\r\n })\r\n .catch(reason => reject(reason));\r\n });\r\n }\r\n}","import { IStateflowsClientTransport, IStateflowsClientTransportFactory } from \"@stateflows/common\";\r\nimport { HttpTransport } from \"./http-transport\";\r\n\r\nexport class HttpTransportFactory implements IStateflowsClientTransportFactory {\r\n constructor(private url: string) {}\r\n\r\n getTransport(): Promise {\r\n return Promise.resolve(new HttpTransport(this.url));\r\n }\r\n}\r\n\r\nexport function UseHttp(url: string): IStateflowsClientTransportFactory {\r\n return new HttpTransportFactory(url);\r\n}"],"mappings":"AAAA,OAAuE,cAAAA,MAAkB,qBAElF,IAAMC,EAAN,KAA0D,CAC7D,YAAoBC,EAAa,CAAb,SAAAA,EACZA,EAAI,MAAM,EAAE,GAAK,MACjBA,EAAMA,EAAM,IAEpB,CAEA,qBAAgD,CAC5C,OAAO,IAAI,QAAyB,MAAOC,EAASC,IAAW,CAC3D,MAAM,GAAG,KAAK,GAAG,6BAA6B,EACzC,KAAK,MAAMC,GAAUF,EAAQ,MAAME,EAAO,KAAK,CAAoB,CAAC,EACpE,MAAMC,GAAUF,EAAOE,CAAM,CAAC,CACvC,CAAC,CACL,CAEA,KAAKC,EAAwBC,EAAmC,CAC5D,OAAO,IAAI,QAAoB,MAAOL,EAASC,IAAW,CACtD,MACI,GAAG,KAAK,GAAG,kBACX,CACI,OAAQ,OACR,QAAS,CACL,OAAU,mBACV,eAAgB,kBACpB,EACA,KAAM,KAAK,UAAU,CACjB,iBAAkB,KAAK,UAAUG,CAAU,EAC3C,YAAa,KAAK,UAAUC,CAAK,CACrC,CAAC,CACL,CACJ,EACK,KAAK,MAAMH,GAAU,CAClB,IAAII,EAAqB,MAAMJ,EAAO,KAAK,EACvCK,EAAW,KAAK,MAAMD,EAAmB,cAAc,EACvDE,EAAa,KAAK,MAAMF,EAAmB,gBAAgB,EAC9DD,EAAc,SAAWE,EAE1B,IAAIE,EAAa,IAAIZ,EAAWQ,EAAOC,EAAmB,YAAaE,CAAU,EAEjFR,EAAQS,CAAU,CACtB,CAAC,EACA,MAAMN,GAAUF,EAAOE,CAAM,CAAC,CACvC,CAAC,CACL,CACJ,EC3CO,IAAMO,EAAN,KAAwE,CAC3E,YAAoBC,EAAa,CAAb,SAAAA,CAAc,CAElC,cAAoD,CAChD,OAAO,QAAQ,QAAQ,IAAIC,EAAc,KAAK,GAAG,CAAC,CACtD,CACJ,EAEO,SAASC,EAAQF,EAAgD,CACpE,OAAO,IAAID,EAAqBC,CAAG,CACvC","names":["SendResult","HttpTransport","url","resolve","reject","result","reason","behaviorId","event","stateflowsResponse","response","validation","sendResult","HttpTransportFactory","url","HttpTransport","UseHttp"]} \ No newline at end of file diff --git a/Transport/@stateflows/http-client/package.json b/Transport/@stateflows/http-client/package.json new file mode 100644 index 00000000..dd486f43 --- /dev/null +++ b/Transport/@stateflows/http-client/package.json @@ -0,0 +1,33 @@ +{ + "name": "@stateflows/http-client", + "version": "0.9.0", + "description": "HTTP-based client for Stateflows framework", + "main": "dist/index.js", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "files": [ + "dist" + ], + "scripts": { + "build": "tsup", + "build:dev": "tsup --watch", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "Stateflows", + "state-machine", + "activity", + "workflow" + ], + "author": "Stateflows", + "license": "MIT", + "homepage": "https://www.stateflows.net", + "dependencies": { + "@microsoft/signalr": "^8.0.0", + "@stateflows/common": "^0.9.0" + }, + "devDependencies": { + "tsup": "^8.0.1", + "typescript": "^5.3.3" + } +} diff --git a/Transport/@stateflows/http-client/src/classes/http-transport-factory.ts b/Transport/@stateflows/http-client/src/classes/http-transport-factory.ts new file mode 100644 index 00000000..a6e73319 --- /dev/null +++ b/Transport/@stateflows/http-client/src/classes/http-transport-factory.ts @@ -0,0 +1,14 @@ +import { IStateflowsClientTransport, IStateflowsClientTransportFactory } from "@stateflows/common"; +import { HttpTransport } from "./http-transport"; + +export class HttpTransportFactory implements IStateflowsClientTransportFactory { + constructor(private url: string) {} + + getTransport(): Promise { + return Promise.resolve(new HttpTransport(this.url)); + } +} + +export function UseHttp(url: string): IStateflowsClientTransportFactory { + return new HttpTransportFactory(url); +} \ No newline at end of file diff --git a/Transport/@stateflows/http-client/src/classes/http-transport.ts b/Transport/@stateflows/http-client/src/classes/http-transport.ts new file mode 100644 index 00000000..e1872dbb --- /dev/null +++ b/Transport/@stateflows/http-client/src/classes/http-transport.ts @@ -0,0 +1,47 @@ +import { Event, BehaviorClass, BehaviorId, IStateflowsClientTransport, SendResult } from "@stateflows/common"; + +export class HttpTransport implements IStateflowsClientTransport { + constructor(private url: string) { + if (url.slice(-1) != '/') { + url = url + '/'; + } + } + + getAvailableClasses(): Promise { + return new Promise(async (resolve, reject) => { + fetch(`${this.url}stateflows/availableClasses`) + .then(async result => resolve(await result.json() as BehaviorClass[])) + .catch(reason => reject(reason)); + }); + } + + send(behaviorId: BehaviorId, event: Event): Promise { + return new Promise(async (resolve, reject) => { + fetch( + `${this.url}stateflows/send`, + { + method: "POST", + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + behaviorIdString: JSON.stringify(behaviorId), + eventString: JSON.stringify(event) + }) + } + ) + .then(async result => { + let stateflowsResponse = await result.json(); + let response = JSON.parse(stateflowsResponse.responseString); + let validation = JSON.parse(stateflowsResponse.validationString); + (event as any).Response = response; + + let sendResult = new SendResult(event, stateflowsResponse.eventStatus, validation); + + resolve(sendResult); + }) + .catch(reason => reject(reason)); + }); + } +} \ No newline at end of file diff --git a/Transport/@stateflows/http-client/src/index.ts b/Transport/@stateflows/http-client/src/index.ts new file mode 100644 index 00000000..6d49867b --- /dev/null +++ b/Transport/@stateflows/http-client/src/index.ts @@ -0,0 +1 @@ +export { UseHttp } from "./classes/http-transport-factory"; \ No newline at end of file diff --git a/Transport/@stateflows/http-client/tsconfig.json b/Transport/@stateflows/http-client/tsconfig.json new file mode 100644 index 00000000..ffee188b --- /dev/null +++ b/Transport/@stateflows/http-client/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "module": "es2015", + "target": "es2019", + "moduleResolution": "node", + "noImplicitAny": true, + "removeComments": true, + "preserveConstEnums": true, + "sourceMap": true, + "outDir": "dist", + "declaration": true + }, + "include": ["src/**/*"] +} \ No newline at end of file diff --git a/Transport/@stateflows/http-client/tsup.config.ts b/Transport/@stateflows/http-client/tsup.config.ts new file mode 100644 index 00000000..b7fa80ee --- /dev/null +++ b/Transport/@stateflows/http-client/tsup.config.ts @@ -0,0 +1,11 @@ +import { defineConfig } from "tsup"; + +export default defineConfig({ + entry: ["src/index.ts"], + format: ["cjs", "esm"], + dts: true, + splitting: false, + sourcemap: true, + clean: true, + minify: true +}); \ No newline at end of file diff --git a/Transport/@stateflows/signalr-client/package.json b/Transport/@stateflows/signalr-client/package.json index eb88143a..7f93d905 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.8.0", + "version": "0.9.0", "description": "SignalR-based client for Stateflows framework", "main": "dist/index.js", "module": "./dist/index.mjs", @@ -25,10 +25,11 @@ "license": "MIT", "homepage": "https://www.stateflows.net", "dependencies": { - "@microsoft/signalr": "^8.0.0" + "@microsoft/signalr": "^8.0.0", + "@stateflows/common": "^0.9.0" }, "devDependencies": { - "tsup": "^7.3.0", + "tsup": "^8.0.1", "typescript": "^5.3.3" } } diff --git a/Transport/@stateflows/signalr-client/src/classes/signalr-transport-factory.ts b/Transport/@stateflows/signalr-client/src/classes/signalr-transport-factory.ts new file mode 100644 index 00000000..3efd7db8 --- /dev/null +++ b/Transport/@stateflows/signalr-client/src/classes/signalr-transport-factory.ts @@ -0,0 +1,14 @@ +import { IStateflowsClientTransport, IStateflowsClientTransportFactory } from "@stateflows/common"; +import { SignalRTransport } from "./signalr-transport"; + +export class SignalRTransportFactory implements IStateflowsClientTransportFactory { + constructor(private url: string) {} + + getTransport(): Promise { + return Promise.resolve(new SignalRTransport(this.url)); + } +} + +export function UseSignalR(url: string): IStateflowsClientTransportFactory { + return new SignalRTransportFactory(url); +} \ No newline at end of file diff --git a/Transport/@stateflows/signalr-client/src/classes/signalr-transport.ts b/Transport/@stateflows/signalr-client/src/classes/signalr-transport.ts new file mode 100644 index 00000000..4eb7640e --- /dev/null +++ b/Transport/@stateflows/signalr-client/src/classes/signalr-transport.ts @@ -0,0 +1,55 @@ +import { HubConnection, HubConnectionBuilder, HubConnectionState } from "@microsoft/signalr"; +import { BehaviorClass, BehaviorId, IStateflowsClientTransport, SendResult } from "@stateflows/common"; + +export class SignalRTransport implements IStateflowsClientTransport { + #hub: Promise | null = null; + + private get hub(): Promise { + if (this.#hub == null) { + this.#hub = new Promise((resolve, reject) => { + let hub = new HubConnectionBuilder() + .withUrl(this.url + "stateflows_v1") + .build(); + + hub.start().then(() => resolve(hub)); + }); + } + + return this.#hub; + } + + private get reconnectingHub(): Promise { + return new Promise(async (resolve, reject) => { + let hub = await this.hub; + if (hub.state != HubConnectionState.Connected) { + hub.start() + .then(() => resolve(hub)) + .catch(reason => reject(reason)); + } else { + resolve(hub); + } + }); + } + + constructor(private url: string) { + if (url.slice(-1) != '/') { + url = url + '/'; + } + } + + getAvailableClasses(): Promise { + return new Promise(async (resolve, reject) => { + let hub = await this.reconnectingHub; + let result = await hub.invoke('GetAvailableClasses'); + resolve(result); + }); + } + + send(behaviorId: BehaviorId, event: Event): Promise { + return new Promise(async (resolve, reject) => { + let hub = await this.reconnectingHub; + let result = await hub.invoke("Send", behaviorId, JSON.stringify(event)); + resolve(JSON.parse(result)); + }); + } +} \ No newline at end of file diff --git a/Transport/@stateflows/signalr-client/src/index.ts b/Transport/@stateflows/signalr-client/src/index.ts index 09465976..cae5780e 100644 --- a/Transport/@stateflows/signalr-client/src/index.ts +++ b/Transport/@stateflows/signalr-client/src/index.ts @@ -1,27 +1 @@ -export { StateflowsClient } from "./classes/stateflows-client"; -export { BehaviorClass } from "./ids/behavior.class"; -export { BehaviorId } from "./ids/behavior.id"; -export { StateMachineId } from "./ids/state-machine.id"; -export { ActivityId } from "./ids/activity.id"; -export { Event } from "./events/event"; -export { Request } from "./events/request"; -export { InitializationRequest } from "./events/initialization.request"; -export { InitializationResponse } from "./events/initialization.response"; -export { Response } from "./events/response"; -export { BehaviorStatusRequest } from "./events/behavior-status.request"; -export { BehaviorStatusResponse } from "./events/behavior-status.response"; -export { PlantUmlRequest } from "./events/plant-uml.request"; -export { PlantUmlResponse } from "./events/plant-uml.response"; -export { IBehaviorLocator } from "./interfaces/behavior.locator"; -export { IBehavior } from "./interfaces/behavior"; -export { ISystem } from "./interfaces/system"; -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 { EventStatus } from "./enums/event-status"; -export { BehaviorStatus } from "./enums/behavior-status"; -export { AvailableBehaviorClassesRequest } from "./events/available-behavior-classes.request"; -export { AvailableBehaviorClassesResponse } from "./events/available-behavior-classes.response"; -export { BehaviorInstancesRequest } from "./events/behavior-instances.request"; -export { BehaviorInstancesResponse } from "./events/behavior-instances.response"; \ No newline at end of file +export { UseSignalR } from "./classes/signalr-transport-factory"; \ No newline at end of file diff --git a/Transport/Stateflows.Transport.AspNetCore.SignalR.Client/Behavior.cs b/Transport/Stateflows.Transport.AspNetCore.SignalR.Client/Behavior.cs index f9d97908..1150458f 100644 --- a/Transport/Stateflows.Transport.AspNetCore.SignalR.Client/Behavior.cs +++ b/Transport/Stateflows.Transport.AspNetCore.SignalR.Client/Behavior.cs @@ -4,7 +4,7 @@ using Stateflows.Common.Extensions; using Stateflows.Common.Exceptions; -namespace Stateflows.Transport.AspNetCore.SignalR.Client +namespace Stateflows.Transport.SignalR.Client { internal class Behavior : IBehavior { diff --git a/Transport/Stateflows.Transport.AspNetCore.SignalR.Client/BehaviorProvider.cs b/Transport/Stateflows.Transport.AspNetCore.SignalR.Client/BehaviorProvider.cs index 4c8e7f7b..1289dfc5 100644 --- a/Transport/Stateflows.Transport.AspNetCore.SignalR.Client/BehaviorProvider.cs +++ b/Transport/Stateflows.Transport.AspNetCore.SignalR.Client/BehaviorProvider.cs @@ -3,7 +3,7 @@ using Stateflows.Common.Utilities; using Stateflows.Common.Interfaces; -namespace Stateflows.Transport.AspNetCore.SignalR.Client +namespace Stateflows.Transport.SignalR.Client { internal class BehaviorProvider : IBehaviorProvider { diff --git a/Transport/Stateflows.Transport.AspNetCore.SignalR.Client/DependencyInjection.cs b/Transport/Stateflows.Transport.AspNetCore.SignalR.Client/DependencyInjection.cs index 91a71250..ca2f2767 100644 --- a/Transport/Stateflows.Transport.AspNetCore.SignalR.Client/DependencyInjection.cs +++ b/Transport/Stateflows.Transport.AspNetCore.SignalR.Client/DependencyInjection.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Stateflows.Common.Interfaces; using Stateflows.Common.Registration.Interfaces; -using Stateflows.Transport.AspNetCore.SignalR.Client; +using Stateflows.Transport.SignalR.Client; namespace Stateflows { diff --git a/Transport/Stateflows.Transport.AspNetCore.SignalR.Client/Stateflows.Transport.AspNetCore.SignalR.Client.csproj b/Transport/Stateflows.Transport.AspNetCore.SignalR.Client/Stateflows.Transport.AspNetCore.SignalR.Client.csproj index 4ebb134f..23ef2df6 100644 --- a/Transport/Stateflows.Transport.AspNetCore.SignalR.Client/Stateflows.Transport.AspNetCore.SignalR.Client.csproj +++ b/Transport/Stateflows.Transport.AspNetCore.SignalR.Client/Stateflows.Transport.AspNetCore.SignalR.Client.csproj @@ -5,7 +5,7 @@ enable enable Stateflows;state-machine;activity;workflow;SignalR;signal-r - 0.8.0-alpha + $(STATEFLOWS_VERSION) SignalR transport client for Stateflows framework True Stateflows diff --git a/Transport/Stateflows.Transport.AspNetCore.SignalR/DependencyInjection.cs b/Transport/Stateflows.Transport.AspNetCore.SignalR/DependencyInjection.cs index 5eb9dfa7..dd2dd822 100644 --- a/Transport/Stateflows.Transport.AspNetCore.SignalR/DependencyInjection.cs +++ b/Transport/Stateflows.Transport.AspNetCore.SignalR/DependencyInjection.cs @@ -11,7 +11,7 @@ public static class DependencyInjection private static bool hubMapped = false; [DebuggerHidden] - public static IEndpointRouteBuilder MapStateflowsTransportHub(this IEndpointRouteBuilder builder, Action? configureOptions = null) + public static IEndpointRouteBuilder MapStateflowsSignalRTransport(this IEndpointRouteBuilder builder, Action? configureOptions = null) { if (!hubMapped) { diff --git a/Transport/Stateflows.Transport.AspNetCore.SignalR/Stateflows.Transport.AspNetCore.SignalR.csproj b/Transport/Stateflows.Transport.AspNetCore.SignalR/Stateflows.Transport.AspNetCore.SignalR.csproj index 4bc4feb9..c762fc2a 100644 --- a/Transport/Stateflows.Transport.AspNetCore.SignalR/Stateflows.Transport.AspNetCore.SignalR.csproj +++ b/Transport/Stateflows.Transport.AspNetCore.SignalR/Stateflows.Transport.AspNetCore.SignalR.csproj @@ -4,7 +4,7 @@ net6.0 enable enable - 0.8.0-alpha + $(STATEFLOWS_VERSION) SignalR transport for Stateflows framework Stateflows https://www.stateflows.net diff --git a/Transport/Stateflows.Transport.Http.Client/Behavior.cs b/Transport/Stateflows.Transport.Http.Client/Behavior.cs new file mode 100644 index 00000000..2385b068 --- /dev/null +++ b/Transport/Stateflows.Transport.Http.Client/Behavior.cs @@ -0,0 +1,33 @@ +using Stateflows.Common; +using Stateflows.Common.Extensions; + +namespace Stateflows.Transport.Http.Client +{ + internal class Behavior : IBehavior + { + private readonly StateflowsApiClient _apiClient; + + public BehaviorId Id { get; } + + public Behavior(StateflowsApiClient apiClient, BehaviorId id) + { + _apiClient = apiClient; + Id = id; + } + + public async Task SendAsync(TEvent @event) + where TEvent : Event, new() + { + return await _apiClient.SendAsync(Id, @event); + + //return new SendResult(@event, result.Status, result.Validation); + } + + public async Task> RequestAsync(Request request) + where TResponse : Response, new() + { + var result = await SendAsync(request as Event); + return new RequestResult(request, result.Status, result.Validation); + } + } +} diff --git a/Transport/Stateflows.Transport.Http.Client/BehaviorProvider.cs b/Transport/Stateflows.Transport.Http.Client/BehaviorProvider.cs new file mode 100644 index 00000000..5b21aa24 --- /dev/null +++ b/Transport/Stateflows.Transport.Http.Client/BehaviorProvider.cs @@ -0,0 +1,37 @@ +using Stateflows.Common; +using Stateflows.Common.Utilities; +using Stateflows.Common.Interfaces; + +namespace Stateflows.Transport.Http.Client +{ + internal class BehaviorProvider : IBehaviorProvider + { + private readonly StateflowsApiClient _apiClient; + + public BehaviorProvider(StateflowsApiClient apiClient) + { + _apiClient = apiClient; + + Task.Run(async () => + { + BehaviorClasses = await _apiClient.GetAvailableClassesAsync(); + BehaviorClassesChanged?.Invoke(this); + }); + } + + public bool IsLocal => false; + + public IEnumerable BehaviorClasses { get; set; } = new List(); + + public event ActionAsync? BehaviorClassesChanged; + + public bool TryProvideBehavior(BehaviorId id, out IBehavior? behavior) + { + behavior = BehaviorClasses.Any(c => id.BehaviorClass == c) + ? new Behavior(_apiClient, id) + : null; + + return behavior != null; + } + } +} diff --git a/Transport/Stateflows.Transport.Http.Client/DependencyInjection.cs b/Transport/Stateflows.Transport.Http.Client/DependencyInjection.cs new file mode 100644 index 00000000..09c61d88 --- /dev/null +++ b/Transport/Stateflows.Transport.Http.Client/DependencyInjection.cs @@ -0,0 +1,34 @@ +using Microsoft.Extensions.DependencyInjection; +using Stateflows.Common.Interfaces; +using Stateflows.Common.Registration.Interfaces; +using Stateflows.Transport.Http.Client; + +namespace Stateflows +{ + public static class DependencyInjection + { + public static IStateflowsClientBuilder AddHttpTransport(this IStateflowsClientBuilder builder, Func baseUriProvider, Action? clientBuilderAction = null) + { + if (baseUriProvider == null) + throw new ArgumentNullException(nameof(baseUriProvider)); + + + var clientBuilder = builder.ServiceCollection + .AddSingleton(provider => new BehaviorProvider(provider.GetRequiredService())) + .AddHttpClient((provider, client) => client.BaseAddress = baseUriProvider(provider)) + ; + + if (clientBuilder != null) + { + clientBuilderAction?.Invoke(clientBuilder); + } + + return builder; + } + + public static IStateflowsClientBuilder AddHttpTransport(this IStateflowsClientBuilder builder, Func> baseUriProviderAsync, Action? clientBuilderAction = null) + { + return builder.AddHttpTransport(serviceProvider => baseUriProviderAsync(serviceProvider).GetAwaiter().GetResult(), clientBuilderAction); + } + } +} diff --git a/Storage/Stateflows.Storage.EntityFrameworkCore.6.0/Stateflows - Backup.Storage.EntityFrameworkCore.6.0.csproj b/Transport/Stateflows.Transport.Http.Client/Stateflows.Transport.Http.Client.csproj similarity index 58% rename from Storage/Stateflows.Storage.EntityFrameworkCore.6.0/Stateflows - Backup.Storage.EntityFrameworkCore.6.0.csproj rename to Transport/Stateflows.Transport.Http.Client/Stateflows.Transport.Http.Client.csproj index 31b05041..5cdd7fd2 100644 --- a/Storage/Stateflows.Storage.EntityFrameworkCore.6.0/Stateflows - Backup.Storage.EntityFrameworkCore.6.0.csproj +++ b/Transport/Stateflows.Transport.Http.Client/Stateflows.Transport.Http.Client.csproj @@ -1,31 +1,23 @@ - + net6.0 enable enable - Entity Framework Core 6.0 storage for Stateflows framework - 0.7.0-alpha + $(STATEFLOWS_VERSION) + MinimalAPI-based HTTP transport client for Stateflows framework Stateflows https://www.stateflows.net stateflows-logo-1024.png - git + README.md https://github.com/Stateflows/framework - Stateflows;state-machine;activity;workflow;EF;EFCore;EntityFrameworkCore;entity-framework-core + git + Stateflows;state-machine;activity;workflow;MinimalAPI;minimal-api;http;rest True - README.md LICENSE ..\..\NuGet - - $(WarningsAsErrors);NU1605 - - - - $(WarningsAsErrors);NU1605 - - True @@ -42,11 +34,13 @@ - + - + + + diff --git a/Transport/Stateflows.Transport.Http.Client/StateflowsApiClient.cs b/Transport/Stateflows.Transport.Http.Client/StateflowsApiClient.cs new file mode 100644 index 00000000..eff1306a --- /dev/null +++ b/Transport/Stateflows.Transport.Http.Client/StateflowsApiClient.cs @@ -0,0 +1,45 @@ +using System.Net; +using System.Net.Http.Json; +using Stateflows.Common; +using Stateflows.Common.Utilities; +using Stateflows.Common.Extensions; +using Stateflows.Common.Transport.Classes; + +namespace Stateflows.Transport.Http.Client +{ + public class StateflowsApiClient + { + private readonly HttpClient _httpClient; + + public StateflowsApiClient(HttpClient httpClient) + { + _httpClient = httpClient; + } + + public async Task SendAsync(BehaviorId behaviorId, Event @event) + { + var requestResult = await _httpClient.PostAsJsonAsync( + "/stateflows/send", + new StateflowsRequest() { Event = @event, BehaviorId = behaviorId } + ); + if (requestResult.StatusCode == HttpStatusCode.OK) + { + var result = await requestResult.Content.ReadFromJsonAsync(); + if (result != null) + { + if (result.Response != null) + { + @event.Respond(result.Response); + } + + return new SendResult(@event, result.EventStatus, result.Validation); + } + } + + return new SendResult(@event, EventStatus.Rejected); + } + + public async Task> GetAvailableClassesAsync() + => await _httpClient.GetFromJsonAsync>($"/stateflows/availableClasses") ?? Array.Empty(); + } +} \ No newline at end of file diff --git a/Transport/Stateflows.Transport.Http/DependencyInjection.cs b/Transport/Stateflows.Transport.Http/DependencyInjection.cs new file mode 100644 index 00000000..d0af1225 --- /dev/null +++ b/Transport/Stateflows.Transport.Http/DependencyInjection.cs @@ -0,0 +1,63 @@ +using System.Diagnostics; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Routing; +using Microsoft.AspNetCore.Builder; +using Stateflows.Common; +using Stateflows.Common.Interfaces; +using Stateflows.Common.Extensions; +using Stateflows.Common.Transport.Classes; + +namespace Stateflows.Transport.Http +{ + public static class DependencyInjection + { + private static bool apiMapped = false; + + [DebuggerHidden] + public static IEndpointRouteBuilder MapStateflowsHttpTransport(this IEndpointRouteBuilder builder, Action? routeHandlerBuilderAction = null) + { + if (!apiMapped) + { + var routeBuilder = builder.MapPost( + "/stateflows/send", + async ( + StateflowsRequest input, + IBehaviorLocator locator + ) => + { + var behaviorId = new BehaviorId(input.BehaviorId.Type, input.BehaviorId.Name, input.BehaviorId.Instance); + if (locator.TryLocateBehavior(behaviorId, out var behavior)) + { + var result = await behavior.SendAsync(input.Event); + return Results.Ok( + new StateflowsResponse() + { + EventStatus = result.Status, + Validation = result.Validation, + Response = result.Event.GetResponse() + } + ); + } + else + { + return Results.NotFound(); + } + } + ); + + routeHandlerBuilderAction?.Invoke(routeBuilder); + + routeBuilder = builder.MapGet( + "/stateflows/availableClasses", + (IBehaviorClassesProvider provider) => Results.Ok(provider.AllBehaviorClasses) + ); + + routeHandlerBuilderAction?.Invoke(routeBuilder); + + apiMapped = true; + } + + return builder; + } + } +} diff --git a/Transport/Stateflows.Transport.Http/Stateflows.Transport.Http.csproj b/Transport/Stateflows.Transport.Http/Stateflows.Transport.Http.csproj new file mode 100644 index 00000000..c30eb2e6 --- /dev/null +++ b/Transport/Stateflows.Transport.Http/Stateflows.Transport.Http.csproj @@ -0,0 +1,44 @@ + + + + net6.0 + enable + enable + $(STATEFLOWS_VERSION) + MinimalAPI-based HTTP transport for Stateflows framework + Stateflows + https://www.stateflows.net + stateflows-logo-1024.png + README.md + https://github.com/Stateflows/framework + git + Stateflows;state-machine;activity;workflow;MinimalAPI;minimal-api;http;rest + True + LICENSE + ..\..\NuGet + + + + + + + + + True + \ + + + True + \ + + + True + \ + + + + + + + +