コード例 #1
0
        private void WriteTransportMessageAndSendToPeers(TransportMessage transportMessage, List <Peer> peers, SendContext context, ProtoBufferWriter bufferWriter)
        {
            bufferWriter.Reset();
            bufferWriter.WriteTransportMessage(transportMessage, _environment);

            if (context.PersistencePeer == null && transportMessage.IsPersistTransportMessage)
            {
                bufferWriter.WritePersistentPeerIds(transportMessage, transportMessage.PersistentPeerIds);
            }

            foreach (var target in peers)
            {
                var isPersistent = context.WasPersisted(target.Id);
                bufferWriter.SetWasPersisted(isPersistent);

                SendToPeer(transportMessage, bufferWriter, target);
            }

            if (context.PersistencePeer != null)
            {
                bufferWriter.WritePersistentPeerIds(transportMessage, context.PersistentPeerIds);

                SendToPeer(transportMessage, bufferWriter, context.PersistencePeer);
            }
        }
コード例 #2
0
        public void should_serialize_transport_message_and_set_WasPersisted(bool?previousWasPersistedValue, bool newWasPersistedValue)
        {
            var transportMessage = TestDataBuilder.CreateTransportMessage <FakeCommand>();

            transportMessage.WasPersisted = previousWasPersistedValue;

            var writer = new ProtoBufferWriter();

            writer.WriteTransportMessage(transportMessage);
            writer.SetWasPersisted(newWasPersistedValue);

            var deserializedTransportMessage1 = Serializer.Deserialize <TransportMessage>(new MemoryStream(writer.Buffer, 0, writer.Position));

            deserializedTransportMessage1.Id.ShouldEqual(transportMessage.Id);
            deserializedTransportMessage1.Environment.ShouldEqual(transportMessage.Environment);
            deserializedTransportMessage1.WasPersisted.ShouldEqual(newWasPersistedValue);
        }