-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removing mult-targetting and upgrading test projects to core 3.1
- Loading branch information
Showing
31 changed files
with
551 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<LangVersion>7.1</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\REstate.Remote\REstate.Remote.csproj" /> | ||
<ProjectReference Include="..\..\..\REstate\REstate.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Update="SourceLink.Create.CommandLine" Version="2.8.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Grpc.Core; | ||
using REstate; | ||
using REstate.Remote; | ||
using Serilog; | ||
|
||
namespace Client | ||
{ | ||
class Program | ||
{ | ||
static async Task Main(string[] args) | ||
{ | ||
var logger = new LoggerConfiguration() | ||
.MinimumLevel.Information() | ||
.WriteTo.Console() | ||
.CreateLogger(); | ||
|
||
Log.Logger = logger; | ||
|
||
REstateHost.Agent.Configuration | ||
.RegisterComponent(new GrpcRemoteHostComponent( | ||
new GrpcHostOptions | ||
{ | ||
Channel = new Channel("localhost", 12345, ChannelCredentials.Insecure), | ||
UseAsDefaultEngine = true | ||
})); | ||
|
||
var stateEngine = REstateHost.Agent | ||
.GetStateEngine<string, string>(); | ||
|
||
var remoteLoggerSchematic = REstateHost.Agent | ||
.CreateSchematic<string, string>("LoggerMachine") | ||
|
||
.WithState("CreatedAndReady", state => state | ||
.AsInitialState()) | ||
|
||
.WithState("Ready", state => state | ||
.WithTransitionFrom("CreatedAndReady", "log") | ||
.WithReentrance("log") | ||
.WithAction("log info", action => action | ||
.DescribedAs("Logs the payload as a message.") | ||
.WithSetting("messageFormat", "{schematicName}({machineId}) entered {state} on {input}. Message: {payload}") | ||
.OnFailureSend("logFailure"))) | ||
|
||
.WithState("LogFailure", state => state | ||
.AsSubstateOf("Ready") | ||
.DescribedAs("A message failed to log.") | ||
.WithAction("log error", action => action | ||
.DescribedAs("Logs the failure.") | ||
.WithSetting("messageFormat", "Logging failed, message was: {payload}")) | ||
.WithTransitionFrom("Ready", "logFailure")) | ||
|
||
.Build(); | ||
|
||
// Metadata can be attached to each machine (an instance of a schematic). | ||
// e.g. MachineName, or a correlationId of some kind. | ||
var metadata = new Dictionary<string, string> | ||
{ | ||
["MachineName"] = Environment.MachineName | ||
}; | ||
|
||
try | ||
{ | ||
var machine = await stateEngine.CreateMachineAsync(remoteLoggerSchematic, metadata); | ||
|
||
var result = await machine.SendAsync("log", "Hello from client!"); | ||
|
||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Logger.Fatal("An error occured that crashed the app.", ex); | ||
throw; | ||
} | ||
|
||
Console.WriteLine("Press enter to close..."); | ||
Console.ReadLine(); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
examples/Client-Server/Server/Configuration/REstate/ServerConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Server.Configuration.REstate | ||
{ | ||
public class ServerConfiguration | ||
{ | ||
public ServerBinding Binding { get; set; } | ||
|
||
public string RepositoryConnectionString { get; set; } | ||
} | ||
|
||
public class ServerBinding | ||
{ | ||
public string Address { get; set; } | ||
|
||
public int Port { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Grpc.Core; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Configuration.Memory; | ||
using REstate; | ||
using REstate.Engine.Repositories.Redis; | ||
using Serilog; | ||
using Server.Configuration.REstate; | ||
|
||
namespace Server | ||
{ | ||
class Program | ||
{ | ||
static async Task Main(string[] args) | ||
{ | ||
var logger = new LoggerConfiguration() | ||
.MinimumLevel.Verbose() | ||
.WriteTo.Console() | ||
.CreateLogger(); | ||
|
||
Log.Logger = logger; | ||
|
||
var serverShutdownCancellationSource = new CancellationTokenSource(); | ||
|
||
Console.CancelKeyPress += (sender, eventArgs) => | ||
serverShutdownCancellationSource.Cancel(); | ||
|
||
var configuration = new ConfigurationBuilder() | ||
.Add(new MemoryConfigurationSource | ||
{ | ||
InitialData = new Dictionary<string, string> | ||
{ | ||
["REstate:Server:Binding:Address"] = "0.0.0.0", | ||
["REstate:Server:Binding:Port"] = "12345" | ||
} | ||
}) | ||
.AddEnvironmentVariables() | ||
.Build(); | ||
|
||
var serverConfiguration = configuration | ||
.GetSection("REstate:Server") | ||
.Get<ServerConfiguration>(); | ||
|
||
//var redisMultiplexer = await StackExchange.Redis.ConnectionMultiplexer | ||
// .ConnectAsync(serverConfiguration.RepositoryConnectionString); | ||
|
||
//REstateHost.Agent.Configuration | ||
// .RegisterComponent( | ||
// component: new RedisRepositoryComponent( | ||
// restateDatabase: redisMultiplexer.GetDatabase())); | ||
|
||
var server = REstateHost.Agent | ||
.AsRemote() | ||
.CreateGrpcServer(new ServerPort( | ||
host: serverConfiguration.Binding.Address, | ||
port: serverConfiguration.Binding.Port, | ||
credentials: ServerCredentials.Insecure)); | ||
|
||
logger.Information("Starting REstate gRPC server."); | ||
|
||
serverShutdownCancellationSource.Token.Register(() => | ||
server.ShutdownAsync().GetAwaiter().GetResult()); | ||
|
||
while (true) | ||
{ | ||
await server.StartAsync(); | ||
|
||
if (server.ShutdownTask.IsFaulted) | ||
{ | ||
logger.Error("Server ran into a fault, restarting."); | ||
|
||
continue; | ||
} | ||
|
||
break; | ||
} | ||
|
||
logger.Information("Shutdown of REstate gRPC server completed."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<LangVersion>7.1</LangVersion> | ||
<ServerGarbageCollection>true</ServerGarbageCollection> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" /> | ||
<PackageReference Include="StackExchange.Redis" Version="1.2.6" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.1.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.1.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\REstate.Engine.Connectors.AzureServiceBus\REstate.Engine.Connectors.AzureServiceBus.csproj" /> | ||
<ProjectReference Include="..\..\..\REstate.Engine.Repositories.Redis\REstate.Engine.Repositories.Redis.csproj" /> | ||
<ProjectReference Include="..\..\..\REstate.Remote\REstate.Remote.csproj" /> | ||
<ProjectReference Include="..\..\..\REstate\REstate.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Update="SourceLink.Create.CommandLine" Version="2.8.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
12 changes: 12 additions & 0 deletions
12
examples/NaturalSchematicExamples/NaturalSchematicExamples.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\REstate\REstate.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
21 changes: 21 additions & 0 deletions
21
examples/NaturalSchematicExamples/ProvisoningSystem/ProvisioningSystem.Preconditions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using REstate.Natural; | ||
|
||
namespace NaturalSchematicExamples | ||
{ | ||
public partial class ProvisioningSystem | ||
{ | ||
public class NoReservationsRemain | ||
: NaturalPrecondition<DeprovisionSignal> | ||
{ | ||
public override Task<bool> ValidateAsync( | ||
ConnectorContext context, | ||
DeprovisionSignal signal, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return Task.FromResult(true); | ||
} | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
examples/NaturalSchematicExamples/ProvisoningSystem/ProvisioningSystem.Signals.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace NaturalSchematicExamples | ||
{ | ||
public partial class ProvisioningSystem | ||
{ | ||
/// <summary> | ||
/// Categorization interface for signals that are | ||
/// accepted in the <see cref="Provisioned"/> state. | ||
/// </summary> | ||
public interface IProvisionedSignal | ||
{ | ||
} | ||
|
||
public class ReserveSignal : IProvisionedSignal | ||
{ | ||
|
||
} | ||
|
||
public class ReleaseSignal : IProvisionedSignal | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Informs the provisioning system that provisioning has completed. | ||
/// </summary> | ||
public class ProvisioningCompleteSignal : IProvisionedSignal | ||
{ | ||
/// <summary> | ||
/// The initial reservation that triggered provisioning | ||
/// </summary> | ||
public ReserveSignal Reservation { get; set; } | ||
} | ||
|
||
public class DeprovisionSignal | ||
{ | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
examples/NaturalSchematicExamples/ProvisoningSystem/ProvisioningSystem.States.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using REstate; | ||
using REstate.Natural; | ||
|
||
namespace NaturalSchematicExamples | ||
{ | ||
public partial class ProvisioningSystem | ||
{ | ||
[Description("The resource has not yet been provisioned")] | ||
public class Unprovisioned | ||
: StateDefinition | ||
{ | ||
} | ||
|
||
public class Provisioning | ||
: StateDefinition<ReserveSignal> | ||
, INaturalAction<ReserveSignal> | ||
{ | ||
[Description("Provision necessary resource and forwards the Reservation")] | ||
public async Task InvokeAsync( | ||
ConnectorContext context, | ||
ReserveSignal reserveSignal, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
await context.Machine.SignalAsync( | ||
new ProvisioningCompleteSignal | ||
{ | ||
Reservation = reserveSignal | ||
}, | ||
cancellationToken); | ||
} | ||
} | ||
|
||
public class Provisioned | ||
: StateDefinition<IProvisionedSignal> | ||
, INaturalAction<IProvisionedSignal> | ||
{ | ||
[Description("Handle Reservation/Release as a counter")] | ||
public Task InvokeAsync( | ||
ConnectorContext context, | ||
IProvisionedSignal provisionedSignal, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
public class Deprovisioning | ||
: StateDefinition<DeprovisionSignal> | ||
, INaturalAction<DeprovisionSignal> | ||
{ | ||
public Deprovisioning(IAgent agent) | ||
{ | ||
Agent = agent; | ||
} | ||
|
||
public IAgent Agent { get; } | ||
|
||
[Description("Deprovision all resources allocated")] | ||
public async Task InvokeAsync( | ||
ConnectorContext context, | ||
DeprovisionSignal deprovisionSignal, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
await Agent | ||
.GetStateEngine<TypeState, TypeState>() | ||
.DeleteMachineAsync(context.Machine.MachineId, cancellationToken); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.