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
        protected virtual void WriteBodyAsync()
        {
            var op = Context.Operation;

            //一个文件失败,则把整个过程看作失败
            try
            {
                _fs     = FileInfo.OpenRead();
                _buffer = new byte[AsyncData.HttpContext.Client.Setting.WriteBufferSize];
                var ee = new DataProgressEventArgs(_fs.Length, 0L);
                if (op == null)
                {
                    OnProgressChanged(ee);
                }
                else
                {
                    op.Post(__ => OnProgressChanged(ee), null);
                }
                ReadFileAsync();
            }
            catch (Exception ex)
            {
                AsyncData.Exception = ex;
                AsyncData.NotifyAsyncComplete();
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 通知异步的操作完成
 /// </summary>
 protected virtual void CallCompleteCallback()
 {
     if (AsyncData != null)
     {
         AsyncData.NotifyAsyncComplete();
     }
 }
 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);
 }