void ReadFileAsync() { _fs.BeginRead(_buffer, 0, _buffer.Length, _ => { try { var count = _fs.EndRead(_); var ee = new DataProgressEventArgs(_fs.Length, _fs.Position); var op = Context.Operation; if (op == null) { OnProgressChanged(ee); } else { op.Post(__ => OnProgressChanged(ee), null); } if (count == 0) { _fs.Close(); WriteFooterAsync(); } else { AsyncData.AsyncStreamWrite(_buffer, 0, count, true, __ => ReadFileAsync()); } } catch (Exception ex) { AsyncData.Exception = ex; AsyncData.NotifyAsyncComplete(); } }, null); }
/// <summary> /// 写入头信息 /// </summary> protected virtual void WriteFooterAsync() { AsyncData.AsyncStreamWrite(System.Text.Encoding.ASCII.GetBytes("\r\n"), true, _ => { if (AsyncData.Exception == null) { _callback(); } }); }
protected override void WriteBodyAsync() { if (Data != null) { AsyncData.AsyncStreamWrite(Data, true, _ => WriteFooterAsync()); } else { WriteFooterAsync(); } }
void BeginReadSourceStream() { Stream.BeginRead(_buffer, 0, _buffer.Length, _ => { try { var count = Stream.EndRead(_); if (count > 0) { AsyncData.AsyncStreamWrite(_buffer, 0, count, true, __ => BeginReadSourceStream()); } else { AsyncData.NotifyAsyncComplete(); } } catch (Exception ex) { AsyncData.Exception = ex; AsyncData.NotifyAsyncComplete(); } }, this); }
/// <summary> /// 写入头信息 /// </summary> protected virtual void WriteHeaderAsync() { AsyncData.AsyncStreamWrite(GetFieldHeaderBuffer(), true, _ => WriteBodyAsync()); }
void FlushWriteFileAsync() { var endingstr = "--" + RequestBoundary + "--"; AsyncData.AsyncStreamWrite(Message.Encoding.GetBytes(endingstr), false, null); }