tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [43/50] [abbrv] tinkerpop git commit: Gremlin .NET: Use application/vnd.gremlin-v3.0+json by default
Date Tue, 18 Jul 2017 13:09:20 GMT
Gremlin .NET: Use application/vnd.gremlin-v3.0+json by default


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/8fd4c8cd
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/8fd4c8cd
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/8fd4c8cd

Branch: refs/heads/master
Commit: 8fd4c8cdc7a8299af47e592389b3183a9c64c1ee
Parents: 8cdc941
Author: Jorge Bay Gondra <jorgebaygondra@gmail.com>
Authored: Fri Jul 14 18:44:43 2017 +0200
Committer: Jorge Bay Gondra <jorgebaygondra@gmail.com>
Committed: Fri Jul 14 18:44:43 2017 +0200

----------------------------------------------------------------------
 gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs       |  5 +++--
 .../src/Gremlin.Net/Driver/ConnectionFactory.cs           |  6 ++++--
 gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs    | 10 ++++++++--
 .../src/Gremlin.Net/Driver/JsonMessageSerializer.cs       |  9 +++++++--
 4 files changed, 22 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8fd4c8cd/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
index 126b461..3d3e902 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
@@ -36,20 +36,21 @@ namespace Gremlin.Net.Driver
     {
         private readonly GraphSONReader _graphSONReader;
         private readonly GraphSONWriter _graphSONWriter;
-        private readonly JsonMessageSerializer _messageSerializer = new JsonMessageSerializer();
+        private readonly JsonMessageSerializer _messageSerializer;
         private readonly Uri _uri;
         private readonly WebSocketConnection _webSocketConnection = new WebSocketConnection();
         private readonly string _username;
         private readonly string _password;
 
         public Connection(Uri uri, string username, string password, GraphSONReader graphSONReader,
-            GraphSONWriter graphSONWriter)
+                          GraphSONWriter graphSONWriter, string mimeType)
         {
             _uri = uri;
             _username = username;
             _password = password;
             _graphSONReader = graphSONReader;
             _graphSONWriter = graphSONWriter;
+            _messageSerializer = new JsonMessageSerializer(mimeType);
         }
 
         public async Task<IReadOnlyCollection<T>> SubmitAsync<T>(RequestMessage
requestMessage)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8fd4c8cd/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionFactory.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionFactory.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionFactory.cs
index e3fd068..e2ff5b7 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionFactory.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionFactory.cs
@@ -31,11 +31,13 @@ namespace Gremlin.Net.Driver
         private readonly GraphSONReader _graphSONReader;
         private readonly GraphSONWriter _graphSONWriter;
         private readonly GremlinServer _gremlinServer;
+        private readonly string _mimeType;
 
         public ConnectionFactory(GremlinServer gremlinServer, GraphSONReader graphSONReader,
-            GraphSONWriter graphSONWriter)
+                                 GraphSONWriter graphSONWriter, string mimeType)
         {
             _gremlinServer = gremlinServer;
+            _mimeType = mimeType;
             _graphSONReader = graphSONReader ?? throw new ArgumentNullException(nameof(graphSONReader));
             _graphSONWriter = graphSONWriter ?? throw new ArgumentNullException(nameof(graphSONWriter));
         }
@@ -43,7 +45,7 @@ namespace Gremlin.Net.Driver
         public Connection CreateConnection()
         {
             return new Connection(_gremlinServer.Uri, _gremlinServer.Username, _gremlinServer.Password,
_graphSONReader,
-                _graphSONWriter);
+                                 _graphSONWriter, _mimeType);
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8fd4c8cd/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs
index 9781a7c..a251ab7 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs
@@ -34,6 +34,11 @@ namespace Gremlin.Net.Driver
     /// </summary>
     public class GremlinClient : IGremlinClient
     {
+        /// <summary>
+        /// Defines the default mime type to use.
+        /// </summary>
+        public const string DefaultMimeType = "application/vnd.gremlin-v3.0+json";
+        
         private readonly ConnectionPool _connectionPool;
 
         /// <summary>
@@ -42,12 +47,13 @@ namespace Gremlin.Net.Driver
         /// <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)
+                             GraphSONWriter graphSONWriter = null, string mimeType = null)
         {
             var reader = graphSONReader ?? new GraphSON3Reader();
             var writer = graphSONWriter ?? new GraphSON3Writer();
-            var connectionFactory = new ConnectionFactory(gremlinServer, reader, writer);
+            var connectionFactory = new ConnectionFactory(gremlinServer, reader, writer,
mimeType ?? DefaultMimeType);
             _connectionPool = new ConnectionPool(connectionFactory);
         }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8fd4c8cd/gremlin-dotnet/src/Gremlin.Net/Driver/JsonMessageSerializer.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/JsonMessageSerializer.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/JsonMessageSerializer.cs
index c3270bf..53a546c 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/JsonMessageSerializer.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/JsonMessageSerializer.cs
@@ -28,7 +28,12 @@ namespace Gremlin.Net.Driver
 {
     internal class JsonMessageSerializer
     {
-        private const string MimeType = "application/vnd.gremlin-v2.0+json";
+        private readonly string _mimeType;
+
+        public JsonMessageSerializer(string mimeType)
+        {
+            _mimeType = mimeType;
+        }
 
         public byte[] SerializeMessage(string msg)
         {
@@ -37,7 +42,7 @@ namespace Gremlin.Net.Driver
 
         private string MessageWithHeader(string messageContent)
         {
-            return $"{(char) MimeType.Length}{MimeType}{messageContent}";
+            return $"{(char) _mimeType.Length}{_mimeType}{messageContent}";
         }
 
         public TMessage DeserializeMessage<TMessage>(byte[] message)


Mime
View raw message