Inheritance: IDisposable
示例#1
0
        public static StreamCapture New()
        {
            var capture = new StreamCapture();

            Current = capture;
            return(capture);
        }
示例#2
0
        void ReadStreams(StreamCapture capture)
        {
            var expected = capture.DeserializedStreams.Count;

            for (var i = 0; i < expected; i++)
            {
                ReadStream(capture);
            }
        }
示例#3
0
        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);
        }
示例#4
0
 public T Receive <T>()
 {
     using (var capture = StreamCapture.New())
     {
         var result = ReadBsonMessage <T>();
         ReadStreams(capture);
         log.Write(EventType.Diagnostic, "Received: {0}", result);
         return(result);
     }
 }
示例#5
0
        public void Send <T>(T message)
        {
            using (var capture = StreamCapture.New())
            {
                WriteBsonMessage(message);
                WriteEachStream(capture.SerializedStreams);
            }

            log.Write(EventType.Diagnostic, "Sent: {0}", message);
        }
示例#6
0
        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);
        }
示例#7
0
 public static StreamCapture New()
 {
     var capture = new StreamCapture();
     Current = capture;
     return capture;
 }