示例#1
0
        public void TestKillProcess()
        {
            string  path = "C:\\SoftwareMiner\\CryptoDredge_0.9.3\\start-BCD-bcd-zpool.bat";
            Process _runningMinerProcess;
            var     startInfo = new ProcessStartInfo();

            startInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(path);
            startInfo.CreateNoWindow   = false;
            startInfo.UseShellExecute  = true;
            //        startInfo.RedirectStandardOutput = false;
            startInfo.FileName   = path;
            _runningMinerProcess = System.Diagnostics.Process.Start(startInfo);
            string message = DateTime.Now.ToString("yyyy-MM-dd HH':'mm") + " start " + path;

            EasyLog.Log(@"c:\\Log\\minerlog.txt", message);
            System.Threading.Thread.Sleep(10000);
            if (_runningMinerProcess != null)
            {
                MinerControl.KillProcessAndChildrens(_runningMinerProcess.Id);
                message = DateTime.Now.ToString("yyyy-MM-dd HH':'mm") + " stop " + _runningMinerProcess.StartInfo.FileName;
                EasyLog.Log(@"c:\\Log\\minerlog.txt", message);
                _runningMinerProcess = null;
            }
            Assert.AreEqual(null, _runningMinerProcess);
        }
示例#2
0
 public void DisplayBallonMessage(string message, int mSeconds)
 {
     if (!string.IsNullOrEmpty(message))
     {
         notifyIcon.BalloonTipText = message;
         EasyLog.LogInfo(message);
     }
     notifyIcon.ShowBalloonTip(mSeconds);
 }
示例#3
0
 private static void CloseExistsMiner()
 {
     if (_runningMinerProcess != null)
     {
         KillProcessAndChildrens(_runningMinerProcess.Id);
         string message = DateTime.Now.ToString("yyyy-MM-dd HH':'mm") + " stop " + _runningMinerProcess.StartInfo.FileName;
         EasyLog.Log("minerlog.txt", message);
         _runningMinerProcess = null;
     }
 }
示例#4
0
 void OnTimerEvent(object sender, EventArgs e)
 {
     if (_noSleep && DateTime.Now >= _stopSleeping)
     {
         _noSleep = false;
         EasyLog.LogInfo("OnTimerEvent->Stop Trigger");
         AllowSleep();
         DisplayBallonMessage("Time-Marker reached: Allow sleep mode !!!", 3000);
         rbAllow.Checked = true;
         return;
     }
     if (_noSleep)
     {
         SetThreadExecutionState(_processor | _monitor);
         Debug.WriteLine("No Sleep Event !");
     }
 }
示例#5
0
        public static bool IsSecondInstance(string title)
        {
            string proc = Process.GetCurrentProcess().ProcessName;

            EasyLog.LogDebug("ProcessName: {0}", proc);

            Process[] procs = Process.GetProcessesByName(proc);

            if (procs.Length > 1)
            {
                EasyLog.LogDebug("There is an instance of the Application already running !");

                IntPtr hWnd = IntPtr.Zero;

                // Find the real windows
                var windows = GetWindows();
                foreach (var window in windows)
                {
                    if (window.WinTitle == title)
                    {
                        hWnd = (IntPtr)window.MainWindowHandle;
                    }
                }

                // get the window handle
                // if iconic, we need to restore the window

                if (IsIconic(hWnd))
                {
                    ShowWindowAsync(hWnd, SW_SHOW);
                }

                if (!IsWindowVisible(hWnd))
                {
                    ShowWindowAsync(hWnd, SW_SHOW);
                }
                // bring it to the foreground

                SetForegroundWindow(hWnd);
                // exit our process

                return(true);
            }

            return(false);
        }
示例#6
0
        private void WaitTimer(IntPtr handle)
        {
            // Waiting for the timer to expire
            //
            if (WaitForSingleObject(handle, INFINITE) != 0)
            {
                EasyLog.LogError("Last Error = {0}", Marshal.GetLastWin32Error());
            }
            else
            {
                EasyLog.LogError("Timer expired @ {0}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
                OnAwakeFromSleeping();
            }

            // Closing the timer
            //
            CloseHandle(handle);
        }
示例#7
0
 private static void RunMiner(string path)
 {
     try
     {
         var startInfo = new ProcessStartInfo();
         startInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(path);
         startInfo.CreateNoWindow   = false;
         startInfo.UseShellExecute  = true;
         //        startInfo.RedirectStandardOutput = false;
         startInfo.FileName   = path;
         _runningMinerProcess = System.Diagnostics.Process.Start(startInfo);
         string message = DateTime.Now.ToString("yyyy-MM-dd HH':'mm") + " start " + path;
         EasyLog.Log("minerlog.txt", message);
     }
     catch (Exception err)
     {
         throw new Exception("Please verify the configuration file [miner.json] or your .bat file  has invalid config.", err);
     }
 }