Beispiel #1
0
 public async Task HandleAsync()
 {
     switch (request.ObjectType)
     {
     case ObjectType.Request:
     {
         ClientConnection    clientConnection = null;
         CommunicationObject userObject;
         var clientConnections = serviceProvider.ConnectionsService.GetUserClientConnections(request.UserId);
         if (clientConnections != null)
         {
             clientConnection = clientConnections.FirstOrDefault(opt => opt.IsProxiedClientConnection && opt.ProxyNodeWebSocket != null);
         }
         if (clientConnection == null)
         {
             clientConnection = new ClientConnection(request.UserId, current.NodeWebSocket);
             serviceProvider.ConnectionsService.AddOrUpdateUserConnection(request.UserId, clientConnection);
         }
         if (clientConnection.IsEncryptedConnection)
         {
             byte[] decryptedData = Encryptor.SymmetricDataDecrypt(
                 request.CommunicationData,
                 clientConnection.SignPublicKey,
                 clientConnection.SymmetricKey,
                 NodeData.Instance.NodeKeys.Password).DecryptedData;
             userObject = ObjectSerializer.BytesToCommunicationObject(decryptedData);
         }
         else
         {
             userObject = ObjectSerializer.BytesToCommunicationObject(request.CommunicationData);
         }
         IRequestHandler requestHandler = ClientWebSocketRequestManager.InitRequestHandler(
             (Request)userObject,
             clientConnection,
             clientRequestService,
             serviceProvider);
         Response response;
         try
         {
             response = await requestHandler.CreateResponseAsync().ConfigureAwait(false);
         }
         catch
         {
             response = new ResultResponse(request.RequestId, null, ErrorCode.UnknownError);
         }
         SendResponse(response, clientConnection, current);
     }
     break;
     }
 }
 private CommunicationObject ConvertReceivedDataToCommucicatonObject(byte[] data)
 {
     if (client.IsEncryptedConnection)
     {
         data = Encryptor.SymmetricDataDecrypt(
             data,
             client.SignPublicKey,
             client.SymmetricKey,
             NodeData.Instance.NodeKeys.Password)
                .DecryptedData;
     }
     return(ObjectSerializer.BytesToCommunicationObject(
                data,
                Newtonsoft.Json.NullValueHandling.Ignore,
                new RequestJsonConverter(),
                new ClientResponseJsonConverter(),
                new CommunicationObjectJsonConverter()));
 }