private string GetScriptFileName(UpgradeScript script) { string fileName = "Upgrade" + script.From.ToString() + "to" + script.To.ToString() + _databaseType + ".sql"; string fullPath = Path.Combine(_scriptPath, fileName); return(fullPath); }
private void listRequiredUpgrades_DoubleClick(object sender, EventArgs e) { if (listRequiredUpgrades.SelectedItems.Count != 1) { return; } UpgradeScript script = listRequiredUpgrades.SelectedItems[0].Tag as UpgradeScript; string scriptToExecute = GetScriptFileName(script); try { System.Diagnostics.Process.Start("notepad.exe", scriptToExecute); } catch (Exception) { MessageBox.Show("Notepad could not be started."); } }
public bool CreateUpgradePath() { _upgradePath = new UpgradeScripts(); int from = _application.Database.CurrentVersion; int to = _application.Database.RequiredVersion; // Actually create the path. while (from != to) { UpgradeScript script = _upgradeScripts.GetScriptUpgradingFrom(from); if (script == null) { MessageBox.Show("Upgrade path not found. Please contact support", "hMailServer"); return(false); } string fileName = GetScriptFileName(script); if (!File.Exists(fileName)) { MessageBox.Show("Required file for upgrade not found:" + Environment.NewLine + fileName, "hMailServer"); return(false); } _upgradePath.Add(script); from = script.To; } DisplayUpgradePath(); return(true); }
public void DoUpgrade() { using (new WaitCursor()) { buttonClose.Enabled = false; buttonUpgrade.Enabled = false; hMailServer.Database database = _application.Database; try { database.BeginTransaction(); } catch (Exception e) { HandleUpgradeError(database, e, "Transaction"); return; } // Run the prerequisites script. string prerequisitesScript = GetPrerequisitesScript(); if (!string.IsNullOrEmpty(prerequisitesScript)) { string fullScriptPath = Path.Combine(_scriptPath, prerequisitesScript); try { database.ExecuteSQLScript(fullScriptPath); } catch (Exception ex) { HandleUpgradeError(database, ex, fullScriptPath); return; } } foreach (ListViewItem item in listRequiredUpgrades.Items) { UpgradeScript script = item.Tag as UpgradeScript; string scriptToExecute = GetScriptFileName(script); try { // Make sure the database.EnsurePrerequisites(script.To); database.ExecuteSQLScript(scriptToExecute); item.SubItems.Add("Complete"); Application.DoEvents(); } catch (Exception e) { item.SubItems.Add("Error"); HandleUpgradeError(database, e, scriptToExecute); return; } } try { database.CommitTransaction(); } catch (Exception e) { HandleUpgradeError(database, e, "Transaction"); return; } Marshal.ReleaseComObject(database); // Database has been upgraded. Reinitialize the connections. _application.Reinitialize(); RemoveErrorLog(); buttonClose.Enabled = true; } }
private string GetScriptFileName(UpgradeScript script) { string fileName = "Upgrade" + script.From.ToString() + "to" + script.To.ToString() + _databaseType + ".sql"; string fullPath = Path.Combine(_scriptPath, fileName); return fullPath; }
public void Add(UpgradeScript script) { _upgradeScripts.Add(script); }