예제 #1
0
        public override async Task <Func <Func <IProtocolReader, ITransportMetadata, TResult>, Task <TResult> > > WriteAndReadData <TResult>(ITransport transport, ITransportMetadata metadata, Action <IProtocolWriter> handler)
        {
            Func <Task <TransportMessage> > receiveHandler;

            using (var buffer = new MemoryStream())
            {
                var writer = new XmlProtocolWriter(buffer);
                handler(writer);

                buffer.Position = 0;

                var data = buffer.ToArray();
                receiveHandler = await transport.SendAndReceive(new TransportMessage(data, VolatileTransportMetadata.FromMetadata(metadata)));
            }

            return(new Func <Func <IProtocolReader, ITransportMetadata, TResult>, Task <TResult> >(async(readHandler) =>
            {
                var receivedData = await receiveHandler();

                using (var buffer = new MemoryStream(receivedData.Payload))
                {
                    var reader = new XmlProtocolReader(buffer);

                    return readHandler(reader, receivedData.Metadata);
                }
            }));
        }
예제 #2
0
        public override async Task WriteData(ITransport transport, string messageId, ITransportMetadata metadata, Action <IProtocolWriter> handler)
        {
            using (var buffer = new MemoryStream())
            {
                var writer = new XmlProtocolWriter(buffer);
                handler(writer);

                buffer.Position = 0;

                var data = buffer.ToArray();
                await transport.Send(messageId, new TransportMessage(data, VolatileTransportMetadata.FromMetadata(metadata)));
            }
        }
예제 #3
0
        public byte[] Write(Action <IProtocolWriter> handler)
        {
            using (var buffer = new MemoryStream())
            {
                var writer = new XmlProtocolWriter(buffer);
                handler(writer);

                buffer.Position = 0;

                var data = buffer.ToArray();

                return(data);
            }
        }