Esempio n. 1
0
        private async Task <bool> CreateNewBackup()
        {
            if (!connectivity.IsConnected)
            {
                throw new NetworkConnectionException();
            }

            using (Stream dbStream = fileStore.OpenRead(DatabaseConstants.DB_NAME))
            {
                return(await cloudBackupService.UploadAsync(dbStream));
            }
        }
Esempio n. 2
0
        private async Task EnqueueBackupTaskAsync(int attempts = 0)
        {
            if (!connectivity.IsConnected)
            {
                throw new NetworkConnectionException();
            }

            logger.Info("Enqueue Backup upload.");

            await semaphoreSlim.WaitAsync(BACKUP_OPERATION_TIMEOUT,
                                          cancellationTokenSource.Token);

            try
            {
                if (await cloudBackupService.UploadAsync(await fileStore.OpenReadAsync(DatabasePathHelper.DbPath)))
                {
                    logger.Info("Upload complete. Release Semaphore.");
                    semaphoreSlim.Release();
                    await toastService.ShowToastAsync(Strings.BackupCreatedMessage);
                }
                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(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.");
        }
Esempio n. 3
0
        private async Task EnqueueBackupTaskAsync(int attempts = 0)
        {
            if (!connectivity.IsConnected)
            {
                throw new NetworkConnectionException();
            }

            await semaphoreSlim.WaitAsync(ServiceConstants.BACKUP_OPERATION_TIMEOUT,
                                          cancellationTokenSource.Token);

            try
            {
                if (await cloudBackupService.UploadAsync(fileStore.OpenRead(DatabasePathHelper.GetDbPath())))
                {
                    semaphoreSlim.Release();
                }
                else
                {
                    cancellationTokenSource.Cancel();
                }
            }
            catch (FileNotFoundException ex)
            {
                logManager.Error(ex, "Backup failed because database was not found.");
            }
            catch (OperationCanceledException ex)
            {
                logManager.Error(ex, "Enqueue Backup failed.");
                await Task.Delay(ServiceConstants.BACKUP_REPEAT_DELAY);
                await EnqueueBackupTaskAsync(attempts + 1);
            }
            catch (ServiceException ex)
            {
                logManager.Error(ex, "ServiceException when tried to enqueue Backup.");
                throw;
            }
            catch (BackupAuthenticationFailedException ex)
            {
                logManager.Error(ex, "BackupAuthenticationFailedException when tried to enqueue Backup.");
                throw;
            }

            logManager.Warn("Enqueue Backup failed.");
        }