Пример #1
0
        private async Task ValidateCache()
        {
            if (IsCacheValid)
            {
                return;
            }

            try
            {
                _cachedItems = await _wrappedReader.GetPeopleAsync();

                _dataDateTime = DateTime.Now;
            }
            catch
            {
                _cachedItems = new List <Person>()
                {
                    new Person()
                    {
                        GivenName  = "No Data Available",
                        FamilyName = string.Empty,
                        Rating     = 0,
                        StartDate  = DateTime.Today,
                    }
                };
                InvalidateCache();
            }
        }
        public Task <ViewResult> WithTask()
        {
            ViewData["Title"]        = "Using Task";
            ViewData["RequestStart"] = DateTime.Now;

            Task <IReadOnlyCollection <Person> > peopleTask = reader.GetPeopleAsync();

            Task <ViewResult> resultTask = peopleTask.ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    var errors = task.Exception !.Flatten().InnerExceptions;
                    return(View("Error", errors));
                }

                IReadOnlyCollection <Person> people = task.Result;
                ViewData["RequestEnd"] = DateTime.Now;
                return(View("Index", people));
            });

            return(resultTask);
        }
Пример #3
0
        public async Task <List <Person> > GetPeopleAsync()
        {
            try
            {
                return(await _wrappedReader.GetPeopleAsync());
            }
            catch (Exception ex)
            {
                await _logger?.LogException(ex);

                throw;
            }
        }
Пример #4
0
        public async Task <List <Person> > GetPeopleAsync()
        {
            _retryCount++;
            try
            {
                var people = await _wrappedReader.GetPeopleAsync();

                _retryCount = 0;
                return(people);
            }
            catch (Exception)
            {
                if (_retryCount >= 3)
                {
                    throw;
                }
                await Task.Delay(_retryDelay);

                return(await this.GetPeopleAsync());
            }
        }
Пример #5
0
 public async Task RefreshPeople()
 {
     People = await Reader.GetPeopleAsync();
 }