Esempio n. 1
0
        public static Message CreateMessage(
            string messageType,
            IEnumerable <MessageHash> predecessors,
            Guid objectId,
            object body)
        {
            // Convert the anonymous typed object to an ExpandoObject.
            var expandoBody = JsonConvert.DeserializeObject <ExpandoObject>(
                JsonConvert.SerializeObject(body));
            object document = new
            {
                MessageType  = messageType,
                Predecessors = predecessors
                               .Select(p => p.ToString())
                               .ToArray(),
                ObjectId = objectId,
                Body     = expandoBody
            };
            var messageHash = new MessageHash(ComputeHash(document));

            return(new Message(
                       messageType,
                       predecessors.ToImmutableList(),
                       objectId,
                       expandoBody,
                       messageHash));
        }
Esempio n. 2
0
 public static Message FromMemento(MessageMemento memento)
 {
     return(new Message(
                memento.MessageType,
                memento.Predecessors
                .Select(h => MessageHash.Parse(h))
                .ToImmutableList(),
                memento.ObjectId,
                memento.Body,
                MessageHash.Parse(memento.Hash)));
 }
Esempio n. 3
0
 private Message(
     string type,
     ImmutableList <MessageHash> predecessors,
     Guid objectId,
     ExpandoObject body,
     MessageHash hash)
 {
     _type         = type;
     _predecessors = predecessors;
     _objectId     = objectId;
     _body         = body;
     _hash         = hash;
 }
Esempio n. 4
0
 public Candidate(MessageHash messageHash, T value)
 {
     _messageHash = messageHash;
     _value       = value;
 }