protected override CachedTask <EventPoolResponse> GetData(bool force, CancellationToken token)
        {
            if (force ||
                Pool == null ||
                (Pool != null && Pool.AlwaysRefresh == true) ||
                (_previousSettings.Item1 != _settings.SearchPeriod || _previousSettings.Item2 != _settings.SearchInPast))
            {
                if (!_settings.ExcludedCategoriesByPool.ContainsKey(_poolId))
                {
                    _settings.ExcludedCategoriesByPool.Add(_poolId, new int[0]);
                }
                if (!_settings.ExcludedTagsByPool.ContainsKey(_poolId))
                {
                    _settings.ExcludedTagsByPool.Add(_poolId, new string[0]);
                }

                var request = new EventPoolRequest
                {
                    PoolId           = _poolId,
                    HoursCount       = (int)_settings.SearchPeriod,
                    IsInPast         = _settings.SearchInPast,
                    UserTickets      = _settings.UserTickets.ToArray(),
                    FavoriteEventIds = _settings.FavoriteItemIds.ToArray(),
                    Language         = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName
                };
                return(CachedTask.Create(() => _eventsService.GetEventPoolAsync(request, token), _poolId, DateTime.Now.Add(CacheDuration)));
            }
            return(CachedTask.NoNewData <EventPoolResponse>());
        }
Esempio n. 2
0
 protected override CachedTask <BeersResponse> GetData(bool force, CancellationToken token)
 {
     if (force)
     {
         return(CachedTask.Create(() => _beerService.GetBeersAsync(token)));
     }
     return(CachedTask.NoNewData <BeersResponse>());
 }
Esempio n. 3
0
        protected override CachedTask <FeedsResponse> GetData(bool force, CancellationToken token)
        {
            if (!force)
            {
                return(CachedTask.NoNewData <FeedsResponse>());
            }

            var request = new FeedsRequest
            {
                Language           = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName,
                IncludeGeneralFeed = true
            };

            return(CachedTask.Create(() => _feedsService.GetFeedsAsync(request, token)));
        }
Esempio n. 4
0
        protected override CachedTask <FeedItemContentResponse> GetData(bool force, CancellationToken token)
        {
            if (!force)
            {
                return(CachedTask.NoNewData <FeedItemContentResponse>());
            }

            var request = new FeedItemContentRequest
            {
                Language = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName,
                ItemId   = Item.Id
            };

            return(CachedTask.Create(() => _newsService.GetFeedItemContentAsync(request, token), Item.Id, DateTime.Now.Add(CacheDuration)));
        }
        protected override CachedTask <EventItemResponse> GetData(bool force, CancellationToken token)
        {
            if (force)
            {
                var request = new EventItemRequest
                {
                    ItemId      = _itemId,
                    UserTickets = _settings.UserTickets.ToArray(),
                    Language    = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName
                };

                return(CachedTask.Create(() => _eventsService.GetEventItemAsync(request, token), _itemId, DateTime.Now.Add(CacheDuration)));
            }

            return(CachedTask.NoNewData <EventItemResponse>());
        }
Esempio n. 6
0
        protected override CachedTask <CoursesResponse> GetData(bool force, CancellationToken token)
        {
            if (!force)
            {
                return(CachedTask.NoNewData <CoursesResponse>());
            }

            return(CachedTask.Create(() => _requestHandler.ExecuteAsync(() =>
            {
                var request = new CoursesRequest
                {
                    Language = CultureInfo.CurrentCulture.TwoLetterISOLanguageName
                };
                return _moodleService.GetCoursesAsync(request, token);
            })));
        }
Esempio n. 7
0
        protected override CachedTask <FoodResponse> GetData(bool force, CancellationToken token)
        {
            if (!force)
            {
                return(CachedTask.NoNewData <FoodResponse>());
            }

            var request = new FoodRequest
            {
                Language = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName,
                MealTime = MealTime,
                Date     = MealDate,
                UserName = _credentials.UserName
            };

            Func <Task <FoodResponse> > getter = () => _menuService.GetMenusAsync(request, token);

            if (MealDate.Date == DateTime.Now.Date)
            {
                return(CachedTask.Create(getter, MealTime.GetHashCode(), DateTime.Now.Date.AddDays(1)));
            }
            return(CachedTask.DoNotCache(getter));
        }
Esempio n. 8
0
        protected override CachedTask <ScheduleResponse> GetData(bool force, CancellationToken token)
        {
            if (!force)
            {
                return(CachedTask.NoNewData <ScheduleResponse>());
            }

            Func <Task <ScheduleResponse> > getter = () => _requestHandler.ExecuteAsync(() =>
            {
                var request = new ScheduleRequest
                {
                    Language  = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName,
                    WeekStart = WeekDate
                };
                return(_isaService.GetScheduleAsync(request, token));
            });

            if (DateTime.Now >= WeekDate && (DateTime.Now - WeekDate).TotalDays < DaysInWeek)
            {
                // cache ID must be non-zero so that other requests don't think this can be used as a placeholder
                return(CachedTask.Create(getter, 1, WeekDate.AddDays(DaysInWeek)));
            }
            return(CachedTask.DoNotCache(getter));
        }