Exemple #1
0
        /// <summary>
        /// Synchronizes the races in the <paramref name="context"/> with the
        /// races from <paramref name="races"/>.
        /// </summary>
        /// <param name="context">The database context</param>
        /// <param name="srlService">The SRL service</param>
        /// <param name="races">The SRL races</param>
        public static async Task SyncRaces(
            DatabaseContext context
            , SRLService srlService
            , List <SRLRace> races)
        {
            List <Race> res = UpdateSRLRaces(context, races);

            await UpdateDroppedRacesAsync(context, srlService, res).ConfigureAwait(false);
        }
Exemple #2
0
        /// <summary>
        /// Initializes the SRL service
        /// </summary>
        private static void InitSrlService()
        {
            double updateInterval = LoadUpdateInterval();

            Logger.Info($"Update Interval set to {updateInterval}ms");

            _srlService           = new SRLService(updateInterval);
            _srlService.OnUpdate += OnSrlUpdate;
        }
Exemple #3
0
        /// <summary>
        /// Attempts to fetch and update race details of race entities
        /// which are no longer in the SRL race list.
        /// </summary>
        /// <param name="context">The database context</param>
        /// <param name="srlService">The srl service</param>
        /// <param name="updatedRaces">The list of updated races</param>
        public static async Task UpdateDroppedRacesAsync(
            DatabaseContext context
            , SRLService srlService
            , List <Race> updatedRaces)
        {
            List <Race> remainingActiveRaces = context
                                               .Races
                                               .Local
                                               .Where(r => r.IsActive && !updatedRaces.Any(ur => ur.SrlId.Equals(r.SrlId, StringComparison.CurrentCultureIgnoreCase)))
                                               .ToList();

            foreach (Race race in remainingActiveRaces)
            {
                try
                {
                    Logger.Info($"({race.Id}) Dropped, Fetching race...");

                    SRLRace srlRace
                        = await srlService.GetRaceAsync(race.SrlId).ConfigureAwait(false);

                    Logger.Info($"({race.Id}) Race fetched, Synchronizing...");

                    SyncRace(context, srlRace);
                }
                catch (Exception ex)
                {
                    Logger.Error($"({race.SrlId}) Exception thrown", ex);

                    race.ConsecutiveUpdateFailures++;

                    if (race.ConsecutiveUpdateFailures > 10)
                    {
                        Logger.Info($"({race.SrlId}) Deactivating race...");

                        race.IsActive = false;
                        if (race.State < SRLApiClient.Endpoints.RaceState.Finished)
                        {
                            race.State = SRLApiClient.Endpoints.RaceState.Unknown;
                        }
                    }
                }
            }
        }