public void StopAll(Func <IMachineMetadata, MachineConfiguration, bool> predicate, Action updateAction) { foreach (var machine in appState.GetMachines(predicate)) { if (!machine.IsPoweredOn) { logger.LogInformation($"Skipping stop {machine}"); continue; } var configuration = appState.Configuration.Machines.FirstOrDefault(c => c.Uuid == machine.Uuid); if (configuration == null) { continue; } if (configuration.SaveState) { machineController.SaveState(machine); } else if (!machineController.AcpiPowerOff(machine, 90000)) { logger.LogError($"Failed to power off via ACPI {machine}, forcing"); machineController.PowerOff(machine); } updateAction(); } }
private ToolStripItem[] BuildSubMenu(IMachineMetadata machine) { return(new ToolStripItem[] { new MachineStatusToolStripItem(machine), new ToolStripSeparator(), new ToolStripMenuItem( "Headless start", null, (_, __) => new Task(() => machineController.Start(machine, true)).Start() ), new ToolStripMenuItem( "Normal start", null, (_, __) => new Task(() => machineController.Start(machine, false)).Start() ), new ToolStripSeparator(), new ToolStripMenuItem( "Save State", null, (_, __) => new Task(() => machineController.SaveState(machine)).Start() ), new ToolStripMenuItem( "ACPI Shutdown", null, (_, __) => new Task(() => machineController.AcpiPowerOff(machine, 90000)).Start() ), new ToolStripMenuItem( "Power off", null, (_, __) => new Task(() => machineController.PowerOff(machine)).Start() ), new ToolStripSeparator(), new ToolStripMenuItem( "Reset", null, (_, __) => machineController.Reset(machine) ) }); }