public static IDbConnection GetDbConnection(DbConnectionTypes dbType, string connectionString) { IDbConnection connection = null; switch (dbType) { case DbConnectionTypes.SQL: connection = new SqlConnection(connectionString); break; case DbConnectionTypes.XML: // TODO: Implement XML Connection (path name) break; case DbConnectionTypes.DOCUMENT: // TODO: Implement Document DB connection break; default: connection = null; break; } connection.Open(); return(connection); }
public ActionResult Refresh(DbConnectionTypes connectionType, string connectionString) { UpdateState(connectionType, connectionString); state.Databases = state.CurrentProvider?.RefreshDatabases(); return(View("Index", state)); }
private void UpdateState(DbConnectionTypes connectionType, string connectionString = null) { if (string.IsNullOrWhiteSpace(connectionString)) { connectionString = GetDefaultConnectionString(connectionType); } state.DbConnectionType = connectionType; state.ConnectionString = connectionString; state.CurrentProvider = GetProvider(connectionType, connectionString); state.Databases = null; state.SelectedDatabase = null; }
private string GetDefaultConnectionString(DbConnectionTypes connectionType) { switch (connectionType) { case DbConnectionTypes.MsSql: return("Data Source=localhost;Integrated Security=True;"); case DbConnectionTypes.Postgres: return("Server=localhost;Port=5432;User Id=postgres;Password=postgres;"); case DbConnectionTypes.Oracle: return("Data Source=127.0.0.1:1521/xe;User Id=oracle;Password=oracle;"); default: return(null); } }
private Provider GetProvider(DbConnectionTypes connectionType, string connectionString) { Provider provider; switch (connectionType) { case DbConnectionTypes.MsSql: provider = new MsSqlProvider(connectionString); break; case DbConnectionTypes.Postgres: provider = new PostgresProvider(connectionString); break; case DbConnectionTypes.Oracle: provider = new OracleProvider(connectionString); break; default: return(null); } return(provider); }
public XmlRepository(string filePath) { _dbType = DbConnectionTypes.XML; _connectionString = filePath; }
public ActionResult SelectConnectionType(DbConnectionTypes connectionType) { UpdateState(connectionType); return(View("Index", state)); }
public DocumentRepository(string connectionString) { _dbType = DbConnectionTypes.DOCUMENT; _connectionString = connectionString; }
/// <summary> /// Loads a config file into a XMLDocument and populates a DBConnectionTypes collection of the /// database connection details found in the config file. /// </summary> /// <param name="config">The name (and path) of a config file containing <connection> elements</param> /// <returns>A Collection of Connection Types</returns> private DbConnectionTypes LoadConfig ( string config ) { try { this.ReadXml(config); DbConnectionTypes connectionTypes = new DbConnectionTypes(); DataRow connectionsRow = this.Tables["connections"].Rows[0]; // Read the available connections from the connections collection // -------------------------------------------------------------- foreach (DataRow connectionRow in connectionsRow.GetChildRows("connections_connection")) { DbConnectionType connectionType = new DbConnectionType(); connectionType.Name = connectionRow["name"].ToString(); connectionType.DbTypeName = connectionRow["type"].ToString(); connectionType.InternalProviderName = connectionRow["internalProvider"].ToString(); // Read the Settings for this connection type // -------------------------------------------------------------- foreach (DataRow settingsRow in connectionRow.GetChildRows("connection_settings")) { if (settingsRow.Table.Columns.Contains("file")) { connectionType.SupportsFile = GetSettingState(settingsRow["file"].ToString(),false); connectionType.PromptFile = GetSettingValue(settingsRow["file"].ToString()); } if (settingsRow.Table.Columns.Contains("server")) { connectionType.SupportsServer = GetSettingState(settingsRow["server"].ToString(),true); connectionType.PromptServer = GetSettingValue(settingsRow["server"].ToString()); } if (settingsRow.Table.Columns.Contains("name")) { connectionType.SupportsName = GetSettingState(settingsRow["name"].ToString(),true); connectionType.PromptName = GetSettingValue(settingsRow["name"].ToString()); } if (settingsRow.Table.Columns.Contains("userid")) { connectionType.SupportsUserID = GetSettingState(settingsRow["userid"].ToString(),true); connectionType.PromptUserID = GetSettingValue(settingsRow["userid"].ToString()); } if (settingsRow.Table.Columns.Contains("password")) { connectionType.SupportsPassword = GetSettingState(settingsRow["password"].ToString(),true); connectionType.PromptPassword = GetSettingValue(settingsRow["password"].ToString()); } if (settingsRow.Table.Columns.Contains("filter")) { connectionType.SupportsFilter = GetSettingState(settingsRow["filter"].ToString(),false); connectionType.PromptFilter = GetSettingValue(settingsRow["filter"].ToString()); } } // Read each of the Providers Details // -------------------------------------------------------------- foreach (DataRow providersRow in connectionRow.GetChildRows("connection_providers")) { foreach (DataRow providerRow in providersRow.GetChildRows("providers_provider")) { DbConnectionProvider connectionProvider = new DbConnectionProvider(); connectionProvider.Name = providerRow["name"].ToString(); connectionProvider.ProviderTypeName = providerRow["type"].ToString(); connectionProvider.Parent = connectionType; connectionProvider.Template = Regex.Replace(providerRow["provider_Text"].ToString(), @"[\r\t\n]", ""); if (providerRow.Table.Columns.Contains("allowEmptyParameters")) connectionProvider.AllowEmptyParameters = GetSettingState(providerRow["allowEmptyParameters"].ToString(), true); if (providerRow.Table.Columns.Contains("enabled")) connectionProvider.Enabled = GetSettingState(providerRow["enabled"].ToString(),true); if (providerRow.Table.Columns.Contains("fileMask")) connectionProvider.FileMask = providerRow["fileMask"].ToString(); connectionType.Providers.Add(connectionProvider); } } connectionTypes.Add(connectionType); } return connectionTypes; } catch (Exception ex) { throw new ApplicationException(String.Format("Could not reference the ProviderConfig.xml configuration file: {0}\n{1}", config, ex.Message)); } }
public ProviderConfig( string config ) { _connectionTypes = LoadConfig ( config ); }
public SqlRepository(string connectionString) { _dbType = DbConnectionTypes.SQL; _connectionString = connectionString; }