public async Task <TaskCompletionType> Upload() { if (!IsLoggedIn) { await Login(); } try { using (var dbstream = fileStore.OpenRead(OneDriveAuthenticationConstants.DB_NAME)) { var uploadedItem = await OneDriveClient .Drive .Root .ItemWithPath(Path.Combine(OneDriveAuthenticationConstants.BACKUP_FOLDER_NAME, OneDriveAuthenticationConstants.BACKUP_NAME)) .Content .Request() .PutAsync <Item>(dbstream); return(uploadedItem != null ? TaskCompletionType.Successful : TaskCompletionType.Unsuccessful); } } catch (OneDriveException ex) { Insights.Report(ex, Insights.Severity.Error); return(TaskCompletionType.Unsuccessful); } }
/// <summary> /// Uploads a copy of the current database. /// </summary> /// <returns>Returns a TaskCompletionType which indicates if the task was successful or not</returns> public async Task <bool> Upload() { if (OneDriveClient == null) { OneDriveClient = await oneDriveAuthenticator.LoginAsync(); } await LoadBackupFolder(); await LoadArchiveFolder(); await DeleteCleanupOldBackups(); await ArchiveCurrentBackup(); using (var dbstream = fileStore.OpenRead(DatabaseConstants.DB_NAME)) { var uploadedItem = await OneDriveClient .Drive .Root .ItemWithPath(Path.Combine(DatabaseConstants.BACKUP_FOLDER_NAME, DatabaseConstants.BACKUP_NAME)) .Content .Request() .PutAsync <Item>(dbstream); return(uploadedItem != null); } }
/// <inheritdoc /> public async Task <bool> CreateNewBackup() { if (!connectivity.IsConnected) { throw new NetworkConnectionException(); } using (var dbstream = fileStore.OpenRead(DatabaseConstants.DB_NAME)) { return(await backupService.Upload(dbstream)); } }
private async Task <bool> CreateNewBackup() { if (!connectivity.IsConnected) { throw new NetworkConnectionException(); } using (var dbStream = fileStore.OpenRead(DatabaseConstants.DB_NAME)) { return(await cloudBackupService.Upload(dbStream) .ConfigureAwait(false)); } }
public override Stream GetAttachment(string id, string attachmentName) { var entityAttachmentDir = AttachmentsDirectoryPath + "/" + id; var attachmentFilePath = entityAttachmentDir + "/" + attachmentName; if (!Exist(id)) { throw new KeyNotFoundNoSQLException(); } if (!fileStore.Exists(attachmentFilePath)) { throw new AttachmentNotFoundNoSQLException(); } return(fileStore.OpenRead(attachmentFilePath)); }
/// <summary> /// Uploads a copy of the current database. /// </summary> /// <returns>Returns a TaskCompletionType which indicates if the task was successful or not</returns> public async Task <bool> Upload() { if (OneDriveClient.IsAuthenticated) { await GetBackupFolder(); } using (var dbstream = fileStore.OpenRead(DatabaseConstants.DB_NAME)) { var uploadedItem = await OneDriveClient .Drive .Root .ItemWithPath(Path.Combine(DatabaseConstants.BACKUP_FOLDER_NAME, DatabaseConstants.BACKUP_NAME)) .Content .Request() .PutAsync <Item>(dbstream); return(uploadedItem != null); } }
private async Task <List <Session> > GetSessionsAsync(bool forceRefresh = false) { if (forceRefresh || (DateTime.UtcNow - Settings.LastSyncTime).TotalMinutes >= SessionRefreshAfterMinutes || !_fileStore.Exists(SessionsFileName)) { await DownloadSessionsAsync(); } var sessionData = _fileStore.OpenRead(SessionsFileName); var sessions = _jsonConverter.DeserializeObject <Session[]>(sessionData); #if DEBUG foreach (var session in sessions) { var num = (session.id % 11) + 1; session.sessionStartDate = GetRandomSessionTime(num); session.sessionTime = session.sessionStartDate.ToString("hh:mm tt dddd"); session.startTime = num.ToString(); } #endif return(new List <Session>(sessions)); }
public byte[] LoadImage(string name) { var path = this.fileStore.NativePath(nativePath) + name; return(ReadFully(fileStore.OpenRead(path))); }