예제 #1
0
        /// <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));
        }
예제 #2
0
        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));
        }
예제 #3
0
        /// <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));
        }
예제 #4
0
        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));
        }