heljoyLiu commented on a change in pull request #1263: dotnet: add session mode 
connection
URL: https://github.com/apache/tinkerpop/pull/1263#discussion_r394831049
 
 

 ##########
 File path: gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
 ##########
 @@ -235,17 +243,52 @@ private void NotifyAboutConnectionFailure(Exception 
exception)
 
         private async Task SendMessageAsync(RequestMessage message)
         {
+            if (_sessionEnabled)
+            {
+                message = RebuildSessionMessage(message);
+            }
             var graphsonMsg = _graphSONWriter.WriteObject(message);
             var serializedMsg = 
_messageSerializer.SerializeMessage(graphsonMsg);
             await 
_webSocketConnection.SendMessageAsync(serializedMsg).ConfigureAwait(false);
         }
 
+        private RequestMessage RebuildSessionMessage(RequestMessage message)
+        {
+            if (message.Processor == Tokens.OpsAuthentication)
+            {
+                return message;
+            }
+
+            var msgBuilder = RequestMessage.Build(message.Operation)
+              
.OverrideRequestId(message.RequestId).Processor(Tokens.ProcessorSession);
+            foreach(var kv in message.Arguments)
+            {
+                msgBuilder.AddArgument(kv.Key, kv.Value);
+            }
+            msgBuilder.AddArgument(Tokens.ArgsSession, _sessionId);
+            return msgBuilder.Create();
+        }
+
         public async Task CloseAsync()
         {
             Interlocked.Exchange(ref _connectionState, Closed);
+
+            if (_sessionEnabled)
+            {
+                await CloseSession().ConfigureAwait(false);
+            }
             await _webSocketConnection.CloseAsync().ConfigureAwait(false);
         }
 
+        private async Task CloseSession()
+        {
+            // build a request to close this session, 'gremlin' in args as 
tips and not be executed actually
+            var msg = 
RequestMessage.Build(Tokens.OpsClose).Processor(Tokens.ProcessorSession)
+              .AddArgument(Tokens.ArgsGremlin, "session.close()").Create();
 
 Review comment:
   I don't notice that sorry, and a good job to bound to client, great
   I will remove 'close'  in this PR, 
   and another PR for javascript is going on. thanks

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to