Пример #1
0
        ///<summary>This is a wrapper method for MiscData.MakeABackup() that will show a progress window so that the user can see progress.
        ///Set isSilent to true to suppress the failure message boxes.  However, the progress window will always be shown.
        ///Returns false if making a backup failed.</summary>
        public static bool MakeABackup(bool isSilent, BackupLocation backupLocation, bool isSecurityLogged = true)
        {
            if (DataConnection.DBtype == DatabaseType.Oracle)
            {
                return(false);               //Because MiscData.MakeABackup() is not yet Oracle compatible.
            }
#if DEBUG
            switch (MessageBox.Show("Would you like to make a backup of the DB?", "DEBUG ONLY", MessageBoxButtons.YesNoCancel))
            {
            case DialogResult.Cancel:
                return(false);

            case DialogResult.No:
                return(true);

            case DialogResult.Yes:
            default:
                //do nothing, make backup like usual.
                break;
            }
#endif
            //Create a thread that will show a window and then stay open until the closing action is called.
            Action actionCloseBackupProgress = ODProgressOld.ShowProgressStatus("BackupProgress", null);
            try {
                MiscData.MakeABackup();
                actionCloseBackupProgress(); //Close the progress window.
            }
            catch (Exception ex) {           //MiscData.MakeABackup() could have thrown an exception.
                actionCloseBackupProgress(); //Close the progress window.
                //Show the user that something what went wrong when not in silent mode.
                if (!isSilent)
                {
                    if (ex.Message != "")
                    {
                        MessageBox.Show(ex.Message);
                    }
                    //Reusing translation in ClassConvertDatabase, since it is most likely the only place a translation would have been performed previously.
                    MsgBox.Show("ClassConvertDatabase", "Backup failed. Your database has not been altered.");
                }
                return(false);
            }
            if (isSecurityLogged && PrefC.GetStringNoCache(PrefName.UpdateStreamLinePassword) != "abracadabra")
            {
                SecurityLogs.MakeLogEntryNoCache(Permissions.Backup, 0, Lan.g("Backups", "A backup was created when running the") + " " + backupLocation.ToString());
            }
            return(true);
        }