/// <summary> /// Deploys a database. /// </summary> public void DeployDatabase(DatabaseDeploymentStructure structure) { try { DatabaseDeployer ds = new DatabaseDeployer(); ds.DeployDatabase(structure); } catch (DeployCancelException ex) { // Deployment has been cancelled EventManager.OnNotificationMessage("*** Deployment stopped! " + ex.Message); } }
/// <summary> /// Deploys the source database to the destination database. Only stored procedures, views and functions /// are deployed. /// </summary> internal void DeployDatabase(DatabaseDeploymentStructure structure) { EventManager.OnNotificationMessage("Starting deployment..."); InitializeServices(structure.Databases); try { // Deploy objects foreach(IDatabaseObject obj in structure.DatabaseObjects) { if(obj.IncludeInDeployment) { bool retry; do { retry = false; // Assume we won't retry operation try { // Signal that deployment started DatabaseTransferEventArgs e = new DatabaseTransferEventArgs(obj); EventManager.OnDatabaseTransferBegin(e); obj.Deploy(_sourceDbService, _destinationDbService); // Signal that deployment completed EventManager.OnDatabaseTransferComplete(e); } catch (DeployCancelException) { throw; } catch (Exception ex) { DeployErrorForm dlg = new DeployErrorForm(); dlg.ErrorMessage = ex.Message; dlg.SetLocalInfo("Object Name:", obj.Name); dlg.SetRemoteInfo("Type:", obj.TypeName); DialogResult result = dlg.ShowDialog(); switch (result) { case DialogResult.Retry: retry = true; break; case DialogResult.Ignore: break; // Skip to next file case DialogResult.Cancel: throw new DeployCancelException("User cancelled."); } } } while (retry); } } } catch (DeployCancelException ex) { // Deployment has been cancelled EventManager.OnNotificationMessage("*** Deployment stopped! " + ex.Message); } ShutdownServices(); EventManager.OnNotificationMessage("Deployment completed."); }
/// <summary> /// Scans the views in the database. /// </summary> private void ScanViews(DatabaseDeploymentStructure structure) { // Retrieve views in dest db and build hashtable with them DataTable destviews = _destinationDbService.GetViews().Tables[0]; Hashtable destviewstable = new Hashtable(); foreach(DataRow row in destviews.Rows) { DbView view = new DbView(row); destviewstable.Add(view.Name, view); } // Retrieve views from source and build structure DataTable sourceviews = _sourceDbService.GetViews().Tables[0]; foreach(DataRow row in sourceviews.Rows) { DbView view = new DbView(row); // Does this view already exist in destination? view.IsNew = !destviewstable.ContainsKey(view.Name); structure.Add(view); } }
/// <summary> /// Scans the procedures in the database. /// </summary> private void ScanProcedures(FilterCollection excludeProcedures, DatabaseDeploymentStructure structure) { // Retrieve procs in dest db and build a hashtable with them DataTable destprocs = _destinationDbService.GetProcedures().Tables[0]; Hashtable destprocstable = new Hashtable(); foreach(DataRow row in destprocs.Rows) { DbStoredProcedure proc = new DbStoredProcedure(row); destprocstable.Add(proc.Name, proc); } // Retrieve stored procedures and build deployment structure DataTable sourceprocs = _sourceDbService.GetProcedures().Tables[0]; foreach(DataRow row in sourceprocs.Rows) { DbStoredProcedure proc = new DbStoredProcedure(row); // Does this proc already exist in destination? proc.IsNew = !destprocstable.ContainsKey(proc.Name); if(!excludeProcedures.IsMatching(proc.Name)) structure.Add(proc); } }
/// <summary> /// Scans a database for objects to deploy. /// </summary> internal DatabaseDeploymentStructure ScanDatabase(DeploymentProject project, DatabasePair databases) { InitializeServices(databases); DatabaseDeploymentStructure structure = new DatabaseDeploymentStructure(databases); ScanProcedures(project.ActiveDeployConfig.DatabaseSettings.ExcludeProcedures, structure); ScanViews(structure); ShutdownServices(); return structure; }
/// <summary> /// Populates the database list. /// </summary> private void PopulateDatabaseList(DatabaseDeploymentStructure structure) { // Add objects foreach (IDatabaseObject obj in structure.DatabaseObjects) { GLItem item = _databaselist.Items.Add(obj.Name); item.Tag = obj; item.Checked = true; item.SubItems[(int)DatabaseListColumns.Type].Text = obj.TypeName; ProgressBar pb = new ProgressBar(); pb.Maximum = 100; item.SubItems[(int)DatabaseListColumns.Progress].Control = pb; if (obj.IsNew) item.ForeColor = Color.Blue; } }
/// <summary> /// Scans the database to find the objects to deploy. /// </summary> private void ScanDatabase() { try { if (_currentProject.ActiveDeployConfig.DatabaseSettings.Databases.Count == 0) { MessageBox.Show(this, "No databases have been configured.", "Configuration missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } SetStatusText("Scanning database..."); _tabcontrol.SelectedTab = _databasetab; LockUI(); _databaselist.Items.Clear(); // Just pick the first pair (GUI has no support for multiple database pairs yet...) DatabasePair databases = _currentProject.ActiveDeployConfig.DatabaseSettings.Databases[0]; // Scan structure _scannedDbStructure = DeploymentManager.Instance.ScanDatabase(_currentProject, databases); SetStatusText(string.Format("Found {0} database object(s) to deploy.", _scannedDbStructure.DatabaseObjects.Count)); PopulateDatabaseList(_scannedDbStructure); } catch (Exception ex) { ShowNonFatalException(ex); } UnlockUI(); }
/// <summary> /// Resets variables and UI when a project is loaded or created. /// </summary> private void ResetProjectState() { _filelist.Items.Clear(); _fileQueueList.Items.Clear(); _databaselist.Items.Clear(); _folderTree.Nodes.Clear(); _lastUploadTime = DateTime.MinValue; _deployStructure = null; _scannedDbStructure = null; _databaseComparison = null; }