diff --git a/Auditing/VotingEventEncoding.cs b/Auditing/VotingEventEncoding.cs index 9090d87..ea45fbd 100644 --- a/Auditing/VotingEventEncoding.cs +++ b/Auditing/VotingEventEncoding.cs @@ -7,7 +7,7 @@ namespace Webvoto.VotingSystem.Auditing; public static class VotingEventEncoding { - public static readonly int LatestVersion = 4; // itentionally not a const! + public static readonly int LatestVersion = 5; // itentionally not a const! public static byte[] Encode(VotingEventRecord ve, int version, byte[] lastEventSignature = null) => Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(getFields(ve, version, lastEventSignature))); @@ -77,6 +77,14 @@ .. getFields(ve, 3), ve.VoterAddressId?.ToString(), ], + 5 => [ + .. getFields(ve, 4), + ve.GeolocationTimestamp?.ToString("u"), + ve.GeolocationLatitude?.ToString(), + ve.GeolocationLongitude?.ToString(), + ve.GeolocationAccuracy?.ToString(), + ], + _ => throw new NotImplementedException() }; } diff --git a/Auditing/VotingEventRecord.cs b/Auditing/VotingEventRecord.cs index 007f0fb..3a53c1e 100644 --- a/Auditing/VotingEventRecord.cs +++ b/Auditing/VotingEventRecord.cs @@ -85,5 +85,13 @@ public class VotingEventRecord { public Guid? CampaignNotificationId { get; set; } public Guid? VoterAddressId { get; set; } + + public DateTime? GeolocationTimestamp { get; set; } + + public double? GeolocationLatitude { get; set; } + + public double? GeolocationLongitude { get; set; } + + public double? GeolocationAccuracy { get; set; } } } diff --git a/Counter/Csv/CsvReaderBase.cs b/Counter/Csv/CsvReaderBase.cs index 1e8b01d..2ee1797 100644 --- a/Counter/Csv/CsvReaderBase.cs +++ b/Counter/Csv/CsvReaderBase.cs @@ -45,6 +45,8 @@ public IEnumerable GetRecords() { protected int? ParseNullableInt(string s) => IsNull(s) ? null : int.Parse(s); + protected double? ParseNullableDouble(string s) => IsNull(s) ? null : double.Parse(s); + protected bool? ParseNullableBool(string s) => IsNull(s) ? null : s switch { "0" => false, "1" => true, diff --git a/Counter/Csv/VotingEventsCsvReader.cs b/Counter/Csv/VotingEventsCsvReader.cs index 3e86659..4c9692d 100644 --- a/Counter/Csv/VotingEventsCsvReader.cs +++ b/Counter/Csv/VotingEventsCsvReader.cs @@ -114,6 +114,19 @@ public class VotingEventCsvRecord { // V4 [Optional] public string VoterAddressId { get; set; } + + // V5 + [Optional] + public string GeolocationTimestamp { get; set; } + + [Optional] + public string GeolocationLatitude { get; set; } + + [Optional] + public string GeolocationLongitude { get; set; } + + [Optional] + public string GeolocationAccuracy { get; set; } } public class VotingEventsCsvReader : CsvReaderBase { @@ -173,5 +186,9 @@ public static VotingEventsCsvReader Open(FileInfo file) { PasswordId = ParseNullableGuid(r.PasswordId), CampaignNotificationId = ParseNullableGuid(r.CampaignNotificationId), VoterAddressId = ParseNullableGuid(r.VoterAddressId), + GeolocationTimestamp = ParseNullableDate(r.GeolocationTimestamp), + GeolocationLatitude = ParseNullableDouble(r.GeolocationLatitude), + GeolocationLongitude = ParseNullableDouble(r.GeolocationLongitude), + GeolocationAccuracy = ParseNullableDouble(r.GeolocationAccuracy) }; }