diff --git a/Example.Shared/Example.Shared.csproj b/Example.Shared/Example.Shared.csproj index d4550ea..f70710d 100644 --- a/Example.Shared/Example.Shared.csproj +++ b/Example.Shared/Example.Shared.csproj @@ -7,7 +7,8 @@ - diff --git a/mROA.Codegen/obj/Debug/netstandard2.0/mROA.Codegen.AssemblyInfo.cs b/mROA.Codegen/obj/Debug/netstandard2.0/mROA.Codegen.AssemblyInfo.cs index e6b02ee..b928b02 100644 --- a/mROA.Codegen/obj/Debug/netstandard2.0/mROA.Codegen.AssemblyInfo.cs +++ b/mROA.Codegen/obj/Debug/netstandard2.0/mROA.Codegen.AssemblyInfo.cs @@ -1,24 +1,23 @@ //------------------------------------------------------------------------------ // -// Этот код создан программой. -// Исполняемая версия:4.0.30319.42000 +// This code was generated by a tool. // -// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае -// повторной генерации кода. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. // //------------------------------------------------------------------------------ using System; using System.Reflection; -[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Codegen")] +[assembly: System.Reflection.AssemblyCompanyAttribute("YaslePoy")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] -[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d780d0ea0b8c501b99358c1e89abc9fa4c46f959")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5bcdb968f0f857381cbf8b7f5ee99b5e8a5f6b36")] +[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.4.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.4+f7341269329d5c55e14b1f5149986c2d97cad020")] [assembly: System.Reflection.AssemblyProductAttribute("mROA.Codegen")] [assembly: System.Reflection.AssemblyTitleAttribute("mROA.Codegen")] -[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] +[assembly: System.Reflection.AssemblyVersionAttribute("1.0.4.0")] +[assembly: System.Reflection.AssemblyMetadataAttribute("RepositoryUrl", "https://github.com/YaslePoy/mROA")] // Создано классом WriteCodeFragment MSBuild. diff --git a/mROA.Codegen/obj/mROA.Codegen.csproj.nuget.g.props b/mROA.Codegen/obj/mROA.Codegen.csproj.nuget.g.props index 353ed1c..6f36b67 100644 --- a/mROA.Codegen/obj/mROA.Codegen.csproj.nuget.g.props +++ b/mROA.Codegen/obj/mROA.Codegen.csproj.nuget.g.props @@ -5,18 +5,18 @@ NuGet $(MSBuildThisFileDirectory)project.assets.json $(UserProfile)\.nuget\packages\ - C:\Users\Mikhail\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages + C:\Users\Mimm\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages PackageReference 6.12.0 - + - C:\Users\Mikhail\.nuget\packages\microsoft.codeanalysis.analyzers\3.3.4 + C:\Users\Mimm\.nuget\packages\microsoft.codeanalysis.analyzers\3.3.4 \ No newline at end of file diff --git a/mROA.Test/obj/Debug/net9.0/mROA.Test.AssemblyInfo.cs b/mROA.Test/obj/Debug/net9.0/mROA.Test.AssemblyInfo.cs index e1a72d2..88a7ebf 100644 --- a/mROA.Test/obj/Debug/net9.0/mROA.Test.AssemblyInfo.cs +++ b/mROA.Test/obj/Debug/net9.0/mROA.Test.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Test")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+0b455b8dd8fd256581b224169026e33dad4a222b")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f7341269329d5c55e14b1f5149986c2d97cad020")] [assembly: System.Reflection.AssemblyProductAttribute("mROA.Test")] [assembly: System.Reflection.AssemblyTitleAttribute("mROA.Test")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/mROA.Test/obj/Release/net9.0/mROA.Test.AssemblyInfo.cs b/mROA.Test/obj/Release/net9.0/mROA.Test.AssemblyInfo.cs index 6c712e6..0f87981 100644 --- a/mROA.Test/obj/Release/net9.0/mROA.Test.AssemblyInfo.cs +++ b/mROA.Test/obj/Release/net9.0/mROA.Test.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Test")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Release")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+71e92f0301b2ba7aaaf7dca368a62bfba8554ca4")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f7341269329d5c55e14b1f5149986c2d97cad020")] [assembly: System.Reflection.AssemblyProductAttribute("mROA.Test")] [assembly: System.Reflection.AssemblyTitleAttribute("mROA.Test")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/mROA.Test/obj/Release/net9.0/mROA.Test.GeneratedMSBuildEditorConfig.editorconfig b/mROA.Test/obj/Release/net9.0/mROA.Test.GeneratedMSBuildEditorConfig.editorconfig index 2110ab6..41d3a9e 100644 --- a/mROA.Test/obj/Release/net9.0/mROA.Test.GeneratedMSBuildEditorConfig.editorconfig +++ b/mROA.Test/obj/Release/net9.0/mROA.Test.GeneratedMSBuildEditorConfig.editorconfig @@ -8,7 +8,7 @@ build_property.PlatformNeutralAssembly = build_property.EnforceExtendedAnalyzerRules = build_property._SupportedPlatformList = Linux,macOS,Windows build_property.RootNamespace = mROA.Test -build_property.ProjectDir = C:\Users\Mikhail\Projects\VisualStudioProjects\mROA\mROA.Test\ +build_property.ProjectDir = C:\Users\Mimm\Projects\VisualStudioProjects\mROA\mROA.Test\ build_property.EnableComHosting = build_property.EnableGeneratedComInterfaceComImportInterop = build_property.EffectiveAnalysisLevelStyle = 9.0 diff --git a/mROA.Test/obj/mROA.Test.csproj.nuget.g.props b/mROA.Test/obj/mROA.Test.csproj.nuget.g.props index 92a05d6..f0b8464 100644 --- a/mROA.Test/obj/mROA.Test.csproj.nuget.g.props +++ b/mROA.Test/obj/mROA.Test.csproj.nuget.g.props @@ -5,12 +5,12 @@ NuGet $(MSBuildThisFileDirectory)project.assets.json $(UserProfile)\.nuget\packages\ - C:\Users\Mikhail\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages + C:\Users\Mimm\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages PackageReference 6.12.0 - + @@ -21,6 +21,6 @@ - C:\Users\Mikhail\.nuget\packages\nunit.analyzers\4.6.0 + C:\Users\Mimm\.nuget\packages\nunit.analyzers\4.6.0 \ No newline at end of file diff --git a/mROA/Implementation/Backend/BasicExecutionModule.cs b/mROA/Implementation/Backend/BasicExecutionModule.cs index c40de4c..b54c623 100644 --- a/mROA/Implementation/Backend/BasicExecutionModule.cs +++ b/mROA/Implementation/Backend/BasicExecutionModule.cs @@ -43,70 +43,82 @@ public class BasicExecutionModule : IExecuteModule return Execute(currentCommand, context, parameter, command); } - private static FinalCommandExecution Execute(MethodInfo currentCommand, object context, object? parameter, + private static ICommandExecution Execute(MethodInfo currentCommand, object context, object? parameter, ICallRequest command) { - var finalResult = currentCommand.Invoke(context, parameter is null ? [] : [parameter]); - return new TypedFinalCommandExecution + try { - CommandId = command.CommandId, Result = finalResult, - CallRequestId = command.CallRequestId, - Type = currentCommand.ReturnType - }; + var finalResult = currentCommand.Invoke(context, parameter is null ? [] : [parameter]); + return new TypedFinalCommandExecution + { + CommandId = command.CommandId, Result = finalResult, + CallRequestId = command.CallRequestId, + Type = currentCommand.ReturnType + }; + } + catch (Exception e) + { + return new ExceptionCommandExecution + { + CallRequestId = command.CallRequestId, CommandId = command.CommandId, + Exeption = e.ToString() + }; + } } - private AsyncCommandExecution ExecuteAsync(MethodInfo currentCommand, object context, object? parameter, + private ICommandExecution ExecuteAsync(MethodInfo currentCommand, object context, object? parameter, ICallRequest command) { var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; + try + { + var result = (Task)currentCommand.Invoke(context, parameter is null ? [token] : [parameter, token])!; - var result = (Task)currentCommand.Invoke(context, parameter is null ? [token] : [parameter, token])!; - var exec = new AsyncCommandExecution(tokenSource) - { CommandId = command.CommandId, CallRequestId = command.CallRequestId }; - result.ContinueWith(_ => { PostFinalizedCallback(exec, null); }, token); + result.Wait(token); - return exec; + + return new FinalCommandExecution { CommandId = command.CommandId, CallRequestId = command.CallRequestId }; + } + catch (Exception e) + { + return new ExceptionCommandExecution + { + CallRequestId = command.CallRequestId, CommandId = command.CommandId, + Exeption = e.ToString() + }; + } } - private AsyncCommandExecution TypedExecuteAsync(MethodInfo currentCommand, object context, object? parameter, + private ICommandExecution TypedExecuteAsync(MethodInfo currentCommand, object context, object? parameter, ICallRequest command) { var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; - - var result = - (Task)currentCommand.Invoke(context, parameter is null ? [token] : [parameter, token])!; - var exec = new AsyncCommandExecution(tokenSource) - { CommandId = command.CommandId, CallRequestId = command.CallRequestId }; - - result.ContinueWith(task => + try { - try + var result = + (Task)currentCommand.Invoke(context, parameter is null ? [token] : [parameter, token])!; + + result.Wait(token); + + var finalResult = result.GetType().GetProperty("Result")?.GetValue(result); + return new TypedFinalCommandExecution { - var finalResult = task.GetType().GetProperty("Result")?.GetValue(task); - PostFinalizedCallback(exec, finalResult); - } - catch (Exception e) - { - _serialisationModule.PostResponse(new ExceptionCommandExecution {CallRequestId = exec.CallRequestId, CommandId = exec.CommandId, ClientId = exec.ClientId, Reason = e.InnerException.InnerException.ToString()}); - } - - }, token); - - return exec; - } - - private void PostFinalizedCallback(AsyncCommandExecution request, object? result) - { - _serialisationModule.PostResponse(new TypedFinalCommandExecution + CallRequestId = command.CallRequestId, + Result = result, + CommandId = command.CommandId, + Type = finalResult.GetType() + }; + } + catch (Exception e) { - CallRequestId = request.CallRequestId, - Result = result, - CommandId = request.CommandId, - ClientId = request.ClientId, - Type = typeof(object) - }); + return new ExceptionCommandExecution + { + CallRequestId = command.CallRequestId, CommandId = command.CommandId, + Exeption = e.ToString() + }; + } } } \ No newline at end of file diff --git a/mROA/Implementation/Backend/JsonSerialisationModule.cs b/mROA/Implementation/Backend/JsonSerialisationModule.cs index 9087db1..54b8992 100644 --- a/mROA/Implementation/Backend/JsonSerialisationModule.cs +++ b/mROA/Implementation/Backend/JsonSerialisationModule.cs @@ -10,7 +10,7 @@ public class JsonSerialisationModule : ISerialisationModule private IInteractionModule _dataSource; private IExecuteModule _executeModule; private IMethodRepository _methodRepository; - + public void HandleIncomingRequest(int clientId, byte[] command) { DefaultCallRequest request = JsonSerializer.Deserialize(command); @@ -18,9 +18,9 @@ public class JsonSerialisationModule : ISerialisationModule if (request.Parameter is not null) { var parameter = _methodRepository.GetMethod(request.CommandId).GetParameters().First().ParameterType; - request.Parameter = (( JsonElement)request.Parameter).Deserialize(parameter); + request.Parameter = ((JsonElement)request.Parameter).Deserialize(parameter); } - + var response = _executeModule.Execute(request); response.ClientId = clientId; PostResponse(response); @@ -28,21 +28,24 @@ public class JsonSerialisationModule : ISerialisationModule public void PostResponse(ICommandExecution call) { - var texted = string.Empty; - 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 exeptionCommandExecution) - { - texted = JsonSerializer.Serialize(exeptionCommandExecution); - } - + 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/FinalCommandExecution.cs b/mROA/Implementation/FinalCommandExecution.cs index 2da715e..01e44de 100644 --- a/mROA/Implementation/FinalCommandExecution.cs +++ b/mROA/Implementation/FinalCommandExecution.cs @@ -27,26 +27,5 @@ public class ExceptionCommandExecution : ICommandExecution public Guid CallRequestId { get; init; } public int ClientId { get; set; } public int CommandId { get; set; } - public string Reason { get; set; } -} - -public class AsyncCommandExecution : ICommandExecution -{ - public Guid CallRequestId { get; init; } - [JsonIgnore] - public int ClientId { get; set; } - [JsonIgnore] - public int CommandId { get; set; } - - public void Cancel() - { - LocalToken.Cancel(); - } - - private CancellationTokenSource LocalToken; - - public AsyncCommandExecution(CancellationTokenSource localToken) - { - LocalToken = localToken; - } + public string Exeption { get; set; } } \ No newline at end of file diff --git a/mROA/Implementation/Frontend/JsonFrontendSerialisationModule.cs b/mROA/Implementation/Frontend/JsonFrontendSerialisationModule.cs index 42c2d42..fb8102a 100644 --- a/mROA/Implementation/Frontend/JsonFrontendSerialisationModule.cs +++ b/mROA/Implementation/Frontend/JsonFrontendSerialisationModule.cs @@ -24,8 +24,14 @@ public class JsonFrontendSerialisationModule public async Task> GetFinalCommandExecution(Guid requestId) { var receiveMessage = await _interactionModule.ReceiveMessage(); - var str = Encoding.UTF8.GetString(receiveMessage); - var parsed = JsonSerializer.Deserialize>(receiveMessage); + // var str = Encoding.UTF8.GetString(receiveMessage); + var document = JsonDocument.Parse(receiveMessage); + if (document.RootElement.TryGetProperty("Exeption", out var exeptionElement)) + { + throw new RemoteException(exeptionElement.GetString()) { CallRequestId = requestId }; + } + + var parsed = document.Deserialize>(); while (parsed.CallRequestId != requestId) { receiveMessage = await _interactionModule.ReceiveMessage(); @@ -51,4 +57,10 @@ public class JsonFrontendSerialisationModule public void Bake() { } +} + +public class RemoteException(string error) : Exception +{ + public Guid CallRequestId; + public override string Message => error; } \ No newline at end of file diff --git a/mROA/obj/mROA.csproj.nuget.g.props b/mROA/obj/mROA.csproj.nuget.g.props index 721d876..7f9c9db 100644 --- a/mROA/obj/mROA.csproj.nuget.g.props +++ b/mROA/obj/mROA.csproj.nuget.g.props @@ -5,12 +5,12 @@ NuGet $(MSBuildThisFileDirectory)project.assets.json $(UserProfile)\.nuget\packages\ - C:\Users\Mikhail\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages + C:\Users\Mimm\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages PackageReference 6.12.0 - + \ No newline at end of file