Пример #1
0
        public async Task <HallDTO> LoadHallAsync(string id, HallDTO hallCached, CancellationToken cancellationToken)
        {
            if (CheckConnection())
            {
                try
                {
                    string content = await LoadAsync(new Uri($"{App.UriBase}/api/Halls/{id}?hash={hallCached.GetHashCode()}"), cancellationToken);

                    if (string.IsNullOrEmpty(content))
                    {
                        return(hallCached);
                    }
                    HallDTO hall = JsonConvert.DeserializeObject <HallDTO>(content);
                    await DependencyService.Get <CachingService>().WriteHallAsync(hall);

                    return(hall);
                }
                catch (Exception ex)
                {
                    if (ex is HttpRequestException || ex is WebException)
                    {
                        return(hallCached);
                    }
                    else if (ex is OperationCanceledException)
                    {
                        throw ex;
                    }
                }
            }
            return(hallCached);
        }