Exemplo n.º 1
0
        public byte[] SerializeEvent(ISourcedEvent e)
        {
            byte[] content;
            using (var ms = new MemoryStream())
            {
                serializer.Serialize(e, e.GetType(), ms);
                content = ms.ToArray();
            }

            byte[] messageContractBuffer;
            using (var ms = new MemoryStream())
            {
                var name = e.GetType().GetContractName();
                var messageContract = new MessageContract(name, content.Length, 0, e.EventIdentifier, e.EventSequence);
                serializer.Serialize(messageContract, typeof(MessageContract), ms);
                messageContractBuffer = ms.ToArray();
            }

            using (var ms = new MemoryStream())
            {
                var headerContract = new MessageHeaderContract(messageContractBuffer.Length);
                headerContract.WriteHeader(ms);
                ms.Write(messageContractBuffer, 0, messageContractBuffer.Length);
                ms.Write(content, 0, content.Length);
                return ms.ToArray();
            }
        }
Exemplo n.º 2
0
        public byte[] SerializeEvent(ISourcedEvent e)
        {
            byte[] content;
            using (var ms = new MemoryStream())
            {
                serializer.Serialize(e, e.GetType(), ms);
                content = ms.ToArray();
            }

            byte[] messageContractBuffer;
            using (var ms = new MemoryStream())
            {
                var name            = e.GetType().GetContractName();
                var messageContract = new MessageContract(name, content.Length, 0, e.EventIdentifier, e.EventSequence);
                serializer.Serialize(messageContract, typeof(MessageContract), ms);
                messageContractBuffer = ms.ToArray();
            }

            using (var ms = new MemoryStream())
            {
                var headerContract = new MessageHeaderContract(messageContractBuffer.Length);
                headerContract.WriteHeader(ms);
                ms.Write(messageContractBuffer, 0, messageContractBuffer.Length);
                ms.Write(content, 0, content.Length);
                return(ms.ToArray());
            }
        }