Exemple #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);
        }
Exemple #2
0
        private bool HandleBase(IBlock block)
        {
            if (block is EventBlock)
            {
                return(false);
            }

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

            // <REPLY get(1, info, status)>
            // 1 status[GO]
            // 1 ECoS2
            // 1 ProtocolVersion[0.5]
            // 1 ApplicationVersion[4.2.2]
            // 1 HardwareVersion[2.1]
            // <END 0(OK) >

            foreach (var e in block.ListEntries)
            {
                if (e == null)
                {
                    return(false);
                }
                if (e.ObjectId != Globals.ID_EV_BASEOBJECT)
                {
                    return(false);
                }

                switch (e.ObjectId)
                {
                case Globals.ID_EV_BASEOBJECT:
                {
                    var item = GetObjectBy(Globals.ID_EV_BASEOBJECT);
                    if (item == null)
                    {
                        lock (_objects)
                        {
                            item = new Ecos2();
                            if (item.Parse(e.Arguments))
                            {
                                item.ObjectId = Globals.ID_EV_BASEOBJECT;
                                _objects.Add(item);
                            }
                        }
                    }
                    else
                    {
                        item.Parse(e.Arguments);
                    }
                }
                break;
                }
            }

            _modified = true;

            return(true);
        }