TriggerListeners() public method

public TriggerListeners ( Sensor sensor ) : void
sensor Sensor
return void
Beispiel #1
0
        public void Attach(SensorRegistry registry)
        {
            if (this.Registry != null)
            {
                throw new Exception("Can't attach: Invalid State");
            }
            this.Registry = registry;

            try{
                var reader = new StreamReader(new FileStream(FilePath, FileMode.Open));

                while (true)
                {
                    var line = reader.ReadLine();
                    if (line == null)
                    {
                        break;
                    }
                    int    vali  = line.IndexOf(" ");
                    string sname = line.Substring(0, vali);
                    string value = line.Substring(vali + 1);
                    // backward compat patch between 0.5 -> 0.6
                    if (sname == "DistanceRun" || sname == "FuelConsumed" || sname == "TripTime" || sname == "IdleTime")
                    {
                        sname = "Common." + sname;
                    }

                    var sensor = Registry.Sensor(sname);
                    if (sensor != null && sensor is IPersistentSensor)
                    {
                        try{
                            ((IPersistentSensor)sensor).RestoreState(value);
                            Registry.TriggerListeners(sensor);
                        }catch (Exception e) {
                            Logger.error("SensorStorage", "fail on RestoreState: " + sname, e);
                        }
                    }
                    else
                    {
                        Logger.error("SensorStorage", "bad sensor: " + sname);
                    }
                }
                reader.Close();
            }catch (FileNotFoundException) {
                Logger.error("SensorStorage", "File not found");
            }catch (Exception e) {
                Logger.error("SensorStorage", "error reading", e);
            }
        }
Beispiel #2
0
        public void Attach(SensorRegistry registry)
        {
            if (this.Registry != null)
            throw new Exception("Can't attach: Invalid State");
            this.Registry = registry;

            try{
            var reader = new StreamReader(new FileStream( FilePath, FileMode.Open));

            while(true){
                var line = reader.ReadLine();
                if (line == null)
                    break;
                int vali = line.IndexOf(" ");
                string sname = line.Substring(0, vali);
                string value = line.Substring(vali+1);
                // backward compat patch between 0.5 -> 0.6
                if (sname == "DistanceRun" || sname == "FuelConsumed" || sname == "TripTime" || sname == "IdleTime")
                {
                    sname = "Common."+sname;
                }

                var sensor = Registry.Sensor(sname);
                if (sensor != null && sensor is IPersistentSensor){
                    try{
                        ((IPersistentSensor)sensor).RestoreState(value);
                        Registry.TriggerListeners(sensor);
                    }catch(Exception e){
                        Logger.error("SensorStorage", "fail on RestoreState: "+sname, e);
                    }
                }else{
                    Logger.error("SensorStorage", "bad sensor: "+sname);
                }
            }
            reader.Close();
            }catch(FileNotFoundException){
            Logger.error("SensorStorage", "File not found");
            }catch(Exception e){
            Logger.error("SensorStorage", "error reading", e);
            }
        }