Ejemplo n.º 1
0
 public static Message CreateMessage(
     string topic,
     string messageType,
     Predecessors predecessors,
     Guid objectId,
     object body)
 {
     return CreateMessage(
         new TopicSet().Add(topic),
         messageType,
         predecessors,
         objectId,
         body);
 }
Ejemplo n.º 2
0
        public static Message CreateMessage(
            TopicSet topicSet,
            string messageType,
            Predecessors predecessors,
            Guid objectId,
            object body)
        {
            // Convert the anonymous typed object to an ExpandoObject.
            var expandoBody = JsonConvert.DeserializeObject<ExpandoObject>(
                JsonConvert.SerializeObject(body));
            var predecessorList = predecessors.ToImmutableList();
            object document = new
            {
                MessageType = messageType,
                Predecessors = predecessorList
                    .Select(p => new
                    {
                        Role = p.Role,
                        Hash = p.Hash.ToString()
                    })
                    .ToArray(),
                ObjectId = objectId,
                Body = expandoBody
            };
            var messageHash = new MessageHash(ComputeHash(document));

            return new Message(
                topicSet.ToImmutableList(),
                messageType,
                predecessorList,
                objectId,
                expandoBody,
                messageHash);
        }