public static void AddDbManager(this ServiceCollection services, DbEngine engine)
        {
            IServiceProvider serviceProvider = services.BuildServiceProvider();
            ILoggerFactory   loggerFactory   = serviceProvider.GetService <ILoggerFactory>();

            services.AddScoped <IDbManager>(_ => DbManagerFactory.Create(engine, loggerFactory));
        }
Example #2
0
        public SimpleDbExtractor(ILoggerFactory loggerFactory, DbEngine dbEngine, string host, string database,
                                 bool trustedConnection = true, string username = null, string password = null)
        {
            _logger    = loggerFactory.CreateLogger <SimpleDbExtractor>();
            _dbEngine  = dbEngine;
            _dbManager = DbManagerFactory.Create(dbEngine, loggerFactory);
            IDictionary <string, string> parameters = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(host))
            {
                parameters[DbParametersKeys.HostKey] = host;
            }
            if (!string.IsNullOrEmpty(database))
            {
                parameters[DbParametersKeys.DatabaseKey] = database;
            }
            parameters[DbParametersKeys.UseTrustedConnectionKey] = trustedConnection.ToString();

            if (username == null && password == null)
            {
                parameters[DbParametersKeys.UseIntegratedSecurityKey] = true.ToString();
            }
            else
            {
                parameters[DbParametersKeys.LoginKey]    = username;
                parameters[DbParametersKeys.PasswordKey] = password;
                parameters[DbParametersKeys.UseIntegratedSecurityKey] = false.ToString();
            }

            _connectionString = ConnectionStringBuilder.Build(dbEngine, parameters);
        }
        public void TestCreate(DbEngine dbEngine, bool integratedSecurity, string userName, string password, bool useScripts)
        {
            IDbManager             dbManager   = DbManagerFactory.Create(dbEngine, _loggerFactory);
            Tuple <string, string> hostAndName = _hostAndDatabaseOptions[dbEngine];
            string connectionString            = dbManager.Create(dbEngine, hostAndName.Item1, hostAndName.Item2,
                                                                  integratedSecurity, userName, password, useScripts ? _scripts: new List <string>());

            Assert.NotNull(connectionString);
            bool result = dbManager.DropDatabase(connectionString);

            Assert.True(result);
        }
Example #4
0
        public SimpleDbExtractor(ILoggerFactory loggerFactory, DbEngine dbEngine, string connectionString)
        {
            _logger = loggerFactory.CreateLogger <SimpleDbExtractor>();
            if (string.IsNullOrEmpty(connectionString))
            {
                _logger.LogError("Connection string is Null.");
                throw new ArgumentNullException(connectionString);
            }

            _connectionString = connectionString;
            _dbEngine         = dbEngine;
            _dbManager        = DbManagerFactory.Create(dbEngine, loggerFactory);
        }
        public void TestInit(DbEngine dbEngine, bool integratedSecurity, string userName, string password)
        {
            IDbManager                   dbManager   = DbManagerFactory.Create(dbEngine, _loggerFactory);
            Tuple <string, string>       hostAndName = _hostAndDatabaseOptions[dbEngine];
            IDictionary <string, string> options     = new Dictionary <string, string>()
            {
                { DbParametersKeys.HostKey, hostAndName.Item1 },
                { DbParametersKeys.DatabaseKey, hostAndName.Item2 },
                { DbParametersKeys.UseIntegratedSecurityKey, integratedSecurity.ToString() },
                { DbParametersKeys.LoginKey, userName },
                { DbParametersKeys.PasswordKey, password }
            };

            string connectionString = ConnectionStringBuilder.Build(dbEngine, options);
            bool   result           = dbManager.CreateDatabase(connectionString, true);

            Assert.True(result);
            result = dbManager.Init(connectionString, _scripts);
            Assert.True(result);
            result = dbManager.DropDatabase(connectionString);
            Assert.True(result);
        }
 private IDbManager CreateTestDbManager(DbEngine dbEngine)
 {
     return(DbManagerFactory.Create(dbEngine, _loggerFactory));
 }