/// <summary> /// Load game parameters from remote API asynchronously /// </summary> /// <returns>Game parameter object, null if loading failed</returns> public async Task <GameParameter> InitializeGameAsync(CancellationToken cancellationToken) { GameParameter gameParameter = null; if (String.IsNullOrEmpty(_URI)) { return(null); } try { using (HttpClient httpClient = new HttpClient()) { _logger.Debug("Start calling third party API to load parameters..."); HttpResponseMessage response = await httpClient.GetAsync(_URI, cancellationToken); _logger.Debug($"Load parameter completed with status code {response.StatusCode}"); if (response.IsSuccessStatusCode) { gameParameter = await response.Content.ReadAsAsync <GameParameter>(); _logger.Debug($"Parameter loaded : {gameParameter.ToString()}"); } } } catch (WebException we) { _logger.Error("Error in calling external API", we); } catch (OperationCanceledException oe) { _logger.Error("Operation is cancelled", oe); throw; } return(gameParameter); }