private void SaveEditedParkingLocation() { // save the edits var parkingLocation = Window.ParkingLocationControl.GetCurrentObject() as ParkingLocation; var newParkingLocationName = DisplayItem.ParkingLocationName; var newParkingLocationGPS = new GPSCoordinates(DisplayItem.ParkingLocationLatitude, DisplayItem.ParkingLocationLongitude); // write only to database if there was a change if ((parkingLocation.Name != newParkingLocationName) || (parkingLocation.Coordinates.Latitude != newParkingLocationGPS.Latitude) || (parkingLocation.Coordinates.Longitude != newParkingLocationGPS.Longitude)) { if (DataAccessAdapter.EditParkingLocationName_GPS(parkingLocation.Id, newParkingLocationName, newParkingLocationGPS, out string errorMessage) == PersistenceManager.E_DBReturnCode.no_error) { ShowMessage("Parking location data successfully changed.", E_MessageType.info); // synchronize the display items of the main window and the lister window ViewModelManager.SynchronizeDisplayItems(DisplayItem, _listerWindow.Controler.CurrentDisplayItem); } else { ShowMessage("Error editing Parking location data." + errorMessage, E_MessageType.error); } } else { ShowMessage("No change done.", E_MessageType.info); } }
public async Task <ActionResult <GPSCoordinates> > PostGPSCoordinates(GPSCoordinatesResource gpsCoortinates) { gpsCoortinates.TimeStamp = DateTime.Now; if (gpsCoortinates.Speed == 0) //Wyznaczenie prędkości na podstawie ostatniego wpisu { var gps = GetLastGPSCoordinate(gpsCoortinates.CarId); if (gps != null) { double deltaTimeSeconds = gpsCoortinates.TimeStamp.Subtract(gps.TimeStamp).TotalSeconds; if (deltaTimeSeconds < 60) //Jeśli poprzedni wpis był mniej niż 60 sekund temu oblicz prędkość { double deltaX = Math.Abs(gpsCoortinates.Latitude - gps.Latitude); double deltaY = Math.Abs(gpsCoortinates.Longitude - gps.Longitude); double distance = Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2)) * 110.57; //double speedD = ((distance / deltaTimeSeconds) * 3600); int speed = (int)((distance / deltaTimeSeconds) * 3600); gpsCoortinates.Speed = speed; } } } GPSCoordinates gpsDb = _mapper.Map <GPSCoordinates>(gpsCoortinates); gpsDb.CarId = gpsCoortinates.CarId; gpsDb.Car = await _context.Cars.FindAsync(gpsCoortinates.CarId); _context.GpsCoordinateses.Add(gpsDb); await _context.SaveChangesAsync(); await _hub.Clients.All.SendAsync(gpsCoortinates); return(CreatedAtAction("GetGPSCoordinates", new { id = gpsCoortinates.Id }, gpsCoortinates)); }
public static Coordinate GPSToLatLong(GPSCoordinates gps) { const int accuracy = 5; double latitude = 0; latitude += gps.Latitude.Degree + gps.Latitude.Minute / 60 + gps.Latitude.Second / 3600; if (gps.Latitude.Compass == Compass.South) { latitude *= -1; } latitude = Math.Round(latitude, accuracy); double longitude = 0; longitude += gps.Longitude.Degree + gps.Longitude.Minute / 60 + gps.Longitude.Second / 3600; if (gps.Longitude.Compass == Compass.West) { longitude *= -1; } longitude = Math.Round(longitude, accuracy); return(new Coordinate(latitude, longitude)); }
public Task UpdateCoordinatesAsync(GPSCoordinates coordinates) { ActorEventSource.Current.ActorMessage(this, "Updating GPS coordiantes to VehicleId to {0}", this.State.CurrentVehicleLiveData.VehicleId); this.State.CurrentVehicleLiveData.GPSCoordinates = coordinates; return(Task.FromResult(true)); }
public void GPSUpdatedHandler(GPSCoordinates coordinates) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("Coordinates")); } }
// PUT api/LiveVehicle/3/GPSCoordinates // HttpPut "{vehicleId}/GPSCoordinates" private static void UpdateGPSCoordinates(int vehicleID, GPSCoordinates coordinates) { Uri serviceAddress = new Uri(SeatMapGatewayServiceUrl + "LiveVehicle/" + vehicleID.ToString() + "/GPSCoordinates"); HttpWebRequest req = WebRequest.CreateHttp(serviceAddress); string data = JsonConvert.SerializeObject(coordinates); //This gives you the byte array. var dataToSend = Encoding.UTF8.GetBytes(data); req.ContentType = "application/json"; req.ContentLength = dataToSend.Length; req.Method = "PUT"; req.GetRequestStream().Write(dataToSend, 0, dataToSend.Length); var response = req.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); //Console.WriteLine("********************************"); Console.WriteLine(responseFromServer); //Console.WriteLine(" "); }
private long AddParkingLocation(string parkingLocationName, GPSCoordinates parkingLocationGPS, out string errorMessage) { long newId = -1; // write to database (newId == -1 in case of error, so no additional error handling required) DataAccessAdapter.AddParkingLocation(parkingLocationName, parkingLocationGPS, out newId, out errorMessage); return(newId); }
private void SaveEditedShootingLocation() { // save the edits var shootingLocation = Window.ShootingLocationControl.GetCurrentObject() as ShootingLocation; var newShootingLocationName = DisplayItem.ShootingLocationName; var newShootingLocationGPS = new GPSCoordinates(DisplayItem.ShootingLocationLatitude, DisplayItem.ShootingLocationLongitude); var newPhoto1 = ImageTools.BitmapImageToByteArray(DisplayItem.Photo_1); var newPhoto2 = ImageTools.BitmapImageToByteArray(DisplayItem.Photo_2); var newPhoto3 = ImageTools.BitmapImageToByteArray(DisplayItem.Photo_3); var oldPhoto1 = shootingLocation.Photos?.ElementAtOrDefault(0)?.ImageBytes; var oldPhoto2 = shootingLocation.Photos?.ElementAtOrDefault(1)?.ImageBytes; var oldPhoto3 = shootingLocation.Photos?.ElementAtOrDefault(2)?.ImageBytes; // write only to database if there was a change if ((shootingLocation.Name != newShootingLocationName) || (shootingLocation.Coordinates.Latitude != newShootingLocationGPS.Latitude) || (shootingLocation.Coordinates.Longitude != newShootingLocationGPS.Longitude) || (!ImageTools.SamePhoto(oldPhoto1, newPhoto1)) || (!ImageTools.SamePhoto(oldPhoto2, newPhoto2)) || (!ImageTools.SamePhoto(oldPhoto3, newPhoto3))) { var newPhotosAsByteArray = new List <byte[]>(); if (newPhoto1 != null) { newPhotosAsByteArray.Add(newPhoto1); } if (newPhoto2 != null) { newPhotosAsByteArray.Add(newPhoto2); } if (newPhoto3 != null) { newPhotosAsByteArray.Add(newPhoto3); } if (DataAccessAdapter.EditShootingLocation(shootingLocation.Id, newShootingLocationName, newShootingLocationGPS, newPhotosAsByteArray, out string errorMessage) == PersistenceManager.E_DBReturnCode.no_error) { ShowMessage("Shooting location data successfully changed.", E_MessageType.info); // synchronize the display items of the main window and the lister window // do this for the current item (detail view) and the concerned item in the list view (AllDisplayItems) ViewModelManager.SynchronizeDisplayItems(DisplayItem, _listerWindow.Controler.CurrentDisplayItem); var selectedDisplayItem = _listerWindow.Controler.AllDisplayItems.FirstOrDefault(d => (d.Tag as ShootingLocation).Id == shootingLocation.Id); ViewModelManager.SynchronizeDisplayItems(DisplayItem, selectedDisplayItem); } else { ShowMessage("Error editing Shooting location data." + errorMessage, E_MessageType.error); } } else { ShowMessage("No change done.", E_MessageType.info); } }
//TBD to send to Azure Event Hubs //static readonly string EventHubName = Properties.Settings.Default.EventHubName; public static void SendEventDirectToServiceFabricMicroservice(GPSCoordinatesEvent gpsCoordVehicleEvent) { GPSCoordinates coordinates = new GPSCoordinates(); coordinates.Latitude = gpsCoordVehicleEvent.Latitude; coordinates.Longitude = gpsCoordVehicleEvent.Longitude; //Call Http Service to update GPS coordinates UpdateGPSCoordinates(gpsCoordVehicleEvent.VehicleId, coordinates); }
//[Route("{vehicleId}/GPSCoordinates", Name = "UpdateVehicleGPSCoordinates")] public IActionResult UpdateVehicleGPSCoordinates(int vehicleId, [FromBody] GPSCoordinates coordinates) { //Create and update the vehicle actor just in case it didn't exist ActorId vehicleActorId = new ActorId(vehicleId); var vehicleProxy = ActorProxy.Create <ILiveVehicleActor>(vehicleActorId, "fabric:/LiveVStatefulApp"); //Add/Update data to Vehicle Actor vehicleProxy.UpdateCoordinatesAsync(coordinates).Wait(); return(new HttpStatusCodeResult(200)); //200 OK }
public static void Go(GPSCoordinates coordinates) { var latitude = coordinates.Latitude; var longitude = coordinates.Longitude; var cpLat = GPSCoordinatesHelper.GetPosition(latitude, E_CoordinateType.Latitude); var cpLong = GPSCoordinatesHelper.GetPosition(longitude, E_CoordinateType.Longitude); var url = c_googleMapsPlaceUrl + new GPSCoordinatesHelper(latitude, cpLat).ToGoogleMapsString() + "+" + new GPSCoordinatesHelper(longitude, cpLong).ToGoogleMapsString(); Process.Start(c_chrome_exe, url); }
public async Task<GPSCoordinates> GetCurrentCoordinates() { var locator = new Geolocator() { DesiredAccuracy = 50 }; var coordinates = new GPSCoordinates(); if (locator.IsGeolocationEnabled && locator.IsGeolocationEnabled) { var pos = await locator.GetPositionAsync(timeout: 10000); coordinates.Latitude = pos.Latitude; coordinates.Longitude = pos.Longitude; } return coordinates; }
public void Localization_ConvertCoordinates_CorrectCoordinates() { GPSCoordinates gps = new GPSCoordinates( new GPSLocalization(46, 58, 41.0376, Compass.North), new GPSLocalization(23, 18, 12.582, Compass.East) ); Coordinate coordinate = Coordinates.GPSToLatLong(gps); Coordinate expectedCoordinate = new Coordinate(46.978066, 23.303495); double errorBound = 0.00001; Assert.InRange(coordinate.Latitude, expectedCoordinate.Latitude - errorBound, expectedCoordinate.Latitude + errorBound ); Assert.InRange(coordinate.Longitude, expectedCoordinate.Longitude - errorBound, expectedCoordinate.Longitude + errorBound ); }
public void Localization_ConvertCoordinates_2_CorrectCoordinates() { GPSCoordinates gps = new GPSCoordinates( new GPSLocalization(34, 33, 36.72, Compass.South), new GPSLocalization(58, 24, 50.7888, Compass.West) ); Coordinate coordinate = Coordinates.GPSToLatLong(gps); Coordinate expectedCoordinate = new Coordinate(-34.560200, -58.414108); double errorBound = 0.00001; Assert.InRange(coordinate.Latitude, expectedCoordinate.Latitude - errorBound, expectedCoordinate.Latitude + errorBound ); Assert.InRange(coordinate.Longitude, expectedCoordinate.Longitude - errorBound, expectedCoordinate.Longitude + errorBound ); }
static void UpdateCoordinatesBackward() { Console.WriteLine("\nUpdating vehicles' coordinates backward"); //UPDATE COORDINATES VEHICLE 1 ////////////////////////////////////////// int vehicleId1 = 1; GPSCoordinates coordinates1 = new GPSCoordinates(); //Seattle Pike's Place --> --> 47.608875, -122.340098 coordinates1.Latitude = 47.608875; coordinates1.Longitude = -122.340098; //Call Http Service to update GPS coordinates UpdateGPSCoordinates(vehicleId1, coordinates1); ///////////////////////////////////////////////////////////////////////// //UPDATE COORDINATES VEHICLE 2 ////////////////////////////////////////// int vehicleId2 = 2; GPSCoordinates coordinates2 = new GPSCoordinates(); //Seattle STARBUCKS ORIGINAL coordinates 47.610021, -122.342649 coordinates2.Latitude = 47.610021; coordinates2.Longitude = -122.342649; //Call Http Service to update GPS coordinates UpdateGPSCoordinates(vehicleId2, coordinates2); ///////////////////////////////////////////////////////////////////////// //UPDATE COORDINATES VEHICLE 3 ////////////////////////////////////////// int vehicleId3 = 3; GPSCoordinates coordinates3 = new GPSCoordinates(); //Seattle CONVENTION CENTER coordinates 47.612283, -122.331918 coordinates3.Latitude = 47.612283; coordinates3.Longitude = -122.331918; //Call Http Service to update GPS coordinates UpdateGPSCoordinates(vehicleId3, coordinates3); ///////////////////////////////////////////////////////////////////////// Console.WriteLine("##### END OF COORDINATES FORWARD UPDATE #####"); Console.WriteLine("#############################################"); }
static void UpdateCoordinatesForward() { Console.WriteLine("\nUpdating vehicles' coordinates forward"); //UPDATE COORDINATES VEHICLE 1 ////////////////////////////////////////// int vehicleId1 = 1; GPSCoordinates coordinates1 = new GPSCoordinates(); //Seattle Pike's Place --> move to North to 2nd Av. --> 47.609321, -122.339041 coordinates1.Latitude = 47.609321; coordinates1.Longitude = -122.339041; //Call Http Service to update GPS coordinates UpdateGPSCoordinates(vehicleId1, coordinates1); ///////////////////////////////////////////////////////////////////////// //UPDATE COORDINATES VEHICLE 2 ////////////////////////////////////////// int vehicleId2 = 2; GPSCoordinates coordinates2 = new GPSCoordinates(); //Starbucks 1st --> move to Virginia St. --> 47.610515, -122.343569 coordinates2.Latitude = 47.610515; coordinates2.Longitude = -122.343569; //Call Http Service to update GPS coordinates UpdateGPSCoordinates(vehicleId2, coordinates2); ///////////////////////////////////////////////////////////////////////// //UPDATE COORDINATES VEHICLE 3 ////////////////////////////////////////// int vehicleId3 = 3; GPSCoordinates coordinates3 = new GPSCoordinates(); //Seattle Convention Center --> move to 7th Av. --> 47.611636, -122.333409 coordinates3.Latitude = 47.611636; coordinates3.Longitude = -122.333409; //Call Http Service to update GPS coordinates UpdateGPSCoordinates(vehicleId3, coordinates3); ///////////////////////////////////////////////////////////////////////// Console.WriteLine("##### END OF COORDINATES FORWARD UPDATE #####"); Console.WriteLine("#############################################"); }
internal static E_DBReturnCode SmartAddCountry(SettingsDisplayItem displayItem, out string errorMessage) { var countryName = displayItem.CountryName; var areaName = displayItem.AreaName; var subAreaName = displayItem.SubAreaName; var subjectLocationName = displayItem.SubjectLocationName; double? subjectLocationNameLatitude = displayItem.SubjectLocationLatitude; double? subjectLocationNameLongitude = displayItem.SubjectLocationLongitude; GPSCoordinates subjectLocationCoordinates = new GPSCoordinates(subjectLocationNameLatitude, subjectLocationNameLongitude); // some consistency checks if (string.IsNullOrEmpty(countryName)) { throw new Exception("Country must be set when adding a country (DataAccessAdapter::SmartAddCountry).\n"); } if (!string.IsNullOrEmpty(subAreaName) && string.IsNullOrEmpty(areaName)) { throw new Exception("Area name must be set if SubArea name is set (DataAccessAdapter::SmartAddCountry\n"); } return(PersistenceManager.SmartAddCountry(countryName, areaName, subAreaName, subjectLocationName, subjectLocationCoordinates, out errorMessage)); }
internal static E_DBReturnCode SmartAddShootingLocation(LocationDisplayItem displayItem, long subjectLocationId, long parkingLocationId, out string errorMessage) { var photosAsByteArray = new List <byte[]>(); if (displayItem.Photo_1 != null) { photosAsByteArray.Add(ImageTools.BitmapImageToByteArray(displayItem.Photo_1)); } if (displayItem.Photo_2 != null) { photosAsByteArray.Add(ImageTools.BitmapImageToByteArray(displayItem.Photo_2)); } if (displayItem.Photo_3 != null) { photosAsByteArray.Add(ImageTools.BitmapImageToByteArray(displayItem.Photo_3)); } var shootingLocationName = displayItem.ShootingLocationName; var shootingLocationGPS = new GPSCoordinates(displayItem.ShootingLocationLatitude, displayItem.ShootingLocationLongitude); return(PersistenceManager.SmartAddShootingLocation(subjectLocationId, parkingLocationId, photosAsByteArray, shootingLocationName, shootingLocationGPS, out errorMessage)); }
/// <summary> /// (DEPRECATED) Binds the rover location data being sent by StatusUpdater to PushPin on the Map /// </summary> private void setRoverPinLocation() { bool messageReceived = false; var startTime = DateTime.UtcNow; roverCoordinates = new GPSCoordinates(); roverPin = new Pushpin(); //Wait for the StatusUpdater to send the location of the rover BEFORE the pushpin is set, or else DataBinding will not occur while (roverCoordinates.Location == null && (DateTime.UtcNow - startTime < TimeSpan.FromSeconds(2))) { //loop until the rover coordinates have been received, timeout after 2 seconds messageReceived = true; } //if the message was successfully received, bind the location if (messageReceived) { roverPin.Location = roverCoordinates.Location; formatRoverPin(); } }
private void SaveEditedSubjectLocation() { // save the edits var subLocation = Window.Settings_SubjectLocationControl.GetCurrentObject() as SubjectLocation; var newSubjectLocationName = DisplayItem.SubjectLocationName; var newSubjectLocationGPS = new GPSCoordinates(DisplayItem.SubjectLocationLatitude, DisplayItem.SubjectLocationLongitude); // write only to database if there was a change if ((subLocation.Name != newSubjectLocationName) || (subLocation.Coordinates.Latitude != newSubjectLocationGPS.Latitude) || (subLocation.Coordinates.Longitude != newSubjectLocationGPS.Longitude)) { if (DataAccessAdapter.EditSubjectLocationName_GPS(subLocation.Id, newSubjectLocationName, newSubjectLocationGPS, out string errorMessage) == PersistenceManager.E_DBReturnCode.no_error) { ShowMessage("Subject location data successfully changed.", E_MessageType.info); } else { ShowMessage("Error editing Subject location data." + errorMessage, E_MessageType.error); } } else { ShowMessage("No change done.", E_MessageType.info); } }
internal void SubjectLocationGoogleSearch() { var gps = new GPSCoordinates(DisplayItem.SubjectLocationLatitude, DisplayItem.SubjectLocationLongitude); GoogleMapsHelper.Go(gps); }
public GPSViewModel() { Coordinates = StatusUpdater.Instance.RoverStatus.GPSCoordinates; StatusUpdater.Instance.GPSCoordinatesUpdated += new StatusUpdater.GPSCoordinatesUpdatedDelegate(this.GPSUpdatedHandler); }
internal void Add() { // error message string errorMessage = string.Empty; // data from UI var subjectLocation = Window.Location_SubjectLocationControl.GetCurrentObject() as SubjectLocation; var parkingLocation = Window.ParkingLocationControl.GetCurrentObject() as ParkingLocation; var shootingLocationName = DisplayItem.ShootingLocationName; // db operations might take a while Mouse.OverrideCursor = Cursors.Wait; // set parking location (if new parking location, initial value is -1) long parkingLocationId = parkingLocation != null ? parkingLocation.Id : -1; // create new parking location if necessary if ((parkingLocation == null) && (!string.IsNullOrEmpty(DisplayItem.ParkingLocationName))) { // get name of parking location from UI var parkingLocationName = DisplayItem.ParkingLocationName; var parkingLocationGPS = new GPSCoordinates(DisplayItem.ParkingLocationLatitude, DisplayItem.ParkingLocationLongitude); parkingLocationId = AddParkingLocation(parkingLocationName, parkingLocationGPS, out errorMessage); if (parkingLocationId == -1) { ShowMessage("Error writing parking locations to database\n" + errorMessage, E_MessageType.error); return; } } // add country to database var success = DataAccessAdapter.SmartAddShootingLocation(DisplayItem, subjectLocation.Id, parkingLocationId, out errorMessage); switch (success) { case E_DBReturnCode.no_error: // update the lister view AddListerDisplayItem(shootingLocationName); ShowMessage("Photo Location successfully added", E_MessageType.success); break; case E_DBReturnCode.error: ShowMessage("Error adding PhotoLocation to database\n" + errorMessage, E_MessageType.error); break; case E_DBReturnCode.already_existing: ShowMessage("PhotoLocation already existing\n" + errorMessage, E_MessageType.info); break; default: Debug.Assert(false); throw new Exception("Unknown enum value in LocationTabControler::Add"); } // reset cursor Mouse.OverrideCursor = null; // clear the controls and refresh controls ClearUI(); RefreshShootingLocationsFromDB(); RefreshParkingLocationsFromDB(); RefreshShootLocationControl(); RefreshParkingLocationControl(); // reset cursor Mouse.OverrideCursor = null; Window.Location_CountryControl.SetFocus(); }
internal static E_DBReturnCode AddParkingLocation(string parkingLocationName, GPSCoordinates parkingLocationCoordinates, out long id, out string errorMessage) { return(PersistenceManager.AddParkingLocation(parkingLocationName, parkingLocationCoordinates, out id, out errorMessage)); }
internal static E_DBReturnCode EditShootingLocation(long id, string name, GPSCoordinates coordinates, List <byte[]> photosAsByteArray, out string errorMessage) { return(PersistenceManager.EditShootingLocation(id, name, coordinates, photosAsByteArray, out errorMessage)); }
internal static E_DBReturnCode EditParkingLocationName_GPS(long id, string name, GPSCoordinates coordinates, out string errorMessage) { return(PersistenceManager.EditParkingLocationName_GPS(id, name, coordinates, out errorMessage)); }
//Updated coordinates from status update private void UpdateGPS(GPSCoordinates gpsCoordinates) { roverCoordinates = gpsCoordinates; roverCoordinateString = "Rover: " + gpsCoordinates.Location.ToString(); }