public Task <Guest> GetAsync(int aGuestId) { return(Task.Run(() => { Guest vResult = new Guest(); using (var vHttp = new HttpClient()) { vHttp.BaseAddress = new Uri(_ApiUrl); //HTTP GET var responseTask = vHttp.GetAsync("Guests/" + aGuestId); responseTask.Wait(); var vResponseTask = responseTask.Result; if (vResponseTask.IsSuccessStatusCode) { var readTask = vResponseTask.Content.ReadAsStringAsync(); readTask.Wait(); string vJson = readTask.Result; return vResult.FromJson(vJson); } else //web api sent error response { return null; } } })); }
public void FromJson(Json json) { // Only when the game session is playing that json is parsed and merged if (State == GameState.Playing) { Json host = json.ReadObject("host"), guest = json.ReadObject("guest"); if (host != null && guest != null) { Host.FromJson(host); Guest.FromJson(guest); } if (json.HasKey("state")) { State = (GameState)json.ReadInteger("state"); } } }