Esempio n. 1
0
        public static Thermostat ConnectToThermostat(IEventMetadata eventMetadata, IEventStore eventStore, ConnectToThermostatCommand cmd)
        {
            ValidateTemperature(cmd.Temperature);
            ValidateSetpoint(cmd.HeatSetpoint);
            ValidateCoolSetpoint(cmd.CoolSetpoint);
            ValidateMode(cmd.Mode);
            ValidateSystemStatus(cmd.SystemStatus);
            ValidateTenantId(cmd.TenantId);

            var thermostatId = cmd.ThermostatId;
            var connectToControllerCommand = new ConnectThermostat(cmd.ThermostatAggregateId);
            var commandBus = CommandBus.Instance;

            commandBus.Execute(connectToControllerCommand);

            var thermostat = new Thermostat(cmd.ThermostatAggregateId, eventMetadata, eventStore,
                                            (double)cmd.Temperature, (double)cmd.HeatSetpoint, (double)cmd.CoolSetpoint,
                                            cmd.Mode, cmd.SystemStatus, cmd.Humidity);

            Repository <Thermostat> thermostatRepo = new Repository <Thermostat>(eventStore);
            var found = thermostatRepo.GetById(new CompositeAggregateId(cmd.TenantId, cmd.ThermostatAggregateId, "Thermostat"));

            return(found);
        }
 public void Handle(ConnectThermostat message)
 {
     //Validate
     //Process
 }