public async Task PrepareLocationHistoryAsync(MemoryStream memoryStream, string fileName, string requestId, ProgressChangedEventHandler callback) { _ = _repository.SaveLocationHistoryFileAsync(memoryStream, fileName, requestId); var locationHistory = await BorderCrossingHelper.ExtractJsonAsync(memoryStream, callback); AddLocationHistory(locationHistory, requestId); }
public async Task <List <CheckPoint> > ParseLocationHistoryAsync(LocationHistory locationHistory, QueryRequest model, ProgressChangedEventHandler callback) { var locations = BorderCrossingHelper.PrepareLocations(locationHistory, model.IntervalType); var filteredLocations = locations.Where(l => l.Date >= model.StartDate && l.Date <= model.EndDate).OrderBy(l => l.TimestampMsUnix).ToList(); var currentLocation = filteredLocations.First(); var currentCountry = GetCountryName(currentLocation.Point); var i = 0; var count = filteredLocations.Count(); var checkPoints = new List <CheckPoint> { BorderCrossingHelper.LocationToCheckPoint(currentLocation, currentCountry) }; foreach (var location in filteredLocations) { await Task.Run(() => { i++; callback(this, new ProgressChangedEventArgs((int)(100.0 * i / count), null)); var countryName = GetCountryName(location.Point); if (currentCountry == countryName) { currentLocation = location; return; } var range = locationHistory.Locations.Where(lh => lh.TimestampMsUnix >= currentLocation.TimestampMsUnix && lh.TimestampMsUnix <= location.TimestampMsUnix).ToList(); var checkPoint = BorderCrossingHelper.FindCheckPoint(range, currentLocation, currentCountry, location, countryName, GetCountryName); checkPoints.Add(checkPoint); currentCountry = countryName; currentLocation = location; }); } var last = filteredLocations.Last(); checkPoints.Add(BorderCrossingHelper.LocationToCheckPoint(last, GetCountryName(last.Point))); return(checkPoints); }