Beispiel #1
0
 public ThemeItem()
 {
     Clickable  = false;
     Active     = new ThemeItemState(null);
     Off        = new ThemeItemState(null);
     Routes     = new List <ThemeItemRoute>();
     Dimensions = new List <ThemeItemDimension>();
 }
Beispiel #2
0
        public bool Parse(JToken tkn)
        {
            JObject o = tkn as JObject;

            if (o == null)
            {
                return(false);
            }

            if (o["id"] != null)
            {
                UniqueIdentifier = (int)o["id"];
            }

            if (UniqueIdentifier == -1)
            {
                return(false);
            }

            if (o["name"] != null)
            {
                Name = o["name"].ToString();
            }
            if (o["clickable"] != null)
            {
                Clickable = (bool)o["clickable"];
            }
            if (o["active"] != null)
            {
                Active = new ThemeItemState(o["active"] as JObject);
            }
            if (o["off"] != null)
            {
                Off = new ThemeItemState(o["off"] as JObject);
            }

            if (o["routes"] != null)
            {
                var ar = o["routes"] as JArray;
                if (ar != null)
                {
                    foreach (var e in ar)
                    {
                        if (e == null)
                        {
                            continue;
                        }

                        ThemeItemRoute route = new ThemeItemRoute();
                        if (route.Parse(e))
                        {
                            Routes.Add(route);
                        }
                    }
                }
            }

            if (o["dimensions"] != null)
            {
                var ar = o["dimensions"] as JArray;
                if (ar != null)
                {
                    foreach (var e in ar)
                    {
                        if (e == null)
                        {
                            continue;
                        }

                        ThemeItemDimension dim = new ThemeItemDimension();
                        if (dim.Parse(e))
                        {
                            Dimensions.Add(dim);
                        }
                    }
                }
            }

            if (Dimensions == null || Dimensions.Count < 4)
            {
                int n = Dimensions.Count;

                for (int i = n - 1; i < 4; ++i)
                {
                    Dimensions.Add(new ThemeItemDimension {
                        Value = "1x1", X = 1, Y = 1
                    });
                }
            }

            return(true);
        }