private void BetStop(bet_stop e, dbEntities cnn, string routeKey) { using (var dbContextTransaction = cnn.Database.BeginTransaction()) { var sectionName = string.Empty; var spParams = string.Empty; try { sectionName = "bet_stop"; spParams = "EXECUTE PROCEDURE BET_EVENTBETSTOP_I("; spParams += SourceId + ","; spParams += e.event_id.Split(':').Last() + ","; spParams += e.product + ","; spParams += "'" + e.groups?.Trim() + "',"; spParams += e.market_status + ","; spParams += e.GeneratedAt + ")"; cnn.Database.ExecuteSqlCommand(spParams.Trim()); dbContextTransaction.Commit(); SerilogHelper.Information($"{routeKey} {UtcHelper.GetDifferenceFromTimestamp(e.timestamp) + "ms"}"); } catch (Exception ex) { dbContextTransaction.Rollback(); SerilogHelper.Exception($"Unknown exception in {routeKey} SectionName:{sectionName} SQL:{spParams.Trim()}", ex); } } }
private void BetSettlement(bet_settlement e, dbEntities db, string routeKey) { using (var dbContextTransaction = db.Database.BeginTransaction()) { var sectionName = string.Empty; var spParams = string.Empty; try { var marketIdList = string.Empty; var specifierList = string.Empty; var outcomeIdList = string.Empty; var resultList = string.Empty; var certaintyList = string.Empty; var productList = string.Empty; foreach (var market in e.outcomes) { var marketId = market.id; var specifier = market.specifiers?.Split('=').LastOrDefault()?.Trim(); foreach (var outcome in market.Items) { marketIdList += marketId + ","; specifierList += specifier + ","; outcomeIdList += outcome.id.Split(':').LastOrDefault() + ","; resultList += outcome.result + ","; certaintyList += e.certainty + ","; productList += e.product + ","; marketId = 0; if (!string.IsNullOrEmpty(specifier)) { specifier = "*"; } } } sectionName = "bet_settlement"; spParams = "EXECUTE PROCEDURE BET_EVENTRESULTS_I_MULTI("; spParams += SourceId + ","; spParams += e.event_id.Split(':').Last() + ","; spParams += "'" + marketIdList.Substring(0).Trim() + "',"; spParams += "'" + specifierList.Substring(0).Trim() + "',"; spParams += "'" + outcomeIdList.Substring(0).Trim() + "',"; spParams += "'" + resultList.Substring(0).Trim() + "',"; spParams += "'" + certaintyList.Substring(0).Trim() + "',"; spParams += "'" + productList.Substring(0).Trim() + "',"; spParams += e.GeneratedAt + ")"; db.Database.ExecuteSqlCommand(spParams.Trim()); dbContextTransaction.Commit(); SerilogHelper.Information($"{routeKey} {UtcHelper.GetDifferenceFromTimestamp(e.timestamp) + "ms"}"); } catch (Exception ex) { dbContextTransaction.Rollback(); SerilogHelper.Exception($"Unknown exception in {routeKey} SectionName:{sectionName} SQL:{spParams.Trim()}", ex); } } }
private void BetCancel(bet_cancel e, dbEntities db, string routeKey) { var sectionName = string.Empty; using (var dbContextTransaction = db.Database.BeginTransaction()) { try { sectionName = "bet_cancel"; foreach (var market in e.market) { var specifier = market.specifiers?.Split('=').LastOrDefault().Trim(); var spParams = "EXECUTE PROCEDURE BET_EVENTBETCANCEL_I("; spParams += SourceId + ","; spParams += e.event_id.Split(':').Last() + ","; spParams += e.product + ","; spParams += e.start_time + ","; spParams += e.end_time + ","; spParams += market.id + ","; spParams += "'" + specifier + "',"; spParams += market.void_reason + ","; spParams += e.GeneratedAt + ")"; db.Database.ExecuteSqlCommand(spParams.Trim()); } dbContextTransaction.Commit(); SerilogHelper.Information(string.Format("{0} {1}", routeKey, UtcHelper.GetDifferenceFromTimestamp(e.timestamp) + "ms")); } catch (Exception ex) { dbContextTransaction.Rollback(); SerilogHelper.Exception(string.Format("Unknown exception in {0} {1} {2}", routeKey, sectionName, e.event_id), ex); } } }
private void FixtureChange(fixture_change e, dbEntities db, string routeKey) { var sectionName = string.Empty; using (var dbContextTransaction = db.Database.BeginTransaction()) { try { sectionName = "fixture_change"; var spParams = "EXECUTE PROCEDURE BET_EVENTFIXTURECHANGE_I("; spParams += SourceId + ","; spParams += e.event_id.Split(':').Last() + ","; spParams += e.product + ","; spParams += e.change_type + ","; spParams += e.GeneratedAt + ")"; db.Database.ExecuteSqlCommand(spParams.Trim()); dbContextTransaction.Commit(); SerilogHelper.Information(string.Format("{0} {1}", routeKey, UtcHelper.GetDifferenceFromTimestamp(e.timestamp) + "ms")); } catch (Exception ex) { dbContextTransaction.Rollback(); SerilogHelper.Exception(string.Format("Unknown exception in {0} {1} {2}", routeKey, sectionName, e.event_id), ex); } } }
private void OddsChange(odds_change e, dbEntities cnn, string routeKey) { using (var dbContextTransaction = cnn.Database.BeginTransaction()) { var spParams = string.Empty; var sectionName = string.Empty; try { var eventId = e.event_id.Split(':').Last(); var product = e.product; var generatedAt = e.timestamp; var clockStopped = 0; if (e.odds?.market != null) { sectionName = "odds_change"; var marketIdList = string.Empty; var specifierList = string.Empty; var statusList = string.Empty; var favoriteList = string.Empty; var outcomeIdList = string.Empty; var outcomeStatusList = string.Empty; var outcomeOddList = string.Empty; foreach (var market in e.odds.market) { var marketId = market.id; var specifier = market.specifiers?.Split('=').LastOrDefault()?.Trim(); var marketStatus = market.status; if (market.outcome != null) { foreach (var outcome in market.outcome) { sectionName = "odds_change.market.outcome"; marketIdList += marketId + ","; specifierList += specifier + ","; statusList += marketStatus + ","; favoriteList += market.favourite + ","; outcomeIdList += outcome.id.Split(':').LastOrDefault() + ","; outcomeStatusList += outcome.active + ","; outcomeOddList += outcome.odds.ToString(_nfi) + ","; marketId = 0; if (!string.IsNullOrEmpty(specifier)) { specifier = "*"; } } } else { marketIdList += market.id + ","; specifierList += specifier + ","; statusList += market.status + ","; favoriteList += market.favourite + ","; outcomeIdList += string.Empty + ","; outcomeStatusList += string.Empty + ","; outcomeOddList += string.Empty + ","; } } sectionName = "execute BETDATA_ODDSCHANGE"; spParams = "EXECUTE PROCEDURE BETDATA_ODDSCHANGE_MULTI("; spParams += SourceId + ","; spParams += eventId + ","; spParams += "'" + marketIdList.Substring(0).Trim() + "',"; spParams += "'" + specifierList.Substring(0).Trim() + "',"; spParams += "'" + statusList.Substring(0).Trim() + "',"; spParams += "'" + favoriteList.Substring(0).Trim() + "',"; spParams += "'" + outcomeIdList.Substring(0).Trim() + "',"; spParams += "'" + outcomeStatusList.Substring(0).Trim() + "',"; spParams += "'" + outcomeOddList.Substring(0).Trim() + "',"; spParams += generatedAt + ")"; cnn.Database.ExecuteSqlCommand(spParams.Trim()); } if (e.sport_event_status != null) { sectionName = "odds_change.sport_event_status"; var periodNumberList = string.Empty; var periodHomeScoreList = string.Empty; var periodAwayScoreList = string.Empty; var periodMatchStatusCodeList = string.Empty; if (e.sport_event_status?.period_scores != null) { if (e.sport_event_status.period_scores.Length > 0) { sectionName = "odds_change.sport_event_status.period_scores"; periodNumberList = e.sport_event_status.period_scores .Aggregate(string.Empty, (current, s) => current + "," + s.number).Substring(1) .Trim(); periodHomeScoreList = e.sport_event_status.period_scores .Aggregate(string.Empty, (current, s) => current + "," + s.home_score).Substring(1) .Trim(); periodAwayScoreList = e.sport_event_status.period_scores .Aggregate(string.Empty, (current, s) => current + "," + s.away_score).Substring(1) .Trim(); periodMatchStatusCodeList = e.sport_event_status.period_scores .Aggregate(string.Empty, (current, s) => current + "," + s.match_status_code) .Substring(1).Trim(); periodNumberList += ","; periodHomeScoreList += ","; periodAwayScoreList += ","; periodMatchStatusCodeList += ","; } } if (e.sport_event_status?.clock?.stopped != null) { clockStopped = e.sport_event_status.clock.stopped ? 1 : 0; } sectionName = "execute BET_EVENTDETAILS_UI"; spParams = "EXECUTE PROCEDURE BET_EVENTDETAILS_UI("; spParams += SourceId + ","; spParams += eventId + ","; spParams += product + ","; spParams += "'" + e.sport_event_status?.clock?.match_time + "',"; spParams += "'" + e.sport_event_status?.clock?.stoppage_time + "',"; spParams += "'" + e.sport_event_status?.clock?.stoppage_time_announced + "',"; spParams += "'" + e.sport_event_status?.clock?.remaining_time + "',"; spParams += "'" + e.sport_event_status?.clock?.remaining_time_in_period + "',"; spParams += clockStopped + ","; spParams += (e.sport_event_status?.statistics?.corners.home ?? 0) + ","; spParams += (e.sport_event_status?.statistics?.corners.away ?? 0) + ","; spParams += (e.sport_event_status?.statistics?.red_cards.home ?? 0) + ","; spParams += (e.sport_event_status?.statistics?.red_cards.away ?? 0) + ","; spParams += (e.sport_event_status?.statistics?.yellow_cards.home ?? 0) + ","; spParams += (e.sport_event_status?.statistics?.yellow_cards.away ?? 0) + ","; spParams += (e.sport_event_status?.statistics?.yellow_red_cards.home ?? 0) + ","; spParams += (e.sport_event_status?.statistics?.yellow_red_cards.away ?? 0) + ","; spParams += e.sport_event_status?.status + ","; spParams += e.sport_event_status?.home_score.ToString(_nfi) + ","; spParams += e.sport_event_status?.away_score.ToString(_nfi) + ","; spParams += e.sport_event_status?.match_status + ","; spParams += (e.odds?.betstop_reason ?? 0) + ","; spParams += (e.odds?.betting_status ?? 0) + ","; spParams += "'" + periodNumberList.Substring(0).Trim() + "',"; spParams += "'" + periodHomeScoreList.Substring(0).Trim() + "',"; spParams += "'" + periodAwayScoreList.Substring(0).Trim() + "',"; spParams += "'" + periodMatchStatusCodeList.Substring(0).Trim() + "',"; spParams += generatedAt + ")"; cnn.Database.ExecuteSqlCommand(spParams.Trim()); } dbContextTransaction.Commit(); SerilogHelper.Information($"{routeKey} {UtcHelper.GetDifferenceFromTimestamp(e.timestamp) + "ms"}"); } catch (Exception ex) { dbContextTransaction.Rollback(); SerilogHelper.Exception( $"Unknown exception in {routeKey} SectionName:{sectionName} SQL:{spParams.Trim()}", ex); } } }