Пример #1
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());
        }
Пример #2
0
            public Dictionary <string, dynamic> Dictify(dynamic objectData, GraphSONWriter writer)
            {
                DateTime value = objectData;
                var      ticks = (value.ToUniversalTime() - UnixStart).Ticks;

                return(GraphSONUtil.ToTypedValue("Date", ticks / TimeSpan.TicksPerMillisecond));
            }
Пример #3
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));
 }
Пример #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>
        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 Dictionary <string, dynamic> Dictify(dynamic objectData, GraphSONWriter writer)
        {
            var point = (Point)objectData;

            return(GraphSONUtil.ToTypedValue("Geoshape",
                                             new Dictionary <string, object> {
                { "coordinates", point.Coordinates }
            }, "janusgraph"));
        }
Пример #6
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;
 }
Пример #7
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);
 }
Пример #8
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);
        }
Пример #9
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);
 }
Пример #10
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, GraphSONWriter writer)
        {
            MyType myType    = objectData;
            var    valueDict = new Dictionary <string, object>
            {
                { "x", myType.X },
                { "y", myType.Y }
            };

            return(GraphSONUtil.ToTypedValue(nameof(TestClass), valueDict, MyType.GraphsonPrefix));
        }
Пример #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="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();
        }
Пример #12
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);
 }
Пример #13
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, GraphSONWriter writer)
        {
            var p     = (JanusGraphP)objectData;
            var value = p.Other == null
                ? writer.ToDict(p.Value)
                : new List <dynamic>
            {
                writer.ToDict(p.Value), writer.ToDict(p.Other)
            };

            var dict = new Dictionary <string, dynamic>
            {
                { "predicate", p.OperatorName },
                { "value", value }
            };

            return(GraphSONUtil.ToTypedValue("JanusGraphP", dict, "janusgraph"));
        }
Пример #14
0
 public Dictionary <string, dynamic> Dictify(dynamic objectData, GraphSONWriter writer)
 {
     return(GraphSONUtil.ToTypedValue(nameof(TestClass), objectData.Value, TestNamespace));
 }
Пример #15
0
 protected JsonNetMessageSerializer(string mimeType, GraphSONWriter graphSonWriter)
 {
     _graphSONWriter = graphSonWriter;
     _mimeTypeBytes  = Encoding.UTF8.GetBytes($"{(char)mimeType.Length}{mimeType}");
 }
Пример #16
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());
        }
Пример #17
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)
 {
 }
        public Dictionary <string, dynamic> Dictify(dynamic objectData, GraphSONWriter writer)
        {
            var relationIdentifier = (RelationIdentifier)objectData;

            return(GraphSONUtil.ToTypedValue("RelationIdentifier", ValueDict(relationIdentifier), "janusgraph"));
        }
Пример #19
0
            public Dictionary <string, dynamic> Dictify(dynamic objectData, GraphSONWriter writer)
            {
                TimeSpan value = objectData;

                return(GraphSONUtil.ToTypedValue("Double", value.TotalMilliseconds));
            }
 public Dictionary <string, dynamic> Dictify(dynamic objectData, GraphSONWriter writer)
 {
     return(_typedValue);
 }