private async Task <GeolocationDto> GetLocationMethod() { // TODO: try catch var result = new GeolocationDto(); var loc = await Geolocation.GetLastKnownLocationAsync(); if (loc == null) { // potential long running method var request = new GeolocationRequest(GeolocationAccuracy.Best); loc = await Geolocation.GetLocationAsync(request); } if (loc != null) { result.Latitude = loc.Latitude; result.Longitude = loc.Longitude; result.Altitude = loc.Altitude; result.Accuracy = loc.Accuracy; result.VerticalAccuracy = loc.VerticalAccuracy; result.Speed = loc.Speed; result.Course = loc.Course; result.Timestamp = loc.Timestamp; //https://stackoverflow.com/questions/42569245/detect-or-prevent-if-user-uses-fake-location result.IsMock = loc.IsFromMockProvider; } return(result); }
public async Task <bool> UpdateGeodata(ClaimsPrincipal userClaims, GeolocationDto geolocation) { var user = await _userManager.GetUserAsync(userClaims); if (user == null) { return(false); } _profileRepo.LoadProfileWithGeo(user); user.Profile.LastGeolocation.Latitude = user.Profile.Geolocation.Latitude; user.Profile.LastGeolocation.Longitude = user.Profile.Geolocation.Longitude; user.Profile.Geolocation.Latitude = geolocation.Latitude; user.Profile.Geolocation.Longitude = geolocation.Longitude; _geoRepo.Update(user.Profile.Geolocation); _lastGeoRepo.Update(user.Profile.LastGeolocation); _geolocationHistoryRepo.AddGeolocationHistoryRecord(user.Profile, geolocation); _logger.LogCritical($"Before commit: {geolocation.Longitude} : {geolocation.Latitude}"); if (!_uow.Commit()) { return(false); } ApplyGeolocationToAllFriends(user); return(true); }
public IHttpActionResult GetProcessInstanceGeo(Guid?processInstanceId) { //Recupero l'entity ProcessInstance entity = _processInstanceService.Get <ProcessInstance, Guid?>(processInstanceId); //Compongo il dto GeolocationDto dto = Mapper.Map <GeolocationDto>(entity); //Ritorno i risultati return(Ok(dto)); }
private GeolocationHistory CreateNewHistoryRecord(Profile profile, GeolocationDto geolocation) { var geolocationHistoryRecord = new GeolocationHistory { Time = DateTime.Now, Profile = profile, ProfileId = profile.Id, Latitude = geolocation.Latitude, Longitude = geolocation.Longitude, }; return(geolocationHistoryRecord); }
public GeolocationDto GetUserIP() { var API_KEY = "at_ENcYw3BCj6JYzkowcbp4QfrhY0dpx"; var API_URL = "https://geo.ipify.org/api/v1?"; string url = API_URL + $"apiKey={API_KEY}"; string resultData = string.Empty; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); using (HttpWebResponse response = (HttpWebResponse)req.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { resultData = reader.ReadToEnd(); } GeolocationDto model = JsonConvert.DeserializeObject <GeolocationDto>(resultData); return(model); }
public async Task UpdateGeodata(GeolocationDto geolocation) { await _profileService.UpdateGeodata(Context.User, geolocation); }
public void AddGeolocationHistoryRecord(Profile profile, GeolocationDto geolocation) { DbSet.Add(this.CreateNewHistoryRecord(profile, geolocation)); }