Добавление препроцессора для очистки консоли

This commit is contained in:
2025-02-25 22:38:53 +03:00
parent d1a4d6f97e
commit c36e768210
15 changed files with 61 additions and 30 deletions
@@ -21,8 +21,9 @@ namespace mROA.Implementation.Backend
public ICommandExecution Execute(ICallRequest command, IContextRepository contextRepository,
IRepresentationModule representationModule)
{
#if TRACE
Console.WriteLine(command.GetType().Name);
#endif
if (_cancellationRepo is null)
throw new NullReferenceException("Method repository was not defined");
@@ -34,7 +35,9 @@ namespace mROA.Implementation.Backend
if (command is CancelRequest)
{
#if TRACE
Console.WriteLine("Final cancelling request");
#endif
var cts = _cancellationRepo.GetCancellation(command.Id);
cts.Cancel();
_cancellationRepo.FreeCancelation(command.Id);
@@ -68,7 +71,9 @@ namespace mROA.Implementation.Backend
var result = Execute(currentCommand, context, parameter, command);
if (command.CommandId == -1)
{
#if TRACE
Console.WriteLine("Disposing object");
#endif
contextRepository.ClearObject(command.ObjectId);
}
@@ -118,7 +123,9 @@ namespace mROA.Implementation.Backend
var tokenSource = new CancellationTokenSource();
cancellationRepository.RegisterCancellation(command.Id, tokenSource);
var token = tokenSource.Token;
#if TRACE
token.Register(() => Console.WriteLine($"Cancellation requested check {command.Id}"));
#endif
try
{
var finalParameter = parameter is null
@@ -63,7 +63,9 @@ namespace mROA.Implementation.Frontend
{
while (true)
{
#if TRACE
Console.WriteLine("Waiting for request...");
#endif
var tokenSource = new CancellationTokenSource();
var token = tokenSource.Token;
var defaultRequest =
@@ -74,12 +76,15 @@ namespace mROA.Implementation.Frontend
messageType: MessageType.CancelRequest, token: token);
Task.WaitAny(defaultRequest, cancelRequest);
#if TRACE
Console.WriteLine("Request received");
#endif
if (cancelRequest.IsCompleted)
{
#if TRACE
Console.WriteLine("Cancelling request");
#endif
var req = cancelRequest.Result;
tokenSource.Cancel();
_executeModule.Execute(req, _contextRepository, _representationModule);
@@ -87,7 +87,9 @@ namespace mROA.Implementation
// Console.WriteLine("Receiving {0}", Encoding.Default.GetString(_buffer[..len]));
var message = _serialization.Deserialize<NetworkMessage>(localSpan.Span);
#if TRACE
Console.WriteLine($"Received Message {message.SchemaId} - {message.Id}");
#endif
_messageBuffer.Add(message);
_currentReceiving = Task.Run(async () => await GetNextMessage());
+6 -1
View File
@@ -42,7 +42,9 @@ namespace mROA.Implementation
cancellationToken.Register(async () =>
{
#if TRACE
Console.WriteLine("Cancelling task");
#endif
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CancelRequest,
new CancelRequest
{
@@ -92,7 +94,9 @@ namespace mROA.Implementation
cancellationToken.Register(async () =>
{
#if TRACE
Console.WriteLine("Cancelling task");
#endif
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CancelRequest,
new CancelRequest
{
@@ -106,8 +110,9 @@ namespace mROA.Implementation
errorResponse, successResponse
}, cancellationToken);
#if TRACE
Console.WriteLine($"Handling message");
#endif
if (successResponse.IsCompletedSuccessfully)
return;
+12 -8
View File
@@ -23,9 +23,11 @@ namespace mROA.Implementation
}
}
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, CancellationToken token = default)
public async Task<T> GetMessageAsync<T>(Guid? requestId, MessageType? messageType,
CancellationToken token = default)
{
if (_serialization == null)
throw new NullReferenceException("Serialization toolkit is not initialized");
@@ -43,25 +45,26 @@ namespace mROA.Implementation
return _serialization.Deserialize<T>(rawMessage)!;
}
public async Task<byte[]> GetRawMessage(Guid? requestId = null, MessageType? messageType = null, CancellationToken token = default)
public async Task<byte[]> GetRawMessage(Guid? requestId = null, MessageType? messageType = null,
CancellationToken token = default)
{
if (_interaction == null)
throw new NullReferenceException("Interaction toolkit is not initialized");
var fromBuffer =
_interaction.FirstByFilter(message =>
(requestId is null || message.Id == requestId) &&
(messageType is null || message.SchemaId == messageType));
if (fromBuffer == null)
{
while (token.IsCancellationRequested == false)
{
var message = await _interaction.GetNextMessageReceiving();
if ((requestId is not null && message.Id != requestId) ||
(messageType is not null && message.SchemaId != messageType))
(messageType is not null && message.SchemaId != messageType))
continue;
_interaction.HandleMessage(message);
return message.Data;
}
@@ -82,8 +85,9 @@ namespace mROA.Implementation
throw new NullReferenceException("Interaction toolkit is not initialized");
if (_serialization == null)
throw new NullReferenceException("Serialization toolkit is not initialized");
#if TRACE
Console.WriteLine($"Posting message: {id} - {messageType}");
#endif
var serialized = _serialization.Serialize(payload, payloadType);
await _interaction.PostMessage(new NetworkMessage
+3 -1
View File
@@ -79,7 +79,8 @@ namespace mROA.Implementation
}
}
[JsonIgnore] public T Value { get; private set; }
[JsonIgnore]
public T Value { get; private set; }
// ReSharper disable once MemberCanBePrivate.Global
// ReSharper disable once UnusedMember.Global
@@ -106,6 +107,7 @@ namespace mROA.Implementation
public static implicit operator SharedObject<T>(T value) =>
new(value);
[JsonIgnore]
public IEndPointContext EndPointContext { get; set; } = new EndPointContext
{
RealRepository = TransmissionConfig.RealContextRepository,