Ejemplo n.º 1
0
        public WebSocketConnection(WebSocketSettings settings)
        {
            _client = new ClientWebSocket();
#if NET6_0_OR_GREATER
            if (settings.UseCompression)
            {
                _client.Options.DangerousDeflateOptions = settings.CompressionOptions;
            }
#endif
            settings.WebSocketConfigurationCallback?.Invoke(_client.Options);
        }
Ejemplo n.º 2
0
 public Connection(Uri uri, string username, string password, IMessageSerializer messageSerializer,
                   WebSocketSettings webSocketSettings, string sessionId)
 {
     _uri       = uri;
     _username  = username;
     _password  = password;
     _sessionId = sessionId;
     if (!string.IsNullOrEmpty(sessionId))
     {
         _sessionEnabled = true;
     }
     _messageSerializer   = messageSerializer;
     _webSocketConnection = new WebSocketConnection(webSocketSettings);
 }
Ejemplo n.º 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>
        /// <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());
        }