Exemplo n.º 1
0
        public Message(string signalKey, long id, object value, DateTime created)
        {
            SignalKey = signalKey;
            Value     = value;
            Id        = id;
            Created   = created;

            _command = new Lazy <SignalCommand>(() =>
            {
                if (!SignalCommand.IsCommand(this))
                {
                    return(null);
                }

                var command = Value as SignalCommand;

                // Optimization for in memory message store
                if (command != null)
                {
                    return(command);
                }

                // Otherwise deserialize the message value
                string rawValue = Value as string;
                if (rawValue == null)
                {
                    return(null);
                }

                return(DependencyResolver.Resolve <IJsonSerializer>().Parse <SignalCommand>(rawValue));
            });
        }
Exemplo n.º 2
0
        private void SerializePesistentResponse(PersistentResponse response, TextWriter writer)
        {
            var jsonWriter = new JsonTextWriter(writer);

            jsonWriter.WriteStartObject();

            jsonWriter.WritePropertyName("MessageId");
            jsonWriter.WriteValue(response.MessageId);

            jsonWriter.WritePropertyName("Disconnect");
            jsonWriter.WriteValue(response.Disconnect);

            jsonWriter.WritePropertyName("TimedOut");
            jsonWriter.WriteValue(response.TimedOut);

            if (response.TransportData != null)
            {
                jsonWriter.WritePropertyName("TransportData");
                jsonWriter.WriteStartObject();

                object value;
                if (response.TransportData.TryGetValue("Groups", out value))
                {
                    jsonWriter.WritePropertyName("Groups");
                    jsonWriter.WriteStartArray();
                    foreach (var group in (IEnumerable <string>)value)
                    {
                        jsonWriter.WriteValue(group);
                    }
                    jsonWriter.WriteEndArray();
                }

                jsonWriter.WriteEndObject();
            }

            jsonWriter.WritePropertyName("Messages");
            jsonWriter.WriteStartArray();

            for (int i = 0; i < response.Messages.Count; i++)
            {
                for (int j = response.Messages[i].Offset; j < response.Messages[i].Offset + response.Messages[i].Count; j++)
                {
                    Message message = response.Messages[i].Array[j];
                    if (!SignalCommand.IsCommand(message))
                    {
                        jsonWriter.WriteRawValue(message.Value);
                    }
                }
            }

            jsonWriter.WriteEndArray();
            jsonWriter.WriteEndObject();
        }
Exemplo n.º 3
0
 private void ProcessResults(MessageResult result)
 {
     for (int i = 0; i < result.Messages.Count; i++)
     {
         for (int j = result.Messages[i].Offset; j < result.Messages[i].Offset + result.Messages[i].Count; j++)
         {
             Message message = result.Messages[i].Array[j];
             if (SignalCommand.IsCommand(message))
             {
                 var command = _serializer.Parse <SignalCommand>(message.Value);
                 ProcessCommand(command);
             }
         }
     }
 }
Exemplo n.º 4
0
        private List <object> ProcessResults(List <Message> source)
        {
            var messageValues = new List <object>();

            foreach (var message in source)
            {
                if (SignalCommand.IsCommand(message))
                {
                    ProcessCommand(message);
                }
                else
                {
                    messageValues.Add(message.Value);
                }
            }
            return(messageValues);
        }
Exemplo n.º 5
0
        private List <object> ProcessResults(IList <Message> source)
        {
            var messageValues = new List <object>();

            foreach (var message in source)
            {
                if (SignalCommand.IsCommand(message))
                {
                    var command = WrappedValue.Unwrap <SignalCommand>(message.Value, _serializer);
                    ProcessCommand(command);
                }
                else
                {
                    messageValues.Add(WrappedValue.Unwrap(message.Value, _serializer));
                }
            }
            return(messageValues);
        }