public async Task ReplicationConfig_DailyConfig_LatestShouldGiveStateSequence() { Http.HttpHandler.Default = new ReplicationServerMockHttpHandler(); var replicationConfig = new ReplicationConfig("https://planet.openstreetmap.org/replication/day/", 24 * 3600); var result = await replicationConfig.LatestReplicationState(); Assert.Equal(2569, result.SequenceNumber); }
/// <summary> /// Guesses the sequence number for the diff overlapping the given date time. /// </summary> /// <param name="config">The replication config.</param> /// <param name="dateTime">The date time.</param> /// <returns>The sequence number.</returns> /// <remarks>This is just a guess because the time doesn't always exactly align with the increase of sequence numbers.</remarks> public static async Task <long> GuessSequenceNumberAt(this ReplicationConfig config, DateTime dateTime) { var latest = await config.LatestReplicationState(); var start = latest.EndTimestamp.AddSeconds(-config.Period); var diff = (int)(start - dateTime).TotalSeconds; var leftOver = (diff % config.Period); var sequenceOffset = (diff - leftOver) / config.Period; return(latest.SequenceNumber - sequenceOffset - 1); }
/// <summary> /// Gets an enumerator to loop over incoming diffs. /// </summary> /// <param name="config">The replication config.</param> /// <param name="sequenceNumber">The sequence number, latest if empty.</param> /// <returns>The enumerator moved to the given sequence number or null if the sequence number doesn't exist.</returns> public static async Task <ReplicationDiffEnumerator> GetDiffEnumerator(this ReplicationConfig config, long?sequenceNumber = null) { if (sequenceNumber == null) { // get the latest number. var latest = await config.LatestReplicationState(); sequenceNumber = latest.SequenceNumber; } var enumerator = new ReplicationDiffEnumerator(config); if (!await enumerator.MoveTo(sequenceNumber.Value)) { return(null); } return(enumerator); }