доп. клинап

This commit is contained in:
2025-02-07 17:23:42 +03:00
parent 82af5df488
commit 51323dbd1b
16 changed files with 40 additions and 66 deletions
+1 -1
View File
@@ -17,7 +17,7 @@
<RepositoryUrl>https://github.com/YaslePoy/mROA</RepositoryUrl> <RepositoryUrl>https://github.com/YaslePoy/mROA</RepositoryUrl>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.0.6</Version> <Version>1.0.7</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -14,7 +14,7 @@ namespace mROA.Codegen;
/// When using the source code as a baseline, an incremental source generator is preferable because it reduces the performance overhead. /// When using the source code as a baseline, an incremental source generator is preferable because it reduces the performance overhead.
/// </summary> /// </summary>
[Generator] [Generator]
public class SampleIncrementalSourceGenerator : IIncrementalGenerator public class mROASourceGenerator : IIncrementalGenerator
{ {
private const string Namespace = "mROA.Implementation"; private const string Namespace = "mROA.Implementation";
private const string AttributeName = "SharedObjectInterafceAttribute"; private const string AttributeName = "SharedObjectInterafceAttribute";
+1 -3
View File
@@ -1,5 +1,3 @@
namespace mROA.Abstract; namespace mROA.Abstract;
public interface IFrontendBridge : IInjectableModule public interface IFrontendBridge : IInjectableModule;
{
}
@@ -10,22 +10,32 @@ public class BasicExecutionModule : IExecuteModule
public void Inject<T>(T dependency) public void Inject<T>(T dependency)
{ {
if (dependency is IMethodRepository methodRepo) switch (dependency)
{
case IMethodRepository methodRepo:
_methodRepo = methodRepo; _methodRepo = methodRepo;
break;
if (dependency is IContextRepository contextRepo) case IContextRepository contextRepo:
_contextRepo = contextRepo; _contextRepo = contextRepo;
break;
}
} }
public ICommandExecution Execute(ICallRequest command) public ICommandExecution Execute(ICallRequest command)
{ {
var currentCommand = _methodRepo!.GetMethod(command.CommandId); if (_methodRepo is null)
throw new NullReferenceException("Method repository was not defined");
if (_contextRepo is null)
throw new NullReferenceException("Context repository was not defined");
var currentCommand = _methodRepo.GetMethod(command.CommandId);
if (currentCommand == null) if (currentCommand == null)
throw new Exception($"Command {command.CommandId} not found"); throw new Exception($"Command {command.CommandId} not found");
var context = command.ObjectId != -1 var context = command.ObjectId != -1
? _contextRepo!.GetObject(command.ObjectId) ? _contextRepo.GetObject(command.ObjectId)
: _contextRepo!.GetSingleObject(currentCommand.DeclaringType!); : _contextRepo.GetSingleObject(currentCommand.DeclaringType!);
var parameter = command.Parameter; var parameter = command.Parameter;
if (currentCommand.ReturnType.BaseType == typeof(Task) && if (currentCommand.ReturnType.BaseType == typeof(Task) &&
@@ -61,7 +71,7 @@ public class BasicExecutionModule : IExecuteModule
} }
} }
private ICommandExecution ExecuteAsync(MethodInfo currentCommand, object context, object? parameter, private static ICommandExecution ExecuteAsync(MethodInfo currentCommand, object context, object? parameter,
ICallRequest command) ICallRequest command)
{ {
var tokenSource = new CancellationTokenSource(); var tokenSource = new CancellationTokenSource();
@@ -86,7 +96,7 @@ public class BasicExecutionModule : IExecuteModule
} }
} }
private ICommandExecution TypedExecuteAsync(MethodInfo currentCommand, object context, object? parameter, private static ICommandExecution TypedExecuteAsync(MethodInfo currentCommand, object context, object? parameter,
ICallRequest command) ICallRequest command)
{ {
var tokenSource = new CancellationTokenSource(); var tokenSource = new CancellationTokenSource();
@@ -12,8 +12,8 @@ public class ContextRepository : IContextRepository
private Task<int> _lastIndexFinder = Task.FromResult(0); private Task<int> _lastIndexFinder = Task.FromResult(0);
const int StartupSize = 1024; private const int StartupSize = 1024;
const int GrowSize = 128; private const int GrowSize = 128;
public void FillSingletons(params Assembly[] assembly) public void FillSingletons(params Assembly[] assembly)
@@ -70,7 +70,7 @@ public class ContextRepository : IContextRepository
private int FindLastIndex() private int FindLastIndex()
{ {
for (int i = 0; i < _storage.Length; i++) for (var i = 0; i < _storage.Length; i++)
{ {
if (_storage[i] is null) if (_storage[i] is null)
return i; return i;
@@ -28,23 +28,6 @@ public class JsonSerialisationModule : ISerialisationModule
public void PostResponse(ICommandExecution call) public void PostResponse(ICommandExecution call)
{ {
var texted = JsonSerializer.Serialize(call, call.GetType()); var texted = JsonSerializer.Serialize(call, call.GetType());
// if (call is TypedFinalCommandExecution nonVoidCall)
// {
// texted = JsonSerializer.Serialize(nonVoidCall);
// }
// else if (call is FinalCommandExecution finalCommand)
// {
// texted = JsonSerializer.Serialize(finalCommand);
// }
// else if (call is AsyncCommandExecution asyncCommand)
// {
// texted = JsonSerializer.Serialize(asyncCommand);
// }
// else if (call is ExceptionCommandExecution exceptionCommandExecution)
// {
// texted = JsonSerializer.Serialize(exceptionCommandExecution);
// }
var binary = Encoding.UTF8.GetBytes(texted); var binary = Encoding.UTF8.GetBytes(texted);
_dataSource!.SendTo(call.ClientId, binary); _dataSource!.SendTo(call.ClientId, binary);
} }
@@ -40,6 +40,7 @@ public class NetworkGatewayModule(IPEndPoint endpoint) : IGatewayModule
{ {
if (_interactionModule is null) if (_interactionModule is null)
throw new NullReferenceException("Interaction module is null"); throw new NullReferenceException("Interaction module is null");
while (true) while (true)
{ {
var client = _tcpListener.AcceptTcpClient(); var client = _tcpListener.AcceptTcpClient();
@@ -2,14 +2,10 @@ using mROA.Abstract;
namespace mROA.Implementation.Bootstrap; namespace mROA.Implementation.Bootstrap;
public interface IRoaBuilder public class FullMixBuilder
{ {
void Build(); public List<IInjectableModule> Modules { get; } = [];
}
public class FullMixBuilder : IRoaBuilder
{
public List<IInjectableModule> Modules { get; } = new();
public void Build() public void Build()
{ {
foreach (var module in Modules) foreach (var module in Modules)
+1 -1
View File
@@ -2,7 +2,7 @@
public interface ICallRequest public interface ICallRequest
{ {
Guid CallRequestId { get; internal set; } Guid CallRequestId { get; }
int CommandId { get; } int CommandId { get; }
int ObjectId { get; } int ObjectId { get; }
object? Parameter { get; } object? Parameter { get; }
+3 -3
View File
@@ -11,12 +11,12 @@ public class FinalCommandExecution : ICommandExecution
[JsonIgnore] [JsonIgnore]
public int ClientId { get; set; } public int ClientId { get; set; }
[JsonIgnore] [JsonIgnore]
public int CommandId { get; set; } public int CommandId { get; init; }
} }
public class FinalCommandExecution<T> : FinalCommandExecution public class FinalCommandExecution<T> : FinalCommandExecution
{ {
public T? Result { get; set; } public T? Result { get; init; }
} }
public class TypedFinalCommandExecution : FinalCommandExecution<object> public class TypedFinalCommandExecution : FinalCommandExecution<object>
@@ -29,6 +29,6 @@ public class ExceptionCommandExecution : ICommandExecution
{ {
public Guid CallRequestId { get; init; } public Guid CallRequestId { get; init; }
public int ClientId { get; set; } public int ClientId { get; set; }
public int CommandId { get; set; } public int CommandId { get; init; }
public required string Exception { get; set; } public required string Exception { get; set; }
} }
@@ -1,14 +0,0 @@
using mROA.Abstract;
namespace mROA.Implementation.Frontend;
public class FrontendServiceBuilder
{
protected IInteractionModule.IFrontendInteractionModule? InteractionModule;
protected ISerialisationModule.IFrontendSerialisationModule? SerialisationModule;
public ISerialisationModule.IFrontendSerialisationModule Build()
{
return SerialisationModule!;
}
}
@@ -68,5 +68,5 @@ public class JsonFrontendSerialisationModule
public class RemoteException(string error) : Exception public class RemoteException(string error) : Exception
{ {
public Guid CallRequestId; public Guid CallRequestId;
public override string Message => error; public override string Message => $"Error in request {CallRequestId} : {error}";
} }
@@ -19,11 +19,10 @@ public class NetworkFrontendBridge(IPEndPoint ipEndPoint) : IFrontendBridge
public void Connect() public void Connect()
{ {
_tcpClient.Connect(ipEndPoint);
if (_interactionModule is null) if (_interactionModule is null)
{
throw new Exception("Interaction module was not injected"); throw new Exception("Interaction module was not injected");
}
_tcpClient.Connect(ipEndPoint);
_interactionModule.ServerStream = _tcpClient.GetStream(); _interactionModule.ServerStream = _tcpClient.GetStream();
} }
} }
@@ -10,9 +10,10 @@ public class StreamBasedFrontendInteractionModule : IInteractionModule.IFrontend
{ {
if (ServerStream is null) if (ServerStream is null)
throw new IOException("Server is not connected."); throw new IOException("Server is not connected.");
const int bufferSize = ushort.MaxValue; const int bufferSize = ushort.MaxValue;
byte[] buffer = new byte[bufferSize]; var buffer = new byte[bufferSize];
if (!ServerStream.CanRead) throw new IOException("Server is not connected."); if (!ServerStream.CanRead) throw new IOException("Server is not connected.");
await ServerStream.ReadExactlyAsync(buffer, 0, 2); await ServerStream.ReadExactlyAsync(buffer, 0, 2);
+1 -1
View File
@@ -6,7 +6,7 @@ namespace mROA.Implementation;
public class MethodRepository : IMethodRepository public class MethodRepository : IMethodRepository
{ {
private List<MethodInfo> _methods = []; private readonly List<MethodInfo> _methods = [];
public MethodInfo GetMethod(int id) public MethodInfo GetMethod(int id)
{ {
+1 -1
View File
@@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Title>mROA</Title> <Title>mROA</Title>
<Version>1.1.2</Version> <Version>1.1.3</Version>
<Authors>YaslePoy</Authors> <Authors>YaslePoy</Authors>
<Description>Fast and easy RPC with contex</Description> <Description>Fast and easy RPC with contex</Description>
<RepositoryUrl>https://github.com/YaslePoy/mROA</RepositoryUrl> <RepositoryUrl>https://github.com/YaslePoy/mROA</RepositoryUrl>