public static T CreateThingFromDAL <T>(ThingDAL thing) { Dictionary <string, string> parameters = new Dictionary <string, string>(); T configObj; foreach (ThingParameterDAL tpc in thing.Parameters) { parameters[tpc.Name] = tpc.Value; } //Set Node Identifier //TODO:: NODE parameters[ConfigCore.PARAMETER_NODE_ID] = thing.Node.UniqueIdentifier.ToString(); string configClassName = parameters[ConfigCore.PARAMETER_CONFIG_CLASS]; // String name = myType.FullName; // ServiceCore serviceObj = null; // new ServiceMQ(); //myObject = (MyAbstractClass)Activator.CreateInstance("AssemblyName", "TypeName"); //Type cls = Assembly.GetExecutingAssembly().GetType("HomeManager2.Shared.Config." + configClassName); Type cls = ConfigCore.GetConfigAssembly().GetType("ZoneGuard.Shared.Config." + configClassName); configObj = (T)Activator.CreateInstance(cls, parameters); /*if (configObj.GetType() == typeof(ConfigSensor)) * { * * * }*/ //configObj = new ConfigSensor(parameters); return(configObj); }
public static void ThingConfig_Create(ZoneGuardConfigContext context, ThingDAL thing, ThingParameterDAL[] parameters) { context.Thing.Add(thing); context.SaveChanges(); foreach (ThingParameterDAL param in parameters) { param.Thing = thing; context.ThingParameter.Add(param); } context.SaveChanges(); }
private ThingDAL AddService(ZoneGuardConfigContext context, String Name, String _description, ThingType _type, Dictionary <String, String> parameters) { ThingDAL thing = null; List <ThingParameterDAL> thingParameters = new List <ThingParameterDAL>(); DateTime timestamp = DateTime.UtcNow; thing = new ThingDAL { Name = Name, Description = _description, ThingType = _type, NodeId = null, Timestamp = timestamp }; foreach (KeyValuePair <String, String> kvp in parameters) { thingParameters.Add(new ThingParameterDAL { Name = kvp.Key, Value = kvp.Value, Timestamp = timestamp }); } DbInitializer.ThingConfig_Create(context, thing, thingParameters.ToArray()); return(thing); }
private AlarmZoneDAL AddAlarmZone(ZoneGuardConfigContext context, String name, String description, String[] sensors) { AlarmZoneDAL alarmZone = null; List <AlarmZoneThingDAL> alarmZoneSensors = new List <AlarmZoneThingDAL>(); DateTime timestamp = DateTime.UtcNow; alarmZone = new AlarmZoneDAL { Name = name, Description = description, Enabled = 1, Timestamp = timestamp }; foreach (String sensorName in sensors) { ThingDAL curSensor = context.Thing.Where <ThingDAL>(n => n.ThingType == ThingType.Sensor).Where <ThingDAL>(n => n.Name == sensorName).FirstOrDefault <ThingDAL>(); alarmZoneSensors.Add(new AlarmZoneThingDAL { Enabled = 1, Thing = curSensor, Timestamp = timestamp }); } ; DbInitializer.AddAlarmZone(context, alarmZone, alarmZoneSensors.ToArray()); return(alarmZone); }
//, Dictionary<string, string> parameters private ThingDAL AddMQTTSensor(ZoneGuardConfigContext context, NodeDAL node, String Name, String _description, ThingType _type, String sensorType, String locationId, Boolean isPerimeter, String topicOffset) { ThingDAL thing = null; List <ThingParameterDAL> thingParameters = new List <ThingParameterDAL>(); DateTime timestamp = DateTime.UtcNow; thing = new ThingDAL { Name = Name, Description = _description, ThingType = _type, NodeId = node.Id, Timestamp = timestamp }; thingParameters.Add(new ThingParameterDAL { Name = ConfigCore.PARAMETER_THING_CATEGORY, Value = "sensor", Timestamp = timestamp }); thingParameters.Add(new ThingParameterDAL { Name = ConfigCore.PARAMETER_CONFIG_CLASS, Value = "ConfigSensor", Timestamp = timestamp }); thingParameters.Add(new ThingParameterDAL { Name = ConfigCore.PARAMETER_THING_CLASS, Value = "SensorMQTT", Timestamp = timestamp }); thingParameters.Add(new ThingParameterDAL { Name = ConfigCore.PARAMETER_TYPE, Value = sensorType, Timestamp = timestamp }); thingParameters.Add(new ThingParameterDAL { Name = ConfigCore.PARAMETER_NAME, Value = Name, Timestamp = timestamp }); thingParameters.Add(new ThingParameterDAL { Name = ConfigCore.PARAMETER_IS_PERIMETER, Value = isPerimeter.ToString().ToLower() }); thingParameters.Add(new ThingParameterDAL { Name = ConfigCore.PARAMETER_TOPIC_STATE, Value = topicOffset + locationId.ToLower() + "/" + Name.ToLower() + "/state" }); thingParameters.Add(new ThingParameterDAL { Name = ConfigCore.PARAMETER_TOPIC_COMMAND, Value = "" }); DbInitializer.ThingConfig_Create(context, thing, thingParameters.ToArray()); return(thing); }