Ejemplo n.º 1
0
        public async Task <ServiceResult <PhotoDetails> > SyncPhotoDetailsResultAsync(string id)
        {
            ServiceResult <PhotoDetails> result = new ServiceResult <PhotoDetails>();

            try
            {
                if (NetworkConnection.CheckNetwork())
                {
                    using (HttpClient httpClient = new HttpClient())
                    {
                        var response = await httpClient.GetAsync(new Uri
                                                                 (Constants.ServiceURL + "method=flickr.photos.getInfo&api_key=" + Constants.ApiKey + "&photo_id=" + id));

                        if (response.StatusCode == HttpStatusCode.Ok)
                        {
                            string photosXml = await response.Content.ReadAsStringAsync();

                            XmlSerializer           serializer       = new XmlSerializer(typeof(Models.PhotoDetails.Rsp));
                            StringReader            reader           = new StringReader(photosXml);
                            Models.PhotoDetails.Rsp resultingMessage = (Models.PhotoDetails.Rsp)serializer.Deserialize(reader);

                            _CacheService.SaveData(searchCacheKey + id, resultingMessage.Photo);
                            result.Successful = true;
                            result.Content    = resultingMessage.Photo;
                        }
                        else
                        {
                            result.Content    = null;
                            result.Successful = false;
                            result.Message    = ResourceLoader.GetForCurrentView().GetString("NetworkError");
                        }
                    }
                }
                else
                {
                    result.Message    = ResourceLoader.GetForCurrentView().GetString("NoNetworkConnection");
                    result.Successful = false;
                }
            }
            catch (COMException)
            {
                result.Content    = null;
                result.Successful = false;
                result.Message    = ResourceLoader.GetForCurrentView().GetString("NetworkError");
            }
            catch (XmlException)
            {
                result.Content    = null;
                result.Successful = false;
                result.Message    = ResourceLoader.GetForCurrentView().GetString("NetworkError");
            }
            catch
            {
                result.Content    = null;
                result.Successful = false;
                result.Message    = ResourceLoader.GetForCurrentView().GetString("ServerError");
            }

            return(result);
        }