public void WriteLocationHistory(string userAccount, GoogleJsonLocations googleJsonLocations) { #region INSERT OR IGNORE INTO LocationHistory string sqlCommand = "INSERT OR IGNORE INTO LocationHistory (UserAccount, TimeStamp, Latitude, Longitude, Altitude, Accuracy) " + "Values (@UserAccount, @TimeStamp, @Latitude, @Longitude, @Altitude, @Accuracy) "; using (CommonSqliteCommand commandDatabase = new CommonSqliteCommand(sqlCommand, dbTools.ConnectionDatabase)) //, sqlTransactionSelect)) { //commandDatabase.Prepare(); commandDatabase.Parameters.AddWithValue("@UserAccount", userAccount); commandDatabase.Parameters.AddWithValue("@TimeStamp", dbTools.ConvertFromDateTimeToDBVal(googleJsonLocations.Timestamp)); commandDatabase.Parameters.AddWithValue("@Latitude", googleJsonLocations.Latitude); commandDatabase.Parameters.AddWithValue("@Longitude", googleJsonLocations.Longitude); commandDatabase.Parameters.AddWithValue("@Altitude", googleJsonLocations.Altitude); commandDatabase.Parameters.AddWithValue("@Accuracy", googleJsonLocations.Accuracy); commandDatabase.ExecuteNonQuery(); // Execute the query } #endregion }
private void ExtractPlacemarks(Feature feature) { // Is the passed in value a Placemark? if (feature is Placemark placemark) { SharpKml.Dom.GX.Track track = placemark.Geometry as SharpKml.Dom.GX.Track; SharpKml.Base.Vector[] vector = track.Coordinates.ToArray(); DateTime[] whenElement = track.When.ToArray(); var sqlTransactionBatch = googleLocationDatabaseCache.TransactionBegin(); for (int i = 0; i < vector.Length; i++) { if (i % 5000 == 0) { googleLocationDatabaseCache.TransactionCommit(sqlTransactionBatch); sqlTransactionBatch = googleLocationDatabaseCache.TransactionBegin(); } LocationFoundParam?.Invoke(this, i, i, vector.Length); GoogleJsonLocations googleJsonLocations = new GoogleJsonLocations(); googleJsonLocations.Accuracy = 0; googleJsonLocations.Altitude = vector[i].Altitude == null ? 0 : (float)vector[i].Altitude; googleJsonLocations.Latitude = (float)vector[i].Latitude; googleJsonLocations.Longitude = (float)vector[i].Longitude; googleJsonLocations.Timestamp = whenElement[i]; googleLocationDatabaseCache.WriteLocationHistory(username, googleJsonLocations); } googleLocationDatabaseCache.TransactionCommit(sqlTransactionBatch); } else { // Is it a Container, as the Container might have a child Placemark? if (feature is Container container) { // Check each Feature to see if it's a Placemark or another Container foreach (Feature f in container.Features) { ExtractPlacemarks(f); } } } }
public void Add(GoogleJsonLocations googleJsonLocationsItem) { googleLocationItems.Add(googleJsonLocationsItem.Timestamp, googleJsonLocationsItem); }