public async Task startTrip(String boatId) { String sessionCookie = await login(hc); ongoingTrip = new TripInfo{ startTime = DateTime.Now }; var content = new ContentForRequest { RowerID = rowerId, BoatID = boatId, }.build (sessionCookie); var response = await hc.PostAsync ("http://www.rokort.dk/workshop/row_update.php", content); Console.WriteLine ("Turen er startet, http status " + response.StatusCode + ", response " + await response.Content.ReadAsStringAsync ()); }
async Task fetchTripInfo (string sessionCookie) { HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "http://www.rokort.dk/workshop/workshop2.php"); message.Headers.Add("Cookie", sessionCookie); HttpResponseMessage response = await hc.SendAsync (message); String responseBody = await response.Content.ReadAsStringAsync (); Match match = Regex.Match (responseBody, "<td onclick=\"showWin\\('row_edit.php\\?id=[0-9]*'\\);\"><span class=\"tooltip\"><a href=\"workshop.php\\?lookup=b_[0-9]*\" onclick=\"javascript:return\\(false\\)\">([0-9]*)</a></span></td>" + "[^<]*" + "<td onclick=\"showWin\\('row_edit.php\\?id=([0-9]*)'\\);\"><span class=\"tooltip\"><a href=\"workshop.php\\?lookup=r_" + rowerId + "\" onclick=\"javascript:return\\(false\\)\">[^<]*</a></span></td>" + "[^<]*" + "<td class=\"no_wrap\" onclick=\"showWin\\('row_edit.php\\?id=[0-9]*'\\);\">([^<]*)</td>"); if (match.Success) { string startDateString = DateTime.Now.ToString("yyyy-MM-dd") + " " + match.Groups[3].Value; // match.Groups[3] has values like "12:01" or "08:05" DateTime startDateTime = DateTime.ParseExact (startDateString, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture); ongoingTrip = new TripInfo { id = match.Groups [2].Value, boatID = match.Groups[1].Value, startTime = startDateTime }; } else { ongoingTrip = null; } Console.WriteLine ("onGoingTrip for rower " + rowerId + ": " + ongoingTrip); }