Beispiel #1
0
        public Models.Sitemaps.Sitemaps ListSitemaps()
        {
            var uri = new Uri(string.Format("{0}://{1}:{2}/{3}", Settings.Protocol, Settings.Server, Settings.Port.ToString(), Common.Constants.Api.Sitemaps, string.Empty));

            client.DefaultRequestHeaders.Add("Accept", "application/json");
            CrossLogger.Current.Debug(@"URI: '" + uri.ToString() + "'");

            try
            {
                var response = client.GetAsync(uri).Result;

                if (!response.IsSuccessStatusCode)
                {
                    //Application.Current.MainPage.DisplayAlert("Alert", response.StatusCode.ToString(), "OK");
                    return(null);
                }

                string resultString = response.Content.ReadAsStringAsync().Result;

                //CrossLogger.Current.Debug("Kala", @"Content Response: '" + resultString.ToString() + "'");
                Models.Sitemaps.Sitemaps sitemaps = JsonConvert.DeserializeObject <Models.Sitemaps.Sitemaps>(resultString);
                //CrossLogger.Current.Debug("Kala", "Sitemaps: " + sitemaps.sitemap.Count().ToString());
                return(sitemaps);
            }
            catch
            {
                return(null);
            }
        }
Beispiel #2
0
        public Models.Sitemaps.Sitemaps ListSitemaps()
        {
            var uri = new Uri(string.Format("{0}://{1}:{2}/{3}", Settings.Protocol, Settings.Server, Settings.Port.ToString(), Common.Constants.Api.Sitemaps));

            Client.DefaultRequestHeaders.Add("Accept", "application/json");
            CrossLogger.Current.Debug(@"URI: '" + uri.ToString() + "'");

            try
            {
                var response = Client.GetAsync(uri).Result;

                if (!response.IsSuccessStatusCode)
                {
                    CrossLogger.Current.Error("RestService", "Failed: " + response.StatusCode.ToString());
                    return(null);
                }

                string resultString = response.Content.ReadAsStringAsync().Result;
                CrossLogger.Current.Debug("RestService", "Content Response: " + resultString.ToString());

                try
                {
                    Models.Sitemaps.Sitemaps sitemaps = new Models.Sitemaps.Sitemaps
                    {
                        Sitemap = ((JArray)JToken.Parse(resultString)).ToObject <List <Models.Sitemaps.Sitemap> >()
                    };

                    CrossLogger.Current.Debug("RestService", "Found " + sitemaps.Sitemap.Count.ToString() + " sitemaps");
                    return(sitemaps);
                }
                catch
                {
                    CrossLogger.Current.Error("RestService", "Failed to parse JSON sitemaps response");
                    return(null);
                }
            }
            catch
            {
                CrossLogger.Current.Error("RestService", "Failed to enumerate sitemaps");
                return(null);
            }
        }