using System; using System.Threading; using Google.Protobuf.WellKnownTypes; using MxGateway.Contracts.Proto; namespace MxGateway.Worker.Sta; public sealed class StaCommand { /// Initializes a new instance of the class. /// Identifier of the session. /// Correlation identifier for the command. /// The MXAccess command to execute. /// Timestamp when the command was enqueued. /// Token to cancel the asynchronous operation. public StaCommand( string sessionId, string correlationId, MxCommand command, Timestamp? enqueueTimestamp = null, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(sessionId)) { throw new ArgumentException("STA command requires a session id.", nameof(sessionId)); } if (string.IsNullOrWhiteSpace(correlationId)) { throw new ArgumentException("STA command requires a correlation id.", nameof(correlationId)); } SessionId = sessionId; CorrelationId = correlationId; Command = command ?? throw new ArgumentNullException(nameof(command)); EnqueueTimestamp = enqueueTimestamp ?? Timestamp.FromDateTime(DateTime.UtcNow); CancellationToken = cancellationToken; } /// Gets the session ID for the STA command. public string SessionId { get; } /// Gets the correlation ID for the STA command. public string CorrelationId { get; } /// Gets the MXAccess command to execute. public MxCommand Command { get; } /// Gets the timestamp when the command was enqueued. public Timestamp EnqueueTimestamp { get; } /// Gets the token to cancel the asynchronous operation. public CancellationToken CancellationToken { get; } /// Gets the kind of the MXAccess command. public MxCommandKind Kind => Command.Kind; /// Gets the method name of the command. public string MethodName => Kind.ToString(); }