Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ namespace Oddin.OddsFeedSdk.AMQP.Mapping;
internal class FeedMessageMapper : IFeedMessageMapper
{
public const MarketStatus DEFAULT_MARKET_STATUS = MarketStatus.SUSPENDED;
private readonly IFeedConfiguration _configuration;
private readonly IFeedConfiguration _config;
private readonly IMarketDescriptionFactory _marketDescriptionFactory;
private readonly IProducerManager _producerManager;
private readonly ISportDataBuilder _sportDataBuilder;

public FeedMessageMapper(
IProducerManager producerManager,
IFeedConfiguration configuration,
IFeedConfiguration config,
IMarketDescriptionFactory marketDescriptionFactory,
ISportDataBuilder sportDataBuilder)
{
_producerManager = producerManager;
_marketDescriptionFactory = marketDescriptionFactory;
_sportDataBuilder = sportDataBuilder;
_configuration = configuration;
_config = config;
}

public IOddsChange<T> MapOddsChange<T>(odds_change message, IEnumerable<CultureInfo> cultures, byte[] rawMessage)
Expand Down Expand Up @@ -322,7 +322,7 @@ private IOutcomeOdds GetOutcomeOdds(
outcome.id,
outcome.refid,
_marketDescriptionFactory,
_configuration,
_config,
marketId,
marketSpecifiers,
sportEvent
Expand All @@ -347,7 +347,7 @@ private IMarketWithOdds GetMarketWithOdds(oddsChangeMarket oddsChangeMarket, ISp
oddsChangeMarket.extended_specifiers,
oddsChangeMarket.groups?.Split("|"),
_marketDescriptionFactory,
_configuration.ExceptionHandlingStrategy,
_config.ExceptionHandlingStrategy,
marketStatus,
oddsChangeMarket.favouriteSpecified && oddsChangeMarket.favourite == 1,
oddsChangeMarket.outcome?.Select(outcome =>
Expand Down Expand Up @@ -379,7 +379,7 @@ private IMarketWithOdds GetMarketWithOdds(oddsChangeMarket oddsChangeMarket, ISp
private ISportEvent MapSportEvent(URN id, URN sport, IEnumerable<CultureInfo> cultures)
{
if (cultures is null || cultures.Any() == false)
cultures = new[] { _configuration.DefaultLocale };
cultures = new[] { _config.DefaultLocale };

switch (id?.Type)
{
Expand Down Expand Up @@ -408,7 +408,7 @@ private IMarket GetRollbackBetSettlementMarket(rollback_bet_settlementMarket mes
null,
_marketDescriptionFactory,
sportEvent,
_configuration.ExceptionHandlingStrategy
_config.ExceptionHandlingStrategy
);
}

Expand All @@ -427,7 +427,7 @@ private IMarket GetRollbackBetCancelMarket(rollback_bet_cancelMarket message, IS
null,
_marketDescriptionFactory,
sportEvent,
_configuration.ExceptionHandlingStrategy
_config.ExceptionHandlingStrategy
);
}

Expand All @@ -449,7 +449,7 @@ private IMarketWithSettlement GetMarketWithResults(betSettlementMarket message,
GetOutcomeSettlements(message.Items, message.id, specifiers, sportEvent),
_marketDescriptionFactory,
sportEvent,
_configuration.ExceptionHandlingStrategy,
_config.ExceptionHandlingStrategy,
message.void_reasonSpecified ? message.void_reason : default,
message.void_reason_idSpecified ? message.void_reason_id : default,
message.void_reason_paramsSpecified ? message.void_reason_params : default
Expand All @@ -469,7 +469,7 @@ private IEnumerable<IOutcomeSettlement> GetOutcomeSettlements(
b.result,
b.void_factorSpecified ? b.void_factor : default(double?),
_marketDescriptionFactory,
_configuration,
_config,
marketId,
marketSpecifiers,
sportEvent
Expand All @@ -489,7 +489,7 @@ private IMarketCancel GetMarketWithCancel(bet_cancel_market message, ISportEvent
message.groups?.Split("|"),
_marketDescriptionFactory,
sportEvent,
_configuration.ExceptionHandlingStrategy,
_config.ExceptionHandlingStrategy,
message.void_reasonSpecified ? message.void_reason : default,
message.void_reason_idSpecified ? message.void_reason_id : default,
message.void_reason_paramsSpecified ? message.void_reason_params : default
Expand Down
10 changes: 5 additions & 5 deletions src/Oddin.OddsFeedSdk/Oddin.OddsFeedSdk/AMQP/Mapping/Outcome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Oddin.OddsFeedSdk.AMQP.Mapping;
internal class Outcome : IOutcome
{
private static readonly ILogger _log = SdkLoggerFactory.GetLogger(typeof(Outcome));
private readonly IFeedConfiguration _configuration;
private readonly IFeedConfiguration _config;

private readonly IMarketDescriptionFactory _marketDescriptionFactory;
private readonly int _marketId;
Expand All @@ -26,15 +26,15 @@ public Outcome(
string id,
long refId,
IMarketDescriptionFactory marketDescriptionFactory,
IFeedConfiguration configuration,
IFeedConfiguration config,
int marketId,
IReadOnlyDictionary<string, string> marketSpecifiers,
ISportEvent sportEvent)
{
Id = id;
RefId = refId;
_marketDescriptionFactory = marketDescriptionFactory;
_configuration = configuration;
_config = config;
_marketId = marketId;
_marketSpecifiers = marketSpecifiers;
_sportEvent = sportEvent;
Expand Down Expand Up @@ -76,7 +76,7 @@ public string GetName(CultureInfo culture)
}

if (outcomeName is null)
if (_configuration.ExceptionHandlingStrategy == ExceptionHandlingStrategy.THROW)
if (_config.ExceptionHandlingStrategy == ExceptionHandlingStrategy.THROW)
throw new ItemNotFoundException(Id, "Cannot find outcome name!");
else
return null;
Expand All @@ -85,7 +85,7 @@ public string GetName(CultureInfo culture)
}
catch (SdkException e)
{
e.HandleAccordingToStrategy(GetType().Name, _log, _configuration.ExceptionHandlingStrategy);
e.HandleAccordingToStrategy(GetType().Name, _log, _config.ExceptionHandlingStrategy);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public OutcomeOdds(
string outcomeId,
long outcomeRefId,
IMarketDescriptionFactory marketDescriptionFactory,
IFeedConfiguration configuration,
IFeedConfiguration config,
int marketId,
IReadOnlyDictionary<string, string> marketSpecifiers,
ISportEvent sportEvent)
Expand All @@ -30,7 +30,7 @@ public OutcomeOdds(
outcomeId,
outcomeRefId,
marketDescriptionFactory,
configuration,
config,
marketId,
marketSpecifiers,
sportEvent) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public OutcomeProbabilities(
string outcomeId,
long outcomeRefId,
IMarketDescriptionFactory marketDescriptionFactory,
IFeedConfiguration configuration,
IFeedConfiguration config,
int marketId,
IReadOnlyDictionary<string, string> marketSpecifiers,
ISportEvent sportEvent)
: base(outcomeId, outcomeRefId, marketDescriptionFactory, configuration, marketId, marketSpecifiers, sportEvent)
: base(outcomeId, outcomeRefId, marketDescriptionFactory, config, marketId, marketSpecifiers, sportEvent)
{
Active = active;
Probabilities = probabilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ internal OutcomeSettlement(
int result,
double? voidFactor,
IMarketDescriptionFactory marketDescriptionFactory,
IFeedConfiguration configuration,
IFeedConfiguration config,
int marketId,
IReadOnlyDictionary<string, string> marketSpecifiers,
ISportEvent sportEvent)
: base(id, refId, marketDescriptionFactory, configuration, marketId, marketSpecifiers, sportEvent)
: base(id, refId, marketDescriptionFactory, config, marketId, marketSpecifiers, sportEvent)
{
DeadHeatFactor = deadHeatFactor;

Expand Down
16 changes: 12 additions & 4 deletions src/Oddin.OddsFeedSdk/Oddin.OddsFeedSdk/API/CompetitorCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Oddin.OddsFeedSdk.API.Entities;
using Oddin.OddsFeedSdk.API.Models;
using Oddin.OddsFeedSdk.Common;
using Oddin.OddsFeedSdk.Configuration.Abstractions;

namespace Oddin.OddsFeedSdk.API;

Expand All @@ -19,12 +20,17 @@ internal class CompetitorCache : ICompetitorCache
private readonly IApiClient _apiClient;
private readonly MemoryCache _cache = new(nameof(CompetitorCache));
private readonly TimeSpan _cacheTtl = TimeSpan.FromHours(24);
private readonly IFeedConfiguration _config;
private readonly Semaphore _semaphore = new(1, 1);
private readonly IDisposable _subscription;

public CompetitorCache(IApiClient apiClient)
public CompetitorCache(
IApiClient apiClient,
IFeedConfiguration config
)
{
_apiClient = apiClient;
_config = config;

_subscription = apiClient.SubscribeForClass<IRequestResult<object>>()
.Subscribe(response =>
Expand All @@ -47,7 +53,7 @@ public CompetitorCache(IApiClient apiClient)
_semaphore.WaitOne();
try
{
_log.LogDebug($"Updating Competitor cache from API: {response.Data.GetType()}");
_log.LogDebug("Updating Competitor cache from API: {Type}", response.Data.GetType());
HandleTeamData(response.Culture, competitors);
}
finally
Expand Down Expand Up @@ -114,7 +120,8 @@ private void LoadAndCacheItem(URN id, IEnumerable<CultureInfo> cultures)
}
catch (Exception e)
{
_log.LogError($"Error while fetching competitor profile {e}");
_log.LogError("Error while fetching competitor profile {E}", e);
e.HandleAccordingToStrategy(GetType().Name, _log, _config.ExceptionHandlingStrategy);
continue;
}

Expand All @@ -124,7 +131,8 @@ private void LoadAndCacheItem(URN id, IEnumerable<CultureInfo> cultures)
}
catch (Exception e)
{
_log.LogError($"Error while refreshing competitor {e}");
_log.LogError("Error while refreshing competitor {E}", e);
e.HandleAccordingToStrategy(GetType().Name, _log, _config.ExceptionHandlingStrategy);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ namespace Oddin.OddsFeedSdk.API.Entities;

internal class Tournament : ITournament
{
private readonly IFeedConfiguration _configuration;
private readonly IFeedConfiguration _config;
private readonly IEnumerable<CultureInfo> _cultures;
private readonly ISportDataBuilder _sportDataBuilder;
private readonly URN _sportId;
private readonly ITournamentsCache _tournamentsCache;

public Tournament(URN id, URN sportId, ITournamentsCache tournamentsCache, ISportDataBuilder sportDataBuilder,
IFeedConfiguration configuration, IEnumerable<CultureInfo> cultures)
IFeedConfiguration config, IEnumerable<CultureInfo> cultures)
{
Id = id;
_sportId = sportId;
_tournamentsCache = tournamentsCache;
_sportDataBuilder = sportDataBuilder;
_configuration = configuration;
_config = config;
_cultures = cultures;
}

Expand Down Expand Up @@ -74,7 +74,7 @@ private string GetName(CultureInfo culture)
private LocalizedTournament FetchTournament(IEnumerable<CultureInfo> cultures)
{
var tournament = _tournamentsCache.GetTournament(Id, cultures);
if (tournament is null && _configuration.ExceptionHandlingStrategy == ExceptionHandlingStrategy.THROW)
if (tournament is null && _config.ExceptionHandlingStrategy == ExceptionHandlingStrategy.THROW)
throw new ItemNotFoundException(Id.ToString(), $"Competitor {Id} not found");
return tournament;
}
Expand All @@ -86,7 +86,7 @@ private IEnumerable<ICompetitor> FetchCompetitors(IEnumerable<CultureInfo> cultu
var competitorsIds = FetchTournament(cultures)?.CompetitorIds
?? _tournamentsCache.GetTournamentCompetitors(Id, cultures.First());

if (competitorsIds == null && _configuration.ExceptionHandlingStrategy == ExceptionHandlingStrategy.THROW)
if (competitorsIds == null && _config.ExceptionHandlingStrategy == ExceptionHandlingStrategy.THROW)
throw new ItemNotFoundException(Id.ToString(), "Cannot find competitor ids");
if (competitorsIds == null)
return null;
Expand Down
24 changes: 18 additions & 6 deletions src/Oddin.OddsFeedSdk/Oddin.OddsFeedSdk/API/FixtureCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Oddin.OddsFeedSdk.API.Entities;
using Oddin.OddsFeedSdk.API.Models;
using Oddin.OddsFeedSdk.Common;
using Oddin.OddsFeedSdk.Configuration.Abstractions;

namespace Oddin.OddsFeedSdk.API;

Expand All @@ -17,8 +18,16 @@ internal class FixtureCache : IFixtureCache
private readonly IApiClient _apiClient;
private readonly MemoryCache _cache = new(nameof(FixtureCache));
private readonly TimeSpan _cacheTtl = TimeSpan.FromHours(12);
private readonly IFeedConfiguration _config;

public FixtureCache(IApiClient apiClient) => _apiClient = apiClient;
public FixtureCache(
IApiClient apiClient,
IFeedConfiguration config
)
{
_apiClient = apiClient;
_config = config;
}

public LocalizedFixture GetFixture(URN id, CultureInfo culture)
{
Expand All @@ -35,7 +44,7 @@ public void OnFeedMessageReceived(fixture_change e)

if (id != null)
{
_log.LogDebug($"Invalidating FixtureCache from FEED for: {id}");
_log.LogDebug("Invalidating FixtureCache from FEED for: {Id}", id);
ClearCacheItem(id);
}
}
Expand All @@ -51,7 +60,9 @@ private void LoadAndCacheItem(URN id, CultureInfo culture)
}
catch (Exception e)
{
_log.LogError($"Error while fetching fixture {culture.TwoLetterISOLanguageName}: {e}");
_log.LogError("Error while fetching fixture {CultureTwoLetterIsoLanguageName}: {E}",
culture.TwoLetterISOLanguageName, e);
e.HandleAccordingToStrategy(GetType().Name, _log, _config.ExceptionHandlingStrategy);
return;
}

Expand All @@ -70,7 +81,7 @@ private void LoadAndCacheItem(URN id, CultureInfo culture)
_cache.Set(id.ToString(), item, _cacheTtl.AsCachePolicy());
}

private static CultureInfo StringToCultureInfoOrDefault(string cultureString)
private CultureInfo StringToCultureInfoOrDefault(string cultureString)
{
if (string.IsNullOrWhiteSpace(cultureString))
return default;
Expand All @@ -79,9 +90,10 @@ private static CultureInfo StringToCultureInfoOrDefault(string cultureString)
{
return CultureInfo.GetCultureInfo(cultureString);
}
catch (CultureNotFoundException)
catch (CultureNotFoundException e)
{
_log.LogWarning($"Tv Channel with unparsable language received: {cultureString}");
_log.LogWarning("Tv Channel with unparsable language received: {CultureString}", cultureString);
e.HandleAccordingToStrategy(GetType().Name, _log, _config.ExceptionHandlingStrategy);
}

return default;
Expand Down
Loading