示例#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 App()
        {
            if (config == null)
            {
                config = new Configuration();
                IPlatformInfo platformInfo = DependencyService.Get <IPlatformInfo>();
                CrossLogger.Current.Info("Kala", "Model: " + platformInfo.GetModel());
                CrossLogger.Current.Info("Kala", "Version: " + platformInfo.GetVersion());

                CrossLogger.Current.Debug("Kala", @"URL Settings: '" + Settings.Protocol + "://" + Settings.Server + ":" + Settings.Port.ToString() + "'");
                CrossLogger.Current.Debug("Kala", @"Auth Settings: '" + Settings.Username + " / " + Settings.Password + "'");
                CrossLogger.Current.Debug("Kala", @"Sitemap Settings: '" + Settings.Sitemap + "'");
            }
            ;

            //Initialize FFImageLoading with Authentication
            FFImageLoading.AuthenticatedHttpImageClientHandler.Initialize();

            //TabbedPage setup
            if (tp.Children.Count == 0)
            {
                tp.BackgroundColor    = App.config.BackGroundColor;
                tp.BarBackgroundColor = App.config.BackGroundColor;
                tp.BarTextColor       = App.config.TextColor;

                tp.CurrentPageChanged += (sender, e) =>
                {
                    //Reset screensaver timer
                    App.config.LastActivity = DateTime.Now;
                    CrossLogger.Current.Debug("Kala", "Reset Screensaver timer");
                };

                /**/ //Show a busy signal here as we can't display anything until we have downloaded the sitemap with its items. No async. Pointless..
                sitemaps = Sitemap.GetActiveSitemap(Settings.Sitemap);

                //Selected sitemap was not found, display settings page to make change
                if (sitemaps == null)
                {
                    //Add settings tab
                    MainPage = new Views.Page1();
                }
                else
                {
                    Sitemap sitemap = new Sitemap();
                    sitemap.GetUpdates();
                    sitemap.CreateSitemap(sitemaps);
                    CrossLogger.Current.Debug("Kala", "Got Sitemaps");

                    //Add settings tab last
                    App.tp.Children.Add(new Views.Page1());
                    MainPage = App.tp;
                }
            }
            else
            {
                MainPage = App.tp;
            }
            App.config.Initialized = true;
        }
示例#3
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);
            }
        }
示例#4
0
 public Models.Sitemap.Sitemap LoadItemsFromSitemap(Models.Sitemaps.Sitemap sitemap)
 {
     return(restService.LoadItemsFromSitemap(sitemap));
 }
示例#5
0
文件: Sitemap.cs 项目: johnjore/Kala
        /// <summary>
        /// Create GUI
        /// </summary>
        /// <returns>nothing</returns>
        public void CreateSitemap(Models.Sitemaps.Sitemap sitemap)
        {
            Models.Sitemap.Sitemap items = new RestService().LoadItemsFromSitemap(sitemap);

            //Configuration
            Dictionary <string, string> entry = Helpers.SplitCommand(items.Label);

            //Settings
            if (entry.ContainsKey("fullscreen"))
            {
                try
                {
                    App.Config.FullScreen = Convert.ToBoolean(entry["fullscreen"]);
                    DependencyService.Get <IScreen>().SetFullScreen(App.Config.FullScreen);
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'fullscreen' value: '" + entry["fullscreen"].ToString() + "', " + ex.ToString());
                }
            }

            if (entry.ContainsKey("screensaver"))
            {
                try
                {
                    App.Config.ScreenSaver = Convert.ToInt64(entry["screensaver"]);
                    IScreen ss = DependencyService.Get <IScreen>();
                    ss.ScreenSaver(App.Config.ScreenSaver);

                    App.Config.ScreenSaverType = Models.ScreenSaverTypes.Clock;
                    if (entry.ContainsKey("screensavertype"))
                    {
                        App.Config.ScreenSaverType = (Models.ScreenSaverTypes)Enum.Parse(typeof(Models.ScreenSaverTypes), entry["screensavertype"], true);
                    }

                    switch (App.Config.ScreenSaverType)
                    {
                    case Models.ScreenSaverTypes.Images:
                        if (entry.ContainsKey("screensaverurl"))
                        {
                            Widgets.SetUrl(entry["screensaverurl"]);
                        }
                        else
                        {
                            App.Config.ScreenSaverType = Models.ScreenSaverTypes.Clock;
                        }
                        break;
                    }
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'screensaver' value: '" + entry["screensaver"].ToString() + "', " + ex.ToString());
                }
            }

            if (entry.ContainsKey("kala"))
            {
                try
                {
                    App.Config.Valid = Convert.ToBoolean(entry["kala"]);
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'kala' identifier: '" + entry["kala"].ToString() + "', " + ex.ToString());
                }
            }

            if (entry.ContainsKey("background"))
            {
                try
                {
                    App.Config.BackGroundColor = Color.FromHex(entry["background"]);
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'background' value: '" + entry["background"].ToString() + "', " + ex.ToString());
                }
            }

            if (entry.ContainsKey("cell"))
            {
                try
                {
                    App.Config.CellColor = Color.FromHex(entry["cell"]);
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'cell' value: '" + entry["cell"].ToString() + "', " + ex.ToString());
                }
            }

            if (entry.ContainsKey("text"))
            {
                try
                {
                    App.Config.TextColor = Color.FromHex(entry["text"]);
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'text' value: '" + entry["text"].ToString() + "', " + ex.ToString());
                }
            }

            if (entry.ContainsKey("value"))
            {
                try
                {
                    App.Config.ValueColor = Color.FromHex(entry["value"]);
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'value' value: '" + entry["value"].ToString() + "', " + ex.ToString());
                }
            }

            if (entry.ContainsKey("screenorientation"))
            {
                try
                {
                    IScreen so = DependencyService.Get <IScreen>();
                    so.SetScreenOrientation(entry["screenorientation"]);
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to action 'screenorientation' value: '" + entry["screenorientation"].ToString() + "', " + ex.ToString());
                }
            }

            if (entry.ContainsKey("settings"))
            {
                try
                {
                    App.Config.Settings = Convert.ToBoolean(entry["settings"]);
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to action 'settings' value: '" + entry["settings"].ToString() + "', " + ex.ToString());
                }
            }

            if (App.Config.Valid)
            {
                ParseSitemap(items);

                //Enable screensaver?
                if (App.Config.ScreenSaver > 0)
                {
                    Widgets.Screensaver(App.Config.ScreenSaver);
                    App.Config.ScreenSaver = 0;
                }
            }
        }
示例#6
0
文件: Sitemap.cs 项目: johnjore/Kala
        /// <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());
            }
        }
示例#7
0
        /// <summary>
        /// Create GUI
        /// </summary>
        /// <returns>nothing</returns>
        public void CreateSitemap(Models.Sitemaps.Sitemap sitemap)
        {
            Models.Sitemap.Sitemap items = new RestService().LoadItemsFromSitemap(sitemap);

            //Configuration
            Dictionary <string, string> entry = Helpers.SplitCommand(items.label);

            //Settings
            if (entry.ContainsKey("fullscreen"))
            {
                //Setting is stored locally, else its read too late to take effect on device
                try
                {
                    Settings.Fullscreen = Convert.ToBoolean(entry["fullscreen"]);
                }
                catch
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'fullscreen' value: '" + entry["fullscreen"] + "'");
                }
            }

            if (entry.ContainsKey("screensaver"))
            {
                try
                {
                    //Setting is stored locally, else its read too late to take effect on device
                    Settings.Screensaver = Convert.ToInt16(entry["screensaver"]);
                }
                catch
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'screensaver' value: '" + entry["screensaver"] + "'");
                }
            }

            if (entry.ContainsKey("kala"))
            {
                try
                {
                    App.config.Valid = Convert.ToBoolean(entry["kala"]);
                }
                catch
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'kala' identifier: '" + entry["kala"] + "'");
                }
            }

            if (entry.ContainsKey("background"))
            {
                try
                {
                    App.config.BackGroundColor = Color.FromHex(entry["background"]);
                }
                catch
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'background' value: '" + entry["background"] + "'");
                }
            }

            if (entry.ContainsKey("cell"))
            {
                try
                {
                    App.config.CellColor = Color.FromHex(entry["cell"]);
                }
                catch
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'cell' value: '" + entry["cell"] + "'");
                }
            }
            if (entry.ContainsKey("text"))
            {
                try
                {
                    App.config.TextColor = Color.FromHex(entry["text"]);
                }
                catch
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'text' value: '" + entry["text"] + "'");
                }
            }
            if (entry.ContainsKey("value"))
            {
                try
                {
                    App.config.ValueColor = Color.FromHex(entry["value"]);
                }
                catch
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'value' value: '" + entry["value"] + "'");
                }
            }


            CrossLogger.Current.Info("Kala", "Fullscreen : " + Settings.Fullscreen.ToString());
            CrossLogger.Current.Info("Kala", "Screensaver: " + Settings.Screensaver.ToString());
            CrossLogger.Current.Info("Kala", "Sitemap: " + Settings.Fullscreen.ToString());

            if (App.config.Valid)
            {
                ParseSitemap(items);

                //Enable screensaver?
                if (Settings.Screensaver > 0)
                {
                    Widgets.Screensaver(Settings.Screensaver);
                }
            }
        }
示例#8
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;
                        }
                    }
                }
            }
        }
示例#9
0
文件: App.cs 项目: dragonxu/Kala
        public App()
        {
            if (Config == null)
            {
                Config = new Configuration();
                IPlatformInfo platformInfo = DependencyService.Get <IPlatformInfo>();
                CrossLogger.Current.Info("Kala", "Model: " + platformInfo.GetModel());
                CrossLogger.Current.Info("Kala", "Version: " + platformInfo.GetVersion());
                CrossLogger.Current.Info("Kala", "Wifi MAC address: " + platformInfo.GetWifiMacAddress());

                CrossLogger.Current.Debug("Kala", @"URL Settings: '" + Settings.Protocol + "://" + Settings.Server + ":" + Settings.Port.ToString() + "'");
                CrossLogger.Current.Debug("Kala", @"Auth Settings: '" + Settings.Username + " / " + Settings.Password + "'");
                CrossLogger.Current.Debug("Kala", @"Sitemap Settings: '" + Settings.Sitemap + "'");
            }

            //Initialize FFImageLoading with Authentication
            FFImageLoading.AuthenticatedHttpImageClientHandler.Initialize();

            //TabbedPage setup
            if (Tp.Children.Count == 0)
            {
                Tp.BackgroundColor    = Config.BackGroundColor;
                Tp.BarBackgroundColor = Config.BackGroundColor;
                Tp.BarTextColor       = Config.TextColor;

                Tp.CurrentPageChanged += (sender, e) =>
                {
                    //Reset screensaver timer
                    Config.LastActivity = DateTime.Now;
                    CrossLogger.Current.Debug("Kala", "Reset Screensaver timer");
                };

                //Auto configured sitemap?
                var WifiMac = DependencyService.Get <IPlatformInfo>().GetWifiMacAddress();
                Sitemaps = Sitemap.GetActiveSitemap(WifiMac);

                if (Sitemaps == null)
                {
                    Sitemaps = Sitemap.GetActiveSitemap(Settings.Sitemap);

                    //Selected sitemap was not found, display settings page to make change
                    if (Sitemaps == null)
                    {
                        //Add settings tab with Wifi Mac as default
                        Settings.Sitemap = WifiMac;
                        MainPage         = new Pages.Settings();
                    }
                }

                if (Sitemaps != null)
                {
                    Sitemap sitemap = new Sitemap();
                    sitemap.GetUpdates();
                    sitemap.CreateSitemap(Sitemaps);
                    CrossLogger.Current.Debug("Kala", "Got Sitemaps");

                    if (Config.Settings)
                    {
                        //Add settings tab last
                        Tp.Children.Add(new Pages.Settings());
                    }
                    MainPage = Tp;
                }
            }
            else
            {
                MainPage = Tp;
            }
            Config.Initialized = true;
        }