public async Task UpdatePlatformSettingsAsync() { var platformSettingsRaw = (await _scheduleSettingsApi.List(_overnightMarginSettings.ScheduleMarketId)) .ToList(); var invalidSchedules = InvalidSchedules(platformSettingsRaw); var platformSettings = platformSettingsRaw.Except(invalidSchedules) .Select(ScheduleSettings.Create).ToList(); _readerWriterLockSlim.EnterWriteLock(); try { _rawPlatformSchedule = platformSettings; PlatformCacheWarmUpUnsafe(); } finally { _readerWriterLockSlim.ExitWriteLock(); } if (invalidSchedules.Any()) { await _log.WriteWarningAsync(nameof(ScheduleSettingsCacheService), nameof(UpdatePlatformSettingsAsync), $"Some of ScheduleSettingsContracts were invalid, so they were skipped. The first one: {invalidSchedules.First().ToJson()}"); } }
public async Task UpdateMarketsScheduleSettingsAsync() { var marketsScheduleSettingsRaw = (await _scheduleSettingsApi.List()) .Where(x => !string.IsNullOrWhiteSpace(x.MarketId)) .ToList(); var invalidSchedules = marketsScheduleSettingsRaw.InvalidSchedules(); _readerWriterLockSlim.EnterWriteLock(); try { var platformScheduleSettings = marketsScheduleSettingsRaw .Where(x => x.MarketId == _overnightMarginSettings.ScheduleMarketId).ToList(); var newMarketsScheduleSettings = marketsScheduleSettingsRaw .Except(invalidSchedules) .GroupBy(x => x.MarketId) .ToDictionary(x => x.Key, x => x.ConcatWithPlatform(platformScheduleSettings, x.Key) .Select(ScheduleSettings.Create) .ToList()); _rawMarketScheduleCache = newMarketsScheduleSettings; MarketsCacheWarmUpUnsafe(); } finally { _readerWriterLockSlim.ExitWriteLock(); } if (invalidSchedules.Any()) { await _log.WriteWarningAsync(nameof(ScheduleSettingsCacheService), nameof(UpdateMarketsScheduleSettingsAsync), $"{invalidSchedules.Count} of ScheduleSettingsContracts were invalid, so they were skipped: {invalidSchedules.ToJson()}"); } }