/// <summary> /// 關閉程序 /// </summary> public void Close() { //賦值 IsClose = true; //註冊接收器 ClosingEventReceiver(); ClosedEventReceiver(); //執行 if (ShutDown != null) { ShutDown.Invoke(null, EventArgs.Empty); } }
public Task StartAsync() { if (_launchSettings.OverwriteConfigurationFile || !File.Exists(_launchSettings.ConfigurationFile)) { Cleanup(); CreateVmx(); } // Target exe or file _process = new Process(); var vmwareStartInfo = _process.StartInfo; vmwareStartInfo.FileName = _launchSettings.VMwareExecutable; string vmxPath = "\"" + _launchSettings.ConfigurationFile + "\""; //if (mEdition == VMwareEdition.Player) { vmwareStartInfo.Arguments = vmxPath; } //else //{ // // -x: Auto power on VM. Must be small x, big X means something else. // // -q: Close VMware when VM is powered off. // // Options must come beore the vmx, and cannot use shellexecute // xPSI.Arguments = "-x -q " + xVmxPath; //} vmwareStartInfo.UseShellExecute = false; //must be true to allow elevate the process, sometimes needed if vmware only runs with admin rights _process.EnableRaisingEvents = true; _process.Exited += delegate { ShutDown?.Invoke(this, EventArgs.Empty); }; _process.Start(); return(Task.CompletedTask); }
public Task StartAsync() { var mapFile = Path.ChangeExtension(_settings.IsoFile, ".map"); BochsSupport.TryExtractBochsDebugSymbols(mapFile, BochsDebugSymbolsPath); // Start Bochs without displaying the configuration interface (-q) and using the specified // configuration file (-f). var args = $"-q -f \"{_settings.ConfigurationFile}\""; var processStartInfo = new ProcessStartInfo(_bochsExe, args); _process = new Process(); _process.StartInfo = processStartInfo; _process.EnableRaisingEvents = true; _process.Exited += delegate { var lockFile = _settings.HardDiskFile + ".lock"; if (File.Exists(lockFile)) { try { File.Delete(lockFile); } catch (Exception ex) { throw new Exception($"The lock file couldn't be deleted! It has to be deleted manually. Lock file location: '{lockFile}'.{Environment.NewLine}Exception:{Environment.NewLine}{ex.ToString()}"); } } ShutDown?.Invoke(this, EventArgs.Empty); }; _process.Start(); return(Task.CompletedTask); }
public Task StartAsync() { _port = new SerialPort(_settings.PortName); _port.Open(); Send(""); // Set to digital input Send("CH1.SETMODE(2)"); if (IsOn()) { TogglePowerSwitch(); WaitPowerState(false); // Small pause for discharge Thread.Sleep(1000); } TogglePowerSwitch(); // Give PC some time to turn on, else we will detect it as off right away. WaitPowerState(true); _powerStateThread = new Thread( () => { while (true) { Thread.Sleep(1000); if (!IsOn()) { _port.Close(); ShutDown?.Invoke(this, EventArgs.Empty); break; } } }); _powerStateThread.Start(); return(Task.CompletedTask); }
public Task StartAsync() { CreateVirtualMachine(); var windowsPath = Environment.GetFolderPath(Environment.SpecialFolder.Windows); var vmConnectPath = Path.Combine(windowsPath, "sysnative", "VmConnect.exe"); var processStartInfo = new ProcessStartInfo(vmConnectPath, @"""localhost"" ""Cosmos"""); _process = new Process { StartInfo = processStartInfo, EnableRaisingEvents = true }; _process.Exited += (sender, args) => ShutDown?.Invoke(this, EventArgs.Empty); _process.Start(); RunPowerShellScript("Start-VM -Name Cosmos"); return(Task.CompletedTask); }
public void Start() { CreateVirtualMachine(); // Target exe or file var info = new ProcessStartInfo(@"C:\Windows\sysnative\VmConnect.exe", @"""localhost"" ""Cosmos""") { UseShellExecute = false }; mProcess = new Process(); mProcess.StartInfo = info; mProcess.EnableRaisingEvents = true; mProcess.Exited += delegate { ShutDown?.Invoke(this, EventArgs.Empty); }; mProcess.Start(); RunPowershellScript("Start-VM -Name Cosmos"); }
public void Start() { mPort = new SerialPort(mLaunchSettings.PortName); mPort.Open(); Send(""); // Set to digital input Send("CH1.SETMODE(2)"); if (IsOn()) { TogglePowerSwitch(); WaitPowerState(false); // Small pause for discharge Thread.Sleep(1000); } TogglePowerSwitch(); // Give PC some time to turn on, else we will detect it as off right away. WaitPowerState(true); mPowerStateThread = new Thread(delegate() { while (true) { Thread.Sleep(1000); if (!IsOn()) { mPort.Close(); ShutDown?.Invoke(this, EventArgs.Empty); break; } } }); mPowerStateThread.Start(); }
/// <summary>Initialize and start the Bochs process.</summary> public void Start() { //var xMapFile = Path.ChangeExtension(mLaunchSettings.IsoFile, ".map"); //BochsSupport.TryExtractBochsDebugSymbols(xMapFile, BochsDebugSymbolsPath); mProcess = new Process(); var xBochsStartInfo = mProcess.StartInfo; xBochsStartInfo.FileName = mBochsExe; var xExtraLog = ""; if (mLaunchSettings.UseDebugVersion) { //xExtraLog = "-dbglog \"bochsdbg.log\""; } // Start Bochs without displaying the configuration interface (-q) and using the specified // configuration file (-f). xBochsStartInfo.Arguments = string.Format("-q {1} -f \"{0}\"", mLaunchSettings.ConfigurationFile, xExtraLog); xBochsStartInfo.UseShellExecute = true; if (RedirectOutput) { if (LogOutput == null) { throw new Exception("No LogOutput handler specified!"); } if (LogError == null) { throw new Exception("No LogError handler specified!"); } xBochsStartInfo.RedirectStandardOutput = true; xBochsStartInfo.RedirectStandardError = true; mProcess.OutputDataReceived += (sender, args) => LogOutput(args.Data); mProcess.ErrorDataReceived += (sender, args) => LogError(args.Data); } // Register for process completion event so that we can funnel it to any code that // subscribed to this event in our base class. mProcess.EnableRaisingEvents = true; mProcess.Exited += delegate { var xLockFile = mLaunchSettings.HardDiskFile + ".lock"; if (File.Exists(xLockFile)) { try { File.Delete(xLockFile); } catch (Exception ex) { throw new Exception($"The lock file couldn't be deleted! It has to be deleted manually. Lock file location: '{xLockFile}'.{Environment.NewLine}Exception:{Environment.NewLine}{ex.ToString()}"); } } ShutDown?.Invoke(this, EventArgs.Empty); }; mProcess.Start(); if (RedirectOutput) { mProcess.BeginErrorReadLine(); mProcess.BeginOutputReadLine(); } }
public void Kill() { ShutDown?.Invoke(this, EventArgs.Empty); }
public Task KillAsync() { ShutDown?.Invoke(this, EventArgs.Empty); return(Task.CompletedTask); }