Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 写入头信息
 /// </summary>
 protected virtual void WriteFooterAsync()
 {
     AsyncData.AsyncStreamWrite(System.Text.Encoding.ASCII.GetBytes("\r\n"), true, _ =>
     {
         if (AsyncData.Exception == null)
         {
             _callback();
         }
     });
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 写入头信息
 /// </summary>
 protected virtual void WriteHeaderAsync()
 {
     AsyncData.AsyncStreamWrite(GetFieldHeaderBuffer(), true, _ => WriteBodyAsync());
 }
Ejemplo n.º 6
0
        void FlushWriteFileAsync()
        {
            var endingstr = "--" + RequestBoundary + "--";

            AsyncData.AsyncStreamWrite(Message.Encoding.GetBytes(endingstr), false, null);
        }