public JourneyData GetSpecificJourney(int journeyId) { var journey = repoService.GetList <JourneyData>().FirstOrDefault(t => t.JourneyId == journeyId); if (journey == null) { var _ = JourneysList.FirstOrDefault(t => t.JourneyId == journeyId); if (_ != null) { journey = new JourneyData(); journey.JourneyId = journeyId; journey.JourneyEndDate = _.EndDate; journey.JourneyStartDate = _.StartDate; journey.JourneyNumber = _.JourneyNumber; } } if (journey != null) { journey.GPSData = new List <JourneyCoordinates>(); journey.GPSData.AddRange(repoService.GetList <JourneyCoordinates>().Where(t => t.JourneyId == journeyId).ToList()); } return(journey); }
void GetAndProcessLocation(bool start = false) { if (JourneyData == null) { JourneyData = new JourneyData(); } if (start) { JourneyData.JourneyStartDate = DateTime.Now; JourneyId = JourneyData.JourneyId = JourneyData.JourneyNumber = repoService.Count <JourneyData>(); var data = locService.GetLocationData; data.id = (int)JourneyId; data.EventName = "ST"; data.datapoint = DataPoint = 0; JourneyData.GPSData = new List <JourneyCoordinates> { new JourneyCoordinates { Latitude = data.Latitude, Longitude = data.Longitude, JourneyId = data.id } }; locPoint = data; StoreSQL(); logService.WriteLog("JourneyManager:StartJourney", "Pending journey start logged"); try { if (powerService.CurrentPower < 30) { logService.WriteLog("JourneyManager:StartJourney", "User started journey with power save mode enabled. Unstable results expected."); } } catch (Exception ex) { logService.WriteLog("JourneyManager:StartJourney", "Error in Setting Power Service"); logService.WriteLog("JourneyManager:StartJourney", ex.Message); } } else { JourneyData.JourneyEndDate = DateTime.Now; var data = locService.GetLocationData; data.id = (int)JourneyId; data.EventName = "OFF"; data.datapoint = DataPoint; JourneyData.GPSData.Add(new JourneyCoordinates { Latitude = data.Latitude, Longitude = data.Longitude, JourneyId = data.id }); StoreSQL(); MessageQueue = journeyService.EndJourney(); logService.WriteLog("JourneyManager:EndJourney", "Journey ended"); if (powerService.CurrentPower < 30) { logService.WriteLog("Journey failed to record", "No location could be found. Please ensure sure that power saving mode on your device is disabled whilst driving."); } var locationsForSave = new List <LocationDetails>(); lock (new object()) { JourneyData.GPSData.ForEach(j => locationsForSave.Add(new LocationDetails(j.Latitude, j.Longitude, (new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).AddMilliseconds(DateTime.Now.TimeOfDay.TotalMilliseconds).ToLocalTime()))); StoreSQL(); JourneyData.GPSData.Clear(); } } }