рефакторинг модуля исполнения
This commit is contained in:
@@ -14,7 +14,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Performance")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Performance")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[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.AssemblyProductAttribute("mROA.Performance")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Performance")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Performance")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
<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>
|
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mimm\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
|
||||||
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
||||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.10.1</NuGetToolVersion>
|
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.12.2</NuGetToolVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||||
<SourceRoot Include="C:\Users\Mimm\.nuget\packages\" />
|
<SourceRoot Include="C:\Users\Mimm\.nuget\packages\" />
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Test")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Test")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[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.AssemblyProductAttribute("mROA.Test")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Test")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Test")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
<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>
|
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mimm\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
|
||||||
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
||||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.10.1</NuGetToolVersion>
|
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.12.2</NuGetToolVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||||
<SourceRoot Include="C:\Users\Mimm\.nuget\packages\" />
|
<SourceRoot Include="C:\Users\Mimm\.nuget\packages\" />
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ public class PrepairedExecutionModule : IExecuteModule
|
|||||||
_serialisationModule = serialisationModule;
|
_serialisationModule = serialisationModule;
|
||||||
_contextRepo = contextRepo;
|
_contextRepo = contextRepo;
|
||||||
_serialisationModule.SetExecuteModule(this);
|
_serialisationModule.SetExecuteModule(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICommandExecution Execute(ICallRequest command)
|
public ICommandExecution Execute(ICallRequest command)
|
||||||
@@ -26,54 +25,71 @@ public class PrepairedExecutionModule : IExecuteModule
|
|||||||
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 ? _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;
|
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)
|
||||||
var tokenSource = new CancellationTokenSource();
|
return TypedExecuteAsync(currentCommand, context, parameter, command);
|
||||||
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(task =>
|
|
||||||
{
|
|
||||||
var result = task.GetType().GetProperty("Result").GetValue(task);
|
|
||||||
_serialisationModule.PostResponse(new FinalCommandExecution
|
|
||||||
{
|
|
||||||
ExecutionId = exec.ExecutionId, Result = result, CommandId = command.CommandId,
|
|
||||||
ClientId = command.ClientId
|
|
||||||
});
|
|
||||||
}, token);
|
|
||||||
|
|
||||||
return exec;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentCommand.ReturnType == typeof(Task))
|
if (currentCommand.ReturnType == typeof(Task))
|
||||||
{
|
return ExecuteAsync(currentCommand, context, parameter, command);
|
||||||
var tokenSource = new CancellationTokenSource();
|
|
||||||
var token = tokenSource.Token;
|
|
||||||
|
|
||||||
var result = currentCommand.Invoke(context, parameter is null ? [token] : [parameter, token]) as Task;
|
return Execute(currentCommand, context, parameter, command);
|
||||||
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 Execute(MethodInfo currentCommand, object context, object parameter, ICallRequest request)
|
||||||
|
{
|
||||||
var finalResult = currentCommand.Invoke(context, parameter is null ? [] : [parameter]);
|
var finalResult = currentCommand.Invoke(context, parameter is null ? [] : [parameter]);
|
||||||
return new FinalCommandExecution { CommandId = command.CommandId, Result = finalResult };
|
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;
|
||||||
|
|
||||||
|
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(task =>
|
||||||
|
{
|
||||||
|
var result = task.GetType().GetProperty("Result").GetValue(task);
|
||||||
|
_serialisationModule.PostResponse(new FinalCommandExecution
|
||||||
|
{
|
||||||
|
ExecutionId = exec.ExecutionId, Result = result, CommandId = command.CommandId,
|
||||||
|
ClientId = command.ClientId
|
||||||
|
});
|
||||||
|
}, token);
|
||||||
|
|
||||||
|
return exec;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <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>
|
// </auto-generated>
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[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.AssemblyProductAttribute("mROA")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("mROA")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("mROA")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
<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>
|
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mimm\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
|
||||||
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
||||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.10.1</NuGetToolVersion>
|
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.12.2</NuGetToolVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||||
<SourceRoot Include="C:\Users\Mimm\.nuget\packages\" />
|
<SourceRoot Include="C:\Users\Mimm\.nuget\packages\" />
|
||||||
|
|||||||
Reference in New Issue
Block a user