示例#1
0
        public IDatabaseClient ConnectToDatabase(IConfiguration config)
        {
            var dbConfig     = Configuration.Merge(config);
            var databaseName = config.DatabaseName();

            if (String.IsNullOrEmpty(databaseName))
            {
                throw new ArgumentException("The given configuration does not provide any database name.");
            }

            IDatabaseClient client;

            if (!localClients.TryGetValue(databaseName, out client))
            {
                var dbHandler = SystemContext as IDatabaseHandler;
                if (dbHandler == null)
                {
                    throw new InvalidOperationException("The system context does not handle databases");
                }

                var database = dbHandler.GetDatabase(databaseName);
                if (database == null)
                {
                    throw new InvalidOperationException(String.Format("The database '{0}' could not be found in the current context.", databaseName));
                }

                client = new LocalDatabaseClient(this, database);
                localClients[databaseName] = client;
            }

            return(client);
        }
            protected override void Dispose(bool disposing)
            {
                if (disposing)
                {
                    Client.openConnections--;
                    if (Client.openConnections <= 0)
                    {
                        Client.Dispose();
                    }
                }

                Client = null;

                base.Dispose(disposing);
            }
示例#3
0
        public IDatabaseClient ConnectToDatabase(IConfiguration config)
        {
            var dbConfig = Configuration.Merge(config);
            var databaseName = config.DatabaseName();
            if (String.IsNullOrEmpty(databaseName))
                throw new ArgumentException("The given configuration does not provide any database name.");

            IDatabaseClient client;
            if (!localClients.TryGetValue(databaseName, out client)) {
                var dbHandler = SystemContext as IDatabaseHandler;
                if (dbHandler == null)
                    throw new InvalidOperationException("The system context does not handle databases");

                var database = dbHandler.GetDatabase(databaseName);
                if (database == null)
                    throw new InvalidOperationException(String.Format("The database '{0}' could not be found in the current context.", databaseName));

                client = new LocalDatabaseClient(this, database);
                localClients[databaseName] = client;
            }

            return client;
        }
 public ServerConnector(LocalDatabaseClient client, IDatabaseHandler handler)
     : base(handler)
 {
     Client = client;
     client.openConnections++;
 }
            protected override void Dispose(bool disposing)
            {
                if (disposing) {
                    Client.openConnections--;
                    if (Client.openConnections <= 0) {
                        Client.Dispose();
                    }
                }

                Client = null;

                base.Dispose(disposing);
            }
 public ServerConnector(LocalDatabaseClient client, IDatabaseHandler handler)
     : base(handler)
 {
     Client = client;
     client.openConnections++;
 }