示例#1
0
        public bool OnLeavePage(bool next)
        {
            if (next == false)
            {
                return(true);
            }
            try
            {
                AddToLog("Starting task...");


                // Perform the task...
                hMailServer.eDBtype dbType = Globals.GetDatabaseType(_state["ServerType"]);
                string serverName          = _state["ServerAddress"];
                string portString          = _state["ServerPort"];
                int    port = 0;
                int.TryParse(portString, out port);
                string databaseName = _state["DatabaseName"];

                string userName = _state["Username"];
                string passWord = _state["Password"];

                string serviceDependency = _state["ServiceDependency"];
                SetDependency(serviceDependency);

                if (_state["Authentication"] == "Windows")
                {
                    userName = "";
                    passWord = "";
                }

                hMailServer.Database database = Globals.GetApp().Database;

                if (_state["CreateNew"] == "Yes")
                {
                    AddToLog("Please wait while creating database...");
                    database.CreateExternalDatabase(dbType, serverName, port, databaseName, userName, passWord);
                    AddToLog("Database created.");
                }
                else
                {
                    AddToLog("Please wait while updating database settings...");
                    database.SetDefaultDatabase(dbType, serverName, port, databaseName, userName, passWord);
                    AddToLog("Settings updated.");
                }

                AddToLog("Restarting server...");
                Globals.GetApp().Reinitialize();
                AddToLog("Server restarted.");
                AddToLog("");
                AddToLog("Task completed.");
            }
            catch (Exception ex)
            {
                AddToLog(ex.Message);
                return(false);
            }

            return(true);
        }
示例#2
0
        public void TestDomainAdminAccessDatabase()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            account.AdminLevel = hMailServer.eAdminLevel.hAdminLevelDomainAdmin;
            account.Save();

            hMailServer.Application newApplication = new hMailServer.Application();
            newApplication.Authenticate("*****@*****.**", "test");
            hMailServer.Database database = newApplication.Database;
            database.ExecuteSQL("select");
        }
示例#3
0
        private static void InitializeInternalDatabase()
        {
            try
            {
                hMailServer.Database database = _application.Database;

                database.CreateInternalDatabase();

                // Database has been upgraded. Reinitialize the connections.
                _application.Reinitialize();

                // Re-initialize to connect to the newly created database.
                _application.Reinitialize();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "hMailServer", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#4
0
        public void LoadData()
        {
            _application = APICreator.Application;

            labelVersion.Text = string.Format("{0} ({1})", _application.Version, _application.VersionArchitecture);

            ShowStatistics();

            hMailServer.Database database = _application.Database;

            labelServerType.Text = InternalNames.GetDatabaseServerTypeName(database.DatabaseType);

            if (database.ServerName.Length > 0)
            {
                labelServerHost.Text = database.ServerName;
            }
            else
            {
                labelServerHost.Text = "-";
            }

            if (database.DatabaseName.Length > 0 && database.DatabaseType != eDBtype.hDBTypeMSSQLCE)
            {
                labelName.Text = database.DatabaseName;
            }
            else
            {
                labelName.Text = "-";
            }

            labelDBVersion.Text = database.CurrentVersion.ToString();

            Marshal.ReleaseComObject(database);

            hMailServer.Settings settings = _application.Settings;
            _logging = settings.Logging;
            Marshal.ReleaseComObject(settings);


            DisplayServerState();
            DisplayWarnings();
        }
示例#5
0
        private void HandleUpgradeError(hMailServer.Database database, Exception error, string scriptToExecute)
        {
            try
            {
                database.RollbackTransaction();
            }
            catch (Exception)
            {
                // When an error occurs in MSSQL, the rollback will be done
                // automatically. Hence it's not always an error that we cannot
                // rollback.
                //
                // Maybe we should check the actual cause of the rollback failure...
                //
            }
            finally
            {
                MessageBox.Show(error.Message, scriptToExecute);
            }

            buttonClose.Enabled = true;
            return;
        }
示例#6
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;
            }
        }