public static ConfigAlarmZone CreateConfigAlarmZoneFromDAL(AlarmZoneDAL zone) { Dictionary <string, string> parameters = new Dictionary <string, string>(); ConfigAlarmZone alarmZoneConfig = null; //foreach (ThingParameterDAL tpc in thing.Parameters) { parameters[ConfigCore.PARAMETER_NAME] = zone.Name; parameters[ConfigCore.PARAMETER_CONFIG_CLASS] = "ConfigAlarmZone"; //parameters[PARAMETER_THING_CLASS] = zone.Name; } //string configClassName = parameters[PARAMETER_CONFIG_CLASS]; //Type cls = Assembly.GetExecutingAssembly().GetType("HomeManager2.Shared.Config." + configClassName); alarmZoneConfig = new ConfigAlarmZone(parameters); return(alarmZoneConfig); }
public AlarmZone(ConfigAlarmZone config, IManager manager) : base(config, manager) { }
private async Task LoadFromDatabase() { ZoneGuardConfigContextFactory factory = new ZoneGuardConfigContextFactory(); using (ZoneGuardConfigContext context = factory.CreateDbContext()) { /*************************************************************** * * Load Sensors * ***************************************************************/ List <ThingDAL> things = await context.Thing .Where <ThingDAL>(t => t.ThingType == ThingType.Sensor) .Include(p => p.Parameters) .ToListAsync <ThingDAL>(); foreach (ThingDAL thing in things) { Console.WriteLine(thing.Name); ConfigSensor configSensor = ZoneGuardConfigContextFactory.CreateThingFromDAL <ConfigSensor>(thing); Console.WriteLine(configSensor.toJSON()); //TODO:: More Dynamic addMQTTSensor(new SensorMQTT(configSensor, this), true); addProxySensor(new SensorProxy(configSensor, this), false); } /*************************************************************** * * Load AlarmZones * ***************************************************************/ List <AlarmZoneDAL> alarmZones = await context.AlarmZone .Include(az => az.Sensors) .ThenInclude(pa => pa.Thing) .ToListAsync <AlarmZoneDAL>(); foreach (AlarmZoneDAL zone in alarmZones) { ConfigAlarmZone configAlarmZone = ZoneGuardConfigContextFactory.CreateConfigAlarmZoneFromDAL(zone); AlarmZone alarmZone = new AlarmZone(configAlarmZone, this); alarmManager.addAlarmZone(alarmZone); /* * //if (zone.Enabled == 1) * { * Console.WriteLine("Creating Alarm Zone {0}", zone.Name); * foreach (AlarmZoneThingDAL sensor in zone.Sensors) * { * SensorCore sensorProxy = getSensorByName(sensor.Thing.Name); * SensorLink sensorLink = new SensorLink(sensorProxy, alarmZone, this); * * * //ConfigLink configLink = new ConfigLink(); * * //SensorProxy sensorProxy = new SensorProxy(configSensor, this); * //HEST * //alarmZone.addSensor(sensorProxy); * //if (sensor.Enabled == 1) * //{ * // Console.WriteLine(" Adding Sensor '{0}'", sensor.Thing.Name); * // } * * } * }*/ } } }