рефакторинг модуля исполнения
This commit is contained in:
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Performance")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2f1a1e250b1a9c031df21e3ec1087cb18b8fa784")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9128f3f6ee0d3c89e7e0538ac244a133c746e4df")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("mROA.Performance")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Performance")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
||||
<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.10.1</NuGetToolVersion>
|
||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.12.2</NuGetToolVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<SourceRoot Include="C:\Users\Mimm\.nuget\packages\" />
|
||||
|
||||
@@ -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+2f1a1e250b1a9c031df21e3ec1087cb18b8fa784")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9128f3f6ee0d3c89e7e0538ac244a133c746e4df")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("mROA.Test")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Test")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
||||
<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.10.1</NuGetToolVersion>
|
||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.12.2</NuGetToolVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<SourceRoot Include="C:\Users\Mimm\.nuget\packages\" />
|
||||
|
||||
@@ -17,7 +17,6 @@ public class PrepairedExecutionModule : IExecuteModule
|
||||
_serialisationModule = serialisationModule;
|
||||
_contextRepo = contextRepo;
|
||||
_serialisationModule.SetExecuteModule(this);
|
||||
|
||||
}
|
||||
|
||||
public ICommandExecution Execute(ICallRequest command)
|
||||
@@ -26,10 +25,52 @@ public class PrepairedExecutionModule : IExecuteModule
|
||||
if (currentCommand == null)
|
||||
throw new Exception($"Command {command.CommandId} not found");
|
||||
|
||||
var context = command.ObjectId != -1 ? _contextRepo.GetObject(command.ObjectId) : _contextRepo.GetSingleObject(currentCommand.DeclaringType);
|
||||
var context = command.ObjectId != -1
|
||||
? _contextRepo.GetObject(command.ObjectId)
|
||||
: _contextRepo.GetSingleObject(currentCommand.DeclaringType);
|
||||
var parameter = command.Parameter;
|
||||
|
||||
if (currentCommand.ReturnType.BaseType == typeof(Task) && currentCommand.ReturnType.GenericTypeArguments.Length == 1)
|
||||
if (currentCommand.ReturnType.BaseType == typeof(Task) &&
|
||||
currentCommand.ReturnType.GenericTypeArguments.Length == 1)
|
||||
return TypedExecuteAsync(currentCommand, context, parameter, command);
|
||||
|
||||
if (currentCommand.ReturnType == typeof(Task))
|
||||
return ExecuteAsync(currentCommand, context, parameter, command);
|
||||
|
||||
return Execute(currentCommand, context, parameter, command);
|
||||
}
|
||||
|
||||
private ICommandExecution Execute(MethodInfo currentCommand, object context, object parameter, ICallRequest request)
|
||||
{
|
||||
var finalResult = currentCommand.Invoke(context, parameter is null ? [] : [parameter]);
|
||||
return new FinalCommandExecution
|
||||
{ CommandId = request.CommandId, Result = finalResult, ClientId = request.ClientId };
|
||||
}
|
||||
|
||||
private ICommandExecution ExecuteAsync(MethodInfo currentCommand, object context, object parameter,
|
||||
ICallRequest command)
|
||||
{
|
||||
var tokenSource = new CancellationTokenSource();
|
||||
var token = tokenSource.Token;
|
||||
|
||||
var result = currentCommand.Invoke(context, parameter is null ? [token] : [parameter, token]) as Task;
|
||||
var exec = new AsyncCommandExecution(tokenSource)
|
||||
{ CommandId = command.CommandId, ClientId = command.ClientId };
|
||||
|
||||
result.ContinueWith(_ =>
|
||||
{
|
||||
_serialisationModule.PostResponse(new FinalCommandExecution
|
||||
{
|
||||
ExecutionId = exec.ExecutionId, Result = null, CommandId = command.CommandId,
|
||||
ClientId = command.ClientId
|
||||
});
|
||||
}, token);
|
||||
|
||||
return exec;
|
||||
}
|
||||
|
||||
private ICommandExecution TypedExecuteAsync(MethodInfo currentCommand, object context, object parameter,
|
||||
ICallRequest command)
|
||||
{
|
||||
var tokenSource = new CancellationTokenSource();
|
||||
var token = tokenSource.Token;
|
||||
@@ -51,29 +92,4 @@ public class PrepairedExecutionModule : IExecuteModule
|
||||
|
||||
return exec;
|
||||
}
|
||||
|
||||
if (currentCommand.ReturnType == typeof(Task))
|
||||
{
|
||||
var tokenSource = new CancellationTokenSource();
|
||||
var token = tokenSource.Token;
|
||||
|
||||
var result = currentCommand.Invoke(context, parameter is null ? [token] : [parameter, token]) as Task;
|
||||
var exec = new AsyncCommandExecution(tokenSource)
|
||||
{ CommandId = command.CommandId, ClientId = command.ClientId };
|
||||
|
||||
result.ContinueWith(_ =>
|
||||
{
|
||||
_serialisationModule.PostResponse(new FinalCommandExecution
|
||||
{
|
||||
ExecutionId = exec.ExecutionId, Result = null, CommandId = command.CommandId,
|
||||
ClientId = command.ClientId
|
||||
});
|
||||
}, token);
|
||||
|
||||
return exec;
|
||||
}
|
||||
|
||||
var finalResult = currentCommand.Invoke(context, parameter is null ? [] : [parameter]);
|
||||
return new FinalCommandExecution { CommandId = command.CommandId, Result = finalResult };
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -13,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2f1a1e250b1a9c031df21e3ec1087cb18b8fa784")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9128f3f6ee0d3c89e7e0538ac244a133c746e4df")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("mROA")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("mROA")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
||||
<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.10.1</NuGetToolVersion>
|
||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.12.2</NuGetToolVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<SourceRoot Include="C:\Users\Mimm\.nuget\packages\" />
|
||||
|
||||
Reference in New Issue
Block a user