示例#1
0
 public GremlinClient(GremlinServer gremlinServer, GraphSONReader graphSONReader, GraphSONWriter graphSONWriter,
                      ConnectionPoolSettings connectionPoolSettings          = null,
                      Action <ClientWebSocketOptions> webSocketConfiguration = null, string sessionId = null)
     : this(gremlinServer, graphSONReader, graphSONWriter, SerializationTokens.GraphSON3MimeType,
            connectionPoolSettings, webSocketConfiguration, sessionId)
 {
 }
示例#2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="GremlinClient" /> class for the specified Gremlin Server.
        /// </summary>
        /// <param name="gremlinServer">The <see cref="GremlinServer" /> the requests should be sent to.</param>
        /// <param name="graphSONReader">A <see cref="GraphSONReader" /> instance to read received GraphSON data.</param>
        /// <param name="graphSONWriter">a <see cref="GraphSONWriter" /> instance to write GraphSON data.</param>
        /// <param name="mimeType">The GraphSON version mime type, defaults to latest supported by the server.</param>
        /// <param name="connectionPoolSettings">The <see cref="ConnectionPoolSettings"/> for the connection pool.</param>
        /// <param name="webSocketConfiguration">
        ///     A delegate that will be invoked with the <see cref="ClientWebSocketOptions" />
        ///     object used to configure WebSocket connections.
        /// </param>
        /// <param name="sessionId">The session Id if Gremlin Client in session mode, defaults to null as session-less Client.</param>
        public GremlinClient(GremlinServer gremlinServer, GraphSONReader graphSONReader = null,
                             GraphSONWriter graphSONWriter = null, string mimeType = null,
                             ConnectionPoolSettings connectionPoolSettings          = null,
                             Action <ClientWebSocketOptions> webSocketConfiguration = null, string sessionId = null)
        {
            var reader            = graphSONReader ?? new GraphSON3Reader();
            var writer            = graphSONWriter ?? new GraphSON3Writer();
            var connectionFactory = new ConnectionFactory(gremlinServer, reader, writer, mimeType ?? DefaultMimeType,
                                                          webSocketConfiguration, sessionId);

            // make sure one connection in pool as session mode
            if (!String.IsNullOrEmpty(sessionId))
            {
                if (connectionPoolSettings != null)
                {
                    if (connectionPoolSettings.PoolSize != 1)
                    {
                        throw new ArgumentOutOfRangeException(nameof(connectionPoolSettings), "PoolSize must be 1 in session mode!");
                    }
                }
                else
                {
                    connectionPoolSettings          = new ConnectionPoolSettings();
                    connectionPoolSettings.PoolSize = 1;
                }
            }
            _connectionPool =
                new ConnectionPool(connectionFactory, connectionPoolSettings ?? new ConnectionPoolSettings());
        }
示例#3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="GremlinClient" /> class for the specified Gremlin Server.
        /// </summary>
        /// <param name="gremlinServer">The <see cref="GremlinServer" /> the requests should be sent to.</param>
        /// <param name="messageSerializer">
        ///     A <see cref="IMessageSerializer" /> instance to serialize messages sent to and received
        ///     from the server.
        /// </param>
        /// <param name="connectionPoolSettings">The <see cref="ConnectionPoolSettings" /> for the connection pool.</param>
        /// <param name="webSocketConfiguration">
        ///     A delegate that will be invoked with the <see cref="ClientWebSocketOptions" />
        ///     object used to configure WebSocket connections.
        /// </param>
        /// <param name="sessionId">The session Id if Gremlin Client in session mode, defaults to null as session-less Client.</param>
        public GremlinClient(GremlinServer gremlinServer, IMessageSerializer messageSerializer = null,
                             ConnectionPoolSettings connectionPoolSettings          = null,
                             Action <ClientWebSocketOptions> webSocketConfiguration = null, string sessionId = null)
        {
            messageSerializer = messageSerializer ?? new GraphSON3MessageSerializer();
            var connectionFactory =
                new ConnectionFactory(gremlinServer, messageSerializer, webSocketConfiguration, sessionId);

            // make sure one connection in pool as session mode
            if (!string.IsNullOrEmpty(sessionId))
            {
                if (connectionPoolSettings != null)
                {
                    if (connectionPoolSettings.PoolSize != 1)
                    {
                        throw new ArgumentOutOfRangeException(nameof(connectionPoolSettings), "PoolSize must be 1 in session mode!");
                    }
                }
                else
                {
                    connectionPoolSettings = new ConnectionPoolSettings {
                        PoolSize = 1
                    };
                }
            }
            _connectionPool =
                new ConnectionPool(connectionFactory, connectionPoolSettings ?? new ConnectionPoolSettings());
        }
示例#4
0
 public ConnectionFactory(GremlinServer gremlinServer, GraphSONReader graphSONReader,
                          GraphSONWriter graphSONWriter, string mimeType)
 {
     _gremlinServer  = gremlinServer;
     _mimeType       = mimeType;
     _graphSONReader = graphSONReader ?? throw new ArgumentNullException(nameof(graphSONReader));
     _graphSONWriter = graphSONWriter ?? throw new ArgumentNullException(nameof(graphSONWriter));
 }
示例#5
0
 public ConnectionFactory(GremlinServer gremlinServer, IMessageSerializer messageSerializer,
                          Action <ClientWebSocketOptions> webSocketConfiguration, string sessionId)
 {
     _gremlinServer          = gremlinServer;
     _messageSerializer      = messageSerializer;
     _sessionId              = sessionId;
     _webSocketConfiguration = webSocketConfiguration;
 }
示例#6
0
        public GremlinClient(GremlinServer gremlinServer, GraphSONReader graphSONReader, GraphSONWriter graphSONWriter,
                             string mimeType, ConnectionPoolSettings connectionPoolSettings = null,
                             Action <ClientWebSocketOptions> webSocketConfiguration         = null, string sessionId = null)
        {
            IMessageSerializer messageSerializer;

            switch (mimeType)
            {
            case SerializationTokens.GraphSON3MimeType:
                VerifyGraphSONArgumentTypeForMimeType <GraphSON3Reader>(graphSONReader, nameof(graphSONReader),
                                                                        mimeType);
                VerifyGraphSONArgumentTypeForMimeType <GraphSON3Writer>(graphSONWriter, nameof(graphSONWriter),
                                                                        mimeType);
                messageSerializer = new GraphSON3MessageSerializer(
                    (GraphSON3Reader)graphSONReader ?? new GraphSON3Reader(),
                    (GraphSON3Writer)graphSONWriter ?? new GraphSON3Writer());
                break;

            case SerializationTokens.GraphSON2MimeType:
                VerifyGraphSONArgumentTypeForMimeType <GraphSON2Reader>(graphSONReader, nameof(graphSONReader),
                                                                        mimeType);
                VerifyGraphSONArgumentTypeForMimeType <GraphSON2Writer>(graphSONWriter, nameof(graphSONWriter),
                                                                        mimeType);
                messageSerializer = new GraphSON2MessageSerializer(
                    (GraphSON2Reader)graphSONReader ?? new GraphSON2Reader(),
                    (GraphSON2Writer)graphSONWriter ?? new GraphSON2Writer());
                break;

            default:
                throw new ArgumentException(nameof(mimeType), $"{mimeType} not supported");
            }

            var connectionFactory =
                new ConnectionFactory(gremlinServer, messageSerializer,
                                      new WebSocketSettings {
                WebSocketConfigurationCallback = webSocketConfiguration
            }, sessionId);

            // make sure one connection in pool as session mode
            if (!string.IsNullOrEmpty(sessionId))
            {
                if (connectionPoolSettings != null)
                {
                    if (connectionPoolSettings.PoolSize != 1)
                    {
                        throw new ArgumentOutOfRangeException(nameof(connectionPoolSettings), "PoolSize must be 1 in session mode!");
                    }
                }
                else
                {
                    connectionPoolSettings = new ConnectionPoolSettings {
                        PoolSize = 1
                    };
                }
            }
            _connectionPool =
                new ConnectionPool(connectionFactory, connectionPoolSettings ?? new ConnectionPoolSettings());
        }
示例#7
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="GremlinClient" /> class for the specified Gremlin Server.
        /// </summary>
        /// <param name="gremlinServer">The <see cref="GremlinServer" /> the requests should be sent to.</param>
        /// <param name="graphSONReader">A <see cref="GraphSONReader" /> instance to read received GraphSON data.</param>
        /// <param name="graphSONWriter">a <see cref="GraphSONWriter" /> instance to write GraphSON data.</param>
        /// <param name="mimeType">The GraphSON version mime type, defaults to latest supported by the server.</param>
        public GremlinClient(GremlinServer gremlinServer, GraphSONReader graphSONReader = null,
                             GraphSONWriter graphSONWriter = null, string mimeType = null)
        {
            var reader            = graphSONReader ?? new GraphSON3Reader();
            var writer            = graphSONWriter ?? new GraphSON3Writer();
            var connectionFactory = new ConnectionFactory(gremlinServer, reader, writer, mimeType ?? DefaultMimeType);

            _connectionPool = new ConnectionPool(connectionFactory);
        }
示例#8
0
 public ConnectionFactory(GremlinServer gremlinServer, GraphSONReader graphSONReader,
                          GraphSONWriter graphSONWriter, string mimeType, Action <ClientWebSocketOptions> webSocketConfiguration)
 {
     _gremlinServer          = gremlinServer;
     _mimeType               = mimeType;
     _graphSONReader         = graphSONReader ?? throw new ArgumentNullException(nameof(graphSONReader));
     _graphSONWriter         = graphSONWriter ?? throw new ArgumentNullException(nameof(graphSONWriter));
     _webSocketConfiguration = webSocketConfiguration;
 }
示例#9
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="GremlinClient" /> class for the specified Gremlin Server.
        /// </summary>
        /// <param name="gremlinServer">The <see cref="GremlinServer" /> the requests should be sent to.</param>
        /// <param name="graphSONReader">A <see cref="GraphSONReader" /> instance to read received GraphSON data.</param>
        /// <param name="graphSONWriter">a <see cref="GraphSONWriter" /> instance to write GraphSON data.</param>
        /// <param name="mimeType">The GraphSON version mime type, defaults to latest supported by the server.</param>
        /// <param name="webSocketConfiguration">
        ///     A delegate that will be invoked with the <see cref="ClientWebSocketOptions" />
        ///     object used to configure WebSocket connections.
        /// </param>
        public GremlinClient(GremlinServer gremlinServer, GraphSONReader graphSONReader = null,
                             GraphSONWriter graphSONWriter = null, string mimeType = null,
                             Action <ClientWebSocketOptions> webSocketConfiguration = null)
        {
            var reader            = graphSONReader ?? new GraphSON3Reader();
            var writer            = graphSONWriter ?? new GraphSON3Writer();
            var connectionFactory = new ConnectionFactory(gremlinServer, reader, writer, mimeType ?? DefaultMimeType,
                                                          webSocketConfiguration);

            _connectionPool = new ConnectionPool(connectionFactory);
        }
示例#10
0
        //

        /// <summary>
        ///     Initializes a new instance of the <see cref="GremlinClient" /> class for the specified Gremlin Server.
        /// </summary>
        /// <param name="gremlinServer">The <see cref="GremlinServer" /> the requests should be sent to.</param>
        /// <param name="graphSONReader">A <see cref="GraphSONReader" /> instance to read received GraphSON data.</param>
        /// <param name="graphSONWriter">a <see cref="GraphSONWriter" /> instance to write GraphSON data.</param>
        /// <param name="mimeType">The GraphSON version mime type, defaults to latest supported by the server.</param>
        /// <param name="connectionPoolSettings">The <see cref="ConnectionPoolSettings"/> for the connection pool.</param>
        /// <param name="webSocketConfiguration">
        ///     A delegate that will be invoked with the <see cref="ClientWebSocketOptions" />
        ///     object used to configure WebSocket connections.
        /// </param>
        public GremlinClient(GremlinServer gremlinServer, GraphSONReader graphSONReader = null,
                             GraphSONWriter graphSONWriter = null, string mimeType = null,
                             ConnectionPoolSettings connectionPoolSettings          = null,
                             Action <ClientWebSocketOptions> webSocketConfiguration = null)
        {
            //
            _gremlinServer          = gremlinServer;
            _graphSONReader         = graphSONReader;
            _graphSONWriter         = graphSONWriter;
            _mimeType               = mimeType;
            _connectionPoolSettings = connectionPoolSettings;
            _webSocketConfiguration = webSocketConfiguration;
            //
            NewConnectionPool();
        }
示例#11
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="GremlinClient" /> class for the specified Gremlin Server.
        /// </summary>
        /// <param name="gremlinServer">The <see cref="GremlinServer" /> the requests should be sent to.</param>
        /// <param name="messageSerializer">
        ///     A <see cref="IMessageSerializer" /> instance to serialize messages sent to and received
        ///     from the server.
        /// </param>
        /// <param name="connectionPoolSettings">The <see cref="ConnectionPoolSettings" /> for the connection pool.</param>
        /// <param name="webSocketConfiguration">
        ///     A delegate that will be invoked with the <see cref="ClientWebSocketOptions" />
        ///     object used to configure WebSocket connections.
        /// </param>
        /// <param name="sessionId">The session Id if Gremlin Client in session mode, defaults to null as session-less Client.</param>
        /// <param name="disableCompression">
        ///     Whether to disable compression. Compression is only supported since .NET 6.
        ///     There it is also enabled by default.
        ///
        ///     Note that compression might make your application susceptible to attacks like CRIME/BREACH. Compression
        ///     should therefore be turned off if your application sends sensitive data to the server as well as data
        ///     that could potentially be controlled by an untrusted user.
        /// </param>
        public GremlinClient(GremlinServer gremlinServer, IMessageSerializer messageSerializer = null,
                             ConnectionPoolSettings connectionPoolSettings          = null,
                             Action <ClientWebSocketOptions> webSocketConfiguration = null, string sessionId = null,
                             bool disableCompression = false)
        {
            messageSerializer ??= new GraphSON3MessageSerializer();
            var webSocketSettings = new WebSocketSettings
            {
                WebSocketConfigurationCallback = webSocketConfiguration
#if NET6_0_OR_GREATER
                , UseCompression = !disableCompression
#endif
            };
            var connectionFactory =
                new ConnectionFactory(gremlinServer, messageSerializer, webSocketSettings, sessionId);

            // make sure one connection in pool as session mode
            if (!string.IsNullOrEmpty(sessionId))
            {
                if (connectionPoolSettings != null)
                {
                    if (connectionPoolSettings.PoolSize != 1)
                    {
                        throw new ArgumentOutOfRangeException(nameof(connectionPoolSettings),
                                                              "PoolSize must be 1 in session mode!");
                    }
                }
                else
                {
                    connectionPoolSettings = new ConnectionPoolSettings {
                        PoolSize = 1
                    };
                }
            }
            _connectionPool =
                new ConnectionPool(connectionFactory, connectionPoolSettings ?? new ConnectionPoolSettings());
        }
        public GremlinClientOperation(string hostname, int port, bool enableSsl, string username, string password)
        {
            var gremlinServer = new Driver.GremlinServer(hostname, port, enableSsl, username, password);

            gremlinClient = new Driver.GremlinClient(gremlinServer, new GraphSON2Reader(), new GraphSON2Writer(), Driver.GremlinClient.GraphSON2MimeType);
        }