Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolaj-milewski committed Feb 12, 2024
2 parents d09eb07 + 267fd41 commit 9d7d573
Show file tree
Hide file tree
Showing 185 changed files with 2,351 additions and 792 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/dotnet-test.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,5 @@ $RECYCLE.BIN/
.angular
Transport/@stateflows/signalr-client/dist/
Examples/SignalR/SignalR.Client/ClientApp/.angular/
*.txt
Publish.ps1
4 changes: 2 additions & 2 deletions Core/Stateflows.Common/Activities/Classes/ActivityClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
9 changes: 8 additions & 1 deletion Core/Stateflows.Common/Activities/Classes/ActivityId.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Stateflows.Common.Exceptions;
using Stateflows.Common.Utilities;

namespace Stateflows.Activities
{
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}
3 changes: 1 addition & 2 deletions Core/Stateflows.Common/Activities/Classes/ActivityLocator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Stateflows.Common;
using Stateflows.Activities;
using Stateflows.Activities;

namespace Stateflows.Common.Activities.Classes
{
Expand Down
9 changes: 0 additions & 9 deletions Core/Stateflows.Common/Classes/ActivityClassFactory.cs

This file was deleted.

4 changes: 2 additions & 2 deletions Core/Stateflows.Common/Classes/BehaviorClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
3 changes: 3 additions & 0 deletions Core/Stateflows.Common/Classes/BehaviorId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions Core/Stateflows.Common/Classes/BehaviorType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 4 additions & 2 deletions Core/Stateflows.Common/Classes/SendResult.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using System;

namespace Stateflows.Common
{
Expand All @@ -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<ValidationResult>());
}

public Event Event { get; set; }
Expand Down
9 changes: 0 additions & 9 deletions Core/Stateflows.Common/Classes/StateMachineClassFactory.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using Newtonsoft.Json;
using Stateflows.Activities;
using Stateflows.Common.Exceptions;
using Stateflows.Common.Utilities;

namespace Stateflows.StateMachines
{
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion Core/Stateflows.Common/Stateflows.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageTags>Stateflows;state-machine;activity;workflow</PackageTags>
<AssemblyVersion></AssemblyVersion>
<FileVersion></FileVersion>
<Version>0.8.1-alpha</Version>
<Version>$(STATEFLOWS_VERSION)</Version>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageOutputPath>..\..\NuGet</PackageOutputPath>
Expand Down
2 changes: 1 addition & 1 deletion Core/Stateflows.Common/Tokens/GroupToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public GroupToken()
{ }

public override string Name
=> $"Stateflows.Activities.GroupToken<{TokenInfo<TToken>.TokenName}>";
=> $"Stateflows.Activities.GroupToken<{TokenInfo<TToken>.Name}>";

public List<TToken> Tokens { get; set; } = new List<TToken>();
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Stateflows.Common/Tokens/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static IEnumerable<TToken> CloneTokens<TToken>(this IEnumerable<TToken> t
public static class TokenInfo<TToken>
where TToken : Token, new()
{
public static string TokenName => TokenInfo.GetName(typeof(TToken));
public static string Name => TokenInfo.GetName(typeof(TToken));
}

public static class TokenInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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++)
Expand All @@ -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<Completion>.Name, sourceStateName, targetVertexName);
=> TransitionEffect(EventInfo<CompletionEvent>.Name, sourceStateName, targetVertexName);

public IExecutionSequenceBuilder DefaultTransitionGuard(string sourceStateName, string targetVertexName)
=> TransitionGuard(EventInfo<Completion>.Name, sourceStateName, targetVertexName);
=> TransitionGuard(EventInfo<CompletionEvent>.Name, sourceStateName, targetVertexName);

public IExecutionSequenceBuilder InternalTransitionEffect(string eventName, string sourceStateName)
=> TransitionEffect(eventName, sourceStateName, "");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Stateflows.Testing.StateMachines.Sequence
#nullable enable

namespace Stateflows.Testing.StateMachines.Sequence
{
public interface IExecutionSequenceBuilder
{
Expand Down
2 changes: 1 addition & 1 deletion Core/Stateflows.Testing/Stateflows.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Version>0.8.1-alpha</Version>
<Version>$(STATEFLOWS_VERSION)</Version>
<Title>Stateflows framework testing utilities</Title>
<Authors>Stateflows</Authors>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
Expand Down
26 changes: 26 additions & 0 deletions Core/Stateflows.Transport.Common/Classes/StateflowsRequest.cs
Original file line number Diff line number Diff line change
@@ -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<Event>(EventString);
set => EventString = StateflowsJsonConverter.SerializePolymorphicObject(value);
}

public string BehaviorIdString { get; set; }

[JsonIgnore]
public BehaviorId BehaviorId
{
get => StateflowsJsonConverter.DeserializeObject<BehaviorId>(BehaviorIdString);
set => BehaviorIdString = StateflowsJsonConverter.SerializePolymorphicObject(value);
}
}
}
28 changes: 28 additions & 0 deletions Core/Stateflows.Transport.Common/Classes/StateflowsResponse.cs
Original file line number Diff line number Diff line change
@@ -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<EventValidation>(ValidationString);
set => ValidationString = StateflowsJsonConverter.SerializePolymorphicObject(value);
}

public string ResponseString { get; set; }

[JsonIgnore]
public Response Response
{
get => StateflowsJsonConverter.DeserializeObject<Response>(ResponseString);
set => ResponseString = StateflowsJsonConverter.SerializePolymorphicObject(value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Title>Stateflows framework transport abstractions</Title>
<Version>0.8.1-alpha</Version>
<Version>$(STATEFLOWS_VERSION)</Version>
<Authors>Stateflows</Authors>
<PackageProjectUrl>https://www.stateflows.net</PackageProjectUrl>
<PackageIcon>stateflows-logo-1024.png</PackageIcon>
Expand Down
6 changes: 6 additions & 0 deletions Core/Stateflows/Activities/Classes/Activity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
10 changes: 10 additions & 0 deletions Core/Stateflows/Activities/Classes/DecisionNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Stateflows.Common;

namespace Stateflows.Activities
{
public sealed class DecisionNode<TToken> : ActivityNode
where TToken : Token, new()
{
public string Name => $"Stateflows.Activities.DecisionNode<{TokenInfo<TToken>.Name}>";
}
}
10 changes: 10 additions & 0 deletions Core/Stateflows/Activities/Classes/IterativeActivityNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Stateflows.Common;

namespace Stateflows.Activities
{
public abstract class IterativeActivityNode<TToken> : StructuredActivityNode<TToken>
where TToken : Token, new()
{
public string Name => $"Stateflows.Activities.IterativeActivityNode<{TokenInfo<TToken>.Name}>";
}
}
7 changes: 7 additions & 0 deletions Core/Stateflows/Activities/Classes/MergeNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Stateflows.Activities
{
public sealed class MergeNode : ActivityNode
{
public const string Name = "Stateflows.Activities.MergeNode";
}
}
10 changes: 10 additions & 0 deletions Core/Stateflows/Activities/Classes/ParalellActivityNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Stateflows.Common;

namespace Stateflows.Activities
{
public abstract class ParallelActivityNode<TToken> : StructuredActivityNode<TToken>
where TToken : Token, new()
{
public string Name => $"Stateflows.Activities.ParallelActivityNode<{TokenInfo<TToken>.Name}>";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public virtual Task OnFinalizeAsync()
=> Task.CompletedTask;
}

public abstract class StructuredActivity<TToken> : StructuredActivityNode
public abstract class StructuredActivityNode<TToken> : StructuredActivityNode
where TToken : Token, new()
{
public new IActionContext<TToken> Context => base.Context as IActionContext<TToken>;
Expand Down
Loading

0 comments on commit 9d7d573

Please sign in to comment.