public void TestDbPath_ShouldtTryToParseInterpolatedString_PathShouldntBeEmpty() { var expectedDatabasePath = Path.Combine(Application.persistentDataPath, "foo", "bar"); var actualDatabasePath = DatabasePathHelper.GetFullDatabasePath(expectedDatabasePath); Assert.AreEqual(new DirectoryInfo(expectedDatabasePath).FullName, actualDatabasePath); }
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(); } }
public void TestDbPath_ShouldTryToEscapeRootedDir_PathShouldntBeEmpty() { var testedPath = "./test"; var expectedDatabasePath = Path.Combine(Application.persistentDataPath, testedPath); var actualDatabasePath = DatabasePathHelper.GetFullDatabasePath(testedPath); Assert.AreEqual(new DirectoryInfo(expectedDatabasePath).FullName, actualDatabasePath); }
public void TestDbPath_ShouldParseCorrectlyInterpolatedStringWithLowerCaseChar_PathShouldntBeEmpty() { var expectedDatabasePath = Path.Combine(Application.persistentDataPath, "foo", "bar"); var testedDatabasePath = "${application.persistentDataPath}/foo/bar"; var actualDatabasePath = DatabasePathHelper.GetFullDatabasePath(testedDatabasePath); Assert.AreEqual(new DirectoryInfo(expectedDatabasePath).FullName, actualDatabasePath); }
public void TestDbPath_ShouldReplaceInterpolationWithPersistentDataPathDataPath_PathShouldntBeEmpty() { var expectedDatabasePath = Path.Combine(Application.persistentDataPath, "foo", "bar"); var testedDatabasePath = "${Application.persistentDataPath}/foo/bar"; var actualDatabasePath = DatabasePathHelper.GetFullDatabasePath(testedDatabasePath); Assert.AreEqual(new DirectoryInfo(expectedDatabasePath).FullName, actualDatabasePath); }
public void TestDbPath_ShouldHandleIncorrectInterpolationClosingValue_ShouldReturnInvalidPathToDatabase() { var testedInvalidPath = "${application.persistentDataPath/foo/bar"; // beacuse ${ will point to root dir of project, we will try to extend this path // with application.dataPath var expectedInvalidPath = Path.Combine(Application.persistentDataPath, testedInvalidPath); var actualDatabasePath = DatabasePathHelper.GetFullDatabasePath(testedInvalidPath); Assert.AreEqual(Path.GetFullPath(expectedInvalidPath), actualDatabasePath); }
public void GetDbPath_Platform_CorrectPath(AppPlatform platform, string expectedPathSegment) { // Arrange ExecutingPlatform.Current = platform; // Act string result = DatabasePathHelper.GetDbPath(); // Assert result.ShouldContain(expectedPathSegment); }
public void TestDbPath_ShouldCorrectlyGenerateFullpath_PathShouldntBeEmpty() { var expectedDatabasePath = #if UNITY_EDITOR_OSX || UNITY_IOS || UNITY_STANDALONE_OSX "/Users/user/Library/Application Support/Backtrace/database/path"; #else "C:/users/user/Backtrace/database/path"; #endif var actualDatabasePath = DatabasePathHelper.GetFullDatabasePath(expectedDatabasePath); Assert.AreEqual(new DirectoryInfo(expectedDatabasePath).FullName, actualDatabasePath); }
private async Task EnqueueBackupTaskAsync(int attempts = 0) { if (!connectivity.IsConnected) { throw new NetworkConnectionException(); } logger.Info("Enqueue Backup upload."); await semaphoreSlim.WaitAsync(ServiceConstants.BACKUP_OPERATION_TIMEOUT, cancellationTokenSource.Token); try { if (await cloudBackupService.UploadAsync(fileStore.OpenRead(DatabasePathHelper.GetDbPath()))) { logger.Info("Upload complete. Release Semaphore."); semaphoreSlim.Release(); } else { cancellationTokenSource.Cancel(); } } catch (FileNotFoundException ex) { logger.Error(ex, "Backup failed because database was not found."); } catch (OperationCanceledException ex) { logger.Error(ex, "Enqueue Backup failed."); await Task.Delay(ServiceConstants.BACKUP_REPEAT_DELAY); await EnqueueBackupTaskAsync(attempts + 1); } catch (ServiceException ex) { logger.Error(ex, "ServiceException when tried to enqueue Backup."); throw; } catch (BackupAuthenticationFailedException ex) { logger.Error(ex, "BackupAuthenticationFailedException when tried to enqueue Backup."); throw; } logger.Warn("Enqueue Backup failed."); }
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); }
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(); } }
private async Task DownloadBackup() { if (!connectivity.IsConnected) { return; } var backups = await cloudBackupService.GetFileNames(); if (backups.Contains(DatabaseConstants.BACKUP_NAME)) { using (var backupStream = await cloudBackupService.Restore(DatabaseConstants.BACKUP_NAME, DatabaseConstants.BACKUP_NAME)) { fileStore.WriteFile(DatabaseConstants.BACKUP_NAME, backupStream.ReadToEnd()); } var moveSucceed = fileStore.TryMove(DatabaseConstants.BACKUP_NAME, DatabasePathHelper.GetDbPath(), true); if (!moveSucceed) { throw new BackupException("Error Moving downloaded backup file"); } } }
public string GetFullDatabasePath() { return(DatabasePathHelper.GetFullDatabasePath(DatabasePath)); }
public void TestDbPath_EmptyPathToDatabase_PathShouldBeEmpty() { Assert.IsEmpty(DatabasePathHelper.GetFullDatabasePath(string.Empty)); }