private IDbConnection GetPostgresConnection() { PostgresSetup postgresSetup = m_state["postgresSetup"] as PostgresSetup; string connectionString = postgresSetup?.ConnectionString; string dataProviderString = PostgresSetup.DataProviderString; return(GetConnection(connectionString, dataProviderString)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IMapper mapper) { mapper.ConfigurationProvider.AssertConfigurationIsValid(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); PostgresSetup.SeedTestData(Configuration); } else { app.UseHsts(); } app.UseDefaultFiles(); var cachePeriod = env.IsDevelopment() ? "600" : "604800"; app.UseStaticFiles(new StaticFileOptions { OnPrepareResponse = ctx => { ctx.Context.Response.Headers.Append(new KeyValuePair <string, StringValues>("Cache-Control", $"public, max-age={cachePeriod}")); } }); app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "LMS API V1"); }); app.UseHttpsRedirection(); app.UseMvc(); }
private IDbConnection OpenNewConnection() { IDbConnection connection = null; try { string databaseType = m_state["newDatabaseType"].ToString(); string connectionString = string.Empty; string dataProviderString = string.Empty; if (databaseType == "SQLServer") { SqlServerSetup sqlServerSetup = m_state["sqlServerSetup"] as SqlServerSetup; connectionString = sqlServerSetup.ConnectionString; dataProviderString = sqlServerSetup.DataProviderString; if (string.IsNullOrWhiteSpace(dataProviderString)) { dataProviderString = "AssemblyName={System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}; ConnectionType=System.Data.SqlClient.SqlConnection; AdapterType=System.Data.SqlClient.SqlDataAdapter"; } } else if (databaseType == "MySQL") { MySqlSetup mySqlSetup = m_state["mySqlSetup"] as MySqlSetup; connectionString = mySqlSetup.ConnectionString; dataProviderString = mySqlSetup.DataProviderString; if (string.IsNullOrWhiteSpace(dataProviderString)) { dataProviderString = "AssemblyName={MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d}; ConnectionType=MySql.Data.MySqlClient.MySqlConnection; AdapterType=MySql.Data.MySqlClient.MySqlDataAdapter"; } } else if (databaseType == "Oracle") { OracleSetup oracleSetup = m_state["oracleSetup"] as OracleSetup; connectionString = oracleSetup.ConnectionString; dataProviderString = oracleSetup.DataProviderString; if (string.IsNullOrWhiteSpace(dataProviderString)) { dataProviderString = OracleSetup.DefaultDataProviderString; } } else if (databaseType == "PostgreSQL") { PostgresSetup postgresSetup = m_state["postgresSetup"] as PostgresSetup; connectionString = postgresSetup.ConnectionString; dataProviderString = PostgresSetup.DataProviderString; } else { string destination = m_state["sqliteDatabaseFilePath"].ToString(); connectionString = "Data Source=" + destination + "; Version=3"; dataProviderString = "AssemblyName={System.Data.SQLite, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139}; ConnectionType=System.Data.SQLite.SQLiteConnection; AdapterType=System.Data.SQLite.SQLiteDataAdapter"; } if (!string.IsNullOrEmpty(connectionString) && !string.IsNullOrEmpty(dataProviderString)) { Dictionary <string, string> dataProviderSettings = dataProviderString.ParseKeyValuePairs(); string assemblyName = dataProviderSettings["AssemblyName"]; string connectionTypeName = dataProviderSettings["ConnectionType"]; Assembly assembly = Assembly.Load(new AssemblyName(assemblyName)); Type connectionType = assembly.GetType(connectionTypeName); connection = (IDbConnection)Activator.CreateInstance(connectionType); connection.ConnectionString = connectionString; connection.Open(); } } catch (Exception ex) { MessageBox.Show("Failed to open new database connection: " + ex.Message, "Configuration Error", MessageBoxButton.OK, MessageBoxImage.Error); if (connection != null) { connection.Dispose(); } connection = null; } return(connection); }
/// <summary> /// Creates a new instance of the <see cref="PostgresDatabaseSetupScreen"/> class. /// </summary> public PostgresDatabaseSetupScreen() { m_postgresSetup = new PostgresSetup(); InitializeComponent(); this.Loaded += PostgresDatabaseSetupScreen_Loaded; }