예제 #1
0
        public DriverWrapper(Uri uri, IServerAddressResolver addressResolver, string username, string pass, string realm)
        {
            Uri = uri;
            Username = username;
            Password = pass;
            Realm = realm;

            var authToken = GetAuthToken(username, pass, realm);
            this.driver = addressResolver == null
                ? GraphDatabase.Driver(uri, authToken) 
                : GraphDatabase.Driver(uri, authToken, new Config { Resolver = addressResolver });
        }
예제 #2
0
        /// <summary>
        ///     Creates a new instance of the <see cref="BoltGraphClient" />.
        /// </summary>
        /// <param name="uri">
        ///     If the <paramref name="uris" /> parameter is provided, this will be treated as a <em>virtual URI</em>
        ///     , else it will be the URI connected to.
        /// </param>
        /// <param name="uris">
        ///     A collection of <see cref="Uri" /> instances to connect to using an
        ///     <see cref="IServerAddressResolver" />. Leave <c>null</c> (or empty) if you don't want to use it.
        /// </param>
        /// <param name="username">The username to connect to Neo4j with.</param>
        /// <param name="password">The password to connect to Neo4j with.</param>
        /// <param name="realm">The realm to connect to Neo4j with.</param>
        public BoltGraphClient(Uri uri, IEnumerable <Uri> uris, string username = null, string password = null, string realm = null, EncryptionLevel?encryptionLevel = null, bool serializeNullValues = false)
        {
            var localUris = uris?.ToList();

            if (localUris != null && localUris.Any())
            {
                //TODO - const/etc these
                if (!new [] { "neo4j", "neo4j+s", "neo4j+ssc" }.Contains(uri.Scheme.ToLowerInvariant()))
                {
                    throw new NotSupportedException($"To use the {nameof(BoltGraphClient)} with an Address Resolver you need to use the 'neo4j://' scheme, for the 'uri' parameter, not '{uri.Scheme}'.");
                }

                addressResolver = new AddressResolver(uri, localUris);
            }
            else if (!new [] { "neo4j", "neo4j+s", "neo4j+ssc", "bolt", "bolt+s", "bolt+ssc" }.Contains(uri.Scheme.ToLowerInvariant()))
            {
                throw new NotSupportedException($"To use the {nameof(BoltGraphClient)} you need to provide a 'bolt://' or 'neo4j://' scheme, not '{uri.Scheme}'.");
            }

            this.uri             = uri;
            this.username        = username;
            this.password        = password;
            this.realm           = realm;
            this.encryptionLevel = encryptionLevel;
            PolicyFactory        = new ExecutionPolicyFactory(this);

            JsonConverters = new List <JsonConverter>();
            JsonConverters.AddRange(DefaultJsonConverters);
            JsonContractResolver = DefaultJsonContractResolver;

            ExecutionConfiguration = new ExecutionConfiguration
            {
                UserAgent           = $"Neo4jClient/{GetType().GetTypeInfo().Assembly.GetName().Version}",
                UseJsonStreaming    = true,
                JsonConverters      = JsonConverters,
                Username            = username,
                Password            = password,
                Realm               = realm,
                SerializeNullValues = serializeNullValues
            };

            transactionManager = new BoltTransactionManager(this);
        }
예제 #3
0
        public DriverWrapper(Uri uri, IServerAddressResolver addressResolver, string username, string pass, string realm, EncryptionLevel?encryptionLevel)
        {
            Uri             = uri;
            Username        = username;
            Password        = pass;
            Realm           = realm;
            EncryptionLevel = encryptionLevel;

            var authToken = GetAuthToken(username, pass, realm);

            if (addressResolver != null)
            {
                driver = encryptionLevel == null
                    ? GraphDatabase.Driver(uri, authToken, builder => builder.WithResolver(addressResolver))
                    : GraphDatabase.Driver(uri, authToken, builder => builder.WithResolver(addressResolver).WithEncryptionLevel(encryptionLevel.Value));
            }
            else
            {
                driver = GraphDatabase.Driver(uri, authToken);
            }
        }
예제 #4
0
 public InitialServerAddressProvider(Uri initialServerAddress, IServerAddressResolver resolver)
 {
     _initAddress = initialServerAddress;
     _resolver    = resolver;
 }
 /// <summary>
 /// Gets or internal sets a custom server address resolver used by the routing driver to resolve the initial address used to create the driver.
 /// Such resolution happens: 1) during the very first rediscovery when driver is created.
 /// 2) when all the known routers from the current routing table have failed and driver needs to fallback to the initial address.
 /// </summary>
 /// <param name="resolver">The resolver, default to a resolver that simply pass the initial server address as it is.</param>
 /// <returns>An <see cref="ConfigBuilder"/> instance for further configuration options.</returns>
 public ConfigBuilder WithResolver(IServerAddressResolver resolver)
 {
     _config.Resolver = resolver;
     return(this);
 }
예제 #6
0
 public DriverWrapper(string uri, IServerAddressResolver addressResolver, string username, string pass, string realm)
     :this(new Uri(uri), addressResolver, username, pass, realm)
 {
 }
예제 #7
0
 public DriverWrapper(string uri, IServerAddressResolver addressResolver, string username, string pass, string realm, EncryptionLevel?encryptionLevel)
     : this(new Uri(uri), addressResolver, username, pass, realm, encryptionLevel)
 {
 }