public string OBU1_GetVehicleType(string vehID, [FromBody] string address) { if (string.IsNullOrEmpty(address)) { address = "http://127.0.0.1:8080/TRAAS_WS"; //default address } TraasReference.ServiceImplClient client = new TraasReference.ServiceImplClient(); client.Endpoint.Address = new EndpointAddress(address); try { client.Open(); if (isVehicleActive(address, vehID)) { string vehicleTypeID = client.Vehicle_getTypeID(vehID); return(vehicleTypeID); } throw new FaultException("Vehicle with that ID is not in simulation."); } catch (FaultException e) { client.Abort(); throw new FaultException(e.Message); } catch (Exception e) { throw new FaultException(e.InnerException.ToString()); } finally { client.Close(); } }
public void OBU1_SetVehicleAcceleration(string vehID, [FromBody] string address, [FromBody] double acceleration) { if (string.IsNullOrEmpty(address)) { address = "http://127.0.0.1:8080/TRAAS_WS"; //default address } TraasReference.ServiceImplClient client = new TraasReference.ServiceImplClient(); client.Endpoint.Address = new EndpointAddress(address); try { client.Open(); if (isVehicleActive(address, vehID)) { client.Vehicle_setAccel(vehID, acceleration); } } catch (FaultException e) { client.Abort(); throw new FaultException(e.Message); } catch (Exception e) { throw new FaultException(e.InnerException.ToString()); } finally { client.Close(); } }
public void Obu1_PostMaxSpeed(string vehID, [FromBody] string address) { MySqlConnection conn = new MySqlConnection(connStr); try { conn.Open(); if (string.IsNullOrEmpty(address)) { address = "http://127.0.0.1:8080/TRAAS_WS"; //default address } TraasReference.ServiceImplClient client = new TraasReference.ServiceImplClient(); client.Endpoint.Address = new EndpointAddress(address); try { client.Open(); if (isVehicleActive(address, vehID)) { double vehicleMaxSpeed = client.Vehicle_getMaxSpeed(vehID); MySqlCommand command = new MySqlCommand("INSERT INTO maxspeed (veh_id, max_speed, address) VALUES (@Parname1, @Parname2, @Parname3)", conn); command.Parameters.Add("@Parname1", MySqlDbType.String).Value = vehID; command.Parameters.Add("@Parname2", MySqlDbType.Double).Value = vehicleMaxSpeed; command.Parameters.Add("@Parname3", MySqlDbType.String).Value = address; command.ExecuteNonQuery(); } throw new FaultException("Vehicle with that ID is not in simulation."); } catch (FaultException e) { client.Abort(); throw new FaultException(e.Message); } catch (Exception e) { throw new FaultException(e.InnerException.ToString()); } finally { client.Close(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { conn.Close(); } }
public string[] Obu1_ActiveVehicles([FromBody] string address) { MySqlConnection conn = new MySqlConnection(connStr); try { conn.Open(); if (string.IsNullOrEmpty(address)) { address = "http://127.0.0.1:8080/TRAAS_WS"; //default address } TraasReference.ServiceImplClient client = new TraasReference.ServiceImplClient(); client.Endpoint.Address = new EndpointAddress(address); try { client.Open(); string[] vehicleIDList = client.Vehicle_getIDList(); return(vehicleIDList); } catch (FaultException e) { client.Abort(); throw new FaultException(e.Message); } catch (Exception e) { throw new FaultException(e.InnerException.ToString()); } finally { client.Close(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { conn.Close(); } throw new Exception("Napaka!"); }
public Emissions OBU1_GetVehicleEmissions(string vehID, [FromBody] string address) { if (string.IsNullOrEmpty(address)) { address = "http://127.0.0.1:8080/TRAAS_WS"; //default address } TraasReference.ServiceImplClient client = new TraasReference.ServiceImplClient(); client.Endpoint.Address = new EndpointAddress(address); try { client.Open(); if (isVehicleActive(address, vehID)) { Emissions emissions = new Emissions(); emissions.CO = client.Vehicle_getCOEmission(vehID); emissions.CO2 = client.Vehicle_getCO2Emission(vehID); emissions.HC = client.Vehicle_getHCEmission(vehID); emissions.Noise = client.Vehicle_getNoiseEmission(vehID); emissions.NOx = client.Vehicle_getNOxEmission(vehID); emissions.PMx = client.Vehicle_getPMxEmission(vehID); return(emissions); } throw new FaultException("Vehicle with that ID is not in simulation."); } catch (FaultException e) { client.Abort(); throw new FaultException(e.Message); } catch (Exception e) { throw new FaultException(e.InnerException.ToString()); } finally { client.Close(); } }
public void OBU1_SetVehicleCurrentSpeed(string vehID, [FromBody] string address, [FromBody] double speed) { if (string.IsNullOrEmpty(address)) { address = "http://127.0.0.1:8080/TRAAS_WS"; //default address } TraasReference.ServiceImplClient client = new TraasReference.ServiceImplClient(); client.Endpoint.Address = new EndpointAddress(address); try { if (speed <= 0) { throw new FaultException("Hitrost more biti pozitivna!"); } client.Open(); if (isVehicleActive(address, vehID)) { client.Vehicle_setMaxSpeed(vehID, speed); client.Vehicle_setSpeed(vehID, speed); } } catch (FaultException e) { client.Abort(); throw new FaultException(e.Message); } catch (Exception e) { throw new FaultException(e.InnerException.ToString()); } finally { client.Close(); } }
private bool isVehicleActive(string address, string vehID) { if (string.IsNullOrEmpty(address)) { address = "http://127.0.0.1:8080/TRAAS_WS"; //default address } TraasReference.ServiceImplClient client = new TraasReference.ServiceImplClient(); client.Endpoint.Address = new EndpointAddress(address); try { client.Open(); string[] vehicleIDList = client.Vehicle_getIDList(); foreach (string searchedID in vehicleIDList) { if (searchedID == vehID) { return(true); } } return(false); } catch (FaultException e) { client.Abort(); throw new FaultException(e.Message); } catch (Exception e) { throw new FaultException(e.InnerException.ToString()); } finally { client.Close(); } }
public void Obu1_PostAverageSpeed(string vehID, [FromBody] string address) { MySqlConnection conn = new MySqlConnection(connStr); List <double> seznam = new List <double>(); try { conn.Open(); if (string.IsNullOrEmpty(address)) { address = "http://127.0.0.1:8080/TRAAS_WS"; //default address } TraasReference.ServiceImplClient client = new TraasReference.ServiceImplClient(); client.Endpoint.Address = new EndpointAddress(address); try { client.Open(); int counter = 0; while (counter < 5) { if (isVehicleActive(address, vehID)) { seznam.Add(client.Vehicle_getSpeed(vehID)); } Thread.Sleep(3000); counter++; } } catch (FaultException e) { client.Abort(); throw new FaultException(e.Message); } catch (Exception e) { throw new FaultException(e.InnerException.ToString()); } finally { client.Close(); } if (seznam.Count > 0) { double sum = 0; double average; foreach (double d in seznam) { sum += d; } average = sum / seznam.Count; MySqlCommand command = new MySqlCommand("INSERT INTO averagespeed (veh_id, average_speed, address) VALUES (@Parname1, @Parname2, @Parname3)", conn); command.Parameters.Add("@Parname1", MySqlDbType.String).Value = vehID; command.Parameters.Add("@Parname2", MySqlDbType.Double).Value = average; command.Parameters.Add("@Parname3", MySqlDbType.String).Value = address; command.ExecuteNonQuery(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { conn.Close(); } }