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); }
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); }
internal Task OnFallBackEvent(FallBackEvent args) => FallBackEvent.Raise(args);