diff --git a/mROA.Codegen/mROA.Codegen.csproj b/mROA.Codegen/mROA.Codegen.csproj index c7687af..55fe8a0 100644 --- a/mROA.Codegen/mROA.Codegen.csproj +++ b/mROA.Codegen/mROA.Codegen.csproj @@ -17,7 +17,7 @@ https://github.com/YaslePoy/mROA git True - 1.0.6 + 1.0.7 diff --git a/mROA.Codegen/SampleIncrementalSourceGenerator.cs b/mROA.Codegen/mROASourceGenerator.cs similarity index 99% rename from mROA.Codegen/SampleIncrementalSourceGenerator.cs rename to mROA.Codegen/mROASourceGenerator.cs index 57f635e..dc1a337 100644 --- a/mROA.Codegen/SampleIncrementalSourceGenerator.cs +++ b/mROA.Codegen/mROASourceGenerator.cs @@ -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. /// [Generator] -public class SampleIncrementalSourceGenerator : IIncrementalGenerator +public class mROASourceGenerator : IIncrementalGenerator { private const string Namespace = "mROA.Implementation"; private const string AttributeName = "SharedObjectInterafceAttribute"; diff --git a/mROA/Abstract/IFrontendBridge.cs b/mROA/Abstract/IFrontendBridge.cs index adaa321..103fec2 100644 --- a/mROA/Abstract/IFrontendBridge.cs +++ b/mROA/Abstract/IFrontendBridge.cs @@ -1,5 +1,3 @@ namespace mROA.Abstract; -public interface IFrontendBridge : IInjectableModule -{ -} \ No newline at end of file +public interface IFrontendBridge : IInjectableModule; \ No newline at end of file diff --git a/mROA/Implementation/Backend/BasicExecutionModule.cs b/mROA/Implementation/Backend/BasicExecutionModule.cs index d9e19bf..cf05375 100644 --- a/mROA/Implementation/Backend/BasicExecutionModule.cs +++ b/mROA/Implementation/Backend/BasicExecutionModule.cs @@ -10,22 +10,32 @@ public class BasicExecutionModule : IExecuteModule public void Inject(T dependency) { - if (dependency is IMethodRepository methodRepo) - _methodRepo = methodRepo; - - if (dependency is IContextRepository contextRepo) - _contextRepo = contextRepo; + switch (dependency) + { + case IMethodRepository methodRepo: + _methodRepo = methodRepo; + break; + case IContextRepository contextRepo: + _contextRepo = contextRepo; + break; + } } 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) throw new Exception($"Command {command.CommandId} not found"); var context = command.ObjectId != -1 - ? _contextRepo!.GetObject(command.ObjectId) - : _contextRepo!.GetSingleObject(currentCommand.DeclaringType!); + ? _contextRepo.GetObject(command.ObjectId) + : _contextRepo.GetSingleObject(currentCommand.DeclaringType!); var parameter = command.Parameter; 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) { 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) { var tokenSource = new CancellationTokenSource(); diff --git a/mROA/Implementation/Backend/ContextRepository.cs b/mROA/Implementation/Backend/ContextRepository.cs index a11fd57..8ee451d 100644 --- a/mROA/Implementation/Backend/ContextRepository.cs +++ b/mROA/Implementation/Backend/ContextRepository.cs @@ -12,8 +12,8 @@ public class ContextRepository : IContextRepository private Task _lastIndexFinder = Task.FromResult(0); - const int StartupSize = 1024; - const int GrowSize = 128; + private const int StartupSize = 1024; + private const int GrowSize = 128; public void FillSingletons(params Assembly[] assembly) @@ -70,7 +70,7 @@ public class ContextRepository : IContextRepository private int FindLastIndex() { - for (int i = 0; i < _storage.Length; i++) + for (var i = 0; i < _storage.Length; i++) { if (_storage[i] is null) return i; diff --git a/mROA/Implementation/Backend/JsonSerialisationModule.cs b/mROA/Implementation/Backend/JsonSerialisationModule.cs index 5effc16..3e652cb 100644 --- a/mROA/Implementation/Backend/JsonSerialisationModule.cs +++ b/mROA/Implementation/Backend/JsonSerialisationModule.cs @@ -28,23 +28,6 @@ public class JsonSerialisationModule : ISerialisationModule public void PostResponse(ICommandExecution call) { 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); _dataSource!.SendTo(call.ClientId, binary); } diff --git a/mROA/Implementation/Backend/NetworkGatewayModule.cs b/mROA/Implementation/Backend/NetworkGatewayModule.cs index 8817185..62b85c7 100644 --- a/mROA/Implementation/Backend/NetworkGatewayModule.cs +++ b/mROA/Implementation/Backend/NetworkGatewayModule.cs @@ -40,6 +40,7 @@ public class NetworkGatewayModule(IPEndPoint endpoint) : IGatewayModule { if (_interactionModule is null) throw new NullReferenceException("Interaction module is null"); + while (true) { var client = _tcpListener.AcceptTcpClient(); diff --git a/mROA/Implementation/Bootstrap/FullMixBuilder.cs b/mROA/Implementation/Bootstrap/FullMixBuilder.cs index ed74e41..848480d 100644 --- a/mROA/Implementation/Bootstrap/FullMixBuilder.cs +++ b/mROA/Implementation/Bootstrap/FullMixBuilder.cs @@ -2,14 +2,10 @@ using mROA.Abstract; namespace mROA.Implementation.Bootstrap; -public interface IRoaBuilder +public class FullMixBuilder { - void Build(); -} + public List Modules { get; } = []; -public class FullMixBuilder : IRoaBuilder -{ - public List Modules { get; } = new(); public void Build() { foreach (var module in Modules) diff --git a/mROA/Implementation/CallRequest.cs b/mROA/Implementation/CallRequest.cs index 0f81d37..5ca6a44 100644 --- a/mROA/Implementation/CallRequest.cs +++ b/mROA/Implementation/CallRequest.cs @@ -2,7 +2,7 @@ public interface ICallRequest { - Guid CallRequestId { get; internal set; } + Guid CallRequestId { get; } int CommandId { get; } int ObjectId { get; } object? Parameter { get; } diff --git a/mROA/Implementation/FinalCommandExecution.cs b/mROA/Implementation/FinalCommandExecution.cs index 209b63b..2b960a1 100644 --- a/mROA/Implementation/FinalCommandExecution.cs +++ b/mROA/Implementation/FinalCommandExecution.cs @@ -11,12 +11,12 @@ public class FinalCommandExecution : ICommandExecution [JsonIgnore] public int ClientId { get; set; } [JsonIgnore] - public int CommandId { get; set; } + public int CommandId { get; init; } } public class FinalCommandExecution : FinalCommandExecution { - public T? Result { get; set; } + public T? Result { get; init; } } public class TypedFinalCommandExecution : FinalCommandExecution @@ -29,6 +29,6 @@ public class ExceptionCommandExecution : ICommandExecution { public Guid CallRequestId { get; init; } public int ClientId { get; set; } - public int CommandId { get; set; } + public int CommandId { get; init; } public required string Exception { get; set; } } \ No newline at end of file diff --git a/mROA/Implementation/Frontend/FrontendServiceBuilder.cs b/mROA/Implementation/Frontend/FrontendServiceBuilder.cs deleted file mode 100644 index 7aece5d..0000000 --- a/mROA/Implementation/Frontend/FrontendServiceBuilder.cs +++ /dev/null @@ -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!; - } -} \ No newline at end of file diff --git a/mROA/Implementation/Frontend/JsonFrontendSerialisationModule.cs b/mROA/Implementation/Frontend/JsonFrontendSerialisationModule.cs index e5f5b82..a2464b1 100644 --- a/mROA/Implementation/Frontend/JsonFrontendSerialisationModule.cs +++ b/mROA/Implementation/Frontend/JsonFrontendSerialisationModule.cs @@ -68,5 +68,5 @@ public class JsonFrontendSerialisationModule public class RemoteException(string error) : Exception { public Guid CallRequestId; - public override string Message => error; + public override string Message => $"Error in request {CallRequestId} : {error}"; } \ No newline at end of file diff --git a/mROA/Implementation/Frontend/NetworkFrontendBridge.cs b/mROA/Implementation/Frontend/NetworkFrontendBridge.cs index 2e4dfb5..e5ce65f 100644 --- a/mROA/Implementation/Frontend/NetworkFrontendBridge.cs +++ b/mROA/Implementation/Frontend/NetworkFrontendBridge.cs @@ -19,11 +19,10 @@ public class NetworkFrontendBridge(IPEndPoint ipEndPoint) : IFrontendBridge public void Connect() { - _tcpClient.Connect(ipEndPoint); if (_interactionModule is null) - { throw new Exception("Interaction module was not injected"); - } + + _tcpClient.Connect(ipEndPoint); _interactionModule.ServerStream = _tcpClient.GetStream(); } } \ No newline at end of file diff --git a/mROA/Implementation/Frontend/StreamBasedFrontendInteractionModule.cs b/mROA/Implementation/Frontend/StreamBasedFrontendInteractionModule.cs index bcb5282..6b63246 100644 --- a/mROA/Implementation/Frontend/StreamBasedFrontendInteractionModule.cs +++ b/mROA/Implementation/Frontend/StreamBasedFrontendInteractionModule.cs @@ -10,9 +10,10 @@ public class StreamBasedFrontendInteractionModule : IInteractionModule.IFrontend { if (ServerStream is null) throw new IOException("Server is not connected."); + 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."); await ServerStream.ReadExactlyAsync(buffer, 0, 2); diff --git a/mROA/Implementation/MethodRepository.cs b/mROA/Implementation/MethodRepository.cs index 8074f82..7a9a8bd 100644 --- a/mROA/Implementation/MethodRepository.cs +++ b/mROA/Implementation/MethodRepository.cs @@ -6,7 +6,7 @@ namespace mROA.Implementation; public class MethodRepository : IMethodRepository { - private List _methods = []; + private readonly List _methods = []; public MethodInfo GetMethod(int id) { diff --git a/mROA/mROA.csproj b/mROA/mROA.csproj index fc54a62..3f50110 100644 --- a/mROA/mROA.csproj +++ b/mROA/mROA.csproj @@ -5,7 +5,7 @@ enable enable mROA - 1.1.2 + 1.1.3 YaslePoy Fast and easy RPC with contex https://github.com/YaslePoy/mROA