первый пул рефакторинга
This commit is contained in:
@@ -1,32 +1,25 @@
|
||||
using mROA.Implementation;
|
||||
using mROA.Abstract;
|
||||
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
namespace mROA.Abstract;
|
||||
namespace mROA.Implementation;
|
||||
|
||||
public abstract class RemoteObjectBase
|
||||
public abstract class RemoteObjectBase(int id, IRepresentationModule representationModule)
|
||||
{
|
||||
private readonly int _id;
|
||||
private readonly IRepresentationModule _representationModule;
|
||||
public int Id => _id;
|
||||
public int OwnerId => _representationModule.Id;
|
||||
public int Id => id;
|
||||
public int OwnerId => representationModule.Id;
|
||||
|
||||
public RemoteObjectBase(int id, IRepresentationModule representationModule)
|
||||
{
|
||||
_id = id;
|
||||
_representationModule = representationModule;
|
||||
}
|
||||
|
||||
public async Task<T> GetResultAsync<T>(int methodId, object? parameter = default)
|
||||
protected async Task<T> GetResultAsync<T>(int methodId, object? parameter = default)
|
||||
{
|
||||
var request = new DefaultCallRequest
|
||||
{ CommandId = methodId, ObjectId = _id, Parameter = parameter, ParameterType = parameter?.GetType() };
|
||||
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
||||
{ CommandId = methodId, ObjectId = id, Parameter = parameter, ParameterType = parameter?.GetType() };
|
||||
await representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
||||
|
||||
var successResponse =
|
||||
_representationModule.GetMessageAsync<FinalCommandExecution<T>>(
|
||||
representationModule.GetMessageAsync<FinalCommandExecution<T>>(
|
||||
messageType: MessageType.FinishedCommandExecution, requestId: request.Id);
|
||||
var errorResponse =
|
||||
_representationModule.GetMessageAsync<ExceptionCommandExecution>(
|
||||
representationModule.GetMessageAsync<ExceptionCommandExecution>(
|
||||
messageType: MessageType.ExceptionCommandExecution, requestId: request.Id);
|
||||
Task.WaitAny(successResponse, errorResponse);
|
||||
|
||||
@@ -36,17 +29,17 @@ public abstract class RemoteObjectBase
|
||||
throw errorResponse.Result.GetException();
|
||||
}
|
||||
|
||||
public async Task CallAsync(int methodId, object? parameter = default)
|
||||
protected async Task CallAsync(int methodId, object? parameter = default)
|
||||
{
|
||||
var request = new DefaultCallRequest
|
||||
{ CommandId = methodId, ObjectId = _id, Parameter = parameter, ParameterType = parameter?.GetType() };
|
||||
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
||||
{ CommandId = methodId, ObjectId = id, Parameter = parameter, ParameterType = parameter?.GetType() };
|
||||
await representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
||||
|
||||
var successResponse =
|
||||
_representationModule.GetMessageAsync<FinalCommandExecution>(
|
||||
representationModule.GetMessageAsync<FinalCommandExecution>(
|
||||
messageType: MessageType.FinishedCommandExecution, requestId: request.Id);
|
||||
var errorResponse =
|
||||
_representationModule.GetMessageAsync<ExceptionCommandExecution>(
|
||||
representationModule.GetMessageAsync<ExceptionCommandExecution>(
|
||||
messageType: MessageType.ExceptionCommandExecution, requestId: request.Id);
|
||||
|
||||
Task.WaitAny(successResponse, errorResponse);
|
||||
|
||||
Reference in New Issue
Block a user