public GraphClientFactory(NeoServerConfiguration configuration)
        {
            if (configuration == null)
             throw new ArgumentNullException("configuration", "Neo server configuration is null");

            _configuration = configuration;
        }
Esempio n. 2
0
        public GraphClientFactory(NeoServerConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration", "Neo server configuration is null");
            }

            _configuration = configuration;
        }
Esempio n. 3
0
        /// <inheritdoc cref="IGraphClient.ConnectAsync"/>
        public async Task ConnectAsync(NeoServerConfiguration configuration = null)
        {
            if (Driver == null)
            {
                var driver = configuration == null
                    ? new DriverWrapper(uri, addressResolver, username, password, realm, encryptionLevel)
                    : new DriverWrapper(uri, addressResolver, configuration.Username, configuration.Password, configuration.Realm, configuration.EncryptionLevel);
                Driver = driver;
            }

            var session = Driver.AsyncSession(x => x.WithDefaultAccessMode(AccessMode.Read));

            var serverInformation = await session.RunAsync("CALL dbms.components()").ConfigureAwait(false);

            foreach (var record in await serverInformation.ToListAsync().ConfigureAwait(false))
            {
                var name = record["name"].As <string>();
                if (name.ToLowerInvariant() != "neo4j kernel")
                {
                    continue;
                }

                var version = record["versions"].As <List <object> >();
                ServerVersion = RootApiResponse.GetVersion(version?.First()?.ToString());

                if (ServerVersion >= new Version(3, 0))
                {
                    CypherCapabilities = CypherCapabilities.Cypher30;
                }
                if (ServerVersion >= new Version(4, 0))
                {
                    CypherCapabilities = CypherCapabilities.Cypher40;
                }
                if (ServerVersion >= new Version(4, 4))
                {
                    CypherCapabilities = CypherCapabilities.Cypher44;
                }
            }

            await session.CloseAsync().ConfigureAwait(false);

            IsConnected = true;
        }
Esempio n. 4
0
        /// <inheritdoc />
        public Task ConnectAsync(NeoServerConfiguration configuration = null)
        {
            if (Driver == null)
            {
                var driver = configuration == null
                    ? new DriverWrapper(uri, username, password, realm)
                    : new DriverWrapper(uri, configuration.Username, configuration.Password, configuration.Realm);
                Driver = driver;
            }

            using (var session = Driver.Session(AccessMode.Read))
            {
                var serverInformation = session.Run("CALL dbms.components()");
                foreach (var record in serverInformation)
                {
                    var name = record["name"].As <string>();
                    if (name.ToLowerInvariant() != "neo4j kernel")
                    {
                        continue;
                    }

                    var version = record["versions"].As <List <object> >();
                    ServerVersion = RootApiResponse.GetVersion(version?.First()?.ToString());

                    if (ServerVersion > new Version(3, 0))
                    {
                        CypherCapabilities = CypherCapabilities.Cypher30;
                    }
                }
            }

            IsConnected = true;
#if NET45
            return(Task.FromResult(0));
#else
            return(Task.CompletedTask);
#endif
        }
Esempio n. 5
0
        public virtual async Task ConnectAsync(NeoServerConfiguration configuration = null)
        {
            if (IsConnected)
            {
                return;
            }

            var stopwatch = Stopwatch.StartNew();
            var operationCompletedArgs = new OperationCompletedEventArgs
            {
                QueryText         = "Connect",
                ResourcesReturned = 0
            };

            Action stopTimerAndNotifyCompleted = () =>
            {
                stopwatch.Stop();
                operationCompletedArgs.TimeTaken = stopwatch.Elapsed;
                OnOperationCompleted(operationCompletedArgs);
            };

            try
            {
                configuration = configuration ?? await NeoServerConfiguration.GetConfigurationAsync(
                    RootUri,
                    ExecutionConfiguration.Username,
                    ExecutionConfiguration.Password,
                    ExecutionConfiguration.Realm,
                    ExecutionConfiguration).ConfigureAwait(false);

                RootApiResponse = configuration.ApiConfig;

                if (!string.IsNullOrWhiteSpace(RootApiResponse.Transaction))
                {
                    //  transactionManager = new TransactionManager(this);
                }

                rootNode = string.IsNullOrEmpty(RootApiResponse.ReferenceNode)
                    ? null
                    : new RootNode(long.Parse(GetLastPathSegment(RootApiResponse.ReferenceNode)), this);

                // http://blog.neo4j.org/2012/04/streaming-rest-api-interview-with.html
                ExecutionConfiguration.UseJsonStreaming = ExecutionConfiguration.UseJsonStreaming &&
                                                          RootApiResponse.Version >= new Version(1, 8);

                if (RootApiResponse.Version < new Version(2, 0))
                {
                    cypherCapabilities = CypherCapabilities.Cypher19;
                }

                if (RootApiResponse.Version >= new Version(2, 2))
                {
                    cypherCapabilities = CypherCapabilities.Cypher22;
                }

                if (RootApiResponse.Version >= new Version(2, 2, 6))
                {
                    cypherCapabilities = CypherCapabilities.Cypher226;
                }

                if (RootApiResponse.Version >= new Version(2, 3))
                {
                    cypherCapabilities = CypherCapabilities.Cypher23;
                }

                if (RootApiResponse.Version >= new Version(3, 0))
                {
                    cypherCapabilities = CypherCapabilities.Cypher30;
                }
            }
            catch (AggregateException ex)
            {
                Exception unwrappedException;
                var       wasUnwrapped = ex.TryUnwrap(out unwrappedException);
                operationCompletedArgs.Exception = wasUnwrapped ? unwrappedException : ex;

                stopTimerAndNotifyCompleted();

                if (wasUnwrapped)
                {
                    throw unwrappedException;
                }

                throw;
            }
            catch (Exception e)
            {
                operationCompletedArgs.Exception = e;
                stopTimerAndNotifyCompleted();
                throw;
            }

            stopTimerAndNotifyCompleted();
        }
Esempio n. 6
0
        /// <inheritdoc />
        public void Connect(NeoServerConfiguration configuration = null)
        {
            var connectTask = ConnectAsync(configuration);

            connectTask.Wait();
        }
Esempio n. 7
0
        public virtual async Task ConnectAsync(NeoServerConfiguration configuration = null)
        {
            if (IsConnected)
            {
                return;
            }

            var stopwatch = Stopwatch.StartNew();
            var operationCompletedArgs = new OperationCompletedEventArgs
            {
                QueryText = "Connect",
                ResourcesReturned = 0
            };

            Action stopTimerAndNotifyCompleted = () =>
            {
                stopwatch.Stop();
                operationCompletedArgs.TimeTaken = stopwatch.Elapsed;
                OnOperationCompleted(operationCompletedArgs);
            };

            try
            {
                configuration = configuration ?? await NeoServerConfiguration.GetConfigurationAsync(
                    RootUri,
                    ExecutionConfiguration.Username,
                    ExecutionConfiguration.Password,
                    ExecutionConfiguration).ConfigureAwait(false);

                RootApiResponse = configuration.ApiConfig;

                if (!string.IsNullOrWhiteSpace(RootApiResponse.Transaction))
                {
                    //  transactionManager = new TransactionManager(this);
                }

                rootNode = string.IsNullOrEmpty(RootApiResponse.ReferenceNode)
                    ? null
                    : new RootNode(long.Parse(GetLastPathSegment(RootApiResponse.ReferenceNode)), this);

                // http://blog.neo4j.org/2012/04/streaming-rest-api-interview-with.html
                ExecutionConfiguration.UseJsonStreaming = ExecutionConfiguration.UseJsonStreaming &&
                                                          RootApiResponse.Version >= new Version(1, 8);

                if (RootApiResponse.Version < new Version(2, 0))
                    cypherCapabilities = CypherCapabilities.Cypher19;

                if (RootApiResponse.Version >= new Version(2, 2))
                    cypherCapabilities = CypherCapabilities.Cypher22;

                if (RootApiResponse.Version >= new Version(2, 2, 6))
                    cypherCapabilities = CypherCapabilities.Cypher226;

                if (RootApiResponse.Version >= new Version(2, 3))
                    cypherCapabilities = CypherCapabilities.Cypher23;

                if (RootApiResponse.Version >= new Version(3, 0))
                    cypherCapabilities = CypherCapabilities.Cypher30;
            }
            catch (AggregateException ex)
            {
                Exception unwrappedException;
                var wasUnwrapped = ex.TryUnwrap(out unwrappedException);
                operationCompletedArgs.Exception = wasUnwrapped ? unwrappedException : ex;

                stopTimerAndNotifyCompleted();

                if (wasUnwrapped)
                    throw unwrappedException;

                throw;
            }
            catch (Exception e)
            {
                operationCompletedArgs.Exception = e;
                stopTimerAndNotifyCompleted();
                throw;
            }

            stopTimerAndNotifyCompleted();
        }
Esempio n. 8
0
        public virtual async Task ConnectAsync(NeoServerConfiguration configuration = null)
        {
            if (IsConnected)
            {
                return;
            }

            var stopwatch = Stopwatch.StartNew();
            var operationCompletedArgs = new OperationCompletedEventArgs
            {
                QueryText         = "Connect",
                ResourcesReturned = 0
            };

            void StopTimerAndNotifyCompleted()
            {
                stopwatch.Stop();
                operationCompletedArgs.TimeTaken = stopwatch.Elapsed;
                OnOperationCompleted(operationCompletedArgs);
            }

            try
            {
                configuration = configuration ?? await NeoServerConfiguration.GetConfigurationAsync(
                    RootUri,
                    ExecutionConfiguration.Username,
                    ExecutionConfiguration.Password,
                    ExecutionConfiguration.Realm,
                    ExecutionConfiguration.EncryptionLevel,
                    ExecutionConfiguration).ConfigureAwait(false);

                RootApiResponse = configuration.ApiConfig;

                if (!string.IsNullOrWhiteSpace(RootApiResponse.Transaction))
                {
                    transactionManager = new TransactionManager(this);
                }


                // http://blog.neo4j.org/2012/04/streaming-rest-api-interview-with.html
                ExecutionConfiguration.UseJsonStreaming = ExecutionConfiguration.UseJsonStreaming &&
                                                          RootApiResponse.Version >= new Version(1, 8);

                var version = RootApiResponse.Version;
                if (version < new Version(2, 0))
                {
                    CypherCapabilities = CypherCapabilities.Cypher19;
                }

                if (version >= new Version(2, 2))
                {
                    CypherCapabilities = CypherCapabilities.Cypher22;
                }

                if (version >= new Version(2, 2, 6))
                {
                    CypherCapabilities = CypherCapabilities.Cypher226;
                }

                if (version >= new Version(2, 3))
                {
                    CypherCapabilities = CypherCapabilities.Cypher23;
                }

                if (version >= new Version(3, 0))
                {
                    CypherCapabilities = CypherCapabilities.Cypher30;
                }

                if (version >= new Version(4, 0))
                {
                    CypherCapabilities = CypherCapabilities.Cypher40;
                }
                if (ServerVersion >= new Version(4, 4))
                {
                    CypherCapabilities = CypherCapabilities.Cypher44;
                }
            }
            catch (AggregateException ex)
            {
                var wasUnwrapped = ex.TryUnwrap(out var unwrappedException);
                operationCompletedArgs.Exception = wasUnwrapped ? unwrappedException : ex;

                StopTimerAndNotifyCompleted();

                if (wasUnwrapped)
                {
                    throw unwrappedException;
                }

                throw;
            }
            catch (Exception e)
            {
                operationCompletedArgs.Exception = e;
                StopTimerAndNotifyCompleted();
                throw;
            }

            StopTimerAndNotifyCompleted();
        }