/// <summary> /// Deletes the snapshot identified by <paramref name="metadata" />. /// This call is protected with a circuit-breaker /// </summary> protected override Task DeleteAsync(SnapshotMetadata metadata) { var table = _client.Value.GetTableReference(_settings.TableName); TableOperation getOperation = TableOperation.Retrieve <SnapshotEntry>(metadata.PersistenceId, SnapshotEntry.ToRowKey(metadata.SequenceNr)); TableResult result = table.Execute(getOperation); TableOperation deleteOperation = TableOperation.Delete((SnapshotEntry)result.Result); return(table.ExecuteAsync(deleteOperation)); }
private static SelectedSnapshot ToSelectedSnapshot(SnapshotEntry entry) { var payload = JsonConvert.DeserializeObject(entry.Payload, Type.GetType(entry.Manifest)); return(new SelectedSnapshot(new SnapshotMetadata(entry.PartitionKey, long.Parse(entry.RowKey), new DateTime(entry.SnapshotTimestamp)), payload)); }
/// <summary> /// Asynchronously saves a snapshot. /// This call is protected with a circuit-breaker /// </summary> protected override Task SaveAsync(SnapshotMetadata metadata, object snapshot) { var table = _client.Value.GetTableReference(_settings.TableName); TableOperation upsertOperation = TableOperation.Insert(ToSnapshotEntry(metadata, snapshot)); var entity = (SnapshotEntry)table.Execute(TableOperation.Retrieve <SnapshotEntry>(metadata.PersistenceId, SnapshotEntry.ToRowKey(metadata.SequenceNr))).Result; if (entity != null) { entity.Payload = JsonConvert.SerializeObject(snapshot); upsertOperation = TableOperation.Replace(entity); } return(table.ExecuteAsync(upsertOperation)); }
private static TableQuery <SnapshotEntry> BuildSnapshotTableQuery(string persistenceId, SnapshotSelectionCriteria criteria) { string comparsion = TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, persistenceId), TableOperators.And, TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, SnapshotEntry.ToRowKey(criteria.MaxSequenceNr))); if (criteria.MaxTimeStamp != DateTime.MinValue && criteria.MaxTimeStamp != DateTime.MaxValue) { comparsion = TableQuery.CombineFilters( comparsion, TableOperators.And, TableQuery.GenerateFilterConditionForLong("SnapshotTimestamp", QueryComparisons.LessThanOrEqual, criteria.MaxTimeStamp.Ticks)); } return(new TableQuery <SnapshotEntry>().Where(comparsion)); }