Exemple #1
0
        protected internal virtual async Task updateFromWpAndYp(List <WPEntry> whitePages, Dictionary <string, List <YPEntry> > yellowPages)
        {
            // by default consider all known device as unplugged
            List <YDevice> toRemove = new List <YDevice>(_devices.Values);

            foreach (WPEntry wp in whitePages)
            {
                string serial = wp.SerialNumber;
                if (_devices.ContainsKey(serial))
                {
                    // already there
                    YDevice currdev = _devices[serial];
                    if (!currdev.imm_getLogicalName().Equals(wp.LogicalName))
                    {
                        // Reindex device from its own data
                        await currdev.refresh();

                        _yctx._pushPlugEvent(YAPIContext.PlugEvent.Event.CHANGE, serial);
                    }
                    else if (currdev.imm_getBeacon() > 0 != wp.Beacon > 0)
                    {
                        await currdev.refresh();
                    }

                    toRemove.Remove(currdev);
                }
                else
                {
                    YDevice dev = new YDevice(this, wp, yellowPages);
                    _yctx._yHash.imm_reindexDevice(dev);
                    _devices[serial] = dev;
                    _yctx._pushPlugEvent(YAPIContext.PlugEvent.Event.PLUG, serial);
                    _yctx._Log("HUB: device " + serial + " has been plugged\n");
                }
            }

            foreach (YDevice dev in toRemove)
            {
                string serial = dev.imm_getSerialNumber();
                _yctx._pushPlugEvent(YAPIContext.PlugEvent.Event.UNPLUG, serial);
                _yctx._Log("HUB: device " + serial + " has been unplugged\n");
                _devices.Remove(serial);
            }

            if (_hubSerialNumber == null)
            {
                foreach (WPEntry wp in whitePages)
                {
                    if (wp.NetworkUrl.Equals(""))
                    {
                        _hubSerialNumber = wp.SerialNumber;
                    }
                }
            }

            _yctx._yHash.imm_reindexYellowPages(yellowPages);
        }