Esempio n. 1
0
        public dynamic Objectify(JToken graphsonObject, GraphSONReader reader)
        {
            var x = reader.ToObject(graphsonObject["x"]);
            var y = reader.ToObject(graphsonObject["y"]);

            return(new MyType(x, y));
        }
Esempio n. 2
0
        public dynamic Objectify(JsonElement graphsonObject, GraphSONReader reader)
        {
            var x = reader.ToObject(graphsonObject.GetProperty("x"));
            var y = reader.ToObject(graphsonObject.GetProperty("y"));

            return(new MyType(x, y));
        }
Esempio n. 3
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)
 {
 }
Esempio n. 4
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());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphClient"/> class.
        /// </summary>
        /// <param name="gremlinHostname">The hostname.</param>
        /// <param name="databaseName">Name of the database (case-sensitive).</param>
        /// <param name="graphName">Name of the graph.</param>
        /// <param name="accessKey">The access key.</param>
        public GraphClient(string gremlinHostname, string databaseName, string graphName, string accessKey,
                           int port = 443, bool useSSL = true)
        {
            var server = new GremlinServer(gremlinHostname, port, useSSL, $"/dbs/{databaseName}/colls/{graphName}", accessKey);

            _graphSONReader = new GraphSONJTokenReader();
            _gremlinClient  = new GremlinClient(server, _graphSONReader, mimeType: GremlinClient.GraphSON2MimeType);
        }
Esempio n. 6
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));
 }
Esempio n. 7
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());
        }
Esempio n. 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;
 }
Esempio n. 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>
        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);
        }
        public dynamic Objectify(JToken graphsonObject, GraphSONReader reader)
        {
            if (graphsonObject["coordinates"] != null)
            {
                return(DeserializePointFromCoordinates(graphsonObject["coordinates"]));
            }
            var geometryData = graphsonObject["geometry"];

            throw new InvalidOperationException($"Deserialization of type {geometryData["type"]} is not supported.");
        }
Esempio n. 11
0
 public Connection(Uri uri, string username, string password, GraphSONReader graphSONReader,
                   GraphSONWriter graphSONWriter, string mimeType)
 {
     _uri               = uri;
     _username          = username;
     _password          = password;
     _graphSONReader    = graphSONReader;
     _graphSONWriter    = graphSONWriter;
     _messageSerializer = new JsonMessageSerializer(mimeType);
 }
Esempio n. 12
0
        public dynamic Objectify(JsonElement graphsonObject, GraphSONReader reader)
        {
            if (graphsonObject.TryGetProperty("coordinates", out var coordinatesProperty))
            {
                return(DeserializePointFromCoordinates(coordinatesProperty));
            }
            var geometryData = graphsonObject.GetProperty("geometry");

            throw new InvalidOperationException(
                      $"Deserialization of type {geometryData.GetProperty("type").GetString()} is not supported.");
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
 public Connection(Uri uri, string username, string password, GraphSONReader graphSONReader,
                   GraphSONWriter graphSONWriter, string mimeType, Action <ClientWebSocketOptions> webSocketConfiguration)
 {
     _uri                 = uri;
     _username            = username;
     _password            = password;
     _graphSONReader      = graphSONReader;
     _graphSONWriter      = graphSONWriter;
     _messageSerializer   = new JsonMessageSerializer(mimeType);
     _webSocketConnection = new WebSocketConnection(webSocketConfiguration);
 }
Esempio n. 15
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();
        }
Esempio n. 16
0
 public Connection(Uri uri, string username, string password, GraphSONReader graphSONReader,
                   GraphSONWriter graphSONWriter, string mimeType,
                   Action <ClientWebSocketOptions> webSocketConfiguration, string sessionId)
 {
     _uri       = uri;
     _username  = username;
     _password  = password;
     _sessionId = sessionId;
     if (!string.IsNullOrEmpty(sessionId))
     {
         _sessionEnabled = true;
     }
     _graphSONReader      = graphSONReader;
     _graphSONWriter      = graphSONWriter;
     _messageSerializer   = new JsonMessageSerializer(mimeType);
     _webSocketConnection = new WebSocketConnection(webSocketConfiguration);
 }
 public dynamic Objectify(JsonElement graphsonObject, GraphSONReader reader)
 {
     return(new RelationIdentifier(graphsonObject.GetProperty("relationId").GetString()));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GraphClient"/> class.
 /// </summary>
 /// <param name="gremlinClient">The gremlin client.</param>
 /// <exception cref="ArgumentNullException">gremlinClient</exception>
 internal GraphClient(IGremlinClient gremlinClient)
 {
     _graphSONReader = new GraphSONJTokenReader();
     _gremlinClient  = gremlinClient ?? throw new ArgumentNullException(nameof(gremlinClient));
 }
 public dynamic Objectify(JToken graphsonObject, GraphSONReader reader)
 {
     return(new RelationIdentifier((string)graphsonObject["relationId"]));
 }
 public dynamic Objectify(JsonElement graphsonObject, GraphSONReader reader)
 {
     return(DeserializationResult);
 }
Esempio n. 21
0
 public ResponseHandlerForSingleRequestMessage(GraphSONReader graphSonReader)
 {
     _graphSONReader = graphSonReader;
 }
Esempio n. 22
0
 public dynamic Objectify(JsonElement graphsonObject, GraphSONReader reader)
 {
     return(new TestClass {
         Value = graphsonObject.GetString()
     });
 }
Esempio n. 23
0
            public dynamic Objectify(JToken graphsonObject, GraphSONReader reader)
            {
                var duration = graphsonObject.ToObject <double>();

                return(TimeSpan.FromMilliseconds(duration));
            }
Esempio n. 24
0
 public dynamic Objectify(JToken graphsonObject, GraphSONReader reader)
 {
     return(new TestClass {
         Value = graphsonObject.ToString()
     });
 }
Esempio n. 25
0
            public dynamic Objectify(JToken graphsonObject, GraphSONReader reader)
            {
                var milliseconds = graphsonObject.ToObject <long>();

                return(UnixStart.AddTicks(TimeSpan.TicksPerMillisecond * milliseconds));
            }