добавлен бэкенд тест

This commit is contained in:
2025-02-05 14:50:07 +03:00
parent cc5c595948
commit 5e805a28b0
31 changed files with 173 additions and 366 deletions
+58
View File
@@ -0,0 +1,58 @@
using System.Text;
using mROA.Implementation;
namespace Example.Shared;
[SharedObjectInterface]
public interface IPrinterFactory
{
TransmittedSharedObject<IPrinter> Create(string printerName);
}
[SharedObjectSingleton]
public class PrinterFactory : IPrinterFactory
{
public TransmittedSharedObject<IPrinter> Create(string printerName)
{
return new Printer(){Name = printerName};
}
}
[SharedObjectInterface]
public interface IPrinter
{
string GetName();
TransmittedSharedObject<IPage> Print(string text);
}
public class Printer : IPrinter
{
public string Name;
public string GetName()
{
return Name;
}
public TransmittedSharedObject<IPage> Print(string text)
{
return new Page {Text = text};
}
}
[SharedObjectInterface]
public interface IPage
{
byte[] GetData();
}
public class Page : IPage
{
public string Text;
public byte[] GetData()
{
return Encoding.UTF8.GetBytes(Text);
}
}
+1 -1
View File
@@ -3,7 +3,7 @@
"profiles": { "profiles": {
"DebugRoslynSourceGenerator": { "DebugRoslynSourceGenerator": {
"commandName": "DebugRoslynComponent", "commandName": "DebugRoslynComponent",
"targetProject": "../mROA.Example/mROA.Example.csproj" "targetProject": "../Example.Shared/Example.Shared.csproj"
} }
} }
} }
@@ -175,6 +175,7 @@ namespace {Namespace}
var code = $@"// <auto-generated/> var code = $@"// <auto-generated/>
using mROA;
using System; using System;
using mROA.Implementation; using mROA.Implementation;
using System.Collections.Generic; using System.Collections.Generic;
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Codegen")] [assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Codegen")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f51dd93c8755e9e879dfa42a02f470d64a7d711a")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+cc5c595948305981ceadef95889ffeab017dd2b7")]
[assembly: System.Reflection.AssemblyProductAttribute("mROA.Codegen")] [assembly: System.Reflection.AssemblyProductAttribute("mROA.Codegen")]
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Codegen")] [assembly: System.Reflection.AssemblyTitleAttribute("mROA.Codegen")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
-16
View File
@@ -1,16 +0,0 @@
using mROA.Implementation;
namespace mROA.Example;
[SharedObjectInterface]
public interface ITestController
{
void A();
Task AAsync(CancellationToken cancellationToken);
int B();
Task<int> BAsync(CancellationToken cancellationToken);
TransmittedSharedObject<ITestController> SharedObjectTransmitionTest();
int Parametrized(TestParameter parameter);
TransmittedSharedObject<ITestParameter> GetTestParameter();
string Alphabet();
}
-9
View File
@@ -1,9 +0,0 @@
using mROA.Implementation;
namespace mROA.Example;
[SharedObjectInterface]
public interface ITestParameter
{
public int Test();
}
-25
View File
@@ -1,25 +0,0 @@
using System.Runtime.InteropServices;
using mROA.Implementation;
namespace mROA.Example;
public class MainX
{
public static void Main(string[] args)
{
IRemoteObject x;
// CoCodegenMethodRepository a = new CoCodegenMethodRepository();
unsafe
{
}
}
public unsafe byte[] Convert<T>(T input)
{
var size = Marshal.SizeOf(typeof(T));
var place = Marshal.AllocHGlobal(size);
var pt = (T*)place;
return [];
}
}
-52
View File
@@ -1,52 +0,0 @@
using System.Diagnostics.SymbolStore;
using System.Reflection;
using mROA.Implementation;
namespace mROA.Example;
[SharedObjectSingleton]
public class TestController : ITestController
{
public ITestController? ReturnIfNotNull;
private int _bOut = 5;
public void A()
{
Console.WriteLine("A called");
}
public Task AAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
public int B()
{
return _bOut++;
}
public Task<int> BAsync(CancellationToken cancellationToken)
{
return Task.FromResult(5);
}
public TransmittedSharedObject<ITestController> SharedObjectTransmitionTest()
{
return new TransmissionTestController { ReturnIfNotNull = ReturnIfNotNull ?? new TestController() };
}
public int Parametrized(TestParameter parameter)
{
return parameter.A + parameter.LinkedObject.Value.Test();
}
public TransmittedSharedObject<ITestParameter> GetTestParameter()
{
return new TestParameterInstance();
}
public string Alphabet()
{
return "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
}
@@ -1,86 +0,0 @@
// using System.Text.Json;
// using mROA.Implementation;
//
// namespace mROA.Example;
//
// public class TestControllerRemoteEndpoint(int id, ISerialisationModule.IFrontendSerialisationModule serialisationModule)
// : ITestController, IRemoteObject
// {
// public void A()
// {
// serialisationModule.PostCallRequest(new JsonCallRequest { CommandId = 0, ObjectId = id });
// }
//
// public async Task AAsync(CancellationToken cancellationToken)
// {
// var request = new JsonCallRequest { CommandId = 1, ObjectId = id };
// serialisationModule.PostCallRequest(request);
// await serialisationModule.GetNextCommandExecution<FinalCommandExecution>(request.CallRequestId);
// }
//
// public int B()
// {
// TransmissionConfig.SetupBackendRepository();
// var request = new JsonCallRequest { CommandId = 2, ObjectId = id };
// serialisationModule.PostCallRequest(request);
// var response = serialisationModule.GetNextCommandExecution<FinalCommandExecution>(request.CallRequestId)
// .GetAwaiter().GetResult();
// TransmissionConfig.SetupFrontendRepository();
// var convertation = response.Result! is JsonElement e ? e.Deserialize<int>() : (int)response.Result!;
// return convertation;
// }
//
// public async Task<int> BAsync(CancellationToken cancellationToken)
// {
// var request = new JsonCallRequest { CommandId = 3, ObjectId = id };
// serialisationModule.PostCallRequest(request);
// var response = await serialisationModule.GetFinalCommandExecution<int>(request.CallRequestId);
// var convertation = response.Result! is JsonElement e ? e.Deserialize<int>() : (int)response.Result!;
// return convertation;
// }
//
// public TransmittedSharedObject<ITestController> SharedObjectTransmitionTest()
// {
// TransmissionConfig.SetupBackendRepository();
//
// var request = new JsonCallRequest { CommandId = 4, ObjectId = id };
// serialisationModule.PostCallRequest(request);
// var response = serialisationModule.GetNextCommandExecution<FinalCommandExecution>(request.CallRequestId)
// .GetAwaiter().GetResult();
// TransmissionConfig.SetupFrontendRepository();
// var convertation = response.Result! is JsonElement e
// ? e.Deserialize<TransmittedSharedObject<ITestController>>()!
// : (TransmittedSharedObject<ITestController>)response.Result!;
// return convertation;
// }
//
// public int Parametrized(TestParameter parameter)
// {
// var request = new JsonCallRequest { CommandId = 5, ObjectId = id, Parameter = parameter };
// TransmissionConfig.SetupBackendRepository();
//
// serialisationModule.PostCallRequest(request);
// var response = serialisationModule.GetNextCommandExecution<FinalCommandExecution>(request.CallRequestId)
// .GetAwaiter().GetResult();
//
// TransmissionConfig.SetupFrontendRepository();
// var convertation = response.Result! is JsonElement e ? e.Deserialize<int>() : (int)response.Result!;
// return convertation;
// }
//
// public TransmittedSharedObject<ITestParameter> GetTestParameter()
// {
// TransmissionConfig.SetupBackendRepository();
// var request = new JsonCallRequest { CommandId = 6, ObjectId = id };
// serialisationModule.PostCallRequest(request);
// var response = serialisationModule.GetNextCommandExecution<FinalCommandExecution>(request.CallRequestId)
// .GetAwaiter().GetResult();
// TransmissionConfig.SetupFrontendRepository();
// var convertation = response.Result! is JsonElement e
// ? e.Deserialize<TransmittedSharedObject<ITestParameter>>()
// : (TransmittedSharedObject<ITestParameter>)response.Result!;
// return convertation;
// }
//
// public int Id => id;
// }
-9
View File
@@ -1,9 +0,0 @@
using mROA.Implementation;
namespace mROA.Example;
public class TestParameter
{
public int A { get; set; }
public TransmittedSharedObject<ITestParameter> LinkedObject { get; set; }
}
-6
View File
@@ -1,6 +0,0 @@
namespace mROA.Example;
public class TestParameterInstance : ITestParameter
{
public int Test() => 10;
}
@@ -1,20 +0,0 @@
// using System.Text.Json;
// using mROA.Implementation;
//
// namespace mROA.Example;
//
// public class TestParameterRemoteEndpoint(int id, ISerialisationModule.IFrontendSerialisationModule serialisationModule) : ITestParameter, IRemoteObject{
// public int Test()
// {
// var request = new JsonCallRequest { CommandId = 7, ObjectId = id };
// serialisationModule.PostCallRequest(request);
// var response = serialisationModule.GetNextCommandExecution<FinalCommandExecution>(request.CallRequestId)
// .GetAwaiter().GetResult();
// TransmissionConfig.SetupFrontendRepository();
// var convertation = response.Result! is JsonElement e ? e.Deserialize<int>() : (int)response.Result!;
// TransmissionConfig.SetupBackendRepository();
// return convertation;
// }
//
// public int Id => id;
// }
@@ -1,52 +0,0 @@
using mROA.Implementation;
namespace mROA.Example;
public class TransmissionTestController : ITestController
{
public ITestController ReturnIfNotNull;
public void A()
{
Console.WriteLine("A called alternative");
}
public Task AAsync(CancellationToken cancellationToken)
{
Thread.Sleep(500);
return Task.CompletedTask;
}
public int B()
{
return 456789;
}
public Task<int> BAsync(CancellationToken cancellationToken)
{
return Task.FromResult(465789);
}
public TransmittedSharedObject<ITestController> SharedObjectTransmitionTest()
{
TransmittedSharedObject<ITestController> x = new TestController();
return new TestController { ReturnIfNotNull = this };
}
public int Parametrized(TestParameter parameter)
{
return parameter.A * parameter.LinkedObject.Value.Test();
}
public TransmittedSharedObject<ITestParameter> GetTestParameter()
{
return new TestParameterInstance();
}
public string Alphabet()
{
return "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Reverse().ToString();
}
}
-16
View File
@@ -1,16 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\mROA.Codegen\mROA.Codegen.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
<ProjectReference Include="..\mROA\mROA.csproj"/>
</ItemGroup>
</Project>
@@ -1,22 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Example")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f51dd93c8755e9e879dfa42a02f470d64a7d711a")]
[assembly: System.Reflection.AssemblyProductAttribute("mROA.Example")]
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Example")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Создано классом WriteCodeFragment MSBuild.
@@ -1,8 +0,0 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
@@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mikhail\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.12.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\Mikhail\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
</Project>
@@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
+2 -2
View File
@@ -3,7 +3,7 @@ using System.Net.Sockets;
using System.Reflection; using System.Reflection;
using mROA.Abstract; using mROA.Abstract;
using mROA.Codegen; using mROA.Codegen;
using mROA.Example; using Example.Shared;
using mROA.Implementation; using mROA.Implementation;
namespace mROA.Test; namespace mROA.Test;
@@ -32,7 +32,7 @@ public class FrontendFinalTest
_serialisationModule = new JsonSerialisationModule(); _serialisationModule = new JsonSerialisationModule();
_executeModule = new LaunchReadyExecutionModule(); _executeModule = new BasicExecutionModule();
IInjectableModule[] backendModules = [_methodRepository, _contextRepository, _interactionModule, _serialisationModule, _executeModule]; IInjectableModule[] backendModules = [_methodRepository, _contextRepository, _interactionModule, _serialisationModule, _executeModule];
+1 -1
View File
@@ -2,7 +2,7 @@
// using System.Reflection; // using System.Reflection;
// using System.Text; // using System.Text;
// using System.Text.Json; // using System.Text.Json;
// using mROA.Example; // using Example.Shared;
// using mROA.Implementation; // using mROA.Implementation;
// using Newtonsoft.Json; // using Newtonsoft.Json;
// using JsonSerializer = System.Text.Json.JsonSerializer; // using JsonSerializer = System.Text.Json.JsonSerializer;
-1
View File
@@ -27,7 +27,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\mROA.Example\mROA.Example.csproj" />
<ProjectReference Include="..\mROA\mROA.csproj" /> <ProjectReference Include="..\mROA\mROA.csproj" />
</ItemGroup> </ItemGroup>
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Test")] [assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Test")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f51dd93c8755e9e879dfa42a02f470d64a7d711a")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+cc5c595948305981ceadef95889ffeab017dd2b7")]
[assembly: System.Reflection.AssemblyProductAttribute("mROA.Test")] [assembly: System.Reflection.AssemblyProductAttribute("mROA.Test")]
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Test")] [assembly: System.Reflection.AssemblyTitleAttribute("mROA.Test")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
+17 -5
View File
@@ -6,7 +6,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mROA.Test", "mROA.Test\mROA
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mROA.Codegen", "mROA.Codegen\mROA.Codegen.csproj", "{6CE0ED21-88FD-44B3-B9C6-9B8FA4E07E89}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mROA.Codegen", "mROA.Codegen\mROA.Codegen.csproj", "{6CE0ED21-88FD-44B3-B9C6-9B8FA4E07E89}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mROA.Example", "mROA.Example\mROA.Example.csproj", "{5F4EEF2B-A82C-44DA-8995-AF1668A238EC}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Example", "Example", "{EAE92F5A-664C-41AB-8811-5885524B5347}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Backend", "Example.Backend\Example.Backend.csproj", "{A9BB364E-0BA6-40B9-A293-757BC48EFC06}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Shared", "Example.Shared\Example.Shared.csproj", "{E7703F5B-F2A6-4A88-AA57-EBB1E38D533E}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -26,9 +30,17 @@ Global
{6CE0ED21-88FD-44B3-B9C6-9B8FA4E07E89}.Debug|Any CPU.Build.0 = Debug|Any CPU {6CE0ED21-88FD-44B3-B9C6-9B8FA4E07E89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CE0ED21-88FD-44B3-B9C6-9B8FA4E07E89}.Release|Any CPU.ActiveCfg = Release|Any CPU {6CE0ED21-88FD-44B3-B9C6-9B8FA4E07E89}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CE0ED21-88FD-44B3-B9C6-9B8FA4E07E89}.Release|Any CPU.Build.0 = Release|Any CPU {6CE0ED21-88FD-44B3-B9C6-9B8FA4E07E89}.Release|Any CPU.Build.0 = Release|Any CPU
{5F4EEF2B-A82C-44DA-8995-AF1668A238EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A9BB364E-0BA6-40B9-A293-757BC48EFC06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5F4EEF2B-A82C-44DA-8995-AF1668A238EC}.Debug|Any CPU.Build.0 = Debug|Any CPU {A9BB364E-0BA6-40B9-A293-757BC48EFC06}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F4EEF2B-A82C-44DA-8995-AF1668A238EC}.Release|Any CPU.ActiveCfg = Release|Any CPU {A9BB364E-0BA6-40B9-A293-757BC48EFC06}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F4EEF2B-A82C-44DA-8995-AF1668A238EC}.Release|Any CPU.Build.0 = Release|Any CPU {A9BB364E-0BA6-40B9-A293-757BC48EFC06}.Release|Any CPU.Build.0 = Release|Any CPU
{E7703F5B-F2A6-4A88-AA57-EBB1E38D533E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7703F5B-F2A6-4A88-AA57-EBB1E38D533E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7703F5B-F2A6-4A88-AA57-EBB1E38D533E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7703F5B-F2A6-4A88-AA57-EBB1E38D533E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A9BB364E-0BA6-40B9-A293-757BC48EFC06} = {EAE92F5A-664C-41AB-8811-5885524B5347}
{E7703F5B-F2A6-4A88-AA57-EBB1E38D533E} = {EAE92F5A-664C-41AB-8811-5885524B5347}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal
+4 -3
View File
@@ -1,7 +1,8 @@
using mROA.Abstract;
namespace mROA.Implementation; namespace mROA.Implementation;
public interface IGatewayModule : IDisposable public interface IGatewayModule : IDisposable, IInjectableModule
{ {
void Configure(IInteractionModule interactionModule);
void Run(); void Run();
} }
@@ -0,0 +1,40 @@
using System.Net;
using System.Reflection;
using mROA.Implementation.Bootstrap;
namespace mROA.Implementation;
public static class BasicConfigurationExtensions
{
public static void UseJsonSerialisation(this ServerBootstrap bootstrap)
{
bootstrap.Modules.Add(new JsonSerialisationModule());
}
public static void UseNetworkGateway(this ServerBootstrap bootstrap, IPEndPoint endPoint)
{
bootstrap.Modules.Add(new NetworkGatewayModule(endPoint));
}
public static void UseStreamInteraction(this ServerBootstrap bootstrap)
{
bootstrap.Modules.Add(new StreamBasedInteractionModule());
}
public static void UseBasicExecution(this ServerBootstrap bootstrap)
{
bootstrap.Modules.Add(new BasicExecutionModule());
}
public static void UseCollectableContextRepository(this ServerBootstrap bootstrap, params Assembly[] assemblies)
{
var repo = new ContextRepository();
repo.FillSingletons(assemblies);
bootstrap.Modules.Add(repo);
}
public static void SetupMethodsRepository(this ServerBootstrap bootstrap, IMethodRepository methodRepository)
{
bootstrap.Modules.Add(methodRepository);
}
}
@@ -2,7 +2,7 @@
namespace mROA.Implementation; namespace mROA.Implementation;
public class LaunchReadyExecutionModule : IExecuteModule public class BasicExecutionModule : IExecuteModule
{ {
private IMethodRepository _methodRepo; private IMethodRepository _methodRepo;
private ISerialisationModule _serialisationModule; private ISerialisationModule _serialisationModule;
@@ -19,9 +19,9 @@ public class ContextRepository : IContextRepository
_storage = new object[StartupSize]; _storage = new object[StartupSize];
} }
public void FillSingletons(Assembly assembly) public void FillSingletons(params Assembly[] assembly)
{ {
var types = assembly.GetTypes().Where(type => var types = assembly.SelectMany(x => x.GetTypes()).Where(type =>
type is { IsClass: true, IsAbstract: false, IsGenericType: false } && type is { IsClass: true, IsAbstract: false, IsGenericType: false } &&
type.GetCustomAttributes(typeof(SharedObjectSingletonAttribute), true).Length > 0); type.GetCustomAttributes(typeof(SharedObjectSingletonAttribute), true).Length > 0);
_singletons = _singletons =
@@ -1,6 +1,7 @@
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using mROA.Implementation.Bootstrap;
namespace mROA.Implementation; namespace mROA.Implementation;
@@ -13,24 +13,24 @@ public class NetworkGatewayModule : IGatewayModule
_tcpListener = new TcpListener(endpoint); _tcpListener = new TcpListener(endpoint);
} }
public void Configure(IInteractionModule interactionModule)
{
_interactionModule = interactionModule;
}
public void Run() public void Run()
{ {
_tcpListener.Start(); _tcpListener.Start();
Console.WriteLine($"Listening on {_tcpListener.LocalEndpoint}"); Console.WriteLine($"Listening on {_tcpListener.LocalEndpoint}");
Console.WriteLine("Enter Ctrl-C to stop"); Console.WriteLine("Enter Backspace to stop");
Task.Run(HandleIncomingConnections);
while (true) while (true)
{ {
var key = Console.ReadKey(); var key = Console.ReadKey();
if (key.Key == ConsoleKey.C && key.Modifiers == ConsoleModifiers.Control) if (key.Key == ConsoleKey.Backspace)
break; break;
} }
Task.Run(HandleIncomingConnections); Console.WriteLine("Stopping");
} }
public void Dispose() public void Dispose()
@@ -49,4 +49,14 @@ public class NetworkGatewayModule : IGatewayModule
Console.WriteLine("Client registered"); Console.WriteLine("Client registered");
} }
} }
public void Inject<T>(T dependency)
{
if (dependency is IInteractionModule interactionModule)
_interactionModule = interactionModule;
}
public void Bake()
{
}
} }
@@ -0,0 +1,24 @@
using mROA.Abstract;
namespace mROA.Implementation.Bootstrap;
public interface IBootstrap
{
void Build();
}
public class ServerBootstrap : IBootstrap
{
public List<IInjectableModule> Modules { get; private set; } = new();
public void Build()
{
foreach (var module in Modules)
foreach (var injection in Modules)
module.Inject(injection);
}
public T GetModule<T>()
{
return Modules.OfType<T>().FirstOrDefault();
}
}
+1 -1
View File
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA")] [assembly: System.Reflection.AssemblyCompanyAttribute("mROA")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f51dd93c8755e9e879dfa42a02f470d64a7d711a")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+cc5c595948305981ceadef95889ffeab017dd2b7")]
[assembly: System.Reflection.AssemblyProductAttribute("mROA")] [assembly: System.Reflection.AssemblyProductAttribute("mROA")]
[assembly: System.Reflection.AssemblyTitleAttribute("mROA")] [assembly: System.Reflection.AssemblyTitleAttribute("mROA")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]