public MtStreamReadingContext CreateReadingContext() { if (!_stream.CanRead) { throw new Exception("You can't read from this stream!"); } var r = new MtStreamReadingContext(0); return r; }
public MtStreamReadingContext CreateReadingContext() { if (!_stream.CanRead) { throw new Exception("You can't read from this stream!"); } var r = new MtStreamReadingContext(0); return(r); }
public void Read(MtStreamReadingContext ctx, Action <byte[], bool> readStuffCallback, Action doneCallback) { #if DEBUG && !SILVERLIGHT Debug.Print("Read"); #endif try { var buffer = new byte[ReadBufferSize]; AsyncCallback readCallback = null; readCallback = r => { var count = _stream.EndRead(r); // Create a new array, copy read bytes to there var read = new byte[count]; // Update position ctx._position += count; if (count > 0) { // Copy buffer to final count array Array.Copy(buffer, read, count); readStuffCallback(read, ctx._position >= _stream.Length); } if (ctx._position >= _stream.Length) { doneCallback(); } }; if (ctx._position >= _stream.Length) { throw new Exception("Can't read further, end of stream!"); } // Put cursor in the right place _stream.Position = ctx._position; #if DEBUG && !SILVERLIGHT MultiTasksRuntime.DebugDisplayInfo(); #endif _stream.BeginRead(buffer, 0, ReadBufferSize, readCallback, null); } catch (Exception e) { throw new Exception("Exception on Stream.read.", e); } }
public void Read(MtStreamReadingContext ctx, Action<byte[], bool> readStuffCallback, Action doneCallback) { #if DEBUG && !SILVERLIGHT Debug.Print("Read"); #endif try { var buffer = new byte[ReadBufferSize]; AsyncCallback readCallback = null; readCallback = r => { var count = _stream.EndRead(r); // Create a new array, copy read bytes to there var read = new byte[count]; // Update position ctx._position += count; if (count > 0) { // Copy buffer to final count array Array.Copy(buffer, read, count); readStuffCallback(read, ctx._position >= _stream.Length); } if (ctx._position >= _stream.Length) { doneCallback(); } }; if (ctx._position >= _stream.Length) { throw new Exception("Can't read further, end of stream!"); } // Put cursor in the right place _stream.Position = ctx._position; #if DEBUG && !SILVERLIGHT MultiTasksRuntime.DebugDisplayInfo(); #endif _stream.BeginRead(buffer, 0, ReadBufferSize, readCallback, null); } catch (Exception e) { throw new Exception("Exception on Stream.read.", e); } }