Пример #1
0
        public Models.Sitemap.Sitemap LoadItemsFromSitemap(Models.Sitemaps.Sitemap sitemap)
        {
            client.DefaultRequestHeaders.Add("Accept", "application/json");
            var uri = new Uri(sitemap.link);

            CrossLogger.Current.Debug("Kala", @"URI: '" + uri.ToString() + "'");

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

                if (!response.IsSuccessStatusCode)
                {
                    Application.Current.MainPage.DisplayAlert("Alert", response.StatusCode.ToString(), "OK");
                    throw new Exception($"{response.StatusCode} received from server");
                }

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

                CrossLogger.Current.Debug("Kala", @"Content Response: '" + resultString.ToString() + "'");

                Models.Sitemap.Sitemap items = JsonConvert.DeserializeObject <Models.Sitemap.Sitemap>(resultString);

                return(items);
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Debug("Kala", @"Exception : '" + ex.ToString() + "'");
                Application.Current.MainPage.DisplayAlert("Alert", ex.Message, "OK");
                return(null);
            }
        }
Пример #2
0
        public Models.Sitemap.Sitemap LoadItemsFromSitemap(Models.Sitemaps.Sitemap sitemap)
        {
            try
            {
                Client.DefaultRequestHeaders.Add("Accept", "application/json");
                if (sitemap.Link == null)
                {
                    return(null);
                }
                var uri = new Uri(sitemap.Link);
                Device.BeginInvokeOnMainThread(() => CrossLogger.Current.Debug("Kala", @"URI: '" + uri.ToString() + "'"));

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

                if (!response.IsSuccessStatusCode)
                {
                    return(null);
                }

                string resultString = response.Content.ReadAsStringAsync().Result.ToString();
                Device.BeginInvokeOnMainThread(() => CrossLogger.Current.Debug("Kala", @"Content Response: '" + resultString.ToString() + "'"));

                try
                {
                    Models.Sitemap.Sitemap items = JsonConvert.DeserializeObject <Models.Sitemap.Sitemap>(resultString);
                    return(items);
                }
                catch
                {
                    Device.BeginInvokeOnMainThread(() => CrossLogger.Current.Error("RestService", "Failed to parse JSON sitemap response"));
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Device.BeginInvokeOnMainThread(() => CrossLogger.Current.Error("Kala", @"Exception : '" + ex.ToString() + "'"));
                return(null);
            }
        }
Пример #3
0
        /// <summary>
        /// Parse Sitemap file
        /// </summary>
        /// <returns>nothing</returns>
        private void ParseSitemap(Models.Sitemap.Sitemap items)
        {
            try
            {
                foreach (Models.Sitemap.Widget page in items.Homepage.Widgets)
                {
                    CrossLogger.Current.Debug("Kala", "Label: " + page.Label);

                    //Populate Page, if it contains elements to parse
                    if (page.Label != string.Empty)
                    {
                        Dictionary <string, string> pageKeyValuePairs = Helpers.SplitCommand(page.Label);
                        CrossLogger.Current.Debug("Kala", "Label: " + pageKeyValuePairs["label"]);

                        #region page
                        if (page.LinkedPage != null)
                        {
                            if (pageKeyValuePairs.ContainsKey("sx") && pageKeyValuePairs.ContainsKey("sy") && pageKeyValuePairs.ContainsKey("label"))
                            {
                                if (!pageKeyValuePairs.ContainsKey("icon"))
                                {
                                    pageKeyValuePairs.Add("icon", null);
                                }

                                CrossLogger.Current.Debug("Kala", "Sitemap - Create Grid using: " + pageKeyValuePairs["label"] + ", " + pageKeyValuePairs["sx"] + ", " + pageKeyValuePairs["sy"] + ", " + pageKeyValuePairs["icon"]);
                                Grid grid = CreatePage(pageKeyValuePairs["label"], pageKeyValuePairs["sx"], pageKeyValuePairs["sy"], pageKeyValuePairs["icon"]);

                                foreach (Models.Sitemap.Widget3 item in page.LinkedPage.Widgets)
                                {
                                    ParseWidgets(grid, item);
                                }
                            }
                        }
                        #endregion page
                        else
                        {
                            CrossLogger.Current.Warn("Kala", "Unknown: " + ToString());

                            switch (pageKeyValuePairs["widget"].ToUpper())
                            {
                            case "SITEMAP":
                                CrossLogger.Current.Debug("Kala", "Sitemap:" + pageKeyValuePairs["name"]);

                                Models.Sitemaps.Sitemap sitemaps = GetActiveSitemap(pageKeyValuePairs["name"]);
                                if (sitemaps != null)
                                {
                                    Sitemap sitemap = new Sitemap();
                                    sitemap.CreateSitemap(sitemaps);

                                    CrossLogger.Current.Debug("Kala", "Got ActiveSitemap");
                                }
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Sitemap", "ParseSitemap() crashed: " + ex.ToString());
            }
        }
Пример #4
0
        /// <summary>
        /// Parse Sitemap file
        /// </summary>
        /// <returns>nothing</returns>
        private void ParseSitemap(Models.Sitemap.Sitemap items)
        {
            foreach (Models.Sitemap.Widget page in items.homepage.widget)
            {
                CrossLogger.Current.Debug("Kala", "Label: " + page.label);

                //Populate Page, if it contains elements to parse
                if (page.label != string.Empty)
                {
                    Dictionary <string, string> pageKeyValuePairs = Helpers.SplitCommand(page.label);
                    CrossLogger.Current.Debug("Kala", "Label: " + pageKeyValuePairs["label"]);

                    #region page
                    if (page.linkedPage != null)
                    {
                        Grid grid = null;

                        if (pageKeyValuePairs.ContainsKey("sx") && pageKeyValuePairs.ContainsKey("sy"))
                        {
                            if (pageKeyValuePairs.ContainsKey("icon"))
                            {
                                grid = CreatePage(pageKeyValuePairs["label"], pageKeyValuePairs["sx"], pageKeyValuePairs["sy"], pageKeyValuePairs["icon"]);
                            }
                            else
                            {
                                grid = CreatePage(pageKeyValuePairs["label"], pageKeyValuePairs["sx"], pageKeyValuePairs["sy"], null);
                            }
                        }

                        //Shortcut
                        var w = page.linkedPage.widget;

                        //If more than one item page frame
                        if (w.GetType() == typeof(JArray))
                        {
                            List <Models.Sitemap.Widget3> w_items = ((JArray)w).ToObject <List <Models.Sitemap.Widget3> >();
                            foreach (Models.Sitemap.Widget3 item in w_items)
                            {
                                ParseWidgets(grid, item);
                            }
                        }
                        //If one item in page frame
                        else if (w.GetType() == typeof(JObject))
                        {
                            Models.Sitemap.Widget3 item = ((JObject)w).ToObject <Models.Sitemap.Widget3>();
                            ParseWidgets(grid, item);
                        }
                        else
                        {
                            CrossLogger.Current.Warn("Kala", "Unknown: " + w.ToString());
                        }
                    }
                    #endregion page
                    else
                    {
                        CrossLogger.Current.Warn("Kala", "Unknown: " + ToString());

                        switch (pageKeyValuePairs["widget"].ToUpper())
                        {
                        case "SITEMAP":
                            CrossLogger.Current.Debug("Kala", "Sitemap:" + pageKeyValuePairs["name"]);

                            Models.Sitemaps.Sitemap sitemaps = GetActiveSitemap(pageKeyValuePairs["name"]);
                            if (sitemaps != null)
                            {
                                Sitemap sitemap = new Sitemap();
                                sitemap.CreateSitemap(sitemaps);

                                CrossLogger.Current.Debug("Kala", "Got ActiveSitemap");
                            }
                            break;
                        }
                    }
                }
            }
        }