public static StreamCapture New() { var capture = new StreamCapture(); Current = capture; return(capture); }
void ReadStreams(StreamCapture capture) { var expected = capture.DeserializedStreams.Count; for (var i = 0; i < expected; i++) { ReadStream(capture); } }
static DataStream FindStreamById(StreamCapture capture, Guid id) { var dataStream = capture.DeserializedStreams.FirstOrDefault(d => d.Id == id); if (dataStream == null) { throw new Exception("Unexpected stream!"); } return(dataStream); }
public T Receive <T>() { using (var capture = StreamCapture.New()) { var result = ReadBsonMessage <T>(); ReadStreams(capture); log.Write(EventType.Diagnostic, "Received: {0}", result); return(result); } }
public void Send <T>(T message) { using (var capture = StreamCapture.New()) { WriteBsonMessage(message); WriteEachStream(capture.SerializedStreams); } log.Write(EventType.Diagnostic, "Sent: {0}", message); }
void ReadStream(StreamCapture capture) { var reader = new BinaryReader(stream); var id = new Guid(reader.ReadBytes(16)); var length = reader.ReadInt64(); var dataStream = FindStreamById(capture, id); var tempFile = CopyStreamToFile(id, length, reader); var lengthAgain = reader.ReadInt64(); if (lengthAgain != length) { throw new ProtocolException("There was a problem receiving a file stream: the length of the file was expected to be: " + length + " but less data was actually sent. This can happen if the remote party is sending a stream but the stream had already been partially read, or if the stream was being reused between calls."); } ((IDataStreamInternal)dataStream).Received(tempFile); }
public static StreamCapture New() { var capture = new StreamCapture(); Current = capture; return capture; }