/// <summary> /// Creates a new <see cref="AutomaticProgressReporter" /> class. /// </summary> /// <remarks>This class does not take ownership of and dispose of <paramref name="connection" />.</remarks> /// <param name="connection">A connection.</param> /// <param name="request">A request.</param> /// <param name="interval">A progress interval.</param> /// <param name="cancellationToken">A cancellation token.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="connection" /> /// is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="request" /> /// is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="interval" /> /// is either less than <see cref="ProtocolConstants.MinTimeout" /> or greater than /// <see cref="ProtocolConstants.MaxTimeout" />.</exception> /// <exception cref="OperationCanceledException">Thrown if <paramref name="cancellationToken" /> /// is cancelled.</exception> public static AutomaticProgressReporter Create( IConnection connection, Message request, TimeSpan interval, CancellationToken cancellationToken) { if (connection == null) { throw new ArgumentNullException(nameof(connection)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } if (!TimeoutUtilities.IsValid(interval)) { throw new ArgumentOutOfRangeException( nameof(interval), interval, Strings.Plugin_TimeoutOutOfRange); } cancellationToken.ThrowIfCancellationRequested(); return new AutomaticProgressReporter( connection, request, interval, cancellationToken); }
/// <summary> /// Sets a new request timeout. /// </summary> /// <param name="requestTimeout">The new request timeout.</param> /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="requestTimeout" /> /// is either less than <see cref="ProtocolConstants.MinTimeout" /> or greater than /// <see cref="ProtocolConstants.MaxTimeout" />.</exception> public void SetRequestTimeout(TimeSpan requestTimeout) { if (!TimeoutUtilities.IsValid(requestTimeout)) { throw new ArgumentOutOfRangeException( nameof(requestTimeout), requestTimeout, Strings.Plugin_TimeoutOutOfRange); } RequestTimeout = requestTimeout; }
/// <summary> /// Instantiates a new <see cref="ConnectionOptions" /> class. /// </summary> /// <param name="protocolVersion">The plugin protocol version.</param> /// <param name="minimumProtocolVersion">The minimum plugin protocol version.</param> /// <param name="handshakeTimeout">The plugin handshake timeout.</param> /// <param name="requestTimeout">The plugin request timeout.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="protocolVersion" /> /// is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="minimumProtocolVersion" /> /// is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="protocolVersion" /> /// is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="protocolVersion" /> /// is less than <paramref name="minimumProtocolVersion" />.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="handshakeTimeout" /> /// is either less than <see cref="ProtocolConstants.MinTimeout" /> or greater than /// <see cref="ProtocolConstants.MaxTimeout" />.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="requestTimeout" /> /// is either less than <see cref="ProtocolConstants.MinTimeout" /> or greater than /// <see cref="ProtocolConstants.MaxTimeout" />.</exception> public ConnectionOptions( SemanticVersion protocolVersion, SemanticVersion minimumProtocolVersion, TimeSpan handshakeTimeout, TimeSpan requestTimeout) { if (protocolVersion == null) { throw new ArgumentNullException(nameof(protocolVersion)); } if (minimumProtocolVersion == null) { throw new ArgumentNullException(nameof(minimumProtocolVersion)); } if (minimumProtocolVersion > protocolVersion) { throw new ArgumentOutOfRangeException( nameof(protocolVersion), protocolVersion, string.Format( CultureInfo.CurrentCulture, Strings.Plugin_ProtocolVersionOutOfRange, nameof(protocolVersion), nameof(minimumProtocolVersion))); } if (!TimeoutUtilities.IsValid(handshakeTimeout)) { throw new ArgumentOutOfRangeException( nameof(handshakeTimeout), handshakeTimeout, Strings.Plugin_TimeoutOutOfRange); } if (!TimeoutUtilities.IsValid(requestTimeout)) { throw new ArgumentOutOfRangeException( nameof(requestTimeout), requestTimeout, Strings.Plugin_TimeoutOutOfRange); } ProtocolVersion = protocolVersion; MinimumProtocolVersion = minimumProtocolVersion; HandshakeTimeout = handshakeTimeout; RequestTimeout = requestTimeout; }
/// <summary> /// Initializes a new instance of the <see cref="SymmetricHandshake" /> class. /// </summary> /// <param name="connection">A connection.</param> /// <param name="handshakeTimeout">The handshake timeout.</param> /// <param name="protocolVersion">The handshaker's protocol version.</param> /// <param name="minimumProtocolVersion">The handshaker's minimum protocol version.</param> public SymmetricHandshake( IConnection connection, TimeSpan handshakeTimeout, SemanticVersion protocolVersion, SemanticVersion minimumProtocolVersion) { if (connection == null) { throw new ArgumentNullException(nameof(connection)); } if (!TimeoutUtilities.IsValid(handshakeTimeout)) { throw new ArgumentOutOfRangeException( nameof(handshakeTimeout), handshakeTimeout, Strings.Plugin_TimeoutOutOfRange); } if (protocolVersion == null) { throw new ArgumentNullException(nameof(protocolVersion)); } if (minimumProtocolVersion == null) { throw new ArgumentNullException(nameof(minimumProtocolVersion)); } _connection = connection; _handshakeTimeout = handshakeTimeout; _protocolVersion = protocolVersion; _minimumProtocolVersion = minimumProtocolVersion; _handshakeFailedResponse = new HandshakeResponse(MessageResponseCode.Error, protocolVersion: null); _responseSentTaskCompletionSource = new TaskCompletionSource <int>(); _timeoutCancellationTokenSource = new CancellationTokenSource(handshakeTimeout); _timeoutCancellationTokenSource.Token.Register(() => { _responseSentTaskCompletionSource.TrySetCanceled(); }); CancellationToken = _timeoutCancellationTokenSource.Token; if (!_connection.MessageDispatcher.RequestHandlers.TryAdd(MessageMethod.Handshake, this)) { throw new ArgumentException(Strings.Plugin_HandshakeRequestHandlerAlreadyExists, nameof(connection)); } }
public InitializeRequest(string clientVersion, string culture, TimeSpan requestTimeout) { if (string.IsNullOrEmpty(clientVersion)) { throw new ArgumentException(Strings.ArgumentCannotBeNullOrEmpty, nameof(clientVersion)); } if (string.IsNullOrEmpty(culture)) { throw new ArgumentException(Strings.ArgumentCannotBeNullOrEmpty, nameof(culture)); } if (!TimeoutUtilities.IsValid(requestTimeout)) { throw new ArgumentOutOfRangeException( nameof(requestTimeout), requestTimeout, Strings.Plugin_TimeoutOutOfRange); } ClientVersion = clientVersion; Culture = culture; RequestTimeout = requestTimeout; }