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); } }
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); } } } }
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); } }
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); } } } }