Second Unity code equating session
This commit is contained in:
@@ -30,18 +30,12 @@ namespace mROA.Implementation.Backend
|
|||||||
public ICommandExecution Execute(ICallRequest command, IContextRepository contextRepository,
|
public ICommandExecution Execute(ICallRequest command, IContextRepository contextRepository,
|
||||||
IRepresentationModule representationModule, IEndPointContext endPointContext)
|
IRepresentationModule representationModule, IEndPointContext endPointContext)
|
||||||
{
|
{
|
||||||
#if TRACE
|
|
||||||
Console.WriteLine(command.GetType().Name);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ThrowIfNotInjected(contextRepository);
|
ThrowIfNotInjected(contextRepository);
|
||||||
if (command is CancelRequest)
|
if (command is CancelRequest)
|
||||||
{
|
{
|
||||||
#if TRACE
|
|
||||||
Console.WriteLine("Final cancelling request");
|
|
||||||
#endif
|
|
||||||
return CancelExecution(command);
|
return CancelExecution(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,9 +70,6 @@ namespace mROA.Implementation.Backend
|
|||||||
var result = Execute((invoker as MethodInvoker)!, context, castedParams!, command, execContext);
|
var result = Execute((invoker as MethodInvoker)!, context, castedParams!, command, execContext);
|
||||||
if (command.CommandId == -1)
|
if (command.CommandId == -1)
|
||||||
{
|
{
|
||||||
#if TRACE
|
|
||||||
Console.WriteLine("Disposing object");
|
|
||||||
#endif
|
|
||||||
contextRepository.ClearObject(command.ObjectId, endPointContext);
|
contextRepository.ClearObject(command.ObjectId, endPointContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,9 +180,7 @@ namespace mROA.Implementation.Backend
|
|||||||
var tokenSource = new CancellationTokenSource();
|
var tokenSource = new CancellationTokenSource();
|
||||||
cancellationRepository.RegisterCancellation(command.Id, tokenSource);
|
cancellationRepository.RegisterCancellation(command.Id, tokenSource);
|
||||||
var token = tokenSource.Token;
|
var token = tokenSource.Token;
|
||||||
#if TRACE
|
|
||||||
token.Register(() => Console.WriteLine($"Cancellation requested check {command.Id}"));
|
|
||||||
#endif
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
invoker.Invoke(instance, parameters, new object[] { executionContext, token }, _ =>
|
invoker.Invoke(instance, parameters, new object[] { executionContext, token }, _ =>
|
||||||
|
|||||||
@@ -33,15 +33,6 @@ namespace mROA.Implementation.Backend
|
|||||||
Console.WriteLine("Enter Backspace to stop");
|
Console.WriteLine("Enter Backspace to stop");
|
||||||
|
|
||||||
Task.Run(HandleIncomingConnections);
|
Task.Run(HandleIncomingConnections);
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
var key = Console.ReadKey();
|
|
||||||
if (key.Key == ConsoleKey.Backspace)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("Stopping");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
@@ -62,13 +53,13 @@ namespace mROA.Implementation.Backend
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleIncomingConnections()
|
private async Task HandleIncomingConnections()
|
||||||
{
|
{
|
||||||
ThrowIfNotInjected();
|
ThrowIfNotInjected();
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
var client = _tcpListener.AcceptTcpClient();
|
var client = await _tcpListener.AcceptTcpClientAsync();
|
||||||
Console.WriteLine($"Client connected from {client.Client.RemoteEndPoint}");
|
Console.WriteLine($"Client connected from {client.Client.RemoteEndPoint}");
|
||||||
var interaction = Activator.CreateInstance(_interactionModuleType!) as IChannelInteractionModule;
|
var interaction = Activator.CreateInstance(_interactionModuleType!) as IChannelInteractionModule;
|
||||||
|
|
||||||
@@ -84,10 +75,12 @@ namespace mROA.Implementation.Backend
|
|||||||
var streamExtractor =
|
var streamExtractor =
|
||||||
new ChannelInteractionModule.StreamExtractor(client.GetStream(), _serialization, context);
|
new ChannelInteractionModule.StreamExtractor(client.GetStream(), _serialization, context);
|
||||||
interaction.IsConnected = () => streamExtractor.IsConnected;
|
interaction.IsConnected = () => streamExtractor.IsConnected;
|
||||||
streamExtractor.MessageReceived = message => { interaction.ReceiveChanel.Writer.WriteAsync(message); };
|
streamExtractor.MessageReceived = async message =>
|
||||||
streamExtractor.SingleReceive();
|
{
|
||||||
var connectionRequest = interaction.GetNextMessageReceiving(false)
|
await interaction.ReceiveChanel.Writer.WriteAsync(message);
|
||||||
.GetAwaiter().GetResult()!;
|
};
|
||||||
|
Task.Run(() => streamExtractor.SingleReceive());
|
||||||
|
var connectionRequest = await interaction.ReceiveChanel.Reader.ReadAsync();
|
||||||
var cts = new CancellationTokenSource();
|
var cts = new CancellationTokenSource();
|
||||||
|
|
||||||
switch (connectionRequest.MessageType)
|
switch (connectionRequest.MessageType)
|
||||||
@@ -121,7 +114,6 @@ namespace mROA.Implementation.Backend
|
|||||||
|
|
||||||
|
|
||||||
recoveryInteraction.Restart(false);
|
recoveryInteraction.Restart(false);
|
||||||
Console.WriteLine("Connection recovery for client {0} finished", recoveryRequest.Id);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Channels;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
using Exception = System.Exception;
|
using Exception = System.Exception;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
#if TRACE
|
|
||||||
using System.Diagnostics;
|
|
||||||
#endif
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
@@ -16,8 +13,6 @@ namespace mROA.Implementation.Frontend
|
|||||||
|
|
||||||
private IMethodRepository? _methodRepository;
|
private IMethodRepository? _methodRepository;
|
||||||
|
|
||||||
// private IContextRepository? _realContextRepository;
|
|
||||||
// private IContextRepository? _remoteContextRepository;
|
|
||||||
private IRepresentationModule? _representationModule;
|
private IRepresentationModule? _representationModule;
|
||||||
private IContextualSerializationToolKit? _serializationToolkit;
|
private IContextualSerializationToolKit? _serializationToolkit;
|
||||||
private IEndPointContext _context;
|
private IEndPointContext _context;
|
||||||
@@ -51,9 +46,6 @@ namespace mROA.Implementation.Frontend
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
#if TRACE
|
|
||||||
var sw = new Stopwatch();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
var streamTokenSource = new CancellationTokenSource();
|
var streamTokenSource = new CancellationTokenSource();
|
||||||
|
|
||||||
@@ -69,20 +61,6 @@ namespace mROA.Implementation.Frontend
|
|||||||
|
|
||||||
await foreach (var command in query)
|
await foreach (var command in query)
|
||||||
{
|
{
|
||||||
#if TRACE
|
|
||||||
Console.WriteLine("Waiting for request...");
|
|
||||||
if (sw.IsRunning)
|
|
||||||
{
|
|
||||||
sw.Stop();
|
|
||||||
Console.WriteLine(
|
|
||||||
$"Request handling took {Math.Round(sw.Elapsed.TotalMilliseconds * 1000.0)} microseconds.");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if TRACE
|
|
||||||
Console.WriteLine("Request received");
|
|
||||||
sw.Restart();
|
|
||||||
#endif
|
|
||||||
switch (command.originalType)
|
switch (command.originalType)
|
||||||
{
|
{
|
||||||
case EMessageType.CallRequest:
|
case EMessageType.CallRequest:
|
||||||
|
|||||||
@@ -60,13 +60,9 @@ namespace mROA.Implementation.Frontend
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
var serialized = _serializationToolkit.Serialize(post, _context);
|
var serialized = _serializationToolkit.Serialize(post, _context);
|
||||||
#if TRACE
|
|
||||||
Console.WriteLine("Untrusted write start");
|
|
||||||
#endif
|
|
||||||
await udpClient.SendAsync(serialized, serialized.Length);
|
await udpClient.SendAsync(serialized, serialized.Length);
|
||||||
#if TRACE
|
|
||||||
Console.WriteLine("Untrusted write finished");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user