示例#1
0
        private IEnumerable <Kit> UpdateMatches(Profile profile)
        {
            if (DateTime.Now - profile.LastUpdated < TimeSpan.FromDays(1))
            {
                _logger.LogInfo("All matches are already up to date");
                return(Enumerable.Empty <Kit>());
            }

            Task <IEnumerable <Match> > matchTask;

            if (profile.MatchCount == 0)
            {
                _logger.LogInfo("Fetching all matches...");
                matchTask = _service.ListAllMatches();
            }
            else
            {
                _logger.LogInfo($"Fetching new matches since {profile.LastUpdated.ToShortDateString()}");
                matchTask = _service.ListNewMatches(profile.LastUpdated);
            }

            var matches = matchTask.Result;
            var kits    = matches.Select(m => ModelBuilder.BuildKit(m, DateTime.Now)).ToArray();

            profile.AddMatches(kits);
            profile.LastUpdated = DateTime.Now;

            _logger.LogInfo($"Done fetching {matches.Count()} matches");
            return(kits);
        }
        public async Task <IEnumerable <Match> > ListAllMatches()
        {
            if (TryGetStoredResult("ListAllMatches", out IEnumerable <Match> cached))
            {
                return(cached);
            }

            var result = await _service.ListAllMatches();

            StoreResult("ListAllMatches", result);
            return(result);
        }