Esempio n. 1
0
        /// <summary>
        /// Opens the transport connection with the specified Uri and begins to read from the stream.
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        protected override async Task PerformOpenAsync(Uri uri, CancellationToken cancellationToken)
        {
            // TODO: It is required to call OpenAsync in a server transport, which doesn't make much sense. The server transport is passive and it will be always be open after its creation.
            // We should refactor the transports to remove this need on the server side.
            if (!_tcpClient.Connected)
            {
                if (uri == null)
                {
                    throw new ArgumentNullException(nameof(uri), "The uri is mandatory for a not connected TCP client");
                }
                if (uri.Scheme != UriSchemeNetTcp)
                {
                    throw new ArgumentException($"Invalid URI scheme. Expected is '{UriSchemeNetTcp}'.", nameof(uri));
                }

                if (string.IsNullOrWhiteSpace(_hostName))
                {
                    _hostName = uri.Host;
                }

                await _tcpClient.ConnectAsync(uri.Host, uri.Port).ConfigureAwait(false);
            }

            _stream = _tcpClient.GetStream();
            await _envelopePipe.StartAsync(cancellationToken);
        }
 protected override Task PerformOpenAsync(Uri uri, CancellationToken cancellationToken)
 {
     return(_envelopePipe.StartAsync(cancellationToken));
 }