минирефакторинг
This commit is contained in:
@@ -3,10 +3,10 @@ using mROA.Implementation;
|
|||||||
|
|
||||||
namespace Example.Backend;
|
namespace Example.Backend;
|
||||||
|
|
||||||
|
|
||||||
public class Printer : IPrinter
|
public class Printer : IPrinter
|
||||||
{
|
{
|
||||||
public string Name;
|
public string Name;
|
||||||
|
|
||||||
public string GetName()
|
public string GetName()
|
||||||
{
|
{
|
||||||
return Name;
|
return Name;
|
||||||
@@ -15,6 +15,7 @@ public class Printer : IPrinter
|
|||||||
public async Task<SharedObject<IPage>> Print(string text, CancellationToken cancellationToken = default)
|
public async Task<SharedObject<IPage>> Print(string text, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
// throw new Exception("The method or operation is not implemented.");
|
// throw new Exception("The method or operation is not implemented.");
|
||||||
return new Page {Text = text};
|
// var sharedObject = new Page { Text = text };
|
||||||
|
return new Page { Text = text };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ _ = builder.GetModule<RequestExtractor>()!.StartExtraction();
|
|||||||
Console.WriteLine(TransmissionConfig.OwnershipRepository.GetOwnershipId());
|
Console.WriteLine(TransmissionConfig.OwnershipRepository.GetOwnershipId());
|
||||||
var context = builder.GetModule<RemoteContextRepository>();
|
var context = builder.GetModule<RemoteContextRepository>();
|
||||||
|
|
||||||
var factory = context.GetSingleObject(typeof(IPrinterFactory)) as IPrinterFactory;
|
var factory = context.GetSingleObject<IPrinterFactory>();
|
||||||
|
|
||||||
//правильный порядок команд 8-5-10-7
|
//правильный порядок команд 8-5-10-7
|
||||||
var printer = factory.Create("Test");
|
var printer = factory.Create("Test");
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ public interface IContextRepository : IInjectableModule
|
|||||||
void ClearObject(int id);
|
void ClearObject(int id);
|
||||||
object GetObject(int id);
|
object GetObject(int id);
|
||||||
T? GetObject<T>(int id);
|
T? GetObject<T>(int id);
|
||||||
|
T GetSingleObject<T>();
|
||||||
object GetSingleObject(Type type);
|
object GetSingleObject(Type type);
|
||||||
int GetObjectIndex(object o);
|
int GetObjectIndex(object o);
|
||||||
}
|
}
|
||||||
@@ -21,13 +21,13 @@ public interface ISerialisationModule : IInjectableModule
|
|||||||
public interface IRepresentationModule : IInjectableModule
|
public interface IRepresentationModule : IInjectableModule
|
||||||
{
|
{
|
||||||
int Id { get; }
|
int Id { get; }
|
||||||
Task<T> GetMessageAsync<T>(Guid? requestId = null, MessageType? messageType = null, CancellationToken token = default);
|
Task<T> GetMessageAsync<T>(Guid? requestId = null, EMessageType? messageType = null, CancellationToken token = default);
|
||||||
T GetMessage<T>(Guid? requestId = null, MessageType? messageType = null);
|
T GetMessage<T>(Guid? requestId = null, EMessageType? messageType = null);
|
||||||
T GetMessage<T>(Predicate<NetworkMessage> filter);
|
T GetMessage<T>(Predicate<NetworkMessage> filter);
|
||||||
Task<byte[]> GetRawMessage(Predicate<NetworkMessage> filter, CancellationToken token = default);
|
Task<byte[]> GetRawMessage(Predicate<NetworkMessage> filter, CancellationToken token = default);
|
||||||
|
|
||||||
Task PostCallMessageAsync<T>(Guid id, MessageType messageType, T payload) where T : notnull;
|
Task PostCallMessageAsync<T>(Guid id, EMessageType eMessageType, T payload) where T : notnull;
|
||||||
Task PostCallMessageAsync(Guid id, MessageType messageType, object payload, Type payloadType);
|
Task PostCallMessageAsync(Guid id, EMessageType eMessageType, object payload, Type payloadType);
|
||||||
void PostCallMessage<T>(Guid id, MessageType messageType, T payload) where T : notnull;
|
void PostCallMessage<T>(Guid id, EMessageType eMessageType, T payload) where T : notnull;
|
||||||
void PostCallMessage(Guid id, MessageType messageType, object payload, Type payloadType);
|
void PostCallMessage(Guid id, EMessageType eMessageType, object payload, Type payloadType);
|
||||||
}
|
}
|
||||||
@@ -28,6 +28,7 @@ public class BasicExecutionModule : IExecuteModule
|
|||||||
var context = command.ObjectId != -1
|
var context = command.ObjectId != -1
|
||||||
? contextRepository.GetObject(command.ObjectId)
|
? contextRepository.GetObject(command.ObjectId)
|
||||||
: contextRepository.GetSingleObject(currentCommand.DeclaringType!);
|
: contextRepository.GetSingleObject(currentCommand.DeclaringType!);
|
||||||
|
|
||||||
var parameter = command.Parameter;
|
var parameter = command.Parameter;
|
||||||
|
|
||||||
if (currentCommand.ReturnType.BaseType == typeof(Task) &&
|
if (currentCommand.ReturnType.BaseType == typeof(Task) &&
|
||||||
|
|||||||
@@ -54,12 +54,21 @@ public class ContextRepository : IContextRepository
|
|||||||
|
|
||||||
public T GetObject<T>(int id)
|
public T GetObject<T>(int id)
|
||||||
{
|
{
|
||||||
return id == -1 || _storage.Length <= id ? throw new NullReferenceException("Cannot find that object. It is null"): (T)_storage[id]!;
|
return id == -1 || _storage.Length <= id
|
||||||
|
? throw new NullReferenceException("Cannot find that object. It is null")
|
||||||
|
: (T)_storage[id]!;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T GetSingleObject<T>()
|
||||||
|
{
|
||||||
|
var result = GetSingleObject(typeof(T));
|
||||||
|
return (T)result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public object GetSingleObject(Type type)
|
public object GetSingleObject(Type type)
|
||||||
{
|
{
|
||||||
return _singletons!.GetValueOrDefault(type.GetHashCode()) ?? throw new ArgumentException("Unregistered singleton type");
|
return _singletons!.GetValueOrDefault(type.GetHashCode()) ??
|
||||||
|
throw new ArgumentException("Unregistered singleton type");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetObjectIndex(object o)
|
public int GetObjectIndex(object o)
|
||||||
@@ -81,8 +90,8 @@ public class ContextRepository : IContextRepository
|
|||||||
_storage = nextStorage;
|
_storage = nextStorage;
|
||||||
return _storage.Length;
|
return _storage.Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Inject<T>(T dependency)
|
public void Inject<T>(T dependency)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -39,6 +39,12 @@ public class MultiClientContextRepository(Func<int, IContextRepository> produceR
|
|||||||
return GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()).GetObject<T>(id);
|
return GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()).GetObject<T>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T GetSingleObject<T>()
|
||||||
|
{
|
||||||
|
var result = GetSingleObject(typeof(T));
|
||||||
|
return (T)result;
|
||||||
|
}
|
||||||
|
|
||||||
public object GetSingleObject(Type type)
|
public object GetSingleObject(Type type)
|
||||||
{
|
{
|
||||||
return GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()).GetSingleObject(type);
|
return GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()).GetSingleObject(type);
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class NetworkGatewayModule : IGatewayModule
|
|||||||
interaction.StartInfiniteReceiving();
|
interaction.StartInfiniteReceiving();
|
||||||
interaction.PostMessage(new NetworkMessage
|
interaction.PostMessage(new NetworkMessage
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(), SchemaId = MessageType.IdAssigning,
|
Id = Guid.NewGuid(), MessageType = EMessageType.IdAssigning,
|
||||||
Data = _serialization.Serialize(new IdAssingnment { Id = interaction.ConnectionId })
|
Data = _serialization.Serialize(new IdAssingnment { Id = interaction.ConnectionId })
|
||||||
});
|
});
|
||||||
_hub.RegisterInteraction(interaction);
|
_hub.RegisterInteraction(interaction);
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ public class NetworkFrontendBridge(IPEndPoint ipEndPoint) : IFrontendBridge
|
|||||||
var handle = _interactionModule.CurrentReceivingHandle;
|
var handle = _interactionModule.CurrentReceivingHandle;
|
||||||
handle.WaitOne();
|
handle.WaitOne();
|
||||||
var welcomeMessage = _interactionModule.LastMessage;
|
var welcomeMessage = _interactionModule.LastMessage;
|
||||||
if (welcomeMessage.SchemaId != MessageType.IdAssigning)
|
if (welcomeMessage.MessageType != EMessageType.IdAssigning)
|
||||||
{
|
{
|
||||||
throw new Exception($"Incorrect message type. Must be IdAssigning, current : {welcomeMessage.SchemaId.ToString()}");
|
throw new Exception($"Incorrect message type. Must be IdAssigning, current : {welcomeMessage.MessageType.ToString()}");
|
||||||
}
|
}
|
||||||
_interactionModule.HandleMessage(welcomeMessage);
|
_interactionModule.HandleMessage(welcomeMessage);
|
||||||
TransmissionConfig.OwnershipRepository = new StaticOwnershipRepository(_serialization.Deserialize<IdAssingnment>(welcomeMessage.Data)!.Id);
|
TransmissionConfig.OwnershipRepository = new StaticOwnershipRepository(_serialization.Deserialize<IdAssingnment>(welcomeMessage.Data)!.Id);
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class RequestExtractor : IRequestExtractor
|
|||||||
{
|
{
|
||||||
|
|
||||||
var request =
|
var request =
|
||||||
_representationModule!.GetMessage<DefaultCallRequest>(m => m.Id != lastCommandId && m.SchemaId == MessageType.CallRequest);
|
_representationModule!.GetMessage<DefaultCallRequest>(m => m.Id != lastCommandId && m.MessageType == EMessageType.CallRequest);
|
||||||
lastCommandId = request.Id;
|
lastCommandId = request.Id;
|
||||||
if (request.Parameter is not null)
|
if (request.Parameter is not null)
|
||||||
{
|
{
|
||||||
@@ -74,8 +74,8 @@ public class RequestExtractor : IRequestExtractor
|
|||||||
var result = _executeModule.Execute(request, _contextRepository);
|
var result = _executeModule.Execute(request, _contextRepository);
|
||||||
|
|
||||||
var resultType = result is FinalCommandExecution
|
var resultType = result is FinalCommandExecution
|
||||||
? MessageType.FinishedCommandExecution
|
? EMessageType.FinishedCommandExecution
|
||||||
: MessageType.ExceptionCommandExecution;
|
: EMessageType.ExceptionCommandExecution;
|
||||||
|
|
||||||
_representationModule.PostCallMessage(request.Id, resultType, result, result.GetType());
|
_representationModule.PostCallMessage(request.Id, resultType, result, result.GetType());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,24 +4,20 @@
|
|||||||
|
|
||||||
namespace mROA.Implementation;
|
namespace mROA.Implementation;
|
||||||
|
|
||||||
public class NetworkMessage
|
public sealed class NetworkMessage
|
||||||
{
|
{
|
||||||
public static readonly NetworkMessage Null = new() { SchemaId = MessageType.Unknown, Id = Guid.Empty, Data = [] };
|
public static readonly NetworkMessage Null = new() { MessageType = EMessageType.Unknown, Id = Guid.Empty, Data = [] };
|
||||||
public Guid Id { get; init; }
|
public Guid Id { get; init; }
|
||||||
|
public EMessageType MessageType { get; init; }
|
||||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
|
||||||
public MessageType SchemaId { get; init; }
|
|
||||||
|
|
||||||
public required byte[] Data { get; init; }
|
public required byte[] Data { get; init; }
|
||||||
|
public bool IsValidMessage(Guid? requestId = null, EMessageType? messageType = null)
|
||||||
public bool IsValidMessage(Guid? requestId = null, MessageType? messageType = null)
|
|
||||||
{
|
{
|
||||||
return (requestId is null || Id == requestId) &&
|
return (requestId is null || Id == requestId) &&
|
||||||
(messageType is null || SchemaId == messageType);
|
(messageType is null || MessageType == messageType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum MessageType
|
public enum EMessageType
|
||||||
{
|
{
|
||||||
Unknown,
|
Unknown,
|
||||||
FinishedCommandExecution,
|
FinishedCommandExecution,
|
||||||
|
|||||||
@@ -31,7 +31,12 @@ public class RemoteContextRepository : IContextRepository
|
|||||||
var remote = (T)Activator.CreateInstance(remoteType, id, _representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId()))!;
|
var remote = (T)Activator.CreateInstance(remoteType, id, _representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId()))!;
|
||||||
return remote;
|
return remote;
|
||||||
}
|
}
|
||||||
|
public T GetSingleObject<T>()
|
||||||
|
{
|
||||||
|
var obj = GetSingleObject(typeof(T));
|
||||||
|
return (T)obj;
|
||||||
|
}
|
||||||
|
|
||||||
public object GetSingleObject(Type type)
|
public object GetSingleObject(Type type)
|
||||||
{
|
{
|
||||||
if (_representationProducer == null)
|
if (_representationProducer == null)
|
||||||
|
|||||||
@@ -14,27 +14,26 @@ public abstract class RemoteObjectBase(int id, IRepresentationModule representat
|
|||||||
{
|
{
|
||||||
var request = new DefaultCallRequest
|
var request = new DefaultCallRequest
|
||||||
{ CommandId = methodId, ObjectId = id, Parameter = parameter, ParameterType = parameter?.GetType() };
|
{ CommandId = methodId, ObjectId = id, Parameter = parameter, ParameterType = parameter?.GetType() };
|
||||||
await representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
await representationModule.PostCallMessageAsync(request.Id, EMessageType.CallRequest, request);
|
||||||
|
|
||||||
var localTokenSource = new CancellationTokenSource();
|
var localTokenSource = new CancellationTokenSource();
|
||||||
|
|
||||||
var successResponse =
|
var successResponse =
|
||||||
representationModule.GetMessageAsync<FinalCommandExecution<T>>(
|
representationModule.GetMessageAsync<FinalCommandExecution<T>>(request.Id,
|
||||||
messageType: MessageType.FinishedCommandExecution, requestId: request.Id, token: localTokenSource.Token);
|
EMessageType.FinishedCommandExecution, localTokenSource.Token);
|
||||||
var errorResponse =
|
|
||||||
representationModule.GetMessageAsync<ExceptionCommandExecution>(
|
|
||||||
messageType: MessageType.ExceptionCommandExecution, requestId: request.Id, token: localTokenSource.Token);
|
|
||||||
|
|
||||||
|
var errorResponse =
|
||||||
|
representationModule.GetMessageAsync<ExceptionCommandExecution>(request.Id,
|
||||||
|
EMessageType.ExceptionCommandExecution, localTokenSource.Token);
|
||||||
|
|
||||||
Task.WaitAny(successResponse, errorResponse);
|
Task.WaitAny(successResponse, errorResponse);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (successResponse.IsCompletedSuccessfully)
|
if (successResponse.IsCompletedSuccessfully)
|
||||||
{
|
{
|
||||||
await localTokenSource.CancelAsync();
|
await localTokenSource.CancelAsync();
|
||||||
return successResponse.Result.Result!;
|
return successResponse.Result.Result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
await localTokenSource.CancelAsync();
|
await localTokenSource.CancelAsync();
|
||||||
throw errorResponse.Result.GetException();
|
throw errorResponse.Result.GetException();
|
||||||
}
|
}
|
||||||
@@ -43,14 +42,14 @@ public abstract class RemoteObjectBase(int id, IRepresentationModule representat
|
|||||||
{
|
{
|
||||||
var request = new DefaultCallRequest
|
var request = new DefaultCallRequest
|
||||||
{ CommandId = methodId, ObjectId = id, Parameter = parameter, ParameterType = parameter?.GetType() };
|
{ CommandId = methodId, ObjectId = id, Parameter = parameter, ParameterType = parameter?.GetType() };
|
||||||
await representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
await representationModule.PostCallMessageAsync(request.Id, EMessageType.CallRequest, request);
|
||||||
|
|
||||||
var successResponse =
|
var successResponse =
|
||||||
representationModule.GetMessageAsync<FinalCommandExecution>(
|
representationModule.GetMessageAsync<FinalCommandExecution>(
|
||||||
messageType: MessageType.FinishedCommandExecution, requestId: request.Id);
|
messageType: EMessageType.FinishedCommandExecution, requestId: request.Id);
|
||||||
var errorResponse =
|
var errorResponse =
|
||||||
representationModule.GetMessageAsync<ExceptionCommandExecution>(
|
representationModule.GetMessageAsync<ExceptionCommandExecution>(
|
||||||
messageType: MessageType.ExceptionCommandExecution, requestId: request.Id);
|
messageType: EMessageType.ExceptionCommandExecution, requestId: request.Id);
|
||||||
|
|
||||||
Task.WaitAny(successResponse, errorResponse);
|
Task.WaitAny(successResponse, errorResponse);
|
||||||
|
|
||||||
|
|||||||
@@ -22,16 +22,17 @@ public class RepresentationModule : IRepresentationModule
|
|||||||
|
|
||||||
public int Id => (_interaction ?? throw new NullReferenceException("Interaction is not initialized")).ConnectionId;
|
public int Id => (_interaction ?? throw new NullReferenceException("Interaction is not initialized")).ConnectionId;
|
||||||
|
|
||||||
public async Task<T> GetMessageAsync<T>(Guid? requestId, MessageType? messageType,
|
public async Task<T> GetMessageAsync<T>(Guid? requestId, EMessageType? messageType,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (_serialization == null)
|
if (_serialization == null)
|
||||||
throw new NullReferenceException("Serialization toolkit is not initialized");
|
throw new NullReferenceException("Serialization toolkit is not initialized");
|
||||||
|
|
||||||
return _serialization.Deserialize<T>(await GetRawMessage(m => m.IsValidMessage(requestId, messageType), token))!;
|
var raw = await GetRawMessage(m => m.IsValidMessage(requestId, messageType), token);
|
||||||
|
return _serialization.Deserialize<T>(raw)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetMessage<T>(Guid? requestId = null, MessageType? messageType = null)
|
public T GetMessage<T>(Guid? requestId = null, EMessageType? messageType = null)
|
||||||
{
|
{
|
||||||
return GetMessage<T>(m => m.IsValidMessage(requestId, messageType));
|
return GetMessage<T>(m => m.IsValidMessage(requestId, messageType));
|
||||||
}
|
}
|
||||||
@@ -40,8 +41,8 @@ public class RepresentationModule : IRepresentationModule
|
|||||||
{
|
{
|
||||||
if (_serialization == null)
|
if (_serialization == null)
|
||||||
throw new NullReferenceException("Serialization toolkit is not initialized");
|
throw new NullReferenceException("Serialization toolkit is not initialized");
|
||||||
|
var raw = GetRawMessage(filter).GetAwaiter().GetResult();
|
||||||
return _serialization.Deserialize<T>(GetRawMessage(filter).GetAwaiter().GetResult())!;
|
return _serialization.Deserialize<T>(raw)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<byte[]> GetRawMessage(Predicate<NetworkMessage> filter, CancellationToken token = default)
|
public async Task<byte[]> GetRawMessage(Predicate<NetworkMessage> filter, CancellationToken token = default)
|
||||||
@@ -50,10 +51,7 @@ public class RepresentationModule : IRepresentationModule
|
|||||||
|
|
||||||
if (_interaction == null)
|
if (_interaction == null)
|
||||||
throw new NullReferenceException("Interaction toolkit is not initialized");
|
throw new NullReferenceException("Interaction toolkit is not initialized");
|
||||||
|
|
||||||
// Console.WriteLine(
|
|
||||||
// $"{DateTime.Now.TimeOfDay} {Environment.CurrentManagedThreadId} Representation : Reading");
|
|
||||||
|
|
||||||
if (filter(_interaction.LastMessage))
|
if (filter(_interaction.LastMessage))
|
||||||
{
|
{
|
||||||
_interaction.HandleMessage(_interaction.LastMessage);
|
_interaction.HandleMessage(_interaction.LastMessage);
|
||||||
@@ -71,20 +69,16 @@ public class RepresentationModule : IRepresentationModule
|
|||||||
|
|
||||||
while (!token.IsCancellationRequested)
|
while (!token.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
// Console.WriteLine(
|
|
||||||
// $"{DateTime.Now.TimeOfDay} {Environment.CurrentManagedThreadId} Representation : Receiving message...");
|
|
||||||
var handle = _interaction.CurrentReceivingHandle;
|
var handle = _interaction.CurrentReceivingHandle;
|
||||||
handle.WaitOne();
|
handle.WaitOne();
|
||||||
|
|
||||||
message = _interaction.LastMessage;
|
message = _interaction.LastMessage;
|
||||||
|
|
||||||
// Console.WriteLine(
|
if (!filter(message))
|
||||||
// $"{DateTime.Now.TimeOfDay} {Environment.CurrentManagedThreadId} Representation : Message received {message.SchemaId} - {message.Id}");
|
continue;
|
||||||
if (!filter(message)) continue;
|
|
||||||
|
|
||||||
message = _interaction.LastMessage;
|
message = _interaction.LastMessage;
|
||||||
// Console.WriteLine(
|
|
||||||
// $"{DateTime.Now.TimeOfDay} {Environment.CurrentManagedThreadId} Representation : Message received Successfully {message.SchemaId} - {message.Id}");
|
|
||||||
_interaction.HandleMessage(message);
|
_interaction.HandleMessage(message);
|
||||||
return message.Data;
|
return message.Data;
|
||||||
}
|
}
|
||||||
@@ -92,29 +86,30 @@ public class RepresentationModule : IRepresentationModule
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PostCallMessageAsync<T>(Guid id, MessageType messageType, T payload) where T : notnull
|
public async Task PostCallMessageAsync<T>(Guid id, EMessageType eMessageType, T payload) where T : notnull
|
||||||
{
|
{
|
||||||
await PostCallMessageAsync(id, messageType, payload, typeof(T));
|
await PostCallMessageAsync(id, eMessageType, payload, typeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PostCallMessageAsync(Guid id, MessageType messageType, object payload, Type payloadType)
|
public async Task PostCallMessageAsync(Guid id, EMessageType eMessageType, object payload, Type payloadType)
|
||||||
{
|
{
|
||||||
if (_interaction == null)
|
if (_interaction == null)
|
||||||
throw new NullReferenceException("Interaction toolkit is not initialized");
|
throw new NullReferenceException("Interaction toolkit is not initialized");
|
||||||
if (_serialization == null)
|
if (_serialization == null)
|
||||||
throw new NullReferenceException("Serialization toolkit is not initialized");
|
throw new NullReferenceException("Serialization toolkit is not initialized");
|
||||||
|
|
||||||
await _interaction.PostMessage(new NetworkMessage
|
var message = new NetworkMessage
|
||||||
{ Id = id, SchemaId = messageType, Data = _serialization.Serialize(payload, payloadType) });
|
{ Id = id, MessageType = eMessageType, Data = _serialization.Serialize(payload, payloadType) };
|
||||||
|
await _interaction.PostMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PostCallMessage<T>(Guid id, MessageType messageType, T payload) where T : notnull
|
public void PostCallMessage<T>(Guid id, EMessageType eMessageType, T payload) where T : notnull
|
||||||
{
|
{
|
||||||
PostCallMessageAsync(id, messageType, payload).GetAwaiter().GetResult();
|
PostCallMessageAsync(id, eMessageType, payload).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PostCallMessage(Guid id, MessageType messageType, object payload, Type payloadType)
|
public void PostCallMessage(Guid id, EMessageType eMessageType, object payload, Type payloadType)
|
||||||
{
|
{
|
||||||
PostCallMessageAsync(id, messageType, payload, payloadType).GetAwaiter().GetResult();
|
PostCallMessageAsync(id, eMessageType, payload, payloadType).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user