Пример #1
0
        public IObservable <Post> GetPost(string id)
        {
            return(_cache.GetAndFetchLatest(id,
                                            async() =>
            {
                var result = await _fakeAPI.GetPost(id);
                await Task.Delay(1000); //Fake longer network request, so we visually see the refresh happening on screen!

                //Add visual timestamp to title of a post, this way we see what time the data has been fechted
                result.Title = string.Concat(DateTime.Now.ToString("T", CultureInfo.InvariantCulture), " - ", result.Title);
                return result;
            },
                                            offset =>
            {
                if (CrossConnectivity.Current.IsConnected)
                {
                    TimeSpan elapsed = DateTimeOffset.Now - offset;
                    return elapsed > _cachedPostTime;
                }
                else
                {
                    return false;
                }
            }));
        }
Пример #2
0
        private async Task <Post> GetPostAsync(string id)
        {
            var result = await _fakeAPI.GetPost(id);

            await Task.Delay(1000); //Fake longer network request, so we visually see the refresh happening on screen!

            //Add visual timestamp to title of a post, this way we see what time the data has been fechted
            result.Title = string.Concat(DateTime.Now.ToString("T", CultureInfo.InvariantCulture), " - ", result.Title);
            return(result);
        }
Пример #3
0
 public Task <Post> GetPost(string id)
 {
     return(_internalAPI.GetPost(id));
 }