Esempio n. 1
0
        void UserStreamRead_End(IAsyncResult ar)
        {
            TransStateObjectStream stateObj = (TransStateObjectStream)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                int num = stateObj.UserStream.EndRead(ar);
                if (0 == num)                //for example coping zero-length file
                {
                    FinishTransferingStream(DataStream);
                    OnDataTransfered(null, 0);
                    OnCompleted();
                    stateObj.SetCompleted();
                }
                else
                {
                    DataStream.BeginWrite(_workBuffer,
                                          0,
                                          num,
                                          new AsyncCallback(this.WriteDataStream_End),
                                          stateObj);
                }
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
            catch
            {
                NSTrace.WriteLineError("Non-CLS exception at: " + Environment.StackTrace);
                throw;
            }
        }
Esempio n. 2
0
        private void OnRecieved(IAsyncResult ar)
        {
            ReaderStateObject stateObj = (ReaderStateObject)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();

                int readNum = _socket.EndReceive(ar);
                if (0 == readNum)
                {
                    throw GetClosedException();
                }

                _linesBuilder.PutData(_recvBuffer, readNum, false);
                BuildResponse(stateObj);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
            catch
            {
                NSTrace.WriteLineError("Non-CLS exception at: " + Environment.StackTrace);
                throw;
            }
        }
Esempio n. 3
0
 internal void SetCompleted()
 {
     lock (this)
     {
         this.UpdateContext();
         this._isCompleted = true;
         if (this._wait != null)
         {
             this._wait.Set();
         }
     }
     this.dumpActivityException();
     try
     {
         if (this.CallBack != null)
         {
             this.CallBack(this);
         }
     }
     catch (System.Exception exception)
     {
         NSTrace.WriteLineError("Exception in CB: " + exception.ToString());
         throw;
     }
     catch
     {
         NSTrace.WriteLineError("Non CLS exception in CB: " + Environment.StackTrace.ToString());
         throw;
     }
 }
Esempio n. 4
0
 private void dumpActivityException()
 {
     System.Exception exception = this.Exception;
     if (exception != null)
     {
         int hashCode = Thread.CurrentThread.GetHashCode();
         NSTrace.WriteLineError((string.Format("{0} ---------- Start Exception Info -----------------------------\n", hashCode) + string.Format("{0} Activity: {1}\n", hashCode, this.ActivityName) + string.Format("{0} Stack: {1}\n", hashCode, Environment.StackTrace.ToString())) + string.Format("{0} Exception: {1}\n", hashCode, exception.ToString()) + string.Format("{0} ---------- End   Exception Info -----------------------------", hashCode));
     }
 }
Esempio n. 5
0
        void DataStreamRead_End(IAsyncResult ar)
        {
            TransStateObjectStream stateObj = (TransStateObjectStream)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                int num = DataStream.EndRead(ar);

                DTPStream userStream = (DTPStream)stateObj.UserStream;
                if (num > 0)
                {
                    long require = userStream.AvailableSpace;
                    if (num > require)
                    {
                        num = (int)require;
                    }

                    stateObj.Transfered += num;
                    OnDataTransfered(_workBuffer, num);

                    //write received data to user stream
                    userStream.BeginWrite(_workBuffer,
                                          0,
                                          num,
                                          new AsyncCallback(this.UserStreamWrite_End),
                                          stateObj);
                }
                else
                {
                    userStream.Flush();
                    OnCompleted();
                    stateObj.SetCompleted();
                }
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
            catch
            {
                NSTrace.WriteLineError("Non-CLS exception at: " + Environment.StackTrace);
                throw;
            }
        }
Esempio n. 6
0
        void UserStreamWrite_End(IAsyncResult ar)
        {
            TransStateObjectStream stateObj = (TransStateObjectStream)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                DTPStream userStream = (DTPStream)stateObj.UserStream;
                userStream.EndWrite(ar);

                if (_aborted)
                {
                    throw new FtpAbortedException();
                }

                if (userStream.AvailableSpace > 0)
                {
                    DataStream.BeginRead(_workBuffer,
                                         0,
                                         _workBuffer.Length,
                                         new AsyncCallback(this.DataStreamRead_End),
                                         stateObj);
                }
                else
                {
                    _manuallyClosed = true;

                    userStream.Flush();
                    OnCompleted();
                    stateObj.SetCompleted();
                }
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
            catch
            {
                NSTrace.WriteLineError("Non-CLS exception at: " + Environment.StackTrace);
                throw;
            }
        }