private IDatabase GetDatabase(IDatabaseConnector databaseConnector, out IDatabaseLoader databaseLoader, List <SchemaData> tablesToFetch) { databaseLoader = null; _progress.SetCurrentState("Loading Database From Connection String in NHibernate Config File", ProgressState.Normal); databaseLoader = DatabaseLoaderFacade.GetDatabaseLoader(databaseConnector); databaseLoader.DatabaseObjectsToFetch = tablesToFetch; IDatabase database = null; bool success = false; while (success == false) { try { database = databaseLoader.LoadDatabase(databaseLoader.DatabaseObjectsToFetch, null); new DatabaseProcessor().CreateRelationships(database); success = true; } catch (DatabaseLoaderException e) { var loader = _userInteractor.GetDatabaseLoader(databaseConnector); if (loader == null) { throw new NHibernateConfigException("Could not load the database specified in your config file.", e); } databaseLoader = loader; _progress.SetCurrentState("Loading Database From Connection Information Given", ProgressState.Normal); } } return(database); }
private void RefreshSchema() { // Note: this is only ok because this method only runs on the UI thread. // Two instances of it will not run at once, so this is not a race condition. // The moment it can run from another thread, this assumption is false and the // code is incorrect. if (RefreshingSchema) { return; } databaseLock.WaitOne(); RefreshingSchema = true; IDatabaseLoader loader = CreateDatabaseLoader(form); // Test connection first if (TestConnection(false) == false) { databaseLock.Set(); return; } Thread thread = new Thread( () => { try { IDatabase newDb = loader.LoadDatabase(loader.DatabaseObjectsToFetch, null); new DatabaseProcessor().CreateRelationships(newDb); if (Database == null || Database.IsEmpty) { Database = newDb; DatabaseConnector = loader.DatabaseConnector; NewDatabaseCreated.RaiseEvent(this); return; } var result = new DatabaseProcessor().MergeDatabases(Database, newDb); if (result.AnyChanges) { mainPanel.ShowDatabaseRefreshResults(result, Database, newDb); SchemaRefreshed.RaiseEvent(this); } else { form.SetDatabaseOperationResults(new DatabaseOperationResults("Schema Refresh", true, "No schema changes detected.")); } } finally { databaseLock.Set(); RefreshingSchema = false; } }); thread.Start(); }
private void Save() { if (_Database.ConnectionInformation == null) { IDatabaseLoader dbLoader = DatabasePresenter.CreateDatabaseLoader(ucDatabaseInformation1); try { _Database = dbLoader.LoadDatabase(dbLoader.DatabaseObjectsToFetch, null); } catch (DatabaseLoaderException e) { #region Save what we can _Database.DatabaseType = ucDatabaseInformation1.SelectedDatabaseType; _Database.ConnectionInformation = new Helper.ConnectionStringHelper(); _Database.ConnectionInformation.FileName = ucDatabaseInformation1.ConnectionStringHelper.FileName; _Database.ConnectionInformation.UseIntegratedSecurity = ucDatabaseInformation1.ConnectionStringHelper.UseIntegratedSecurity; _Database.ConnectionInformation.UserName = ucDatabaseInformation1.ConnectionStringHelper.UserName; _Database.ConnectionInformation.Password = ucDatabaseInformation1.ConnectionStringHelper.Password; _Database.ConnectionInformation.Port = ucDatabaseInformation1.ConnectionStringHelper.Port; _Database.ConnectionInformation.ServerName = ucDatabaseInformation1.ConnectionStringHelper.ServerName; _Database.ConnectionInformation.ServiceName = ucDatabaseInformation1.ConnectionStringHelper.ServiceName; #endregion //if (e.InnerException != null && e.InnerException.Message.StartsWith("Database cannot be null, the empty string, or string of only whitespace.")) // return; //else // throw; } } else { //_Database.Name = ucDatabaseInformation1.ConnectionStringHelper.DatabaseName; _Database.DatabaseType = ucDatabaseInformation1.SelectedDatabaseType; var connStringHelper = ucDatabaseInformation1.ConnectionStringHelper; _Database.ConnectionInformation.FileName = connStringHelper.FileName; _Database.ConnectionInformation.UseIntegratedSecurity = connStringHelper.UseIntegratedSecurity; _Database.ConnectionInformation.UserName = connStringHelper.UserName; _Database.ConnectionInformation.Password = connStringHelper.Password; _Database.ConnectionInformation.Port = connStringHelper.Port; _Database.ConnectionInformation.ServerName = connStringHelper.ServerName; _Database.ConnectionInformation.ServiceName = connStringHelper.ServiceName; } }
public void A_SQLCEDatabaseLoader_Is_Returned() { IDatabaseForm form = MockRepository.GenerateMock <IDatabaseForm>(); IMainPanel panel = MockRepository.GenerateMock <IMainPanel>(); DatabasePresenter presenter = new DatabasePresenter(panel, form); form.Stub(t => t.SelectedDatabaseType).Return(DatabaseTypes.SQLCE); form.Stub(t => t.SelectedDatabase).Return("1Table3Columns.sdf"); IDatabaseLoader loader = presenter.CreateDatabaseLoader(); Assert.That(loader, Is.Not.Null); Assert.That(loader, Is.TypeOf(typeof(SQLCEDatabaseLoader))); // Will throw an error if the database connection could not be established. loader.TestConnection(); IDatabase db = loader.LoadDatabase(); Assert.That(db.Name, Is.EqualTo("1Table3Columns")); Assert.That(db.Tables, Has.Count(1)); // Basic check to see if we got the correct database back. }
private void Populate() { nodeNewTables.Nodes.Clear(); advTreeTables.BeginUpdate(); try { // Fetch all schemas for IDatabaseLoader loader = FormDatabase.Instance.CreateDatabaseLoader(); IDatabase newDb = loader.LoadDatabase(loader.DatabaseObjectsToFetch, null); foreach (var schema in newDb.Tables.Select(s => s.Schema).Distinct().Where(s => !ExistingSchemas.Contains(s)).OrderBy(s => s)) { Node schemaNode = new Node(schema) { CheckBoxVisible = true, Checked = false }; nodeNewTables.Nodes.Add(schemaNode); foreach (var table in newDb.Tables.Where(t => t.Schema == schema).Select(t => t.Name).OrderBy(t => t)) { Node tableNode = new Node(table) { CheckBoxVisible = true, Checked = false }; schemaNode.Nodes.Add(tableNode); } } } finally { advTreeTables.EndUpdate(); } }
private void RefreshSchema() { // Note: this is only ok because this method only runs on the UI thread. // Two instances of it will not run at once, so this is not a race condition. // The moment it can run from another thread, this assumption is false and the // code is incorrect. if (RefreshingSchema) { return; } Cursor = Cursors.WaitCursor; databaseLock.WaitOne(); RefreshingSchema = true; IDatabaseLoader loader = CreateDatabaseLoader(); // Test connection first if (TestConnection(false) == false) { databaseLock.Set(); RefreshingSchema = false; Cursor = Cursors.Default; return; } labelNoChanges.Visible = false; labelNoChangesExport.Visible = false; Thread thread = new Thread( () => { try { List <string> schemasToLimit = Database.Tables.Union(Database.Views).Select(t => t.Schema).Distinct().ToList(); IDatabase newDb = loader.LoadDatabase(loader.DatabaseObjectsToFetch, schemasToLimit); new DatabaseProcessor().CreateRelationships(newDb); if (Database.Name == "New Database" && Database.Tables.Count == 0) { var mappingSet = new EntityModel.Controller.MappingLayer.MappingProcessor(new EntityModel.Controller.MappingLayer.OneToOneEntityProcessor()) .CreateOneToOneMapping(newDb, Database.MappingSet.TablePrefixes, Database.MappingSet.ColumnPrefixes, Database.MappingSet.TableSuffixes, Database.MappingSet.ColumnSuffixes); MappingSet = mappingSet; _Database = newDb; if (NewDatabaseCreated != null) { NewDatabaseCreated(mappingSet); } } else { var result = new DatabaseProcessor().MergeDatabases(Database, newDb); if (result.AnyChanges) { databaseChanges1.Fill(result, Database, newDb); modelChanges1.Fill(result, Database, newDb); SetControlEnabled(buttonImport, true); } else { ShowNoChangesLabel(); } } } finally { databaseLock.Set(); RefreshingSchema = false; SetCursor(Cursors.Default); } }); thread.Start(); }
protected override void DoRun(IJobRunEnv env) { IDatabaseLoader loader = m_backup.GetLoader(m_dst); loader.LoadDatabase(m_dst); }
private IDatabase GetDatabase(IDatabaseConnector databaseConnector, out IDatabaseLoader databaseLoader, List<SchemaData> tablesToFetch) { databaseLoader = null; _progress.SetCurrentState("Loading Database From Connection String in NHibernate Config File", ProgressState.Normal); databaseLoader = DatabaseLoaderFacade.GetDatabaseLoader(databaseConnector); databaseLoader.DatabaseObjectsToFetch = tablesToFetch; IDatabase database = null; bool success = false; while (success == false) { try { database = databaseLoader.LoadDatabase(databaseLoader.DatabaseObjectsToFetch, null); new DatabaseProcessor().CreateRelationships(database); success = true; } catch (DatabaseLoaderException e) { var loader = _userInteractor.GetDatabaseLoader(databaseConnector); if (loader == null) throw new NHibernateConfigException("Could not load the database specified in your config file.", e); databaseLoader = loader; _progress.SetCurrentState("Loading Database From Connection Information Given", ProgressState.Normal); } } return database; }