public async Task <SyncState> ReadAsync(CancellationToken cancellationToken) { BlockBlobClient blob = GetBlockBlobClient(); if (await blob.ExistsAsync(cancellationToken)) { string syncStateString; try { await using (var stream = new MemoryStream()) { await blob.DownloadToAsync(stream, cancellationToken); syncStateString = _jsonTextEncoding.GetString(stream.ToArray()); } } catch (Exception ex) { throw new DataStoreException(ex); } return(JsonConvert.DeserializeObject <SyncState>(syncStateString)); } return(SyncState.CreateInitialSyncState()); }
public async Task <SyncState> ReadAsync(CancellationToken cancellationToken = default) { CloudTable table = _client.GetTableReference(Constants.SyncStateTableName); TableOperation retrieveOperation = TableOperation.Retrieve <SyncStateEntity>(Constants.SyncStatePartitionKey, Constants.SyncStateRowKey); TableResult result = await table.ExecuteAsync(retrieveOperation, cancellationToken); return(result.Result is SyncStateEntity syncState ? new SyncState(syncState.SyncedSequence, syncState.Timestamp) : SyncState.CreateInitialSyncState()); }
public async Task <SyncState> ReadAsync(CancellationToken cancellationToken = default) { TableClient tableClient = _tableServiceClient.GetTableClient(Constants.SyncStateTableName); try { var entity = await tableClient.GetEntityAsync <SyncStateEntity>(Constants.SyncStatePartitionKey, Constants.SyncStateRowKey, cancellationToken : cancellationToken); return(new SyncState(entity.Value.SyncedSequence, entity.Value.Timestamp.Value)); } catch (RequestFailedException) { return(SyncState.CreateInitialSyncState()); } }