Пример #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 T Read <T>(byte[] data, Func <IProtocolReader, T> handler)
        {
            using (var buffer = new MemoryStream(data))
            {
                var reader = new XmlProtocolReader(buffer);

                return(handler(reader));
            }
        }
Пример #3
0
        public override async Task ReadData(ITransport transport, string messageId, Action <IProtocolReader, ITransportMetadata> handler)
        {
            var receivedData = await transport.Receive(messageId);

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

                handler(reader, receivedData.Metadata);
            }
        }
Пример #4
0
        public override async Task <TResult> ReadData <TResult>(ITransport transport, Func <IProtocolReader, ITransportMetadata, TResult> handler)
        {
            var receivedData = await transport.Receive();

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

                return(handler(reader, receivedData.Metadata));
            }
        }