Рефакторинг модулей сетевого шлюза и хаба экстракторов
This commit is contained in:
@@ -47,6 +47,12 @@ namespace mROA.Implementation.Backend
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void HubOnOnConnected(IRepresentationModule interaction)
|
private void HubOnOnConnected(IRepresentationModule interaction)
|
||||||
|
{
|
||||||
|
var extractor = CreateExtractor(interaction);
|
||||||
|
_ = extractor.StartExtraction();
|
||||||
|
}
|
||||||
|
|
||||||
|
private IRequestExtractor CreateExtractor(IRepresentationModule interaction)
|
||||||
{
|
{
|
||||||
var extractor = (IRequestExtractor)Activator.CreateInstance(_extractorType)!;
|
var extractor = (IRequestExtractor)Activator.CreateInstance(_extractorType)!;
|
||||||
extractor.Inject(interaction);
|
extractor.Inject(interaction);
|
||||||
@@ -58,7 +64,7 @@ namespace mROA.Implementation.Backend
|
|||||||
extractor.Inject(_serializationToolkit);
|
extractor.Inject(_serializationToolkit);
|
||||||
extractor.Inject(_executeModule);
|
extractor.Inject(_executeModule);
|
||||||
extractor.Inject(_remoteContextRepository);
|
extractor.Inject(_remoteContextRepository);
|
||||||
_ = extractor.StartExtraction();
|
return extractor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,6 +59,33 @@ namespace mROA.Implementation.Backend
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void HandleIncomingConnections()
|
private void HandleIncomingConnections()
|
||||||
|
{
|
||||||
|
ThrowIfNotInjected();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
var client = _tcpListener.AcceptTcpClient();
|
||||||
|
Console.WriteLine($"Client connected from {client.Client.RemoteEndPoint}");
|
||||||
|
var interaction = Activator.CreateInstance(_interactionModuleType!) as INextGenerationInteractionModule;
|
||||||
|
|
||||||
|
foreach (var injectableModule in _injectableModules!)
|
||||||
|
interaction!.Inject(injectableModule);
|
||||||
|
|
||||||
|
interaction!.Inject(_serialization);
|
||||||
|
|
||||||
|
interaction.BaseStream = client.GetStream();
|
||||||
|
|
||||||
|
interaction.PostMessage(new NetworkMessage
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(), SchemaId = MessageType.IdAssigning,
|
||||||
|
Data = _serialization!.Serialize(new IdAssignment { Id = -interaction.ConnectionId })
|
||||||
|
});
|
||||||
|
_hub!.RegisterInteraction(interaction);
|
||||||
|
Console.WriteLine("Client registered");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ThrowIfNotInjected()
|
||||||
{
|
{
|
||||||
if (_hub is null)
|
if (_hub is null)
|
||||||
throw new NullReferenceException("Hub module is null");
|
throw new NullReferenceException("Hub module is null");
|
||||||
@@ -70,28 +97,6 @@ namespace mROA.Implementation.Backend
|
|||||||
throw new NullReferenceException("InteractionModuleType is null");
|
throw new NullReferenceException("InteractionModuleType is null");
|
||||||
if (_serialization is null)
|
if (_serialization is null)
|
||||||
throw new NullReferenceException("Serialization is null");
|
throw new NullReferenceException("Serialization is null");
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
var client = _tcpListener.AcceptTcpClient();
|
|
||||||
Console.WriteLine($"Client connected from {client.Client.RemoteEndPoint}");
|
|
||||||
var interaction = Activator.CreateInstance(_interactionModuleType) as INextGenerationInteractionModule;
|
|
||||||
|
|
||||||
foreach (var injectableModule in _injectableModules)
|
|
||||||
interaction!.Inject(injectableModule);
|
|
||||||
|
|
||||||
interaction!.Inject(_serialization);
|
|
||||||
|
|
||||||
interaction.BaseStream = client.GetStream();
|
|
||||||
|
|
||||||
interaction.PostMessage(new NetworkMessage
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(), SchemaId = MessageType.IdAssigning,
|
|
||||||
Data = _serialization.Serialize(new IdAssignment { Id = -interaction.ConnectionId })
|
|
||||||
});
|
|
||||||
_hub.RegisterInteraction(interaction);
|
|
||||||
Console.WriteLine("Client registered");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user