Skip to content

Commit 40ea02e

Browse files
author
rlovely
committed
Merge master into
2 parents fc921c0 + 231c883 commit 40ea02e

File tree

8 files changed

+74
-15
lines changed

8 files changed

+74
-15
lines changed

.github/workflows/deploy.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This workflow will build a .NET project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3+
4+
name: .NET Deploy
5+
6+
on:
7+
push:
8+
branches: ["master"]
9+
10+
jobs:
11+
build:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: Setup .NET
19+
uses: actions/setup-dotnet@v3
20+
with:
21+
dotnet-version: 7.0.x
22+
23+
- name: Restore dependencies
24+
run: dotnet restore
25+
26+
- name: Build
27+
run: dotnet build --no-restore -c Release
28+
29+
- name: Test
30+
run: dotnet test --verbosity normal
31+
32+
- name: Publish
33+
env:
34+
PUBLISH_KEY: ${{ secrets.PUBLISH_KEY }}
35+
run: dotnet nuget push StateMachine/bin/Release/RoadieRichStateMachine*.nupkg -k $PUBLISH_KEY

.github/workflows/dotnet.yml renamed to .github/workflows/test.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# This workflow will build a .NET project
22
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
33

4-
name: .NET
4+
name: .NET Test
55

66
on:
7-
push:
8-
branches: [ "master" ]
97
pull_request:
10-
branches: [ "master" ]
8+
branches: ["master"]
119

1210
jobs:
1311
build:
@@ -26,8 +24,3 @@ jobs:
2624
run: dotnet build --no-restore
2725
- name: Test
2826
run: dotnet test --no-build --verbosity normal
29-
- name: Upload
30-
uses: actions/upload-artifact@v4
31-
with:
32-
name: RoadieRichStateMachine
33-
path: /home/runner/work/StateMachine/StateMachine/StateMachine/bin/Debug/net7.0/*

StateMachine/Delegates.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
namespace RoadieRichStateMachine
22
{
3+
/// <summary>
4+
/// Determines whether to take a certain transition
5+
/// </summary>
6+
/// <param name="vars">A dictionary of variables shared between all states and transitions</param>
7+
/// <returns>true if the transition should be taken</returns>
38
public delegate bool TransitionConditionDelegate(IDictionary<string, dynamic> vars);
9+
10+
/// <summary>
11+
/// A function run by <see cref="FunctionState"/>
12+
/// </summary>
13+
/// <param name="vars">A dictionary of variables shared between all states and transitions</param>
414
public delegate void FunctionStateFunctionDelegate(IDictionary<string, dynamic> vars);
515
}

StateMachine/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ A simple state machine library. Can use states that are defined using delegates
22

33
```C#
44

5+
```
56
using (StateMachine funcSm = new())
67
{
78
var initFuncState = new FunctionState((vars) => vars["x"] = 0);
@@ -26,4 +27,4 @@ using (StateMachine funcSm = new())
2627
funcSm.InitialState = initFuncState;
2728
funcSm.Run();
2829
}
29-
```
30+
```
Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Library</OutputType>
55
<TargetFramework>net7.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8-
<PackageReadmeFile>README.md</PackageReadmeFile>
8+
<PackageReadmeFile>README.md</PackageReadmeFile>
9+
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
10+
<Title>RoadieRich's State Machine</Title>
11+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
12+
<RepositoryUrl>https://github.com/RoadieRich/StateMachine</RepositoryUrl>
13+
<RepositoryType>git</RepositoryType>
14+
<Authors>RoadieRich</Authors>
15+
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
16+
<Version>1.0.4</Version>
917
</PropertyGroup>
1018

11-
</Project>
19+
<ItemGroup>
20+
<None Include="README.md" Pack="true" PackagePath="" />
21+
</ItemGroup>
22+
23+
</Project>

StateMachine/State.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ public void AddTransitionTo(State to, TransitionConditionDelegate? condition)
1919
transitions.Add(new Transition(to, condition));
2020
}
2121

22-
internal State RunAndGetNextState(IDictionary<string, dynamic> vars)
22+
internal State RunAndGetNextState(int delay, IDictionary<string, dynamic> vars)
2323
{
2424
Enter(vars);
2525
State? next = null;
2626
while (next == null)
2727
{
2828
Inner(vars);
2929
next = GetNextState(vars);
30+
Thread.Sleep(delay);
3031
}
3132
Exit(vars);
3233
return next;

StateMachine/StateMachine.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class StateMachine : IDisposable
1212
/// </summary>
1313
public State InitialState { get; set; } = ExitState;
1414

15+
public int Delay { get; set; } = 0;
16+
1517
/// <summary>
1618
/// If a state's <see cref="Transition"/> points to this state, the state machine is terminated.
1719
/// </summary>
@@ -28,7 +30,7 @@ public void Run(IDictionary<string, dynamic>? vars = null)
2830

2931
while (state != ExitState)
3032
{
31-
state = state.RunAndGetNextState(myVars);
33+
state = state.RunAndGetNextState(Delay, myVars);
3234
}
3335
}
3436

nuget.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<configuration>
2+
<config>
3+
<add key="DefaultPushSource" value="https://api.nuget.org/v3/index.json" protocolVersion="3"/>
4+
</config>
5+
</configuration>

0 commit comments

Comments
 (0)