Inheritance: ServerClientConnector
Example #1
0
        public static IDbConnection CreateDbConnection(this IDatabase database, IConfiguration configuration)
        {
            if (database == null)
                throw new ArgumentNullException("database");
            if (configuration == null)
                throw new ArgumentNullException("configuration");

            var dbName = configuration.GetString("database.name");
            if (!String.IsNullOrEmpty(dbName) &&
                !String.Equals(dbName, database.Name))
                throw new ArgumentException(String.Format("The specified database name '{0}' differs from the original database name '{1}'.",
                    dbName, database.Name));

            var dbHandler = database.System as IDatabaseHandler;
            if (dbHandler == null)
                dbHandler = new SingleDatabaseHandler(database);

            var serverConnector = new EmbeddedServerConnector(dbHandler);
            var clientConnector = new EmbeddedClientConnector(serverConnector);

            var settings = BuildConnectionString(configuration);
            if (String.IsNullOrEmpty(settings.Database))
                settings.Database = database.Name;

            return new DeveelDbConnection(clientConnector, settings);
        }
Example #2
0
        public static IDbConnection CreateDbConnection(this IDatabase database, string userName, string password)
        {
            if (database == null)
                throw new ArgumentNullException("database");

            var dbHandler = database.DatabaseContext.SystemContext as IDatabaseHandler;
            if (dbHandler == null)
                dbHandler = new SingleDatabaseHandler(database);

            var serverConnector = new EmbeddedServerConnector(dbHandler);
            var clientConnector = new EmbeddedClientConnector(serverConnector);

            var settings = new DeveelDbConnectionStringBuilder {
                UserName = userName,
                Password = password,
                Database = database.Name()
            };

            return new DeveelDbConnection(clientConnector, settings);
        }