public async Task <bool> SaveItemAsync(ObdParameters obdParameters, bool isNewItem = false) { HttpClient client = new HttpClient(); client.MaxResponseContentBufferSize = 256000; string RestUrl = "http://3.120.132.27/api/OBDData/"; var uri = new Uri(string.Format(RestUrl, string.Empty)); string json = JsonConvert.SerializeObject(obdParameters); var content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = null; if (isNewItem) { response = await client.PostAsync(uri, content); } if (response.IsSuccessStatusCode) { Debug.WriteLine("**** Item has been Saved ****"); return(true); } else { Debug.WriteLine("**** Item has not been Saved ****"); return(false); } }
public async Task <ObdParameters> getAllCurrentDataAsync() { ObdParameters obdParameters = new ObdParameters(); CommunicationHandler ch = new CommunicationHandler(); StringBuilder sb = new StringBuilder(); try { string pidCode = pidDictionary["RPM"]; obdParameters.Rpm = await ch.getData(BluetoothConnectionHandler.bluetoothConnection.bluetoothSocket, pidCode); sb.Append("RPM: " + obdParameters.Rpm); pidCode = pidDictionary["Speed"]; obdParameters.Speed = await ch.getData(BluetoothConnectionHandler.bluetoothConnection.bluetoothSocket, pidCode); sb.Append("Speed: " + obdParameters.Speed); pidCode = pidDictionary["EngineTemperature"]; obdParameters.engineCoolantTemperature = await ch.getData(BluetoothConnectionHandler.bluetoothConnection.bluetoothSocket, pidCode); sb.Append("EngineTemperature: " + obdParameters.engineCoolantTemperature); pidCode = pidDictionary["throttlePosition"]; obdParameters.throttlePosition = await ch.getData(BluetoothConnectionHandler.bluetoothConnection.bluetoothSocket, pidCode); sb.Append("Throttle Position: " + obdParameters.throttlePosition); pidCode = pidDictionary["massAirflow"]; obdParameters.massAirflow = await ch.getData(BluetoothConnectionHandler.bluetoothConnection.bluetoothSocket, pidCode); sb.Append("Mass Airflow: " + obdParameters.massAirflow); Debug.WriteLine(sb.ToString()); //pidCode = pidDictionary["VIN"]; //obdParameters.VIN = await ch.getData(BluetoothConnectionHandler.bluetoothConnection.bluetoothSocket, pidCode); //sb.Append("VIN: " + obdParameters.VIN); //Debug.WriteLine(sb.ToString()); return(obdParameters); } catch (Exception ex) { if (ex is Java.IO.IOException || ex is System.ArgumentException) { Debug.WriteLine("Exception in get all data is: " + ex.Message); DataHandler.isRunning = false; } throw; } }
public void SaveRecordsUsingRest(ObdParameters obdParameters) { var client = new RestClient("http://3.120.132.27/api/OBDData"); var request = new RestRequest(Method.POST); request.AddHeader("Cache-Control", "no-cache"); request.AddHeader("Content-Type", "application/json"); string json = JsonConvert.SerializeObject(obdParameters); request.AddParameter("undefined", json, ParameterType.RequestBody); IRestResponse response = client.Execute(request); Debug.WriteLine("Item Added: " + json); }