private static void SetUp(IEquipmentController equipmentController, ControllerConfig config) { for (int floorId = 1; floorId <= config.numberOfFloors; ++floorId) { for (int mainCorridorId = 1; mainCorridorId <= config.numberOfMainCorridorsPerFloor; ++mainCorridorId) { for (short sequenceNumber = 1; sequenceNumber <= config.numberOfLightsPerMainCorridor; ++sequenceNumber) { // Create and install MainCorridor Lights var equipmentId = new EquipmentId(floorId.ToString(), $"MC-{mainCorridorId}", EquipmentType.Light, sequenceNumber.ToString()); var mainCorridorLight = new Equipment(equipmentId, config.lightPower); equipmentController.InstallMainCorridorEquipment(mainCorridorLight); } for (short sequenceNumber = 1; sequenceNumber <= config.numberOfAirConditionersPerMainCorridor; ++sequenceNumber) { // Create and install MainCorridor AirConditioners var equipmentId = new EquipmentId(floorId.ToString(), $"MC-{mainCorridorId}", EquipmentType.AirConditioner, sequenceNumber.ToString()); var mainCorridorAirConditioner = new Equipment(equipmentId, config.airConditionerPower); equipmentController.InstallMainCorridorEquipment(mainCorridorAirConditioner); } } for (int subCorridorId = 1; subCorridorId <= config.numberOfSubCorridorsPerFloor; ++subCorridorId) { for (short sequenceNumber = 1; sequenceNumber <= config.numberOfLightsPerSubCorridor; ++sequenceNumber) { // Create and install SubCorridor Lights with sensors var equipmentId = new EquipmentId(floorId.ToString(), $"SC-{subCorridorId}", EquipmentType.Light, sequenceNumber.ToString()); var subCorridorLight = new Equipment(equipmentId, config.lightPower); var sensorId = new EquipmentId(floorId.ToString(), $"SC-{subCorridorId}", EquipmentType.Sensor, sequenceNumber.ToString()); var sensor = new Sensor(sensorId); equipmentController.InstallSubCorridorEquipmentWithSensor(subCorridorLight, sensor); } for (short sequenceNumber = 1; sequenceNumber <= config.numberOfAirConditionersPerSubCorridor; ++sequenceNumber) { // Create and install SubCorridor AirConditioners var equipmentId = new EquipmentId(floorId.ToString(), $"SC-{subCorridorId}", EquipmentType.AirConditioner, sequenceNumber.ToString()); var subCorridorAirConditioner = new Equipment(equipmentId, config.airConditionerPower); equipmentController.InstallSubCorridorEquipment(subCorridorAirConditioner); } } } }
private void Process(string command, IEquipmentController equipmentController) { (bool isValidCommand, Sensor sensor, Signal signal) = Command.Parse(command, equipmentController); if (isValidCommand) { sensor.send(signal); } else { log("Invalid command"); } }
private static void Process(string command, IEquipmentController controller) { (bool isValidCommand, Sensor sensor, Signal signal) = Command.Parse(command, controller); if (isValidCommand) { sensor.send(signal); } else { log("Warning: Invalid command"); log(""); } }
public static (bool, Sensor, Signal) Parse(string command, IEquipmentController controller) { Sensor sensor = null; Signal signal = null; var words = command.Split(' '); string floorId = ""; string subCorridorId = ""; string sequenceId = "1"; SingalType type = SingalType.unknown; // Hard-coded rules to parse command. if (words.Length == 7 && command.Contains("Movement")) { type = SingalType.movement; floorId = words[3][0].ToString(); subCorridorId = words[6]; } else if (words.Length == 11 & command.Contains("No movement")) { type = SingalType.noMovement; floorId = words[4][0].ToString(); subCorridorId = words[7]; } var sensorId = new EquipmentId(floorId, $"SC-{subCorridorId}", EquipmentType.Sensor, sequenceId); sensor = controller.GetSensorById(sensorId); if (sensor is null) { return(false, sensor, signal); } signal = new Signal(sensor, type); return(true, sensor, signal); }
public AuthorityEquipmentDecorator(IEquipmentController equipmentController, String role) { this.EquipmentController = equipmentController; this.Role = role; AuthorizedUsers = new Dictionary <string, List <string> >(); AuthorizedUsers["CheckEquipmentNameUnique"] = new List <string>() { "Director" }; AuthorizedUsers["Delete"] = new List <string>() { "Director" }; AuthorizedUsers["Edit"] = new List <string>() { "Director" }; AuthorizedUsers["Get"] = new List <string>() { "Director" }; AuthorizedUsers["GetAll"] = new List <string>() { "Director" }; AuthorizedUsers["getConsumableEquipment"] = new List <string>() { "Director" }; AuthorizedUsers["getInconsumableEquipment"] = new List <string>() { "Director" }; AuthorizedUsers["Save"] = new List <string>() { "Director" }; }