Example #1
0
        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);
        }
Example #2
0
        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.");
            }
        }
Example #3
0
        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);
        }
Example #4
0
        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;
            }
        }
Example #5
0
        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;
        }
Example #6
0
 public void Add(UpgradeScript script)
 {
     _upgradeScripts.Add(script);
 }
Example #7
0
 public void Add(UpgradeScript script)
 {
     _upgradeScripts.Add(script);
 }