private void BorderOff_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (State) { State = false; OffCommand?.Execute(CommandParameter); } }
private void ExecuteOnOffCommands() { // Make sure to raise the right command, depending on the IsOn state. // Also ensure that each command is executable. if (IsOn && OnCommand != null && OnCommand.CanExecute(OnCommandParameter)) { this.TraceVerbose("Executing OnCommand."); OnCommand.Execute(OnCommandParameter); } if (!IsOn && OffCommand != null && OffCommand.CanExecute(OffCommandParameter)) { this.TraceVerbose("Executing OffCommand."); OffCommand.Execute(OffCommandParameter); } }
public static void Main(string[] args) { // our application will need some reveiver object Television device = new Television(); // our application will need an invoker object, which // in turns relies on concrete command objects: ICommand on = new OnCommand(device); // command to switch device on ICommand off = new OffCommand(device); // command to switch device off ICommand up = new UpCommand(device); // command to turn volume up ICommand down = new DownCommand(device);// command to turn volume down // now we are ready to create our invoker object which // we should think of as some sort of application menu. RemoteControl menu = new RemoteControl(on, off, up, down); // client code is now able to access the invoker object menu.SwitchPowerOn(); menu.RaiseVolume(); menu.RaiseVolume(); menu.RaiseVolume(); menu.LowerVolume(); menu.SwitchPowerOff(); }
static void Main(string[] args) { string input = Console.ReadLine(); ISwitchable device = new Lamp(); ICommand onCommand = new OnCommand(device); ICommand offCommand = new OffCommand(device); Switch @switch = new Switch(onCommand, offCommand); switch (input) { case "On": @switch.On(); break; case "Off": @switch.Off(); break; } }
/** * The Off Command * * @return the Task<CommandResult> command result Task */ public Task <CommandResult> OffCommand() { OffCommand command = new OffCommand(); return(Send(command)); }