Example #1
0
        public async Task Start()
        {
            await _tcpSocketClient.ConnectAsync(_url.Host, _url.Port, _config.EncryptionLevel == EncryptionLevel.Encrypted).ConfigureAwait(false);

            IsOpen = true;
            _config.Logger?.Debug($"~~ [CONNECT] {_url}");

            var version = await DoHandshake().ConfigureAwait(false);

            switch (version)
            {
            case ProtocolVersion.Version1:
                _config.Logger?.Debug("S: [HANDSHAKE] 1");

                var formatV1 = new PackStreamMessageFormatV1(_tcpSocketClient, _config.Logger);
                _writer = formatV1.Writer;
                _reader = formatV1.Reader;
                break;

            case ProtocolVersion.NoVersion:
                throw new NotSupportedException("The Neo4j server does not support any of the protocol versions supported by this client. " +
                                                "Ensure that you are using driver and server versions that are compatible with one another.");

            case ProtocolVersion.Http:
                throw new NotSupportedException("Server responded HTTP. Make sure you are not trying to connect to the http endpoint " +
                                                "(HTTP defaults to port 7474 whereas BOLT defaults to port 7687)");

            default:
                throw new NotSupportedException("Protocol error, server suggested unexpected protocol version: " + version);
            }
        }
Example #2
0
        public async Task Start()
        {
            await _tcpSocketClient.ConnectAsync(_uri).ConfigureAwait(false);

            IsOpen = true;
            _logger?.Debug($"~~ [CONNECT] {_uri}");

            var version = await DoHandshake().ConfigureAwait(false);

            switch (version)
            {
            case ProtocolVersion.Version1:
                SetupPackStreamFormatWriterAndReader();
                break;

            case ProtocolVersion.NoVersion:
                throw new NotSupportedException("The Neo4j server does not support any of the protocol versions supported by this client. " +
                                                "Ensure that you are using driver and server versions that are compatible with one another.");

            case ProtocolVersion.Http:
                throw new NotSupportedException("Server responded HTTP. Make sure you are not trying to connect to the http endpoint " +
                                                $"(HTTP defaults to port 7474 whereas BOLT defaults to port {GraphDatabase.DefaultBoltPort})");

            default:
                throw new NotSupportedException("Protocol error, server suggested unexpected protocol version: " + version);
            }
        }
Example #3
0
        public async Task <IBoltProtocol> ConnectAsync(IDictionary <string, string> routingContext)
        {
            await _tcpSocketClient.ConnectAsync(_uri).ConfigureAwait(false);

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

            var version = await DoHandshakeAsync().ConfigureAwait(false);

            return(SelectBoltProtocol(version, routingContext));
        }
Example #4
0
        public async Task ConnectAsync()
        {
            await _client.ConnectAsync(_uri.Host, _uri.Port, _isSecure);

            bool handshakeSuccess = await Bolt.V1.DoHandShakeAsync(_client);

            if (handshakeSuccess)
            {
                await Bolt.V1.InitAsync(_client, UserAgent);
            }
        }
Example #5
0
        public async Task <IBoltProtocol> ConnectAsync()
        {
            _connMetricsListener?.ConnectionConnecting(_connEvent);
            await _tcpSocketClient.ConnectAsync(_uri).ConfigureAwait(false);

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

            var version = await DoHandshakeAsync().ConfigureAwait(false);

            return(SelectBoltProtocol(version));
        }
Example #6
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);
        }
        public async Task Start()
        {
            await _tcpSocketClient.ConnectAsync(_url.Host, _url.Port, _config.EncryptionLevel == EncryptionLevel.Encrypted).ConfigureAwait(false);

            IsOpen = true;
            _config.Logger?.Debug($"~~ [CONNECT] {_url}");

            var version = await DoHandshake().ConfigureAwait(false);

            if (version != 1)
            {
                throw new NotSupportedException("The Neo4j Server doesn't support this client.");
            }
            _config.Logger?.Debug("S: [HANDSHAKE] 1");

            var formatV1 = new PackStreamMessageFormatV1(_tcpSocketClient, BitConverter, _config.Logger);

            _writer = formatV1.Writer;
            _reader = formatV1.Reader;
        }