Ejemplo n.º 1
0
        /// <summary>
        /// Parses / creates Widgets
        /// </summary>
        /// <returns>nothing</returns>
        private void ParseWidgets(Grid grid, Models.Sitemap.Widget3 item)
        {
            try
            {
                CrossLogger.Current.Debug("Kala", "ID: " + item.WidgetId);
                Dictionary <string, string> itemKeyValuePairs = Helpers.SplitCommand(item.Label);

                if (itemKeyValuePairs != null && itemKeyValuePairs.ContainsKey("widget") && itemKeyValuePairs.ContainsKey("px") && itemKeyValuePairs.ContainsKey("py"))
                {
                    //Position
                    int.TryParse(itemKeyValuePairs["px"], out int px);
                    int.TryParse(itemKeyValuePairs["py"], out int py);

                    //Size
                    int sx = 1;
                    if (itemKeyValuePairs.ContainsKey("sx"))
                    {
                        int.TryParse(itemKeyValuePairs["sx"], out sx);
                    }
                    int sy = 1;
                    if (itemKeyValuePairs.ContainsKey("sy"))
                    {
                        int.TryParse(itemKeyValuePairs["sy"], out sy);
                    }

                    //Gauge-Group
                    int rx = 1;
                    if (itemKeyValuePairs.ContainsKey("rx"))
                    {
                        int.TryParse(itemKeyValuePairs["rx"], out rx);
                    }
                    int ry = 1;
                    if (itemKeyValuePairs.ContainsKey("ry"))
                    {
                        int.TryParse(itemKeyValuePairs["ry"], out ry);
                    }

                    switch (itemKeyValuePairs["widget"].ToUpper())
                    {
                    case "AVATAR":
                        Widgets.Avatar(grid, px, py, sx, sy, JArray.FromObject(item.Widgets));
                        break;

                    case "BARCODE":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Barcode(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "BLIND":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Blind(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "BLANK":
                        Widgets.Blank(grid, px, py, sx, sy);
                        break;

                    case "CALENDAR":
                        Widgets.Calendar(grid, px, py, sx, sy, JArray.FromObject(item.Widgets));
                        break;

                    case "CHART":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Chart(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "CLOCK":
                        Widgets.Clock(grid, px, py, sx, sy);
                        break;

                    case "DIMMER":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Dimmer(grid, px, py, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "FLOORMAP":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.FloormapAsync(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "GAUGE":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Gauge(grid, px, py, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "GAUGE-GROUP":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Gauge_Group(grid, px, py, sx, sy, rx, ry, itemKeyValuePairs["label"], JArray.FromObject(item.Widgets));
                        }
                        break;

                    case "IMAGE":
                        if (!itemKeyValuePairs.ContainsKey("aspect"))
                        {
                            itemKeyValuePairs.Add("aspect", "aspectfill");
                        }

                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Image(grid, px, py, sx, sy, itemKeyValuePairs["label"], itemKeyValuePairs["aspect"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "LAUNCHER":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Launcher(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "MAP":
                        if (!itemKeyValuePairs.ContainsKey("type"))
                        {
                            itemKeyValuePairs.Add("type", "street");
                        }
                        Widgets.Map(grid, px, py, sx, sy, itemKeyValuePairs["type"], JArray.FromObject(item.Widgets));
                        break;

                    case "NUMERICINPUT":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.NumericInput(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "SENSOR":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Sensor(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "SWITCH":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Switch(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "VOICE":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Voice(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "WEATHER":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Weather(grid, px, py, sx, sy, itemKeyValuePairs["label"], JArray.FromObject(item.Widgets));
                        }
                        break;

                    case "WEATHERFORECAST":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.WeatherForecast(grid, px, py, sx, sy, itemKeyValuePairs["label"], JArray.FromObject(item.Widgets));
                        }
                        break;

                    default:
                        CrossLogger.Current.Warn("Kala", "Failed to parse widget. Unknown type: " + item.ToString());
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Kala", "Failed to parse widget: " + ex.ToString());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses / creates Widgets
        /// </summary>
        /// <returns>nothing</returns>
        private void ParseWidgets(Grid grid, Models.Sitemap.Widget3 item)
        {
            try
            {
                CrossLogger.Current.Debug("Kala", "Widget : " + item.widget + ", ID: " + item.widgetId);
                Dictionary <string, string> itemKeyValuePairs = Helpers.SplitCommand(item.label);

                if (itemKeyValuePairs != null && itemKeyValuePairs.ContainsKey("widget") && itemKeyValuePairs.ContainsKey("px") && itemKeyValuePairs.ContainsKey("py"))
                {
                    switch (itemKeyValuePairs["widget"].ToUpper())
                    {
                    case "AVATAR":
                        if (itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy"))
                        {
                            Widgets.Avatar(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], (JObject)item.widget);
                        }
                        break;

                    case "BLANK":
                        Widgets.Blank(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"]);
                        break;

                    case "CALENDAR":
                        if (itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy"))
                        {
                            Widgets.Calendar(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], (JArray)item.widget);
                        }
                        break;

                    case "CLOCK":
                        if (itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy"))
                        {
                            Widgets.Clock(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"]);
                        }
                        break;

                    case "DIMMER":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Dimmer(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["label"], (JObject)item.widget);
                        }
                        break;

                    case "SENSOR":
                        string sx = "1";
                        string sy = "1";
                        if (itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy"))
                        {
                            sx = itemKeyValuePairs["sx"];
                            sy = itemKeyValuePairs["sy"];
                        }

                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Sensor(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], itemKeyValuePairs["label"], (JObject)item.widget);
                        }
                        break;

                    case "GAUGE":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Gauge(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["label"], (JObject)item.widget);
                        }
                        break;

                    case "GAUGE-GROUP":
                        if (itemKeyValuePairs.ContainsKey("label") && itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy"))
                        {
                            var token = JToken.Parse(item.widget.ToString());
                            if (token is JArray)
                            {
                                Widgets.Gauge_Group(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], itemKeyValuePairs["label"], (JArray)item.widget);
                            }
                            else if (token is JObject)
                            {
                                Widgets.Gauge_Group(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], itemKeyValuePairs["label"], (JObject)item.widget);
                            }
                        }
                        break;

                    case "IMAGE":
                        //Parameters
                        if (!itemKeyValuePairs.ContainsKey("aspect"))
                        {
                            itemKeyValuePairs.Add("aspect", "aspectfill");
                        }

                        if (itemKeyValuePairs.ContainsKey("px") && itemKeyValuePairs.ContainsKey("py") && itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy") && itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Image(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], itemKeyValuePairs["label"], itemKeyValuePairs["aspect"], (JObject)item.widget);
                        }
                        break;

                    case "MAP":
                        //Parameters
                        if (!itemKeyValuePairs.ContainsKey("type"))
                        {
                            itemKeyValuePairs.Add("type", "street");
                        }

                        if (itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy"))
                        {
                            Widgets.Map(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], itemKeyValuePairs["type"], (JArray)item.widget);
                        }
                        break;

                    case "SWITCH":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Switch(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["label"], (JObject)item.widget);
                        }
                        break;

                    case "WEATHER":
                        if (itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy") && itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Weather(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], itemKeyValuePairs["label"], (JArray)item.widget);
                        }
                        break;

                    case "WEATHERFORECAST":
                        if (itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy") && itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.WeatherForecast(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], itemKeyValuePairs["label"], (JArray)item.widget);
                        }
                        break;

                    default:
                        CrossLogger.Current.Warn("Kala", "Failed to parse widget. Unknown type: " + item.ToString());
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Kala", "Failed to parse widget: " + ex.ToString());
            }
        }