Пример #1
0
        internal Task <TResponse> SendRequestAndWaitResponse <TResponse>(RequestBase request) where TResponse : ResponseBase
        {
            Interlocked.Increment(ref _lastToken);
            request.Token = _lastToken;
            var requestBytes = _serializer.Serialize(request);
            var command      = new Command(CommandNames.Request, requestBytes);

            return(_requestsHandler.WaitForResponse <TResponse>(request, () => _transport.SendData(_commandParser.ToBytes(command))));
        }
Пример #2
0
        public Command Create <T>(CommandName name, T body)
        {
            string bodyString = _dtoSerializer.Serialize(body);

            return(new Command(name, bodyString)
            {
                UserId = _userIdprovider.UserId
            });
        }
Пример #3
0
        public void Send <T>(T obj) where T : class
        {
            try
            {
                Logger.Trace("SEND ({1}): {0}", obj.GetType().Name, GetSessionName());
                var objBytes = _serializer.Serialize(obj);
                var cmd      = CommandNames.Data;
                if (obj is ResponseBase)
                {
                    cmd = CommandNames.Response;
                }
                if (obj is RequestBase)
                {
                    cmd = CommandNames.Request;
                }

                var commandBytes = _commandParser.ToBytes(cmd, objBytes);
                _performanceMeasurer.HandleOutgoingBytes(commandBytes.LongLength);
                Send(commandBytes, 0, commandBytes.Length);
            }
            catch (Exception exc)
            {
                Logger.Exception(exc, "Tried to send {0} to {1}", obj == null ? "NULL" : obj.GetType().Name, GetSessionName());
                //TODO: log
            }
        }
Пример #4
0
 public string Serialize(Command cmd)
 {
     return(_innerSerializer.Serialize(cmd));
 }