private void _buttonOpenDatabase_Click(object sender, RoutedEventArgs e) { OpenControls.Wpf.Serialisation.RegistryItemSerialiser registryItemSerialiser = new OpenControls.Wpf.Serialisation.RegistryItemSerialiser(_keyPath); OpenControls.Wpf.DatabaseDialogs.Model.DatabaseConfiguration databaseConfiguration = new OpenControls.Wpf.DatabaseDialogs.Model.DatabaseConfiguration(registryItemSerialiser); if (registryItemSerialiser.OpenKey()) { databaseConfiguration.Load(); } OpenControls.Wpf.DatabaseDialogs.ViewModel.OpenDatabaseViewModel openDatabaseViewModel = new OpenControls.Wpf.DatabaseDialogs.ViewModel.OpenDatabaseViewModel(databaseConfiguration); OpenControls.Wpf.DatabaseDialogs.View.OpenDatabaseView openDatabaseView = new OpenControls.Wpf.DatabaseDialogs.View.OpenDatabaseView(new OpenControls.Wpf.DatabaseDialogs.Model.Encryption()); openDatabaseView.DataContext = openDatabaseViewModel; if (openDatabaseView.ShowDialog() != true) { return; } if (!registryItemSerialiser.IsOpen) { registryItemSerialiser.CreateKey(); } databaseConfiguration.Save(); registryItemSerialiser.Close(); try { if (openDatabaseViewModel.SelectedDatabaseProvider == OpenControls.Wpf.DatabaseDialogs.Model.DatabaseProvider.SQLite) { SQLiteDatabase.OpenDatabase(this, openDatabaseViewModel.SQLite_Filename); IDatabaseHost.IConfigurationStore = new DBStore.SQLiteConfigurationStore(IDatabaseHost.Database); IDatabaseHost.ISpeciesStore = new DBStore.SQLiteSpeciesStore(IDatabaseHost.Database); IDatabaseHost.IImagePathsStore = new DBStore.SQLiteImagePathsStore(IDatabaseHost.Database); IDatabaseHost.IImageStore = new DBStore.SQLiteImageStore(IDatabaseHost.Database); } else if (openDatabaseViewModel.SelectedDatabaseProvider == OpenControls.Wpf.DatabaseDialogs.Model.DatabaseProvider.MicrosoftSQLServer) { string server = (openDatabaseViewModel.SqlServerInstances.Count > 0) ? openDatabaseViewModel.SqlServerInstances[openDatabaseViewModel.SelectedSqlServerInstance] : null; SQLServerDatabase.OpenDatabase( this, openDatabaseViewModel.SQLServer_UseLocalServer, server, openDatabaseViewModel.SQLServer_IPAddress, openDatabaseViewModel.SQLServer_Port, openDatabaseViewModel.SQLServer_UseWindowsAuthentication, openDatabaseViewModel.SQLServer_UserName, openDatabaseViewModel.SQLServer_Password, openDatabaseViewModel.SQLServer_DatabaseName); IDatabaseHost.IConfigurationStore = new DBStore.SQLServerConfigurationStore(IDatabaseHost.Database); IDatabaseHost.ISpeciesStore = new DBStore.SQLServerSpeciesStore(IDatabaseHost.Database); IDatabaseHost.IImagePathsStore = new DBStore.SQLServerImagePathsStore(IDatabaseHost.Database); IDatabaseHost.IImageStore = new DBStore.SQLServerImageStore(IDatabaseHost.Database); } else if (openDatabaseViewModel.SelectedDatabaseProvider == OpenControls.Wpf.DatabaseDialogs.Model.DatabaseProvider.PostGreSQL) { PostgreSQLDatabase.OpenDatabase(this, openDatabaseViewModel.PostgreSQL_IPAddress, openDatabaseViewModel.PostgreSQL_Port, openDatabaseViewModel.PostgreSQL_UseWindowsAuthentication, openDatabaseViewModel.PostgreSQL_UserName, openDatabaseViewModel.PostgreSQL_Password, openDatabaseViewModel.PostgreSQL_DatabaseName); IDatabaseHost.IConfigurationStore = new DBStore.PostgreSQLConfigurationStore(IDatabaseHost.Database); IDatabaseHost.ISpeciesStore = new DBStore.PostgreSQLSpeciesStore(IDatabaseHost.Database); IDatabaseHost.IImagePathsStore = new DBStore.PostgreSQLImagePathsStore(IDatabaseHost.Database); IDatabaseHost.IImageStore = new DBStore.PostgreSQLImageStore(IDatabaseHost.Database); } else if (openDatabaseViewModel.SelectedDatabaseProvider == OpenControls.Wpf.DatabaseDialogs.Model.DatabaseProvider.MySQL) { MySQLDatabase.OpenDatabase(this, openDatabaseViewModel.MySQL_IPAddress, openDatabaseViewModel.MySQL_Port, openDatabaseViewModel.MySQL_UseWindowsAuthentication, openDatabaseViewModel.MySQL_UserName, openDatabaseViewModel.MySQL_Password, openDatabaseViewModel.MySQL_DatabaseName); IDatabaseHost.IConfigurationStore = new DBStore.MySQLConfigurationStore(IDatabaseHost.Database); IDatabaseHost.ISpeciesStore = new DBStore.MySQLSpeciesStore(IDatabaseHost.Database); IDatabaseHost.IImagePathsStore = new DBStore.MySQLImagePathsStore(IDatabaseHost.Database); IDatabaseHost.IImageStore = new DBStore.MySQLImageStore(IDatabaseHost.Database); } else { throw new Exception("Unsupported database type"); } } catch (Exception exception) { System.Windows.Forms.MessageBox.Show(exception.Message); return; } ShowSpeciesListView(IDatabaseHost.Database); }
private bool OpenDatabase(out MycoKeyCreator.Library.Database.IDatabase iDatabase, out MycoKeyCreator.Library.Database.KeyManager keyManager) { iDatabase = null; keyManager = null; OpenControls.Wpf.Serialisation.RegistryItemSerialiser registryItemSerialiser = new OpenControls.Wpf.Serialisation.RegistryItemSerialiser(_keyPath); OpenControls.Wpf.DatabaseDialogs.Model.DatabaseConfiguration databaseConfiguration = new OpenControls.Wpf.DatabaseDialogs.Model.DatabaseConfiguration(registryItemSerialiser); if (registryItemSerialiser.OpenKey()) { databaseConfiguration.Load(); } OpenControls.Wpf.DatabaseDialogs.ViewModel.OpenDatabaseViewModel openDatabaseViewModel = new OpenControls.Wpf.DatabaseDialogs.ViewModel.OpenDatabaseViewModel(databaseConfiguration); OpenControls.Wpf.DatabaseDialogs.View.OpenDatabaseView openDatabaseView = new OpenControls.Wpf.DatabaseDialogs.View.OpenDatabaseView(new OpenControls.Wpf.DatabaseDialogs.Model.Encryption()); openDatabaseView.WindowStartupLocation = WindowStartupLocation.CenterOwner; openDatabaseView.Owner = this; openDatabaseView.DataContext = openDatabaseViewModel; if (openDatabaseView.ShowDialog() != true) { return(false); } if (!registryItemSerialiser.IsOpen) { registryItemSerialiser.CreateKey(); } databaseConfiguration.Save(); registryItemSerialiser.Close(); try { OpenControls.Wpf.DatabaseDialogs.Model.Encryption encryption = new OpenControls.Wpf.DatabaseDialogs.Model.Encryption(); if (openDatabaseViewModel.SelectedDatabaseProvider == OpenControls.Wpf.DatabaseDialogs.Model.DatabaseProvider.MicrosoftSQLServer) { MycoKeyCreator.Library.PetaPocoAdapter.SQLServerDatabaseFactory.OpenDatabase( out iDatabase, openDatabaseViewModel.SQLServer_UseLocalServer, openDatabaseViewModel.SelectedSqlServerInstance, openDatabaseViewModel.SQLServer_IPAddress, openDatabaseViewModel.SQLServer_Port, openDatabaseViewModel.SQLServer_UseWindowsAuthentication, openDatabaseViewModel.SQLServer_UserName, encryption.Decrypt(openDatabaseViewModel.SQLServer_Password), openDatabaseViewModel.SQLServer_DatabaseName); } else if (openDatabaseViewModel.SelectedDatabaseProvider == OpenControls.Wpf.DatabaseDialogs.Model.DatabaseProvider.MySQL) { MycoKeyCreator.Library.PetaPocoAdapter.MySQLDatabaseFactory.OpenDatabase( out iDatabase, openDatabaseViewModel.MySQL_IPAddress, openDatabaseViewModel.MySQL_Port, openDatabaseViewModel.MySQL_UseWindowsAuthentication, openDatabaseViewModel.MySQL_UserName, encryption.Decrypt(openDatabaseViewModel.MySQL_Password), openDatabaseViewModel.MySQL_DatabaseName); } else if (openDatabaseViewModel.SelectedDatabaseProvider == OpenControls.Wpf.DatabaseDialogs.Model.DatabaseProvider.PostGreSQL) { MycoKeyCreator.Library.PetaPocoAdapter.PostgreSQLServerDatabaseFactory.OpenDatabase( out iDatabase, openDatabaseViewModel.PostgreSQL_IPAddress, openDatabaseViewModel.PostgreSQL_Port, openDatabaseViewModel.PostgreSQL_UseWindowsAuthentication, openDatabaseViewModel.PostgreSQL_UserName, encryption.Decrypt(openDatabaseViewModel.PostgreSQL_Password), openDatabaseViewModel.PostgreSQL_DatabaseName); } else if (openDatabaseViewModel.SelectedDatabaseProvider == OpenControls.Wpf.DatabaseDialogs.Model.DatabaseProvider.SQLite) { MycoKeyCreator.Library.PetaPocoAdapter.SQLiterDatabaseFactory.OpenDatabase( out iDatabase, openDatabaseViewModel.SQLite_Filename); } else { throw new Exception("Unsupported database type"); } } catch (Exception exception) { System.Windows.Forms.MessageBox.Show(exception.Message); return(false); } keyManager = MycoKeyCreator.Library.PetaPocoAdapter.KeyManagerFactory.BuildKeyManager(iDatabase); return(true); }