/// <summary> /// sends a get with the trip data to the server /// </summary> /// <returns>true false from the server</returns> static public async Task <string> GetProductAsync(Protobuf.Trip trip) { HttpClient client = new HttpClient(); //sends to the server client.BaseAddress = new Uri("http://172.16.21.44/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.GetAsync( "api/MobilClient/TripViaProtobuf/?data=" + Convert.ToBase64String(trip.ToByteArray())); response.EnsureSuccessStatusCode(); // return URI of the created resource. return(await response.Content.ReadAsStringAsync()); }
/// <summary> /// register like it is not in motion /// </summary> /// <param name="speed">the current speed</param> /// <returns></returns> private async Task <bool> NotInMotionAsync(double speed) { //looks if it is in motion with a speed over 15km/h if (speed * 3.6 > 15) { //resets the values speed = 0; count = 0; trip = new Protobuf.Trip(); trip.UserId = userId; trip.Starttime = new Timestamp(); trip.Endtime = new Timestamp(); trip.Starttime.Seconds = Convert.ToInt64(DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds); return(true); } else { //if there is a trip and the connection buffer is 0 if (tripStack.Count > 0 && noConnectionBuffer <= 0) { bool response = false; //trys to sent the trip if (bool.TryParse(await ApiController.GetProductAsync((Protobuf.Trip)tripStack.Peek()), out response) && response) { //removes the top trip tripStack.Pop(); } else { //sets the buffer to 10 to minimice the power usage noConnectionBuffer = 10; } } // if the no connection buffer is over 0 then minus 1 else if (noConnectionBuffer > 0) { noConnectionBuffer--; } //POWERSAVE :: waits 60 sec Thread.Sleep(10000); return(false); } }