Beispiel #1
0
        private void RemoveUnusedConnections(bool removeAllCalled = false)
        {
            try
            {
                if (removeAllCalled)
                {
                    lock (_databaseClients)
                    {
                        if (_databaseClients.Count > 0)
                        {
                            foreach (DatabaseClient databaseClient in _databaseClients)
                            {
                                if (databaseClient == null)
                                {
                                    continue;
                                }

                                lock (databaseClient)
                                {
                                    if (databaseClient.IsAvailable())
                                    {
                                        databaseClient.Disconnect();
                                    }

                                    databaseClient.Dispose();
                                }
                            }

                            _databaseClients.Clear();
                        }
                    }
                }
                else
                {
                    lock (_databaseClients)
                    {
                        if (_databaseClients.Count > 0)
                        {
                            foreach (DatabaseClient databaseClient in _databaseClients.Where(c => !c.IsAvailable()))
                            {
                                lock (databaseClient)
                                    databaseClient.Dispose();
                            }

                            _databaseClients.RemoveAll(c => !c.IsAvailable());
                        }
                    }
                }
            }
            catch
            {
                YupiLogManager.LogWarning("Failed Removing Database Unused Connection.", "Yupi.Data");
            }
        }