示例#1
0
        private async Task <string> BackupBeforeRestoreAsync()
        {
            this.TraceDebug("nettoyage du dossier SqlDir...");
            SqlMessages.Add(new SqlOutput("Cleaning up the buffer directory..."));

            foreach (string file in Directory.GetFiles(ServiceBus.Get <IDataBaseService>().GeBackupDir()))
            {
                try
                {
                    this.TraceDebug(file);
                    SqlMessages.Add(new SqlOutput(file));
                    File.Delete(file);
                }
                catch (Exception e)
                {
                    this.TraceError(e, file);
                    SqlMessages.Add(new SqlOutput(e));
                    SqlMessages.Add(new SqlOutput("This error has no consequence for next restore steps. Continuing..."));
                }
            }

            this.TraceDebug("Fin du nettoyage");
            string backupFilePath = await DoBackup();

            SqlMessages.Add(new SqlOutput("The backup before restore process has succeded. Backup file is store at location:"));
            SqlMessages.Add(new SqlOutput(backupFilePath, SqlOutputKind.Path));

            return(backupFilePath);
        }
示例#2
0
 private void RestartApplication()
 {
     this.TraceDebug("Redemarage de l'application");
     SqlMessages.Add(new SqlOutput("Restarting the application..."));
     DialogFactory.GetDialogView <IMessageDialog>().Show(
         LocalizationManager.GetString("View_BackupRestore_Restart"),
         LocalizationManager.GetString("View_BackupRestore_RestartTitle"),
         MessageDialogButton.OK, MessageDialogImage.Information);
     Application.Current.Restart();
 }
示例#3
0
 private void RestartApplicationWithError()
 {
     this.TraceDebug("Redemarage de l'application en erreur");
     SqlMessages.Add(new SqlOutput("Restarting the application..."));
     DialogFactory.GetDialogView <IMessageDialog>().Show(
         "The database restoration failed. Please contact K-process support at [email protected]",
         "Restoration failed",
         MessageDialogButton.OK, MessageDialogImage.Error);
     Application.Current.Restart();
 }
示例#4
0
        public void OnBatchMessage(object sender, BatchMessageEventArgs args)
        {
            Console.WriteLine("\tOnBatchMessage ...");
            Console.WriteLine("\t\tMessage: " + args.Message);
            Console.WriteLine("\t\tDetail message:" + args.DetailedMessage);

            if (args.DetailedMessage != "")
            {
                sqlMessages.Add(args.DetailedMessage);
            }
            else
            {
                SqlMessages.Add(null);
            }
        }
示例#5
0
        private bool TryPrepareRestore(string source, out string sqlDirSourceFile)
        {
            this.TraceDebug("Préparation de la restauration");
            IDataBaseService dataBaseService = ServiceBus.Get <IDataBaseService>();

            string finalSourcePath = Path.Combine(dataBaseService.GeBackupDir(), "tempRestorationFile");

            try
            {
                if (File.Exists(source))
                {
                    SqlMessages.Add(new SqlOutput("Importing backup file..."));
                    File.Copy(source, finalSourcePath, true);
                }
                else
                {
                    SqlMessages.Add(new SqlOutput("Restore process has failed: The specified file has not been found", SqlOutputKind.Error));
                }
            }
            catch (UnauthorizedAccessException e)
            {
                this.TraceError(e, "Une erreur s'est produite durant le processus de restauration de base de donnée (import du fichier de backup)");
                SqlMessages.Add(new SqlOutput(e));
                SqlMessages.Add(new SqlOutput("Backup file copy has failed. Check files authorization.", SqlOutputKind.Error));
                SqlMessages.Add(new SqlOutput("Restore process is rolled backed and aborted now."));

                sqlDirSourceFile = null;
                return(false);
            }
            catch (Exception e)
            {
                this.TraceError(e, "Une erreur non gérée s'est produite durant le processus de restauration de base de donnée (import du fichier de backup)");
                SqlMessages.Add(new SqlOutput(e));
                SqlMessages.Add(new SqlOutput("A not handled error occured during the importation.", SqlOutputKind.Error));
                SqlMessages.Add(new SqlOutput("Restore process is aborted now."));

                if (File.Exists(finalSourcePath))
                {
                    File.Delete(finalSourcePath);
                }

                sqlDirSourceFile = null;
                return(false);
            }

            sqlDirSourceFile = finalSourcePath;
            return(true);
        }
示例#6
0
        private async Task DoRestore(string source, int version = 3)
        {
            SqlExecutionResult <string> sqlResult = ServiceBus.Get <IDataBaseService>().Restore(source, version, true);

            sqlResult.SqlMessageSent += SqlResultSqlMessageSent;
            try
            {
                await sqlResult.Start();

                sqlResult.SqlMessageSent -= SqlResultSqlMessageSent;
                this.TraceInfo("Le processus de restauration de la base de données s'est déroulé avec succés");
                SqlMessages.Add(new SqlOutput("restore process of the backup file has succeeded.", SqlOutputKind.Success));
                try
                {
                    if (File.Exists(source))
                    {
                        File.Delete(source);
                    }
                }
                catch (Exception ex)
                {
                    SqlMessages.Add(new SqlOutput("An error occured while trying to remove the imported backup file.", SqlOutputKind.Error));
                    this.TraceError("Suppression du fichier temporaire importé pour le processus de restauration", ex);
                }
                RestartApplication();
            }
            catch (Exception e)
            {
                sqlResult.SqlMessageSent -= SqlResultSqlMessageSent;
                this.TraceError(e, "Une erreur s'est produite durant le processus de restauration de base de donnée");
                SqlMessages.Add(new SqlOutput(e.InnerException ?? e));
                SqlMessages.Add(new SqlOutput("Restoration failed and rolled back.", SqlOutputKind.Error));
                try
                {
                    if (File.Exists(source))
                    {
                        File.Delete(source);
                    }
                }
                catch (Exception ex)
                {
                    SqlMessages.Add(new SqlOutput("An error occured while trying to remove the imported backup file.", SqlOutputKind.Error));
                    this.TraceError("Suppression du fichier temporaire importé pour le processus de restauration", ex);
                }
                RestartApplicationWithError();
            }
        }
示例#7
0
        private async Task <string> DoBackup()
        {
            SqlExecutionResult <string> sqlResult = ServiceBus.Get <IDataBaseService>().Backup(true);

            sqlResult.SqlMessageSent += SqlResultSqlMessageSent;
            try
            {
                string source = await sqlResult.Start();

                sqlResult.SqlMessageSent -= SqlResultSqlMessageSent;
                return(source);
            }
            catch (Exception e)
            {
                this.TraceError(e, "Une erreur s'est produite durant le processus de backup de base de donnée");
                SqlMessages.Add(new SqlOutput(e.InnerException ?? e));
                SqlMessages.Add(new SqlOutput("Backup failed and rolled back.", SqlOutputKind.Error));

                return(null);
            }
        }
示例#8
0
 private void SqlResultSqlMessageSent(object sender, SqlInfoMessageEventArgs e)
 {
     this.TraceDebug(e.Message);
     Application.Current.Dispatcher.BeginInvoke(new Action(() => SqlMessages.Add(new SqlOutput(e))), DispatcherPriority.Normal);
 }
示例#9
0
        private bool TryFinalizeBackup(string source, string destination)
        {
            if (string.IsNullOrWhiteSpace(source) || string.IsNullOrWhiteSpace(destination))
            {
                this.TraceDebug("La finalisation du backup est annulée");
                SqlMessages.Add(new SqlOutput("Backup finalization is skipped"));
                return(false);
            }

            this.TraceDebug("Finalisation du backup");
            SqlMessages.Add(new SqlOutput("Copying buffered file in destination folder..."));

            try
            {
                this.TraceDebug("Copie des fichiers {0}, -> {1}".Format(new[] { source, destination }));
                File.Copy(source, destination, true);
                File.Delete(source);
                SqlMessages.Add(new SqlOutput("Backup file created successfuly:", SqlOutputKind.Success));
                SqlMessages.Add(new SqlOutput(destination, SqlOutputKind.Path));
            }
            catch (UnauthorizedAccessException e)
            {
                this.TraceError(e, "Interception de l'erreur de droits sur fichier");
                SqlMessages.Add(new SqlOutput(e));
                SqlMessages.Add(new SqlOutput("Creation of the backup is not allowed in this folder. Check folder security:", SqlOutputKind.Error));
                SqlMessages.Add(new SqlOutput(destination, SqlOutputKind.Path));

                if (File.Exists(source))
                {
                    try
                    {
                        File.Delete(source);
                    }
                    catch (IOException eDelete)
                    {
                        this.TraceError(e, "Erreur lors de la suppression du fichier dans le buffer SQL");
                        SqlMessages.Add(new SqlOutput(eDelete));
                        SqlMessages.Add(new SqlOutput("An error occured while trying to clean up the SQL buffer folder", SqlOutputKind.Error));
                    }
                }

                return(false);
            }
            catch (Exception e)
            {
                this.TraceError(e, "Interception d'une erreur générique");
                SqlMessages.Add(new SqlOutput(e));
                SqlMessages.Add(new SqlOutput("A not handled error occured during the backup process.", SqlOutputKind.Error));

                try
                {
                    if (File.Exists(source))
                    {
                        File.Delete(source);
                    }
                }
                catch (IOException eDelete)
                {
                    this.TraceError(e, "Erreur lors de la suppression du fichier dans le buffer SQL");
                    SqlMessages.Add(new SqlOutput(eDelete));
                    SqlMessages.Add(new SqlOutput("An error occured while trying to clean up the SQL buffer folder", SqlOutputKind.Error));
                }

                return(false);
            }

            return(true);
        }