/// <inheritdoc/> /// <summary> /// Perform the necessary steps to subscribe to the target. /// </summary> /// <param name="masterController">The item this object will be subscribed to</param> public override async Task Subscribe(ElevatorMasterController masterController) { if (this.Subscribed) { return; } var thisBtn = this.FloorButtons.FirstOrDefault(b => { if (b is RequestButton r) { return(r.DestinationFloor == this.FloorNumber); } return(b.FloorNumber == this.FloorNumber); }); // If the button is for this floor, just remove it if (thisBtn != null) { this._floorButtons.Remove(thisBtn); } await base.Subscribe(masterController); this.Subscribed = true; }
/// <summary> /// Subscribes this Button panel to the <see cref="ElevatorMasterController"/> /// </summary> /// <param name="parent"></param> /// <returns></returns> /// <inheritdoc/> public override async Task Subscribe(ElevatorMasterController parent) { if (this.Subscribed) { return; } await Task.WhenAll(this.OpenDoorButton.Subscribe(parent.Elevator.Door), this.CloseDoorButton.Subscribe(parent.Elevator.Door)); await base.Subscribe(parent); }
/// <inheritdoc/> /// <summary> /// Subscribes the specified controller. /// </summary> /// <param name="controller">The controller.</param> /// <returns></returns> public override Task Subscribe(ElevatorMasterController controller) { if (this.Subscribed) { return(Task.CompletedTask); } try { Elevator elevator = controller.Elevator; // This should be handled by the Call panels this.OnPushed += (a, floor) => { try { Logger.LogEvent("Elevator Requested", ("From floor", this.FloorNumber)); // If the elevator's already here, open the door if (elevator.CurrentFloor == this.FloorNumber && (elevator.State == ElevatorState.Arrived || elevator.State == ElevatorState.Idle)) { if (elevator.Door.IsClosedOrClosing) { elevator.Door.RequestOpen(); } } else { // If the elevator isn't already here, tell it to come here elevator.OnNext(new ElevatorCall(this.FloorNumber, this._requestDirection, false)); } } catch (Exception ex) { elevator.OnError(ex); } }; } finally { this.Subscribed = true; } return(Task.CompletedTask); }
/// <inheritdoc/> /// <summary> /// Subscribes this Button panel to the <see cref="T:ElevatorApp.Models.ElevatorMasterController"/> /// </summary> public virtual Task Subscribe(ElevatorMasterController parent) { if (this.Subscribed) { return(Task.CompletedTask); } Logger.LogEvent($"Subscribing {nameof(ButtonPanelBase)}"); this.Subscribe(parent.Elevator); foreach (FloorButton floorButton in this.FloorButtons) { floorButton.Subscribe(parent); } this.Subscribed = true; return(Task.CompletedTask); }