AddListener() public method

public AddListener ( Sensor sensor, Action listener ) : void
sensor Sensor
listener Action
return void
示例#1
0
        public virtual void Attach(SensorRegistry registry)
        {
            if (this.Registry != null)
            {
                throw new Exception("Can't attach: Invalid State");
            }
            this.Registry = registry;

            Settings.Keys.ToList().ForEach((id) => {
                var set    = Settings[id];
                var sensor = Registry.Sensor(id);
                if (sensor == null)
                {
                    return;
                }
                if (set.id != sensor.ID)
                {
                    set.id = sensor.ID;
                    Settings.Remove(id);
                    Settings.Add(set.id, set);
                }
                Logger.trace("SensorTrack", "attach " + set.id + " period " + set.period + " length " + set.length + " gap " + set.gap);
                try{
                    Registry.AddListener(sensor, this.SensorChanged, set.period);
                }catch (Exception) {
                    Logger.trace("SensorTrack", "attach failed" + sensor.ID);
                }
            });

            if (this.TrackPassive)
            {
                Registry.AddPassiveListener(this.SensorChanged);
            }
            if (this.TrackAccum)
            {
                foreach (var s in Registry.Sensors.Where(s => s is IAccumulatorSensor))
                {
                    try{
                        Registry.AddListener(s, this.SensorChanged);
                    }catch (Exception) {
                        Logger.trace("SensorTrack", "attach failed" + s.ID);
                    }
                }
            }
        }
示例#2
0
文件: SensorTrack.cs 项目: cail/hobd
        public virtual void Attach(SensorRegistry registry)
        {
            if (this.Registry != null)
            throw new Exception("Can't attach: Invalid State");
            this.Registry = registry;

            Settings.Keys.ToList().ForEach((id) => {
            var set = Settings[id];
            var sensor = Registry.Sensor(id);
            if (sensor == null)
                return;
            if (set.id != sensor.ID)
            {
                set.id = sensor.ID;
                Settings.Remove(id);
                Settings.Add(set.id, set);
            }
            Logger.trace("SensorTrack", "attach " +set.id + " period " + set.period + " length " + set.length + " gap "+ set.gap);
            try{
                Registry.AddListener(sensor, this.SensorChanged, set.period);
            }catch(Exception){
                Logger.trace("SensorTrack", "attach failed" +sensor.ID);
            }
            });

            if (this.TrackPassive)
            {
            Registry.AddPassiveListener(this.SensorChanged);
            }
            if (this.TrackAccum)
            {
            foreach(var s in Registry.Sensors.Where(s => s is IAccumulatorSensor)){
                try{
                    Registry.AddListener(s, this.SensorChanged);
                }catch(Exception){
                    Logger.trace("SensorTrack", "attach failed" +s.ID);
                }
            }
            }
        }