Пример #1
0
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (!_disposed)
                {
                    _disposed = true;

                    if (_currentUser != null)
                    {
                        if (_currentUser.IsAnonymous)
                        {
                            _performanceCounter.DecrementAnonymousUsers();
                        }
                        else
                        {
                            _performanceCounter.DecrementNonAnonymousUsers();
                        }
                    }

                    if (_connected)
                    {
                        _performanceCounter.DecrementCurrentConnections();
                    }

                    if (disposing)
                    {
                        if (_dataClient != null)
                        {
                            _dataClient.Close();
                            _dataClient = null;
                        }

                        if (_sslStream != null)
                        {
                            _sslStream.Dispose();
                            _sslStream = null;
                        }
                    }
                }
            }
            finally
            {
                FtpLogEntry logEntry = new FtpLogEntry()
                {
                    Date = DateTime.Now,
                    Info = LogInfo.ConnectionTerminated.ToString()
                };
                OnLog(logEntry);

                var serverConnInfos = ((FtpServer)CurrentServer).ConnectionInfos;
                if (serverConnInfos.Contains(ConnectionInfo))
                {
                    serverConnInfos.Remove(ConnectionInfo);
                }
                serverConnInfos.RemoveAll(t => t.ID == this.ID);

                base.Dispose(disposing);
            }
        }