예제 #1
0
        public static bool MakeProjectBackup(Form parentForm, SaveFileDialog saveFileDialog)
        {
            if (PackageManagement.OpenedProject == null || string.IsNullOrWhiteSpace(PackageManagement.OpenedProject.DirectoryPath))
            {
                Helper.ShowMessageBox(MessageBoxStrings.GUI.UNABLE_MAKE_LOCAL_BACKUP_NO_OPEN_PROJ, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            string _namespace = MethodBase.GetCurrentMethod().ToLogFormatFullName();

            Logger.WriteUserEventLog(LoggerMessages.GUI.BGWorker.Backup.Information.MAKE_LOCAL_BACKUP_BEGIN, LoggerMessages.GUI.ActionTaken.SHOW_SAVE_FILE_DLG, _namespace);
            saveFileDialog.ResetValues(FileDialogFilters.BACKUP);
            saveFileDialog.FileName = BackupManager.GetDefaultBackupName();
            DialogResult dResult = saveFileDialog.ShowDialog(parentForm);

            if (dResult == DialogResult.Cancel)
            {
                Logger.WriteUserEventLog(LoggerMessages.GUI.BGWorker.Backup.Information.MAKE_LOCAL_BACKUP_CANCELLED, _namespace);
                return(false);
            }

            Logger.WriteUserEventLog(LoggerMessages.GUI.BGWorker.Backup.Information.BACKUP_SELECTED_PATH + saveFileDialog.FileName + ".", _namespace);

            bool       threadRetVal = true;
            frmLoading loadingForm  = new frmLoading(StringConst.frmLoading.CREATE_PROJ_BACKUP);
            Thread     thread       = new Thread(delegate()
            {
                try
                {
                    BackupManager.CreateProjectBackup(PackageManagement.OpenedProject.DirectoryPath, saveFileDialog.FileName, _namespace);
                }
                catch (Exception ex)
                {
                    Helper.ShowMessageBox(MessageBoxStrings.GUI.UNABLE_MAKE_BACKUP_LOCAL + saveFileDialog.FileName + ".", MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Logger.WriteErrorLog(LoggerMessages.GUI.BGWorker.Backup.Error.BackupCreateFailedLocal(saveFileDialog.FileName), _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                    threadRetVal = false;
                }
                loadingForm.SafeClose();
            });

            thread.Start();
            loadingForm.ShowDialog();
            if (!threadRetVal)
            {
                return(false);
            }

            Helper.ShowMessageBox(MessageBoxStrings.GUI.MAKE_BACKUP_LOCAL_SUCCESS + saveFileDialog.FileName + ".", MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Information);
            Logger.WriteInformationLog(LoggerMessages.GUI.BGWorker.Backup.Information.MAKE_LOCAL_BACKUP_SUCCESS + saveFileDialog.FileName + ".", _namespace);
            return(true);
        }