Beispiel #1
0
        public void Start()
        {
            _connMetricsListener?.ConnectionConnecting(_connEvent);
            _tcpSocketClient.Connect(_uri);

            SetOpened();
            _logger?.Debug($"~~ [CONNECT] {_uri}");
            _connMetricsListener?.ConnectionConnected(_connEvent);

            var version = DoHandshake();

            _boltProtocol = BoltProtocolFactory.Create(version, _tcpSocketClient, _bufferSettings, _logger);
        }
Beispiel #2
0
        public Task StartAsync()
        {
            TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();

            _connMetricsListener?.ConnectionConnecting(_connEvent);
            _tcpSocketClient.ConnectAsync(_uri)
            .ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    tcs.SetException(t.Exception.GetBaseException());
                }
                else if (t.IsCanceled)
                {
                    tcs.SetCanceled();
                }
                else
                {
                    SetOpened();
                    _logger?.Debug($"~~ [CONNECT] {_uri}");
                    _connMetricsListener?.ConnectionConnected(_connEvent);
                    return(DoHandshakeAsync());
                }

                return(Task.FromResult(-1));
            }, TaskContinuationOptions.ExecuteSynchronously).Unwrap()
            .ContinueWith(t =>
            {
                int version = t.Result;

                if (version != -1)
                {
                    try
                    {
                        _boltProtocol = BoltProtocolFactory.Create(version, _tcpSocketClient, _bufferSettings, _logger);
                        tcs.SetResult(null);
                    }
                    catch (AggregateException exc)
                    {
                        tcs.SetException(exc.GetBaseException());
                    }
                    catch (Exception exc)
                    {
                        tcs.SetException(exc);
                    }
                }
            }, TaskContinuationOptions.ExecuteSynchronously);

            return(tcs.Task);
        }