Controller InsertController(ISqLiteContext ctx, IMqttAdapter mqttAdapter) { var controller = _entityFactory.CreateController(); controller.Identifier = mqttAdapter.Identifier; controller.Type = mqttAdapter.Type; controller.InitializationArguments = _jsonSerializerService.Serialize(mqttAdapter.GetInitializationArguments()); ctx.Add(controller); return(controller); }
public void AddAdapter(IMqttAdapter adapter) { using (var ctx = new SqliteContext()) { var controller = _modelFactory.CreateController(); controller.Identifier = adapter.Identifier; controller.Type = adapter.Type; controller.InitializationArguments = _jsonSerializerService.Serialize(adapter.GetInitializationArguments()); foreach (var state in adapter.GetPossibleStates()) { var stateModel = new ControllerStateInformation(); stateModel.State = state.State; stateModel.PowerConsumption = state.PowerConsumption; ctx.Add(stateModel); controller.ControllerStateInformations.Add(stateModel); } ctx.Add(controller); ctx.SaveChanges(); } }