diff --git a/mROA/Implementation/Frontend/RequestExtractor.cs b/mROA/Implementation/Frontend/RequestExtractor.cs index b13a5d1..d8c9e10 100644 --- a/mROA/Implementation/Frontend/RequestExtractor.cs +++ b/mROA/Implementation/Frontend/RequestExtractor.cs @@ -65,7 +65,7 @@ namespace mROA.Implementation.Frontend while (true) { #if TRACE - Console.WriteLine("Waiting for request..."); + Console.WriteLine("Waiting for request..."); #endif var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; @@ -80,12 +80,12 @@ namespace mROA.Implementation.Frontend messageType: MessageType.EventRequest, token: token); Task.WaitAny(defaultRequest, cancelRequest, eventRequest); #if TRACE - Console.WriteLine("Request received"); + Console.WriteLine("Request received"); #endif if (cancelRequest.IsCompleted) { #if TRACE - Console.WriteLine("Cancelling request"); + Console.WriteLine("Cancelling request"); #endif var req = cancelRequest.Result; tokenSource.Cancel(); @@ -118,7 +118,7 @@ namespace mROA.Implementation.Frontend else { tokenSource.Cancel(); - var request = defaultRequest.Result; + var request = eventRequest.Result; _executeModule.Execute(request, _contextRepository, _representationModule); } } diff --git a/mROA/Implementation/NextGenerationInteractionModule.cs b/mROA/Implementation/NextGenerationInteractionModule.cs index 68239ea..5defb89 100644 --- a/mROA/Implementation/NextGenerationInteractionModule.cs +++ b/mROA/Implementation/NextGenerationInteractionModule.cs @@ -9,13 +9,13 @@ namespace mROA.Implementation { public class NextGenerationInteractionModule : INextGenerationInteractionModule { + private const int BufferSize = ushort.MaxValue; + private readonly Memory _buffer = new byte[BufferSize]; + private readonly List _messageBuffer = new(128); + private Task? _currentReceiving; private ISerializationToolkit? _serialization; public int ConnectionId { get; private set; } public Stream? BaseStream { get; set; } - private Task? _currentReceiving; - private const int BufferSize = ushort.MaxValue; - private readonly Memory _buffer = new byte[BufferSize]; - private readonly List _messageBuffer = new (128); public void Inject(T dependency) @@ -36,7 +36,6 @@ namespace mROA.Implementation if (_currentReceiving != null) return _currentReceiving; _currentReceiving = Task.Run(async () => await GetNextMessage()); return _currentReceiving; - } public async Task PostMessage(NetworkMessage message) @@ -46,7 +45,7 @@ namespace mROA.Implementation if (_serialization == null) throw new NullReferenceException("Serialization toolkit is not initialized"); - + // Console.WriteLine("Sending {0}", JsonSerializer.Serialize(message)); @@ -62,6 +61,7 @@ namespace mROA.Implementation } public NetworkMessage[] UnhandledMessages => _messageBuffer.ToArray(); + public NetworkMessage? FirstByFilter(Predicate predicate) { return _messageBuffer.FirstOrDefault(m => predicate(m)); @@ -79,23 +79,23 @@ namespace mROA.Implementation // Console.WriteLine("Receiving message"); var firstBit = (byte)BaseStream.ReadByte(); var secondBit = (byte)BaseStream.ReadByte(); - - var len = BitConverter.ToUInt16(new[] { firstBit, secondBit}); + + var len = BitConverter.ToUInt16(new[] { firstBit, secondBit }); var localSpan = _buffer.Slice(0, len); - + await BaseStream.ReadExactlyAsync(localSpan); // Console.WriteLine("Receiving {0}", Encoding.Default.GetString(_buffer[..len])); var message = _serialization.Deserialize(localSpan.Span); #if TRACE - Console.WriteLine($"Received Message {message.SchemaId} - {message.Id}"); + Console.WriteLine($"Received Message {message.Id} - {message.SchemaId}"); TransmissionConfig.TotalTransmittedBytes += len; Console.WriteLine($"Total recieced bytes are {TransmissionConfig.TotalTransmittedBytes}"); #endif _messageBuffer.Add(message); _currentReceiving = Task.Run(async () => await GetNextMessage()); - + return message; } } diff --git a/mROA/Implementation/RepresentationModule.cs b/mROA/Implementation/RepresentationModule.cs index c04f160..58f2ce5 100644 --- a/mROA/Implementation/RepresentationModule.cs +++ b/mROA/Implementation/RepresentationModule.cs @@ -91,7 +91,7 @@ namespace mROA.Implementation if (_serialization == null) throw new NullReferenceException("Serialization toolkit is not initialized"); #if TRACE - Console.WriteLine($"Posting message: {id} - {messageType}"); + Console.WriteLine($"Posting message: {id} - {messageType} to {Id}"); #endif var serialized = _serialization.Serialize(payload, payloadType); diff --git a/mROA/mROA.csproj b/mROA/mROA.csproj index e9d980c..8723457 100644 --- a/mROA/mROA.csproj +++ b/mROA/mROA.csproj @@ -21,7 +21,7 @@ - + TRACE;