Пример #1
0
        public void Dispose()
        {
            if (_primaryChannel != null)
            {
                _primaryChannel.Disconnect();
            }

            lock (_secondaryChannels)
            {
                foreach (IRequestResponseChannel channel in _secondaryChannels.Values.ToList())
                {
                    if (channel != null)
                    {
                        channel.Disconnect();
                    }
                }
            }
        }
Пример #2
0
        public void ChannelDisconnected(IRequestResponseChannel channel, string reason)
        {
            if (channel == null)
            {
                return;
            }
            try
            {
                foreach (ReaderInfo readerInfo in _readersList)
                {
                    var operation = new DisposeReaderOperation
                    {
                        Database      = readerInfo.DatabaseName,
                        Collection    = readerInfo.CollectionName,
                        ReaderUID     = readerInfo.ReaderId,
                        OperationType = DatabaseOperationType.DisposeReader,
                        SessionId     = CsSessionId
                    };
                    try
                    {
                        _dbEngine.DiposeReader(operation);
                    }
                    catch (SecurityException exc)
                    {
                        if (LoggerManager.Instance.SecurityLogger != null &&
                            LoggerManager.Instance.SecurityLogger.IsErrorEnabled)
                        {
                            LoggerManager.Instance.SecurityLogger.Error("ClientSession.ChannelDisconected() ", exc);
                        }
                    }
                }
                _readersList.Clear();

                _conmmandInfos.Clear();

                _clientDisconnection.DisconnectClient(MiscUtil.GetAddressInfo(channel.PeerAddress.IpAddress,
                                                                              channel.PeerAddress.Port));
                _databaseEngineFactory.Dispose(_noSConnectionString);
                try
                {
                    channel.Disconnect();
                }
                catch (ThreadAbortException e)
                {
                    //Todo: maybe log in future or something.
                }

                // Log Client Disconnected.
                if (LoggerManager.Instance.ServerLogger.IsInfoEnabled)
                {
                    LoggerManager.Instance.ServerLogger.Info("ClientSession.ChannelDisconnected",
                                                             "Client [" + MiscUtil.GetAddressInfo(channel.PeerAddress.IpAddress,
                                                                                                  channel.PeerAddress.Port) + "] with sessionId'" + CsSessionId.SessionId + "' disconnected.");
                }

                LoggerManager.Instance.SetThreadContext(new LoggerContext()
                {
                    ShardName = "", DatabaseName = ""
                });
            }
            catch (Exception e)
            {
                try
                {
                    //Remove client session from session manager.
                    _clientDisconnection.DisconnectClient(MiscUtil.GetAddressInfo(channel.PeerAddress.IpAddress, channel.PeerAddress.Port));
                }
                catch (Exception ex) { }

                if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsErrorEnabled)
                {
                    LoggerManager.Instance.ShardLogger.Error("ClientSessionDisconnect",
                                                             e.Message + " StackTrace: " + e.StackTrace);
                }
            }
        }