Exemple #1
0
        public override async Task <bool> Attempt(string url)
        {
            Result = default(T);

            if (FallBackEventPolicy == ApiFallBackEventPolicy.Raise)
            {
                await FallBackEvent.Raise(new FallBackEvent
                {
                    Url             = url,
                    FriendlyMessage = $"Failed to get results from {url.AsUri().Host}."
                });
            }

            return(true);
        }
Exemple #2
0
        public override async Task <bool> Attempt(string url)
        {
            var cache = ApiResponseCache <T> .Create(url);

            if (!await cache.HasValidValue(CacheAge))
            {
                Error = new Exception("No valid cache is available.");
                return(false);
            }

            Result = cache.Data;

            if (!Silent && FallBackEventPolicy == ApiFallBackEventPolicy.Raise)
            {
                await FallBackEvent.Raise(new FallBackEvent
                {
                    Url             = url,
                    CacheAge        = cache.Age,
                    FriendlyMessage = $"Failed to get fresh results from {url.AsUri().Host}. Using the latest cache from {cache.Age.ToNaturalTime(1)} ago."
                });
            }

            return(true);
        }
Exemple #3
0
 internal Task OnFallBackEvent(FallBackEvent args) => FallBackEvent.Raise(args);