Beispiel #1
0
        private async Task DownloadBackupAsync()
        {
            DateTime backupDate = await GetBackupDateAsync();

            if (settingsFacade.LastDatabaseUpdate > backupDate)
            {
                return;
            }

            List <string> backups = await cloudBackupService.GetFileNamesAsync();

            if (backups.Contains(DatabaseConstants.BACKUP_NAME))
            {
                using (Stream backupStream = await cloudBackupService.RestoreAsync(DatabaseConstants.BACKUP_NAME,
                                                                                   DatabaseConstants.BACKUP_NAME))
                {
                    fileStore.WriteFile(DatabaseConstants.BACKUP_NAME, backupStream.ReadToEnd());
                }

                bool moveSucceed = fileStore.TryMove(DatabaseConstants.BACKUP_NAME,
                                                     DatabasePathHelper.GetDbPath(),
                                                     true);

                if (!moveSucceed)
                {
                    throw new BackupException("Error Moving downloaded backup file");
                }
                contextAdapter.RecreateContext();
            }
        }
Beispiel #2
0
        private async Task <BackupRestoreResult> DownloadBackupAsync(BackupMode backupMode)
        {
            try
            {
                DateTime backupDate = await GetBackupDateAsync();

                if (settingsFacade.LastDatabaseUpdate > backupDate && backupMode == BackupMode.Automatic)
                {
                    logger.Info("Local backup is newer than remote. Don't download backup");
                    return(BackupRestoreResult.Canceled);
                }

                List <string> backups = await cloudBackupService.GetFileNamesAsync();

                if (backups.Contains(DatabaseConstants.BACKUP_NAME))
                {
                    logger.Info("New backup found. Starting download.");
                    using (Stream backupStream = await cloudBackupService.RestoreAsync(DatabaseConstants.BACKUP_NAME,
                                                                                       DatabaseConstants.BACKUP_NAME))
                    {
                        await fileStore.WriteFileAsync(DatabaseConstants.BACKUP_NAME, backupStream.ReadToEnd());
                    }

                    logger.Info("Backup downloaded. Replace current file.");

                    bool moveSucceed = await fileStore.TryMoveAsync(DatabaseConstants.BACKUP_NAME,
                                                                    DatabasePathHelper.DbPath,
                                                                    true);

                    if (!moveSucceed)
                    {
                        throw new BackupException("Error Moving downloaded backup file");
                    }

                    logger.Info("Recreate database context.");
                    contextAdapter.RecreateContext();

                    return(BackupRestoreResult.NewBackupRestored);
                }
            }
            catch (BackupOperationCanceledException ex)
            {
                logger.Error(ex, "Operation canceled during restore backup. Execute logout");
                await LogoutAsync();

                await toastService.ShowToastAsync(Strings.FailedToLoginToBackupMessage, Strings.FailedToLoginToBackupTitle);
            }

            return(BackupRestoreResult.BackupNotFound);
        }
Beispiel #3
0
        private async Task <BackupRestoreResult> DownloadBackupAsync(BackupMode backupMode)
        {
            DateTime backupDate = await GetBackupDateAsync();

            if (settingsFacade.LastDatabaseUpdate > backupDate && backupMode == BackupMode.Automatic)
            {
                logger.Info("Local backup is newer than remote. Don't download backup");
                return(BackupRestoreResult.Canceled);
            }

            List <string> backups = await cloudBackupService.GetFileNamesAsync();

            if (backups.Contains(DatabaseConstants.BACKUP_NAME))
            {
                logger.Info("New backup found. Starting download.");
                using (Stream backupStream = await cloudBackupService.RestoreAsync(DatabaseConstants.BACKUP_NAME,
                                                                                   DatabaseConstants.BACKUP_NAME))
                {
                    fileStore.WriteFile(DatabaseConstants.BACKUP_NAME, backupStream.ReadToEnd());
                }

                logger.Info("Backup downloaded. Replace current file.");

                bool moveSucceed = fileStore.TryMove(DatabaseConstants.BACKUP_NAME,
                                                     DatabasePathHelper.GetDbPath(),
                                                     true);

                if (!moveSucceed)
                {
                    throw new BackupException("Error Moving downloaded backup file");
                }

                logger.Info("Recreate database context.");
                contextAdapter.RecreateContext();

                return(BackupRestoreResult.NewBackupRestored);
            }

            return(BackupRestoreResult.BackupNotFound);
        }
Beispiel #4
0
        private async Task DownloadBackupAsync()
        {
            DateTime backupDate = await GetBackupDateAsync();

            if (settingsFacade.LastDatabaseUpdate > backupDate)
            {
                logger.Info("Last local change is after the last adjustment on the remote backup.");
                return;
            }

            List <string> backups = await cloudBackupService.GetFileNamesAsync();

            if (backups.Contains(DatabaseConstants.BACKUP_NAME))
            {
                logger.Info("New backup found. Starting download.");
                using (Stream backupStream = await cloudBackupService.RestoreAsync(DatabaseConstants.BACKUP_NAME,
                                                                                   DatabaseConstants.BACKUP_NAME))
                {
                    fileStore.WriteFile(DatabaseConstants.BACKUP_NAME, backupStream.ReadToEnd());
                }

                logger.Info("Backup downloaded. Replace current file.");

                bool moveSucceed = fileStore.TryMove(DatabaseConstants.BACKUP_NAME,
                                                     DatabasePathHelper.GetDbPath(),
                                                     true);

                if (!moveSucceed)
                {
                    throw new BackupException("Error Moving downloaded backup file");
                }

                logger.Info("Recreate database context.");
                contextAdapter.RecreateContext();
            }
        }