Пример #1
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"))
            {
                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;
                }
            }
        }
Пример #2
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);
                }
            }
        }
Пример #3
0
        public static async void FloormapAsync(Grid grid, int px, int py, int sx, int sy, string header, JObject data)
        {
            Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Create Floormap Widget");

            try
            {
                Floorplan flooritem = data.ToObject <Floorplan>();
                CrossLogger.Current.Debug("Floormap", "URL: " + flooritem.Url);

                var httpClient = new HttpClient();
                var svgString  = await httpClient.GetStringAsync(flooritem.Url);

                //Loop through SVG and find "ID" and add as Sensor
                MatchCollection matches = Regex.Matches(svgString, "(id=\")(.*)(.\\b(on|off))", RegexOptions.IgnoreCase);
                for (int j = 0; j < matches.Count; j++)
                {
                    string Itemid = matches[j].Groups[2].Value;
                    if (App.Config.Items.Find(s => s.Name == Itemid) == null)
                    {
                        CrossLogger.Current.Debug("Floormap", "Adding: " + Itemid);

                        RestService GetItemUpdate = new RestService();
                        string      state         = GetItemUpdate.GetItem(Itemid);

                        if (state != null)
                        {
                            App.TrackItem sensor = new App.TrackItem
                            {
                                Name  = Itemid,
                                State = state,
                                Type  = Itemtypes.Sensor
                            };
                            App.Config.Items.Add(sensor);
                        }
                    }
                }

                #region w_grid
                Grid w_grid = new Grid
                {
                    RowSpacing        = 0,
                    ColumnSpacing     = 0,
                    Padding           = new Thickness(0, 0, 0, 0),
                    BackgroundColor   = App.Config.CellColor,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                };
                grid.Children.Add(w_grid, px, px + sx, py, py + sy);
                #endregion w_grid

                #region Header
                w_grid.Children.Add(new Label
                {
                    Text                    = header,
                    FontSize                = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                    TextColor               = App.Config.TextColor,
                    BackgroundColor         = App.Config.CellColor,
                    HorizontalTextAlignment = TextAlignment.Center,
                    VerticalTextAlignment   = TextAlignment.Start
                }, 0, 0);
                #endregion Header

                #region SVG
                SvgCachedImage svg = new SvgCachedImage
                {
                    DownsampleToViewSize = false,
                    CacheDuration        = TimeSpan.FromMilliseconds(1000),
                    Aspect = Aspect.AspectFit,
                    BitmapOptimizations = false,
                    Source = SvgImageSource.FromSvgString(svgString)
                };
                w_grid.Children.Add(svg, 0, 0);

                App.TrackItem svgImage = new App.TrackItem
                {
                    State    = svgString,
                    Header   = header,
                    Type     = Itemtypes.Floormap,
                    SvgImage = svg
                };
                App.Config.Items.Add(svgImage);
                #endregion SVG

                CrossLogger.Current.Debug("Floormap", "SVGBefore");
                foreach (App.TrackItem item in App.Config.Items.Where(n => n.Type == Itemtypes.Sensor))
                {
                    svgImage.State = UpdateOnOff(item, svgImage.State);
                }
                svgImage.SvgImage.Source = SvgImageSource.FromSvgString(svgImage.State);
                svgImage.SvgImage.ReloadImage();
                CrossLogger.Current.Debug("Floormap", "SVGAfter");

                //Button must be last to be added to work
                Button dummyButton = new Button
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    BackgroundColor   = Color.Transparent,
                };
                w_grid.Children.Add(dummyButton, 0, 0);
                dummyButton.Clicked += OnDummyButtonClicked;
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Floormap", "Widgets.Floormap crashed: " + ex.ToString());
                Error(grid, px, py, sx, sy, ex.ToString());
            }
        }