Пример #1
0
        public bool Parse(JToken tkn)
        {
            if (_objects != null)
            {
                _objects.Clear();
            }

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

            try
            {
                var o = tkn as JObject;
                if (o == null)
                {
                    return(false);
                }

                if (o["ecosbase"] != null)
                {
                    var ar = o["ecosbase"] as JArray;
                    if (ar != null)
                    {
                        for (int i = 0; i < ar.Count; ++i)
                        {
                            var it = ar[i] as JObject;
                            if (it == null)
                            {
                                continue;
                            }
                            var iit = new Ecos2();
                            iit.ParseJson(it);
                            _objects?.Add(iit);
                        }
                    }
                }

                if (o["locomotives"] != null)
                {
                    var ar = o["locomotives"] as JArray;
                    if (ar != null)
                    {
                        for (int i = 0; i < ar.Count; ++i)
                        {
                            var it = ar[i] as JObject;
                            if (it == null)
                            {
                                continue;
                            }
                            var iit = new Locomotive();
                            iit.ParseJson(it);
                            _objects?.Add(iit);
                        }
                    }
                }

                if (o["accessories"] != null)
                {
                    var ar = o["accessories"] as JArray;
                    if (ar != null)
                    {
                        for (int i = 0; i < ar.Count; ++i)
                        {
                            var it = ar[i] as JObject;
                            if (it == null)
                            {
                                continue;
                            }
                            var iit = new Accessory();
                            iit.ParseJson(it);
                            _objects?.Add(iit);
                        }
                    }
                }

                if (o["feedbacks"] != null)
                {
                    var ar = o["feedbacks"] as JArray;
                    if (ar != null)
                    {
                        for (int i = 0; i < ar.Count; ++i)
                        {
                            var it = ar[i] as JObject;
                            if (it == null)
                            {
                                continue;
                            }
                            var iit = new S88();
                            iit.ParseJson(it);
                            _objects?.Add(iit);
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
                ex.Show();
            }
            return(false);
        }
Пример #2
0
        private bool HandleQuery(IBlock block)
        {
            if (block is EventBlock)
            {
                return(false);
            }

            if (block.Command != null && block.Command.Type != CommandT.QueryObjects)
            {
                return(false);
            }

            var objId = block.Command?.ObjectId;

            foreach (var e in block.ListEntries)
            {
                if (e == null)
                {
                    continue;
                }

                var exist = GetObjectBy(e.ObjectId) != null;
                if (!exist)
                {
                    IItem newItem = null;

                    switch (objId)
                    {
                    case Globals.ID_EV_LOCOMOTIVES:
                        newItem = new Locomotive();
                        break;

                    case Globals.ID_EV_ACCESSORIES:
                        newItem = new Accessory();
                        break;

                    case Globals.ID_EV_S88:
                        newItem = new S88();
                        break;
                    }

                    if (newItem == null)
                    {
                        continue;
                    }

                    if (newItem.Parse(e.Arguments))
                    {
                        newItem.ObjectId = e.ObjectId;

                        var viewItem = (IItemView)newItem;
                        if (!viewItem.HasView)
                        {
                            viewItem.EnableView();
                        }

                        lock (_objects)
                        {
                            _objects.Add(newItem);
                        }

                        newItem.QueryState();
                    }
                }
            }

            _modified = true;

            return(true);
        }