コード例 #1
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;
     }
 }
コード例 #2
0
ファイル: Cmd_RunDTP.cs プロジェクト: kineva1992/repos
        protected virtual void Dispose(bool disposing)
        {
            lock (this)
            {
                _disposed = true;

                if (disposing)
                {
                }

                try
                {
                    FtpDataConnection dc = _currentDC;
                    if (null != dc)
                    {
                        dc.Dispose();
                    }
                }
                catch (Exception e)
                {
                    NSTrace.WriteLineError("DTP.Dispose() ex: " + e.ToString());
                }
                catch
                {
                    NSTrace.WriteLineError("DTP.Dispose() non cls ex: " + Environment.StackTrace);
                }
            }
        }
コード例 #3
0
        private object DoTimeoutOp(int timeout, IOp op)
        {
            this.CheckDisposed();
            object obj2 = null;

            this.StartTimeoutTrack(timeout);
            try
            {
                obj2 = op.Execute();
            }
            catch (Exception exception)
            {
                NSTrace.WriteLineError("SocketEx (ex): " + exception.ToString());
                this.StopTimeoutTrack(exception);
                throw;
            }
            catch
            {
                NSTrace.WriteLineError("SocketEx (non clas ex): " + Environment.StackTrace);
                this.StopTimeoutTrack(this.NonCLSException);
                throw;
            }
            this.StopTimeoutTrack(null);
            return(obj2);
        }
コード例 #4
0
        /*internal void SetCompleted(bool completedSync)
         * {
         *      SetCompleted();
         * }*/

        internal void SetCompleted()
        {
            lock (this)             //sync with 'AsyncWaitHandle' property
            {
                UpdateContext();
                _isCompleted = true;
                if (null != _wait)
                {
                    _wait.Set();
                }
            }

            dumpActivityException();

            try
            {
                if (null != CallBack)
                {
                    CallBack(this);
                }
            }
            catch (Exception e)
            {
                NSTrace.WriteLineError("Exception in CB: " + e.ToString());
                throw;
            }

            /*
             *  catch
             *  {
             *          NSTrace.WriteLineError("Non CLS exception in CB: " + Environment.StackTrace.ToString());
             *          throw;
             *  }
             */
        }
コード例 #5
0
ファイル: FtpResponseReader.cs プロジェクト: kineva1992/repos
        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;
            }
        }
コード例 #6
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;
            }
        }
コード例 #7
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));
     }
 }
コード例 #8
0
        void OnEndConnectCB(IAsyncResult ar)
        {
            Connect_SO stateObj = (Connect_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                _socket.EndConnect(ar);
                _reader.BeginReadResponse(stateObj.Timeout,
                                          new AsyncCallback(this.OnResponse),
                                          stateObj);
            }
            catch (SocketException e)
            {
                if (_disposed)
                {
                    stateObj.Exception = GetDisposedException();
                }
                else if (e.ErrorCode == SockErrors.WSAETIMEDOUT)
                {
                    stateObj.Exception = GetTimeoutException(e);
                }
                else
                {
                    stateObj.Exception = e;
                }
                stateObj.SetCompleted();
            }
            catch (Exception e)
            {
                if (_disposed)
                {
                    stateObj.Exception = GetDisposedException();
                }
                else
                {
                    stateObj.Exception = e;
                }
                stateObj.SetCompleted();
            }
            catch
            {
                if (_disposed)
                {
                    stateObj.Exception = GetDisposedException();
                    stateObj.SetCompleted();
                }
                else
                {
                    NSTrace.WriteLineError("Non-CLS exception at: " + Environment.StackTrace);
                    throw;
                }
            }
        }
コード例 #9
0
        public override void Write(byte[] buffer, int offset, int size)
        {
            if ((0 == _available) || (size > _available))
            {
                string msg = "Trying to write after the end of the stream.";
                NSTrace.WriteLineError(msg);
                throw new EndOfStreamException(msg);
            }

            _stream.Write(buffer, offset, size);
            _available -= size;
        }
コード例 #10
0
        private void dumpActivityException(AsyncResultBase ar)
        {
            Exception exception = ar.Exception;
            int       hashCode  = Thread.CurrentThread.GetHashCode();

            NSTrace.WriteLineError(string.Format("{0} -----------------------------", hashCode));
            NSTrace.WriteLineError(string.Format("{0} Activity: {1}", hashCode, ar.ActivityName));
            NSTrace.WriteLineError(string.Format("{0} Exception: {1}", hashCode, exception.GetType().FullName));
            NSTrace.WriteLineError(string.Format("{0} Message: {1}", hashCode, exception.ToString()));
            NSTrace.WriteLineError(string.Format("{0} Stack: {1}", hashCode, exception.StackTrace));
            NSTrace.WriteLineError(string.Format("{0} -----------------------------", hashCode));
        }
コード例 #11
0
        //this function used by routines - Connect, SendCommandEx, ReadResponse
        void OnResponse(IAsyncResult ar)
        {
            AsyncResultBase stateObj = (AsyncResultBase)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                _response = _reader.EndReadResponse(ar);
                OnResponseReceived();
            }
            catch (SocketException e)
            {
                if (_disposed)
                {
                    stateObj.Exception = GetDisposedException();
                }
                else if (e.ErrorCode == SockErrors.WSAETIMEDOUT)
                {
                    stateObj.Exception = GetTimeoutException(e);
                }
                else
                {
                    stateObj.Exception = e;
                }
            }
            catch (Exception e)
            {
                if (_disposed)
                {
                    stateObj.Exception = GetDisposedException();
                }
                else
                {
                    stateObj.Exception = e;
                }
            }
            catch
            {
                if (_disposed)
                {
                    stateObj.Exception = GetDisposedException();
                }
                else
                {
                    NSTrace.WriteLineError("Non-CLS exception at: " + Environment.StackTrace);
                    throw;
                }
            }
            _response = _reader.Response;
            stateObj.SetCompleted();
        }
コード例 #12
0
        internal static IPEndPoint ConstructEndPoint(IPHostEntry host, int port)
        {
            if (0 >= host.AddressList.Length)
            {
                NSTrace.WriteLineError("Provided host structure do not contains addresses.");
                throw new ArgumentException("Provided host structure do not contains addresses.", "host");
            }
            int index = 0;

            if (1 < host.AddressList.Length)
            {
                index = _rand.Next(host.AddressList.Length - 1);
            }
            return(new IPEndPoint(host.AddressList[index], port));
        }
コード例 #13
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;
            }
        }
コード例 #14
0
 internal SocketEx(SocketBase baseSocket)
 {
     this._opState        = OpState.Finished;
     this._recvTimeout    = -1;
     this._sendTimeout    = -1;
     this._acceptTimeout  = -1;
     this._connectTimeout = -1;
     NSTrace.WriteLineVerbose("-> SocketEx(handle)");
     if (baseSocket == null)
     {
         NSTrace.WriteLineError("EX: SocketEx(handle), handle == null. " + Environment.StackTrace);
         throw new ArgumentNullException("baseSocket");
     }
     this._baseSocket = baseSocket;
     this.Init();
     NSTrace.WriteLineVerbose("<- SocketEx(handle)");
 }
コード例 #15
0
ファイル: Cmd_RunDTP.cs プロジェクト: kineva1992/repos
        internal IAsyncResult BeginExecute(int timeout,
                                           string command,
                                           FtpDataType dataType,
                                           long restart,
                                           DTPStream userStream,
                                           AsyncCallback cb,
                                           object state)
        {
            RunDTP_SO stateObj = new RunDTP_SO(timeout,
                                               command,
                                               dataType,
                                               restart,
                                               userStream,
                                               cb,
                                               state);

            SetProgress(true);
            _currentDC = null;
            try
            {
                //----------------------------------------
                //Lock Control connection to prevent
                //run the command like abort, quit, stat
                //during configuring of data connection
                _cc.BeginLock(Timeout.Infinite,
                              new WaitOrTimerCallback(LockFirst_End),
                              stateObj);
            }
            catch (Exception e)
            {
                SetProgress(false);
                CheckDisposed();

                NSTrace.WriteLineError(_errMsg + e.ToString());
                throw;
            }
            catch
            {
                SetProgress(false);
                CheckDisposed();

                NSTrace.WriteLineError(_errMsgNonCls + Environment.StackTrace.ToString());
                throw;
            }
            return(stateObj);
        }
コード例 #16
0
ファイル: SocketBase.cs プロジェクト: xas/RatioMaster.Core
        static public IPEndPoint ConstructEndPoint(IPHostEntry host, int port)
        {
            if (0 >= host.AddressList.Length)
            {
                NSTrace.WriteLineError("Provided host structure do not contains addresses.");
                throw new ArgumentException("Provided host structure do not contains addresses.", "host");
            }

            foreach (var addr in host.AddressList)
            {
                if (addr.AddressFamily == AddressFamily.InterNetwork)
                {
                    return(new IPEndPoint(addr, port));
                }
            }

            return(new IPEndPoint(IPAddress.Parse("127.0.0.1"), port));
        }
コード例 #17
0
        IPEndPoint ConstructEndPoint(IPHostEntry host, int port)
        {
            if (0 >= host.AddressList.Length)
            {
                string msg = "Provided host structure do not contains addresses.";
                NSTrace.WriteLineError(msg);
                throw new ArgumentException(msg);
            }

            int addressNo = 0;

            if (1 < host.AddressList.Length)
            {
                addressNo = _rand.Next(host.AddressList.Length - 1);
            }

            return(new IPEndPoint(host.AddressList[addressNo], port));
        }
コード例 #18
0
ファイル: Cmd_RunDTP.cs プロジェクト: kineva1992/repos
        void HandleCatch(Exception e,
                         RunDTP_SO stateObj)
        {
            //----------------------------------------
            //Clear context before unlocking
            _client.CurrentDTP = null;

            //----------------------------------------
            //Unlock control connection, now the command
            //like abort, stat, quit could be issued
            try
            {
                UnlockCC(stateObj);
            }
            catch (Exception ex)
            {
                NSTrace.WriteLineError("UnlockCC exception: " + ex.ToString());
            }
            catch
            {
                NSTrace.WriteLineError("UnlockCC non-cls exception: " + Environment.StackTrace);
            }

            if (_disposed)
            {
                stateObj.Exception = GetDisposedException();
            }
            else if (null != e)
            {
                NSTrace.WriteLineError("DTP exception: " + e.ToString());
                stateObj.Exception = e;
            }
            else
            {
                NSTrace.WriteLineError("DTP non cls exception: " + Environment.StackTrace);
            }

            //Do not set completed in case we
            //have non-cls exception
            if (null != stateObj.Exception)
            {
                stateObj.SetCompleted();
            }
        }
コード例 #19
0
        void dumpActivityException()
        {
            Exception e = Exception;

            if (null == e)
            {
                return;
            }

            int    tid = Thread.CurrentThread.GetHashCode();
            string msg = string.Format("{0} ---------- Start Exception Info -----------------------------\n", tid);

            msg += string.Format("{0} Activity: {1}\n", tid, ActivityName);
            msg += string.Format("{0} Stack: {1}\n", tid, Environment.StackTrace.ToString());
            msg += string.Format("{0} Exception: {1}\n", tid, e.ToString());
            msg += string.Format("{0} ---------- End   Exception Info -----------------------------", tid);

            NSTrace.WriteLineError(msg);
        }
コード例 #20
0
        public override IAsyncResult BeginWrite(byte[] buffer,
                                                int offset,
                                                int size,
                                                AsyncCallback callback,
                                                object state
                                                )
        {
            if ((0 == _available) || (size > _available))
            {
                string msg = "Trying to write after the end of the stream.";
                NSTrace.WriteLineError(msg);
                throw new EndOfStreamException(msg);
            }

            IAsyncResult ar = _stream.BeginWrite(buffer, offset, size, callback, state);

            _available -= size;
            return(ar);
        }
コード例 #21
0
        public override int Read(byte[] buffer, int offset, int size)
        {
            if (0 == _available)
            {
                string msg = "Trying to read after the end of the stream.";
                NSTrace.WriteLineError(msg);
                throw new EndOfStreamException(msg);
            }

            if (size > _available)
            {
                size = (int)_available;
            }

            int r = _stream.Read(buffer, offset, size);

            _available -= r;
            return(r);
        }
コード例 #22
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;
            }
        }
コード例 #23
0
ファイル: Cmd_Reset.cs プロジェクト: kineva1992/repos
        void Lock_End(object state, bool timedout)
        {
            Reset_SO stateObj = (Reset_SO)state;

            try
            {
                stateObj.UpdateContext();
                if (timedout)
                {
                    string msg = string.Format("Unable to lock CC within {0} time: ", stateObj.Timeout);
                    NSTrace.WriteLineError(msg + Environment.StackTrace);
                    stateObj.Exception = GetTimeoutException(stateObj.Timeout);
                    stateObj.SetCompleted();
                }
                else
                {
                    try
                    {
                        Cmd_RunDTP curDTP = _client.CurrentDTP;
                        if (null != curDTP)
                        {
                            curDTP.Reset();
                        }
                    }
                    finally
                    {
                        _cc.Unlock();
                    }

                    //----------------------------------------
                    //Wait till DTP finishes
                    _client.BeginWaitForDTPFinished(stateObj.Timeout,
                                                    new WaitOrTimerCallback(DTPFinishedWait_End),
                                                    stateObj);
                }
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
コード例 #24
0
 void OnResponseReceived()
 {
     try
     {
         if (null != ResponseReceived)
         {
             ResponseReceived(this, new ResponseReceivedEventArgs(_response));
         }
     }
     catch (Exception e)
     {
         NSTrace.WriteLineError("OnResponseReceived event ex: " + e.ToString());
         throw;
     }
     catch
     {
         NSTrace.WriteLineError("OnResponseReceived event non cls ex.");
         throw;
     }
 }
コード例 #25
0
ファイル: Cmd_Reset.cs プロジェクト: kineva1992/repos
        void DTPFinishedWait_End(object state, bool timedout)
        {
            Reset_SO stateObj = (Reset_SO)state;

            try
            {
                stateObj.UpdateContext();
                if (timedout)
                {
                    string msg = string.Format("DTP is not finished withing {0} time: ", stateObj.Timeout);
                    NSTrace.WriteLineError(msg + Environment.StackTrace);
                    stateObj.Exception = GetTimeoutException(stateObj.Timeout);
                }
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
            }
            stateObj.SetCompleted();
        }
コード例 #26
0
 void OnCompleted()
 {
     try
     {
         if (null != Completed)
         {
             Completed(this, EventArgs.Empty);
         }
     }
     catch (Exception e)
     {
         NSTrace.WriteLineError("Completed event ex: " + e.ToString());
         throw;
     }
     catch
     {
         NSTrace.WriteLineError("Completed event non cls ex." + Environment.StackTrace.ToString());
         throw;
     }
 }
コード例 #27
0
        void RunDTP_End(IAsyncResult ar)
        {
            GetFile_SO stateObj = (GetFile_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                _currentDTP.EndExecute(ar);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
            }
            catch
            {
                NSTrace.WriteLineError("Non-CLS exception at: " + Environment.StackTrace);
                throw;
            }
            stateObj.SetCompleted();
        }
コード例 #28
0
ファイル: Cmd_RunDTP.cs プロジェクト: kineva1992/repos
        string GetTypeCommand(FtpDataType dataType)
        {
            string typeCmd = "TYPE ";

            if (FtpDataType.Ascii == dataType)
            {
                typeCmd += "A";
            }
            else if (FtpDataType.Binary == dataType)
            {
                typeCmd += "I";
            }
            else
            {
                string msg = string.Format("Data type is unsupported ({0}).", dataType.ToString());
                NSTrace.WriteLineError(msg);
                throw new NotSupportedException(msg);
            }
            return(typeCmd);
        }
コード例 #29
0
        DTPStreamType ValidateInputStream(DTPStream stream)
        {
            //------------------------------------------
            //Validate input
            if (null == stream)
            {
                throw new ArgumentNullException("steam", "The value cannot be null.");
            }

            DTPStreamType dtpType = stream.Type;

            if ((DTPStreamType.ForWriting != dtpType) &&
                (DTPStreamType.ForReading != dtpType))
            {
                string msg = string.Format("Unknown DTP type ({0})", stream.Type.ToString());
                NSTrace.WriteLineError(msg);
                throw new ArgumentException(msg, "type");
            }
            return(dtpType);
        }
コード例 #30
0
        void WriteDataStream_End(IAsyncResult ar)
        {
            TransStateObjectStream stateObj = (TransStateObjectStream)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                DataStream.EndWrite(ar);

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

                if (stateObj.UserStream.AvailableSpace > 0)
                {
                    //read and send more data
                    stateObj.UserStream.BeginRead(_workBuffer,
                                                  0,
                                                  _workBuffer.Length,
                                                  new AsyncCallback(this.UserStreamRead_End),
                                                  stateObj);
                }
                else
                {
                    FinishTransferingStream(DataStream);
                    OnCompleted();
                    stateObj.SetCompleted();
                }
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
            catch
            {
                NSTrace.WriteLineError("Non-CLS exception at: " + Environment.StackTrace);
                throw;
            }
        }