From 74319ccf09b82776179939fe087a837f1864c0e1 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sun, 8 Oct 2017 20:29:42 +0200 Subject: [PATCH] come work on sensorHisotries #77 --- DbStructure/User/SensorHistory.cs | 1 + Quickbird/Services/DataSyncService.cs | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/DbStructure/User/SensorHistory.cs b/DbStructure/User/SensorHistory.cs index cdb4faa..789fc68 100644 --- a/DbStructure/User/SensorHistory.cs +++ b/DbStructure/User/SensorHistory.cs @@ -7,6 +7,7 @@ public class SensorHistory { + //EDIT EF code to make this NOT mapped to a table! Otherwise we will have trouble! //this is used for network communication and by the program at runtime! [Required] diff --git a/Quickbird/Services/DataSyncService.cs b/Quickbird/Services/DataSyncService.cs index 654e745..14eedb3 100644 --- a/Quickbird/Services/DataSyncService.cs +++ b/Quickbird/Services/DataSyncService.cs @@ -244,6 +244,10 @@ private static async Task GetRequestSensorHistoryAsync(MainDbContext db) var table = nameof(db.SensorsHistory); var errors = ""; + //Query local sensors and locations. Mostly used for debug. + var LocalSensors = db.Sensors.ToList(); + var LocalLocation = db.Locations.ToList(); + // Download all the data for each device in turn. foreach (var device in devices) { @@ -322,8 +326,6 @@ private static async Task GetRequestSensorHistoryAsync(MainDbContext db) if (remoteBlocks.Any()) { - var LocalSensors = db.Sensors.ToList(); - var LocalLocation = db.Locations.ToList(); var lastDayOfThisDownloadSet = DateTimeOffset.MinValue; foreach (var remoteBlock in remoteBlocks) @@ -378,7 +380,8 @@ private static async Task GetRequestSensorHistoryAsync(MainDbContext db) { // The data is pulled from the database as serialised raw data blobs. localBlock.DeserialiseData(); - localBlock.LocationID = remoteBlock.LocationID; + localBlock.LocationID = remoteBlock.LocationID; + var linkedLocation = LocalLocation.FirstOrDefault(loc => loc.ID == remoteBlock.LocationID); // The merged object merges using the deserialised Data property. var merged = SensorHistory.Merge(localBlock, remoteBlock);