From 7dd69acb435caaa49b25c612e2abbe23e9148e27 Mon Sep 17 00:00:00 2001 From: "Jesse-PC\\Jesse" Date: Sat, 18 Apr 2015 12:18:10 +1000 Subject: [PATCH] Added ConfigureAwait(false) to the JSON API Calls. This will fix deadlock issues where the wrapper methods are called from a non-async method. Fixed an issue where the PlaceBetResponseStatus and PlaceBetErrorCode enums were named in correctly. --- Enums/PlaceBetErrorCode.cs | 36 ++++++++++++++++----------------- Enums/PlaceBetResponseStatus.cs | 4 ++-- PinnacleClient.cs | 32 ++++++++++++++--------------- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/Enums/PlaceBetErrorCode.cs b/Enums/PlaceBetErrorCode.cs index 983ef2c..e7b1055 100644 --- a/Enums/PlaceBetErrorCode.cs +++ b/Enums/PlaceBetErrorCode.cs @@ -6,23 +6,23 @@ namespace PinnacleWrapper.Enums [JsonConverter(typeof(StringEnumConverter))] public enum PlaceBetErrorCode { - AllBettingClosed, //ALL_BETTING_CLOSED Betting is not allowed at this moment - AllLiveBettingClosed, //ALL_LIVE_BETTING_CLOSED Live betting is not allowed at this moment - BlockedClient, //BLOCKED_CLIENT Client is no longer active - InvalidCountry, //INVALID_COUNTRY Client country is not allowed for betting - BlockedBetting, //BLOCKED_BETTING Not allowed betting for the client - InvalidEvent, //INVALID_EVENT Invalid eventid - AboveMaxBetAmount, //ABOVE_MAX_BET_AMOUNT Stake is above allowed maximum amount - BelowMinBetAmount, //BELOW_MIN_BET_AMOUNT Stake is below allowed minimum amount - OfflineEvent, //OFFLINE_EVENT Bet is submitted on a event that is offline - InsufficientFunds, //INSUFFICIENT_FUNDS Bet is submitted by a client with insufficient funds - LineChanged, //LINE_CHANGED Bet is submitted on a line that has changed - RedCardsChanged, //RED_CARDS_CHANGED Bet is submitted on a live soccer event with changed red card count - ScoreChanged, //SCORE_CHANGED Bet is submitted on a live soccer event with changed score - TimeRestriction, //TIME_RESTRICTION Bet is submitted within too short of a period from the same bet previously placed by a client - PastCutOffTime, //PAST_CUTOFFTIME Bet is submitted on a game after the betting cutoff time - AboveEventMax, //ABOVE_EVENT_MAX Bet cannot be placed because client exceeded allowed maximum of risk on a line - InvalidOddsFormat, //INVALID_ODDS_FORMAT If a bet was submitted with the odds format that is not allowed for the client - ListedPitchersSelectionError //LISTED_PITCHERS_SELECTION_ERROR If bet was submitted with pitcher1MustStart and/or pitcher2MustStart parameters in Place Bet request with values that are not allowed. + ALL_BETTING_CLOSED, //Betting is not allowed at this moment + ALL_LIVE_BETTING_CLOSED, //Live betting is not allowed at this moment + BLOCKED_CLIENT, //Client is no longer active + INVALID_COUNTRY, //Client country is not allowed for betting + BLOCKED_BETTING, //Not allowed betting for the client + INVALID_EVENT, //Invalid eventid + ABOVE_MAX_BET_AMOUNT, //Stake is above allowed maximum amount + BELOW_MIN_BET_AMOUNT, //Stake is below allowed minimum amount + OFFLINE_EVENT, //Bet is submitted on a event that is offline + INSUFFICIENT_FUNDS, //Bet is submitted by a client with insufficient funds + LINE_CHANGED, //Bet is submitted on a line that has changed + RED_CARDS_CHANGED, //Bet is submitted on a live soccer event with changed red card count + SCORE_CHANGED, //Bet is submitted on a live soccer event with changed score + TIME_RESTRICTION, //Bet is submitted within too short of a period from the same bet previously placed by a client + PAST_CUTOFFTIME, //Bet is submitted on a game after the betting cutoff time + ABOVE_EVENT_MAX, //Bet cannot be placed because client exceeded allowed maximum of risk on a line + INVALID_ODDS_FORMAT, //If a bet was submitted with the odds format that is not allowed for the client + LISTED_PITCHERS_SELECTION_ERROR, //If bet was submitted with pitcher1MustStart and/or pitcher2MustStart parameters in Place Bet request with values that are not allowed. } } diff --git a/Enums/PlaceBetResponseStatus.cs b/Enums/PlaceBetResponseStatus.cs index 19dc966..7dc03c6 100644 --- a/Enums/PlaceBetResponseStatus.cs +++ b/Enums/PlaceBetResponseStatus.cs @@ -6,8 +6,8 @@ namespace PinnacleWrapper.Enums [JsonConverter(typeof(StringEnumConverter))] public enum PlaceBetResponseStatus { - Accepted, - PendingAcceptance, // live bets in the danger zone + ACCEPTED, + PENDING_ACCEPTANCE, // live bets in the danger zone PROCESSED_WITH_ERROR } } diff --git a/PinnacleClient.cs b/PinnacleClient.cs index 973091b..f442b08 100644 --- a/PinnacleClient.cs +++ b/PinnacleClient.cs @@ -48,7 +48,7 @@ protected T GetXmlAsync(string requestType, params object[] values) { var response = _httpClient.GetAsync(string.Format(requestType, values)).Result; - var str = _httpClient.GetStringAsync(string.Format(requestType, values)).Result; + //var str = _httpClient.GetStringAsync(string.Format(requestType, values)).Result; response.EnsureSuccessStatusCode(); // throw if web request failed @@ -178,14 +178,14 @@ public Feed GetFeed(int sportId, int[] leagueIds, OddsFormat format, string curr protected async Task GetJsonAsync(string requestType, params object[] values) { - var response = _httpClient.GetAsync(string.Format(requestType, values)).Result; + var response = await _httpClient.GetAsync(string.Format(requestType, values)).ConfigureAwait(false); response.EnsureSuccessStatusCode(); // throw if web request failed var json = await response.Content.ReadAsStringAsync(); // deserialise json async - return JsonConvert.DeserializeObject(json); + return await Task.Factory.StartNew(() => JsonConvert.DeserializeObject(json)); } // ToDo: replace requestData object type with "IJsonSerialisable" @@ -194,7 +194,7 @@ protected async Task PostJsonAsync(string requestType, object requestData) var requestPostData = JsonConvert.SerializeObject(requestData); var response = await _httpClient.PostAsync(requestType, - new StringContent(requestPostData, Encoding.UTF8, "application/json")); + new StringContent(requestPostData, Encoding.UTF8, "application/json")).ConfigureAwait(false); response.EnsureSuccessStatusCode(); // throw if web request failed @@ -204,13 +204,13 @@ protected async Task PostJsonAsync(string requestType, object requestData) return await Task.Factory.StartNew(() => JsonConvert.DeserializeObject(json)); } - public ClientBalance GetClientBalance() + public Task GetClientBalance() { const string uri = "client/balance"; - return GetJsonAsync(uri).Result; + return GetJsonAsync(uri); } - public GetBetsResponse GetBets(BetListType type, DateTime startDate, DateTime endDate) + public Task GetBets(BetListType type, DateTime startDate, DateTime endDate) { // get request uri var sb = new StringBuilder(); @@ -220,10 +220,10 @@ public GetBetsResponse GetBets(BetListType type, DateTime startDate, DateTime en var uri = sb.ToString(); - return GetJsonAsync(uri).Result; + return GetJsonAsync(uri); } - public GetBetsResponse GetBets(List betIds) + public Task GetBets(List betIds) { // get request uri var sb = new StringBuilder(); @@ -232,12 +232,12 @@ public GetBetsResponse GetBets(List betIds) var uri = sb.ToString(); - return GetJsonAsync(uri).Result; + return GetJsonAsync(uri); } - public PlaceBetResponse PlaceBet(PlaceBetRequest placeBetRequest) + public Task PlaceBet(PlaceBetRequest placeBetRequest) { - return PostJsonAsync("bets/place", placeBetRequest).Result; + return PostJsonAsync("bets/place", placeBetRequest); } /// @@ -253,7 +253,7 @@ public PlaceBetResponse PlaceBet(PlaceBetRequest placeBetRequest) /// /// /// - public GetLineResponse GetLine(int sportId, int leagueId, long eventId, int periodNumber, BetType betType, OddsFormat oddsFormat, + public Task GetLine(int sportId, int leagueId, long eventId, int periodNumber, BetType betType, OddsFormat oddsFormat, TeamType? team = null, SideType? side = null, decimal? handicap = null) { if (team == null) @@ -294,13 +294,13 @@ public GetLineResponse GetLine(int sportId, int leagueId, long eventId, int peri var uri = sb.ToString(); - return GetJsonAsync(uri).Result; + return GetJsonAsync(uri); } - public GetInRunningResponse GetInRunning() + public Task GetInRunning() { const string uri = "inrunning"; - return GetJsonAsync(uri).Result; + return GetJsonAsync(uri); } } }