/// <summary> /// Builds a <see cref="FilterDefinition{BsonDocument}" /> corresponding to the <see cref="EventHorizonKey" /> supplied /// </summary> /// <param name="key">An <see cref="EventHorizonKey" /></param> /// <returns>A <see cref="FilterDefinition{BsonDocument}" /> corresponding to the <see cref="EventHorizonKey" /></returns> public static FilterDefinition <BsonDocument> ToFilter(this EventHorizonKey key) { var builder = Builders <BsonDocument> .Filter; var filter = builder.Eq(Constants.ID, key.AsId()); return(filter); }
/// <inheritdoc /> public ulong GetOffset(EventHorizonKey eventHorizon) { using (var es = _database.GetContext()) { return(es.GeodesicsOffsets.SingleOrDefault(_ => _.Id == eventHorizon.AsId())?.Value ?? 0); } }
/// <summary> /// Transforms the <see cref="EventHorizonKey"/> and offset to <see cref="BsonDocument"/> /// </summary> /// <param name="key"></param> /// <param name="offset"></param> /// <returns></returns> public static BsonDocument ToOffsetBson(this EventHorizonKey key, ulong offset) { return(new BsonDocument(new Dictionary <string, object> { { Constants.ID, key.AsId() }, { Constants.OFFSET, offset } })); }
/// <inheritdoc /> public void SetOffset(EventHorizonKey key, ulong offset) { using (var es = _database.GetContext()) { //TODO: this can be optimized so that the update is the thing we expect most and the insert is the edge case var commandText = "INSERT OR REPLACE INTO GeodesicsOffsets (Id, Value) VALUES (@Id,@Value);"; var id = new SqliteParameter("@Id", key.AsId()); var value = new SqliteParameter("@Value", offset); es.Database.ExecuteSqlCommand(commandText, id, value); } }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <param name="offset"></param> /// <returns></returns> public static GeodesicsOffset From(EventHorizonKey key, ulong offset) { return(new GeodesicsOffset { Id = key.AsId(), Value = offset }); }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <param name="offset"></param> /// <param name="partitionKey"></param> /// <returns></returns> public static Offset From(EventHorizonKey key, ulong offset, string partitionKey) { return(new Offset { Id = key.AsId(), Value = offset, PartitionKey = partitionKey }); }
Offset GetOffsetDoc(EventHorizonKey key) { return(_config.Client.CreateDocumentQuery <Offset>(_config.OffsetsUri, GetFeedOptions()) .Where(_ => _.Id == key.AsId()).Take(1).AsEnumerable().SingleOrDefault()); }