コード例 #1
0
        public void CreateDBObjects(DbProviders providerList)
        {
            _provider = providerList;
            switch (providerList)
            {
            case DbProviders.SqlServer:
                _factory = SqlClientFactory.Instance;
                break;

            //case DbProviders.Oracle:
            //    _factory = OracleClientFactory.Instance;
            //    break;
            //case DbProviders.OleDb:
            //   _factory = OleDbFactory.Instance;
            //    break;
            //case DbProviders.ODBC:
            //    _factory = OdbcFactory.Instance;
            //    break;
            case DbProviders.MySql:
                _factory = MySqlClientFactory.Instance;
                break;

            case DbProviders.NpgSql:
                _factory = NpgsqlFactory.Instance;
                break;
            }
            _connection = _factory.CreateConnection();
            _connection.ConnectionString = _connectionstring; //connectString;
            _command            = _factory.CreateCommand();
            _command.Connection = connection;
        }
コード例 #2
0
ファイル: mysqldb_helper.cs プロジェクト: ahammed056/AM
        public void CreateDBObjects(string connectString, DbProviders providerList)
        {
            _provider = providerList;
            switch (providerList)
            {
            case DbProviders.SqlServer:
                _factory = SqlClientFactory.Instance;
                break;

            case DbProviders.OleDb:
                _factory = OleDbFactory.Instance;
                break;

            case DbProviders.ODBC:
                _factory = OdbcFactory.Instance;
                break;

            case DbProviders.MySql:
                _factory = MySqlClientFactory.Instance;
                break;
            }
            _connection = _factory.CreateConnection();
            _command    = _factory.CreateCommand();
            _connection.ConnectionString = connectString;
            _command.Connection          = connection;
        }
コード例 #3
0
        public static async Task InitializeAsync(IConfiguration config)
        {
            DbProviders dbProvider = (DbProviders)Enum.Parse(typeof(DbProviders), config.GetSection("Selectors:DbProvider").Value, true);

            switch (dbProvider)
            {
            case DbProviders.Dapper:
                DictionaryContextFactory factory   = new DictionaryContextFactory();
                DictionaryContext        dbContext = factory.CreateDbContext(config);
                await dbContext.InitializeAsync();

                break;

            case DbProviders.Mongo:
                await new MongoContext(config).InitializeAsync();
                break;

            case DbProviders.CosmosSqlApi:
                await new CosmosSqlApiContext(config).InitializeAsync();
                break;

            default:
                factory   = new DictionaryContextFactory();
                dbContext = factory.CreateDbContext(config);
                await dbContext.InitializeAsync();

                break;
            }
        }
コード例 #4
0
ファイル: DatabaseInfo.cs プロジェクト: HojjatK/roham
        public DatabaseInfo(
            DbProviders provider,
            string dataSource,
            string initialCatalog,
            string userName,
            string password,
            bool pooling)
        {
            switch (provider)
            {
            case DbProviders.SqlServer:
                Init(
                    provider,
                    dataSource,
                    initialCatalog,
                    userName,
                    password,
                    pooling, true, true, true);
                break;

            case DbProviders.SQLite:
                Init(
                    provider,
                    dataSource,
                    initialCatalog,
                    userName,
                    password,
                    pooling, false, false, false);
                break;

            default:
                throw new NotSupportedException($"{provider} is not supported.");
            }
        }
コード例 #5
0
ファイル: DatabaseInfo.cs プロジェクト: HojjatK/roham
        public DatabaseInfo(
            DbProviders provider,
            string connectionString)
        {
            switch (provider)
            {
            case DbProviders.SqlServer:
                var sqlConnStrBuilder = new SqlConnectionStringBuilder(connectionString);
                Init(
                    provider,
                    sqlConnStrBuilder.DataSource,
                    sqlConnStrBuilder.InitialCatalog,
                    sqlConnStrBuilder.IntegratedSecurity ? null : sqlConnStrBuilder.UserID,
                    sqlConnStrBuilder.IntegratedSecurity ? null : sqlConnStrBuilder.Password,
                    sqlConnStrBuilder.Pooling, true, true, true);
                break;

            case DbProviders.SQLite:
                var sqliteConnStrBuilder = new SQLiteConnectionStringBuilder(connectionString);
                Init(
                    provider,
                    sqliteConnStrBuilder.DataSource,
                    null,
                    null,
                    sqliteConnStrBuilder.Password,
                    sqliteConnStrBuilder.Pooling, false, false, false);
                break;

            default:
                throw new NotSupportedException($"{provider} is not supported.");
            }
        }
コード例 #6
0
ファイル: Database - EF.cs プロジェクト: Oman/Maleos
        /// <summary>
        /// Initializes a new instance of the <see cref="Database"/> class.
        /// </summary>
        /// <param name="dbProvider">The db provider.</param>
        public Database(DbProviders.DbProvider dbProvider)
        {
            Check.Require(dbProvider != null, "dbProvider could not be null.");

            this.dbProvider = dbProvider;
            this.queryFactory = dbProvider.GetQueryFactory();
        }
コード例 #7
0
 /// <summary>
 /// Update the provider by keyname in dictionoary and config file
 /// </summary>
 /// <param name="keyname">connectionname</param>
 public void UpdateDBProvider(string keyname)
 {
     if (DbProviders.ContainsKey(keyname))
     {
         DbProviders[keyname] = CurrentProvider;
     }
     DbProviderConnection.Update(DbProviders[keyname]);
 }
コード例 #8
0
ファイル: InstallController.cs プロジェクト: HojjatK/roham
        private DatabaseInfo ExtractDatabaseInfo(InstallViewModel model, bool fromConnectionString)
        {
            DbProviders selectedDbProvider = DbProviders.None;

            Enum.TryParse(model.SelectedDatabaseProvider, out selectedDbProvider);
            var providerFactory = _dbProviderFactory.Create(selectedDbProvider);

            DatabaseInfo dbInfo = null;

            switch (selectedDbProvider)
            {
            case DbProviders.SqlServer:
                if (fromConnectionString)
                {
                    dbInfo = new DatabaseInfo(DbProviders.SqlServer, model.SqlServer.ConnectionString);
                    model.SqlServer.DatabaseServer = dbInfo.DataSource;
                    model.SqlServer.DatabaseName   = dbInfo.InitialCatalog;
                    if (!string.IsNullOrWhiteSpace(dbInfo.UserName) && !string.IsNullOrWhiteSpace(dbInfo.Password))
                    {
                        model.SqlServer.IntegratedSecurity = true;
                        model.SqlServer.Username           = dbInfo.UserName;
                        model.SqlServer.Password           = dbInfo.Password;
                    }
                }
                else
                {
                    dbInfo = new DatabaseInfo(DbProviders.SqlServer,
                                              model.SqlServer.DatabaseServer,
                                              model.SqlServer.DatabaseName,
                                              model.SqlServer.IntegratedSecurity ? null : model.SqlServer.Username,
                                              model.SqlServer.IntegratedSecurity ? null : model.SqlServer.Password,
                                              false);
                }
                break;

            case DbProviders.SQLite:
                if (model.Advanced)
                {
                    dbInfo = new DatabaseInfo(DbProviders.SQLite, model.Sqlite.ConnectionString);
                    model.Sqlite.DataSource = dbInfo.DataSource;
                    model.Sqlite.Password   = dbInfo.Password;
                }
                else
                {
                    dbInfo = new DatabaseInfo(DbProviders.SQLite, model.Sqlite.DataSource, model.Sqlite.DataSource, null, model.Sqlite.Password, true);
                }
                break;

            default:
                throw new DatabaseException($"{model.SelectedDatabaseProvider} database provider not supported",
                                            ErrorMessages.DataProviderNotSupported.Fmt(model.SelectedDatabaseProvider));
            }
            return(dbInfo);
        }
コード例 #9
0
ファイル: DbLayer.cs プロジェクト: cloughin/VoteProject.5
        private static void Initialize(DbProviders provider)
        {
            switch (provider)
            {
            case DbProviders.MsSql:
                _Current = new MsSqlDb();
                break;

            case DbProviders.MySql:
                _Current = new MySqlDb();
                break;
            }
        }
コード例 #10
0
        public IDatabaseProvider Create(DbProviders provider)
        {
            switch (provider)
            {
            case DbProviders.SqlServer:
                return(new SqlServerDatabaseProvider());

            case DbProviders.SQLite:
                return(new SQLiteDatabaseProvider());

            default:
                throw new NotSupportedException($"{provider} is not supported.");
            }
        }
コード例 #11
0
        private void OnRefresh()
        {
            DbProviders = DbProviderFactories.GetFactoryClasses().Rows.OfType <DataRow>()
                          .Select(x => new DbProvider
            {
                Name          = x["Name"]?.ToString(),
                Description   = x["Description"]?.ToString(),
                InvariantName = x["InvariantName"]?.ToString(),
            })
                          .OrderBy(x => x.Name)
                          .ToList();

            DbProvider = DbProviders.FirstOrDefault(x => x.Equals(_selectedProvider));
        }
コード例 #12
0
        public static DbProviderFactory GetProviderForConnection(String connectionName)
        {
            connectionName = connectionName ?? DefaultConnectionName;

            if (String.IsNullOrEmpty(connectionName))
            {
                return(DefaultProviderFactory);
            }

            DbProviderFactory provider = null;

            DbProviders.TryGetValue(connectionName, out provider);

            return(provider ?? DefaultProviderFactory);
        }
コード例 #13
0
 /// <summary>
 /// CreateDBObjects
 /// </summary>
 /// <param name="connectString"></param>
 /// <param name="providerList"></param>
 public void CreateDBObjects(string connectString, DbProviders providerList)
 {
     _provider = providerList;
     switch (providerList)
     {
     case DbProviders.SqlServer:
         _factory = SqlClientFactory.Instance;
         break;
         //for other databases
     }
     _connection = _factory.CreateConnection();
     _command    = _factory.CreateCommand();
     _connection.ConnectionString = connectString;
     _command.Connection          = connection;
 }
コード例 #14
0
        /// <summary>
        /// Reads Connection Strings from Web.config or App.config.
        /// </summary>
        public static void ReadFromConfiguration()
        {
            if (ConfigurationManager.ConnectionStrings != null && ConfigurationManager.ConnectionStrings.Count > 0)
            {
                for (int index = 0; index < ConfigurationManager.ConnectionStrings.Count; index++)
                {
                    var connString = ConfigurationManager.ConnectionStrings[index];

                    ConnectionStrings.AddOrUpdate(connString.Name, connString.ConnectionString, (oldString, newString) => newString);

                    DbProviderFactory provider = GetProviderFactory(connString.ProviderName);

                    DbProviders.AddOrUpdate(connString.Name, provider, (name, oldProvider) => provider);
                }
            }
        }
コード例 #15
0
        public void Remove()
        {
            if (CurrentProvider == null)
            {
                return;
            }
            if (DbProviders.ContainsValue(CurrentProvider))
            {
                //if provider is a subscriber remove from subscriber first
                //if (DbSubsribers.ContainsKey(CurrentProvider.Name))
                //    DbSubsribers.Remove(CurrentProvider.Name);

                DbProviders.Remove(CurrentProvider.Name);
                DbProviderConnection.RemoveByKeyName(CurrentProvider);
            }
        }
コード例 #16
0
 public void Add()
 {
     if (CurrentProvider == null || !CurrentProvider.IsValidWithDatabase())
     {
         return;
     }
     if (DbProviders.ContainsKey(CurrentProvider.Name))
     {
         DbProviders[CurrentProvider.Name] = CurrentProvider;
         DbProviderConnection.Update(CurrentProvider);
         return;
     }
     if (!DbProviders.ContainsKey(CurrentProvider.Name))
     {
         DbProviders.Add(CurrentProvider.Name, CurrentProvider);
         DbProviderConnection.Add(CurrentProvider);
     }
 }
コード例 #17
0
ファイル: DatabaseInfo.cs プロジェクト: HojjatK/roham
 private void Init(
     DbProviders provider,
     string dataSource,
     string initialCatalog,
     string userName,
     string password,
     bool pooling,
     bool supportSchema,
     bool supportFullText,
     bool supportFuture)
 {
     DbProvider      = provider;
     DataSource      = ReplaceDataDirectory(dataSource);
     InitialCatalog  = initialCatalog;
     UserName        = userName;
     Password        = password;
     Pooling         = pooling;
     SupportSchema   = supportSchema;
     SupportFullText = supportFullText;
     SupportFuture   = supportFuture;
 }
コード例 #18
0
        public static void ConfigureDbProvider(this IServiceCollection services, IConfiguration config)
        {
            DbProviders dbProvider = (DbProviders)Enum.Parse(typeof(DbProviders), config.GetSection("Selectors:DbProvider").Value, true);

            switch (dbProvider)
            {
            case DbProviders.Dapper:
                services.ConfigureDapper();
                break;

            case DbProviders.Mongo:
                services.ConfigureMongo();
                break;

            case DbProviders.CosmosSqlApi:
                services.ConfigureAzureCosmosDB();
                break;

            default:
                services.ConfigureEF(config);
                break;
            }
        }
コード例 #19
0
 public void ClearDicProvider()
 {
     DbProviders.Clear();
 }
コード例 #20
0
 /// <summary>
 /// Set the current provider by keyname from dictionary
 /// </summary>
 /// <param name="keyName"></param>
 public void SetCurrentProviderByKeyname(string keyName)
 {
     CurrentProvider = DbProviders.Single(q => q.Key == keyName).Value;
 }
コード例 #21
0
 public bool IsConnectionName(string connectionName)
 {
     return(DbProviders.ContainsKey(connectionName));
 }
コード例 #22
0
ファイル: DbOptions.cs プロジェクト: HojjatK/roham
        public static DbOptions Parse(string[] args)
        {
            bool        showHelp = false, showSql = false, isForce = false, isDebugMode = false;
            DbProviders providerName = DbProviders.SqlServer;
            string      dataSource = "", initialCatalog = "", username = "", password = "";
            string      exportfilename = "", upgradepath = "";
            var         command = DbOptionCommands.None;

            showHelp = false;
            var optionSet = new OptionSet
            {
                { "d", "Drop existing database", _ => command |= DbOptionCommands.Drop },
                { "c", "Create database schema", _ => command |= DbOptionCommands.Create },
                { "e", "Export database schema", _ => command |= DbOptionCommands.ExportSchema },
                { "u", "Upgrade database", _ => command |= DbOptionCommands.Upgrade },
                { "upd=", "Upgrade database with SQL update files, {directory} containing SQL update files", dir => upgradepath = dir },
                { "exf=", "Export database schema {file path}", exf => exportfilename = exf },
                { "p=", "The database {provider} [sqlserver | sqlite. If not specified the default is sqlserver.", p => { if (p == null)
                                                                                                                          {
                                                                                                                              providerName = DbProviders.SqlServer;
                                                                                                                          }
                                                                                                                          else
                                                                                                                          {
                                                                                                                              Enum.TryParse <DbProviders>(p, out providerName);
                                                                                                                          } } },
                { "source=", "The database {source} or server host", s => dataSource = s },
                { "catalog=", "The database {catalog} name", d => initialCatalog = d },
                { "user="******"Database {user} identity", u => username = u },
                { "password="******"Database user {password}", p => password = p },

                { "f", "Forces command to run without getting confirmation from user", _ => isForce = true },
                { "debug", "Execute DbTool in debug mode", _ => isDebugMode = true },
                { "showsql", "Show executed sql commands during dbtool execution", _ => showSql = true },
                { "?|h|help", "Show this message and exit", v => showHelp = v != null },
            };

            optionSet.Parse(args);
            if (args.Length == 0)
            {
                showHelp = true;
            }

            DbOptions o = new DbOptions(
                new DatabaseInfo(providerName, dataSource, initialCatalog, username, password, false),
                command,
                exportfilename,
                upgradepath)
            {
                ShowHelp    = showHelp,
                ShowSql     = showSql,
                IsForce     = isForce,
                IsDebugMode = isDebugMode
            };

            if (showHelp)
            {
                ConsoleLog.WriteSuccess("Roham DbTool Console Application Usage\r\n");
                ConsoleLog.Write(ConsoleColor.White, "DbTool.exe [options]");
                ConsoleLog.WriteInfo("");
                optionSet.WriteOptionDescriptions(Console.Out);
                ConsoleLog.Write(ConsoleColor.White, "\r\nExamples:");
                ConsoleLog.WriteInfo(@"
DbTool -c --source=localhost --catalog=roham-dev --user=sa --password=test
Creates a new sqlserver database named roham-dev in localhost server 

DbTool -c --source=localhost --catalog=roham-dev -e --exf=c:\database\schema.sql
Creates a new sqlserver database named roham-dev and export database 
schema script into c:\database\schema.sql 

DbTool -u --upd=c:\upgrade\scripts --source=localhost --catalog=roham
Runs upgrade scripts located at c:\upgrade\scripts in roham sqlserver 
database at localhost (via IntegratedSecurity)

DbTool -d -c -u --upd:c:\upgrade\scripts --source=localhost --catalog=roham --user=sa --password=test
Drops roham sqlserver database from localhost server and creates a new one 
with same name and then upgrade database with scripts located at c:\upgrade\scripts

DbTool -p=sqlite -c -u --upd=c:\upgrade\scripts --source=c:\database\roham.sqlite --debug --showsql
Creates a new sqlite database at c:\database\roham.sqlite and then runs upgrade scripts 
located at c:\upgrade\scripts in debug mode and show executed sql commands
");
                return(o);
            }

            Validate(o);

            return(o);
        }
コード例 #23
0
ファイル: ConfigModule.cs プロジェクト: HojjatK/roham
 public ConfigModule(DbProviders providerName, bool showSql)
 {
     this.ProviderName = providerName;
     this.ShowSql      = showSql;
 }
コード例 #24
0
 private void OnRefresh()
 {
     DbProviders = Database.DbProvider.GetRegisteredProviders().Select(x => x.Value.Info).ToList();
     DbProvider  = DbProviders.FirstOrDefault(x => x.Equals(_selectedProvider));
 }
コード例 #25
0
 void IDbToolConfigsUpdater.SetDatabase(DbProviders dbProvider, string connectionString)
 {
     DatabaseProvider = dbProvider;
     ConnectionString = connectionString;
 }