예제 #1
0
        public static Guid ResponseId(this BasicMessage message)
        {
            Guid result = default(Guid);

            if (message.Headers.ContainsKey(ResponseIdKey))
            {
                Guid.TryParse(message.Headers[ResponseIdKey], out result);
            }
            return(result);
        }
예제 #2
0
        public void SendMessage(BasicMessage message)
        {
            if (closed)
                throw new InvalidOperationException("Socket is closed");

            using (var stream = protocol.ToStream(new BasicMessage[] { message }))
            {
                stream.Position = 0;
                while (stream.Position < stream.Length)
                {
                    var remainingBytes = stream.Length - stream.Position;
                    var bufferSize = (remainingBytes < maxBufferSize) ? (int)remainingBytes : maxBufferSize;
                    var buffer = new byte[bufferSize];
                    stream.Read(buffer, 0, bufferSize);
                    var sent = clientSocket.Send(buffer);
                    if (sent != bufferSize)
                    {
                        log.WarnFormat("Sent less bytes({0}) than the buffer size({1}).", sent, bufferSize);
                        var bytesToReturn = (stream.Position - bufferSize) + sent;
                        stream.Position = bytesToReturn;
                    }
                }
            }
        }
예제 #3
0
 private void NextMessage(BasicMessage message)
 {
     foreach (var item in observers)
     {
         item.OnNext(message);
     }
 }
예제 #4
0
 public static BasicMessage ResponseId(this BasicMessage message, Guid id)
 {
     message.Headers.Add(ResponseIdKey, id.ToString());
     return(message);
 }
예제 #5
0
 public static Guid Id(this BasicMessage message)
 {
     return(Guid.Parse(message.Headers[MessageIdKey]));
 }
예제 #6
0
 public static BasicMessage Sender(this BasicMessage message, string clientName)
 {
     message.Headers.Add(SenderKey, clientName);
     return(message);
 }
예제 #7
0
 public static string Sender(this BasicMessage message)
 {
     return(message.Headers[SenderKey]);
 }