Skip to content

Commit fbe5cf0

Browse files
Fix code style
1 parent 1522fed commit fbe5cf0

24 files changed

+540
-515
lines changed

mcp_nexus/CommandQueue/CommandQueueService.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ public string QueueCommand(string command)
7777
{
7878
if (m_disposed)
7979
throw new ObjectDisposedException(nameof(CommandQueueService));
80-
80+
8181
if (string.IsNullOrWhiteSpace(command))
8282
throw new ArgumentException("Command cannot be null or empty", nameof(command));
83-
83+
8484
var commandId = Guid.NewGuid().ToString();
8585
m_logger.LogInformation("🔄 QueueCommand START: {CommandId} for command: {Command}", commandId, command);
8686

@@ -108,10 +108,10 @@ public Task<string> GetCommandResult(string commandId)
108108
{
109109
if (m_disposed)
110110
throw new ObjectDisposedException(nameof(CommandQueueService));
111-
111+
112112
if (string.IsNullOrEmpty(commandId))
113113
return Task.FromResult($"Command not found: {commandId}");
114-
114+
115115
// NOTE: Completed commands stay in m_activeCommands for result retrieval
116116
if (m_activeCommands.TryGetValue(commandId, out var command))
117117
{
@@ -142,10 +142,10 @@ public bool CancelCommand(string commandId)
142142
{
143143
if (m_disposed)
144144
throw new ObjectDisposedException(nameof(CommandQueueService));
145-
145+
146146
if (string.IsNullOrEmpty(commandId))
147147
return false;
148-
148+
149149
// First check if command is in active commands (executing or completed)
150150
if (m_activeCommands.TryGetValue(commandId, out var command))
151151
{
@@ -180,7 +180,7 @@ public bool CancelCommand(string commandId)
180180
if (queuedCommand != null)
181181
{
182182
m_logger.LogInformation("Cancelling queued command {CommandId}: {Command}", commandId, queuedCommand.Command);
183-
183+
184184
try
185185
{
186186
queuedCommand.CancellationTokenSource.Cancel();
@@ -202,7 +202,7 @@ public int CancelAllCommands(string? reason = null)
202202
{
203203
if (m_disposed)
204204
throw new ObjectDisposedException(nameof(CommandQueueService));
205-
205+
206206
var reasonText = string.IsNullOrWhiteSpace(reason) ? "No reason provided" : reason;
207207
m_logger.LogWarning("Cancelling ALL commands. Reason: {Reason}", reasonText);
208208

@@ -266,7 +266,7 @@ public int CancelAllCommands(string? reason = null)
266266
{
267267
if (m_disposed)
268268
throw new ObjectDisposedException(nameof(CommandQueueService));
269-
269+
270270
lock (m_currentCommandLock)
271271
{
272272
return m_currentCommand;
@@ -277,7 +277,7 @@ public int CancelAllCommands(string? reason = null)
277277
{
278278
if (m_disposed)
279279
throw new ObjectDisposedException(nameof(CommandQueueService));
280-
280+
281281
var results = new List<(string, string, DateTime, string)>();
282282

283283
// Add current command
@@ -336,7 +336,7 @@ private async Task ProcessCommandQueue()
336336
{
337337
m_currentCommand = queuedCommand;
338338
}
339-
339+
340340
// Update command state to executing
341341
UpdateCommandState(queuedCommand.Id, CommandState.Executing);
342342

@@ -360,12 +360,12 @@ private async Task ProcessCommandQueue()
360360
var resultMessage = queuedCommand.CancellationTokenSource.Token.IsCancellationRequested
361361
? "Command execution was cancelled."
362362
: result;
363-
363+
364364
var wasCompleted = queuedCommand.CompletionSource.TrySetResult(resultMessage);
365-
365+
366366
// Update state atomically - this is safe even if another thread modified the command
367367
UpdateCommandState(queuedCommand.Id, CommandState.Completed);
368-
368+
369369
if (wasCompleted)
370370
{
371371
Interlocked.Increment(ref m_commandsProcessed);
@@ -374,13 +374,13 @@ private async Task ProcessCommandQueue()
374374
{
375375
m_logger.LogDebug("Command {CommandId} was already completed by another thread (race condition handled)", queuedCommand.Id);
376376
}
377-
377+
378378
LogConcurrencyStats();
379379
}
380380
catch (OperationCanceledException)
381381
{
382382
m_logger.LogInformation("Command {CommandId} was cancelled during execution", queuedCommand.Id);
383-
383+
384384
// FIXED: Use TrySetResult to prevent double-completion and update state
385385
var wasCompleted = queuedCommand.CompletionSource.TrySetResult("Command execution was cancelled.");
386386
if (wasCompleted)
@@ -392,13 +392,13 @@ private async Task ProcessCommandQueue()
392392
{
393393
m_logger.LogDebug("Command {CommandId} was already completed by another thread during cancellation", queuedCommand.Id);
394394
}
395-
395+
396396
LogConcurrencyStats();
397397
}
398398
catch (Exception ex)
399399
{
400400
m_logger.LogError(ex, "Error executing command {CommandId}: {Command}", queuedCommand.Id, queuedCommand.Command);
401-
401+
402402
// IMPROVED: Better error handling with detailed error information
403403
var errorMessage = ex switch
404404
{
@@ -408,10 +408,10 @@ private async Task ProcessCommandQueue()
408408
ArgumentException => $"Invalid argument: {ex.Message}",
409409
_ => $"Command execution failed: {ex.GetType().Name}: {ex.Message}"
410410
};
411-
411+
412412
var wasCompleted = queuedCommand.CompletionSource.TrySetResult(errorMessage);
413413
UpdateCommandState(queuedCommand.Id, CommandState.Failed);
414-
414+
415415
if (wasCompleted)
416416
{
417417
Interlocked.Increment(ref m_commandsFailed);
@@ -420,7 +420,7 @@ private async Task ProcessCommandQueue()
420420
{
421421
m_logger.LogDebug("Command {CommandId} was already completed by another thread during error handling", queuedCommand.Id);
422422
}
423-
423+
424424
LogConcurrencyStats();
425425
}
426426
finally
@@ -482,14 +482,14 @@ private void LogConcurrencyStats()
482482
var failed = Interlocked.Read(ref m_commandsFailed);
483483
var cancelled = Interlocked.Read(ref m_commandsCancelled);
484484
var total = processed + failed + cancelled;
485-
485+
486486
if (total > 0)
487487
{
488488
var successRate = total > 0 ? (double)processed / total * 100 : 0;
489-
m_logger.LogInformation("Concurrency Stats - Processed: {Processed}, Failed: {Failed}, Cancelled: {Cancelled}, Success Rate: {SuccessRate:F1}%",
489+
m_logger.LogInformation("Concurrency Stats - Processed: {Processed}, Failed: {Failed}, Cancelled: {Cancelled}, Success Rate: {SuccessRate:F1}%",
490490
processed, failed, cancelled, successRate);
491491
}
492-
492+
493493
m_lastStatsLog = now;
494494
}
495495
}
@@ -508,8 +508,8 @@ private void CleanupCompletedCommands(object? state)
508508
// PERFORMANCE: Use ValueTuple to avoid boxing in foreach
509509
foreach (var (key, command) in m_activeCommands)
510510
{
511-
if (command.State == CommandState.Completed ||
512-
command.State == CommandState.Cancelled ||
511+
if (command.State == CommandState.Completed ||
512+
command.State == CommandState.Cancelled ||
513513
command.State == CommandState.Failed)
514514
{
515515
if (command.QueueTime < cutoffTime)

mcp_nexus/CommandQueue/IsolatedCommandQueueService.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,37 @@ public class IsolatedCommandQueueService : ICommandQueueService, IDisposable
2020
private readonly string m_sessionId;
2121
private readonly ILogger m_logger;
2222
private readonly IMcpNotificationService m_notificationService;
23-
23+
2424
// CONCURRENCY: Thread-safe collections
2525
private readonly ConcurrentQueue<QueuedCommand> m_commandQueue = new();
2626
private readonly ConcurrentDictionary<string, QueuedCommand> m_activeCommands = new();
27-
27+
2828
// SYNCHRONIZATION: Semaphore for queue processing
2929
private readonly SemaphoreSlim m_queueSemaphore = new(0, int.MaxValue);
30-
30+
3131
// CURRENT COMMAND: Thread-safe current command tracking
3232
private volatile QueuedCommand? m_currentCommand;
3333
private readonly object m_currentCommandLock = new();
34-
34+
3535
// LIFECYCLE: Cancellation and disposal
3636
private readonly CancellationTokenSource m_processingCts = new();
3737
private readonly Task m_processingTask;
3838
private volatile bool m_disposed = false;
39-
39+
4040
// COUNTERS: Thread-safe performance tracking
4141
private long m_commandCounter = 0;
4242
private long m_completedCommands = 0;
4343
private long m_failedCommands = 0;
4444
private long m_cancelledCommands = 0;
45-
45+
4646
// CONFIGURATION: Timeout settings
4747
private readonly TimeSpan m_defaultCommandTimeout = TimeSpan.FromMinutes(10);
4848
private readonly TimeSpan m_heartbeatInterval = TimeSpan.FromSeconds(30);
4949

5050
public IsolatedCommandQueueService(
51-
ICdbSession cdbSession,
52-
ILogger logger,
53-
IMcpNotificationService notificationService,
51+
ICdbSession cdbSession,
52+
ILogger logger,
53+
IMcpNotificationService notificationService,
5454
string sessionId)
5555
{
5656
m_cdbSession = cdbSession ?? throw new ArgumentNullException(nameof(cdbSession));
@@ -77,7 +77,7 @@ public string QueueCommand(string command)
7777
var commandNumber = Interlocked.Increment(ref m_commandCounter);
7878
var commandId = $"cmd-{m_sessionId}-{commandNumber:D4}";
7979

80-
m_logger.LogDebug("🔄 Queueing command {CommandId} in session {SessionId}: {Command}",
80+
m_logger.LogDebug("🔄 Queueing command {CommandId} in session {SessionId}: {Command}",
8181
commandId, m_sessionId, command);
8282

8383
// IMMUTABLE: Create command object
@@ -111,7 +111,7 @@ public string QueueCommand(string command)
111111
try
112112
{
113113
await m_notificationService.NotifyCommandStatusAsync(
114-
m_sessionId, commandId, command, "queued",
114+
m_sessionId, commandId, command, "queued",
115115
result: null, progress: 0);
116116
}
117117
catch (Exception ex)
@@ -234,7 +234,7 @@ public int CancelAllCommands(string? reason = null)
234234
m_logger.LogWarning(ex, "Error cancelling current CDB operation during bulk cancel");
235235
}
236236

237-
m_logger.LogInformation("🚫 Cancelled {Count} commands in session {SessionId}: {Reason}",
237+
m_logger.LogInformation("🚫 Cancelled {Count} commands in session {SessionId}: {Reason}",
238238
cancelledCount, m_sessionId, reason ?? "Bulk cancellation");
239239

240240
return cancelledCount;
@@ -338,7 +338,7 @@ private async Task ExecuteCommandSafely(QueuedCommand command)
338338
CompleteCommandSafely(command, result, CommandState.Completed);
339339
Interlocked.Increment(ref m_completedCommands);
340340

341-
m_logger.LogInformation("✅ Command {CommandId} completed in {ElapsedMs}ms",
341+
m_logger.LogInformation("✅ Command {CommandId} completed in {ElapsedMs}ms",
342342
command.Id, stopwatch.ElapsedMilliseconds);
343343
}
344344
finally
@@ -365,7 +365,7 @@ private async Task ExecuteCommandSafely(QueuedCommand command)
365365
CompleteCommandSafely(command, $"Command execution failed: {ex.Message}", CommandState.Failed);
366366
Interlocked.Increment(ref m_failedCommands);
367367

368-
m_logger.LogError(ex, "❌ Command {CommandId} failed after {ElapsedMs}ms",
368+
m_logger.LogError(ex, "❌ Command {CommandId} failed after {ElapsedMs}ms",
369369
command.Id, stopwatch.ElapsedMilliseconds);
370370
}
371371
finally
@@ -508,7 +508,7 @@ public void Dispose()
508508
// CLEANUP: Dispose resources
509509
m_queueSemaphore.Dispose();
510510
m_processingCts.Dispose();
511-
511+
512512
// CLEANUP: Dispose processing task
513513
try
514514
{

0 commit comments

Comments
 (0)