using ZB.MOM.WW.MxGateway.Contracts; namespace ZB.MOM.WW.MxGateway.Server.Workers; /// /// Configuration for the worker frame protocol connection. /// public sealed class WorkerFrameProtocolOptions { /// Default maximum message size in bytes (16 MB). public const int DefaultMaxMessageBytes = 16 * 1024 * 1024; /// /// Initializes worker frame protocol options with a session ID. /// /// Identifier of the session. public WorkerFrameProtocolOptions(string sessionId) : this( sessionId, GatewayContractInfo.WorkerProtocolVersion, DefaultMaxMessageBytes) { } /// /// Initializes worker frame protocol options with all parameters. /// /// Identifier of the session. /// Protocol version number. /// Maximum message size in bytes. public WorkerFrameProtocolOptions( string sessionId, uint protocolVersion, int maxMessageBytes) { if (string.IsNullOrWhiteSpace(sessionId)) { throw new WorkerFrameProtocolException( WorkerFrameProtocolErrorCode.InvalidConfiguration, "Worker frame protocol requires a session id."); } if (protocolVersion == 0) { throw new WorkerFrameProtocolException( WorkerFrameProtocolErrorCode.InvalidConfiguration, "Worker frame protocol requires a non-zero protocol version."); } if (maxMessageBytes <= 0) { throw new WorkerFrameProtocolException( WorkerFrameProtocolErrorCode.InvalidConfiguration, "Worker frame protocol max message size must be greater than zero."); } SessionId = sessionId; ProtocolVersion = protocolVersion; MaxMessageBytes = maxMessageBytes; } /// /// Gets the session identifier. /// public string SessionId { get; } /// /// Gets the worker protocol version. /// public uint ProtocolVersion { get; } /// /// Gets the maximum message size in bytes. /// public int MaxMessageBytes { get; } }