исключения теперь вылетают и по сети

This commit is contained in:
2025-02-06 14:57:20 +03:00
parent f734126932
commit 0dbac36f77
12 changed files with 113 additions and 107 deletions
+2 -1
View File
@@ -7,7 +7,8 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\mROA.Codegen\mROA.Codegen.csproj" OutputItemType="Analyzer"
<ProjectReference Include="..\mROA.Codegen\mROA.Codegen.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"/>
<ProjectReference Include="..\mROA\mROA.csproj" />
</ItemGroup>
@@ -1,24 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия: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.
// </auto-generated>
//------------------------------------------------------------------------------
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.
@@ -5,18 +5,18 @@
<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>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mimm\.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:\Users\Mimm\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)microsoft.codeanalysis.analyzers\3.3.4\buildTransitive\Microsoft.CodeAnalysis.Analyzers.props" Condition="Exists('$(NuGetPackageRoot)microsoft.codeanalysis.analyzers\3.3.4\buildTransitive\Microsoft.CodeAnalysis.Analyzers.props')" />
</ImportGroup>
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<PkgMicrosoft_CodeAnalysis_Analyzers Condition=" '$(PkgMicrosoft_CodeAnalysis_Analyzers)' == '' ">C:\Users\Mikhail\.nuget\packages\microsoft.codeanalysis.analyzers\3.3.4</PkgMicrosoft_CodeAnalysis_Analyzers>
<PkgMicrosoft_CodeAnalysis_Analyzers Condition=" '$(PkgMicrosoft_CodeAnalysis_Analyzers)' == '' ">C:\Users\Mimm\.nuget\packages\microsoft.codeanalysis.analyzers\3.3.4</PkgMicrosoft_CodeAnalysis_Analyzers>
</PropertyGroup>
</Project>
@@ -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")]
@@ -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")]
@@ -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
+3 -3
View File
@@ -5,12 +5,12 @@
<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>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mimm\.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:\Users\Mimm\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
@@ -21,6 +21,6 @@
<Import Project="$(NuGetPackageRoot)microsoft.net.test.sdk\17.12.0\build\netcoreapp3.1\Microsoft.NET.Test.Sdk.props" Condition="Exists('$(NuGetPackageRoot)microsoft.net.test.sdk\17.12.0\build\netcoreapp3.1\Microsoft.NET.Test.Sdk.props')" />
</ImportGroup>
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<PkgNUnit_Analyzers Condition=" '$(PkgNUnit_Analyzers)' == '' ">C:\Users\Mikhail\.nuget\packages\nunit.analyzers\4.6.0</PkgNUnit_Analyzers>
<PkgNUnit_Analyzers Condition=" '$(PkgNUnit_Analyzers)' == '' ">C:\Users\Mimm\.nuget\packages\nunit.analyzers\4.6.0</PkgNUnit_Analyzers>
</PropertyGroup>
</Project>
@@ -43,8 +43,10 @@ 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)
{
try
{
var finalResult = currentCommand.Invoke(context, parameter is null ? [] : [parameter]);
return new TypedFinalCommandExecution
@@ -54,59 +56,69 @@ public class BasicExecutionModule : IExecuteModule
Type = currentCommand.ReturnType
};
}
private AsyncCommandExecution ExecuteAsync(MethodInfo currentCommand, object context, object? parameter,
ICallRequest command)
catch (Exception e)
{
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(_ => { PostFinalizedCallback(exec, null); }, token);
return exec;
return new ExceptionCommandExecution
{
CallRequestId = command.CallRequestId, CommandId = command.CommandId,
Exeption = e.ToString()
};
}
}
private AsyncCommandExecution TypedExecuteAsync(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;
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
{
var finalResult = task.GetType().GetProperty("Result")?.GetValue(task);
PostFinalizedCallback(exec, finalResult);
var result = (Task)currentCommand.Invoke(context, parameter is null ? [token] : [parameter, token])!;
result.Wait(token);
return new FinalCommandExecution { CommandId = command.CommandId, CallRequestId = command.CallRequestId };
}
catch (Exception e)
{
_serialisationModule.PostResponse(new ExceptionCommandExecution {CallRequestId = exec.CallRequestId, CommandId = exec.CommandId, ClientId = exec.ClientId, Reason = e.InnerException.InnerException.ToString()});
return new ExceptionCommandExecution
{
CallRequestId = command.CallRequestId, CommandId = command.CommandId,
Exeption = e.ToString()
};
}
}
}, token);
return exec;
}
private void PostFinalizedCallback(AsyncCommandExecution request, object? result)
private ICommandExecution TypedExecuteAsync(MethodInfo currentCommand, object context, object? parameter,
ICallRequest command)
{
_serialisationModule.PostResponse(new TypedFinalCommandExecution
var tokenSource = new CancellationTokenSource();
var token = tokenSource.Token;
try
{
CallRequestId = request.CallRequestId,
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
{
CallRequestId = command.CallRequestId,
Result = result,
CommandId = request.CommandId,
ClientId = request.ClientId,
Type = typeof(object)
});
CommandId = command.CommandId,
Type = finalResult.GetType()
};
}
catch (Exception e)
{
return new ExceptionCommandExecution
{
CallRequestId = command.CallRequestId, CommandId = command.CommandId,
Exeption = e.ToString()
};
}
}
}
@@ -28,20 +28,23 @@ 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);
+1 -22
View File
@@ -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; }
}
@@ -24,8 +24,14 @@ public class JsonFrontendSerialisationModule
public async Task<FinalCommandExecution<T>> GetFinalCommandExecution<T>(Guid requestId)
{
var receiveMessage = await _interactionModule.ReceiveMessage();
var str = Encoding.UTF8.GetString(receiveMessage);
var parsed = JsonSerializer.Deserialize<FinalCommandExecution<T>>(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<FinalCommandExecution<T>>();
while (parsed.CallRequestId != requestId)
{
receiveMessage = await _interactionModule.ReceiveMessage();
@@ -52,3 +58,9 @@ public class JsonFrontendSerialisationModule
{
}
}
public class RemoteException(string error) : Exception
{
public Guid CallRequestId;
public override string Message => error;
}
+2 -2
View File
@@ -5,12 +5,12 @@
<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>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mimm\.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:\Users\Mimm\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
</Project>