コード例 #1
0
 protected virtual void OnShutDown(DateTime Timestamp)
 {
     ShutDown.Fire(ServerEndPoint, new LogEventArgs()
     {
         Timestamp = Timestamp
     });
 }
コード例 #2
0
ファイル: CSDArchitecture.cs プロジェクト: WaylonYuen/WaylonX
        /// <summary>
        /// 關閉程序
        /// </summary>
        public void Close()
        {
            //賦值
            IsClose = true;

            //註冊接收器
            ClosingEventReceiver();
            ClosedEventReceiver();

            //執行
            if (ShutDown != null)
            {
                ShutDown.Invoke(null, EventArgs.Empty);
            }
        }
コード例 #3
0
        private void shutDown(ShutDown flag)
        {
            ManagementBaseObject outParam = null;
            ManagementClass      sysOS    = new ManagementClass("Win32_OperatingSystem");

            sysOS.Get();
            // enables required security privilege.
            sysOS.Scope.Options.EnablePrivileges = true;
            // get our in parameters
            ManagementBaseObject inParams = sysOS.GetMethodParameters("Win32Shutdown");

            // pass the flag of 0 = System Shutdown
            inParams["Flags"]    = flag;
            inParams["Reserved"] = "0";
            foreach (ManagementObject manObj in sysOS.GetInstances())
            {
                outParam = manObj.InvokeMethod("Win32Shutdown", inParams, null);
            }
        }
コード例 #4
0
ファイル: VMwareHost.cs プロジェクト: jp2masa/ProjectSystems
        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);
        }
コード例 #5
0
ファイル: BochsHost.cs プロジェクト: jp2masa/ProjectSystems
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
ファイル: HyperVHost.cs プロジェクト: jp2masa/ProjectSystems
        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);
        }
コード例 #8
0
        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");
        }
コード例 #9
0
        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();
        }
コード例 #10
0
        /// <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();
            }
        }
コード例 #11
0
ファイル: IntelEdisonHost.cs プロジェクト: tnsr1/XSharp
 public void Kill()
 {
     ShutDown?.Invoke(this, EventArgs.Empty);
 }
コード例 #12
0
 public Task KillAsync()
 {
     ShutDown?.Invoke(this, EventArgs.Empty);
     return(Task.CompletedTask);
 }
コード例 #13
0
 public void Awake()
 {
     shutDown = GetComponent <ShutDown>();
 }
コード例 #14
0
ファイル: Worker.cs プロジェクト: yikliu/WiredIn
 /// <summary>
 /// Catches the shut down activity.
 /// </summary>
 /// <param name="sd">The sd.</param>
 public void CatchShutDownActivity(ShutDown sd)
 {
     sd.Catched = true;
     sd.StateString = judge.CurState.ToString();
 }