Exemplo n.º 1
0
        public void WhenFirstProcessIsRunningAndThenStoppedShouldUpdateTheProcessStatus()
        {
            //Arrange
            Process demoProcess1 = Process.Start(_process1FilePath);

            //Act
            IProcessMonitor pMonitor = ProcessMonitorFactory.BuildDefaultOSProcessMonitor();

            pMonitor.RefreshInformation();

            //Assert
            Assert.AreEqual(2, pMonitor.NbOfProcesses, "NbOfProcesses assertion is wrong");
            Assert.AreEqual(1, pMonitor.NbOfNotRunningProcesses, "NbOfNotRunningProcesses assertion is wrong");
            Assert.AreEqual(1, pMonitor.NbOfRunningProcesses, "NbOfRunningProcesses assertion is wrong");
            Assert.AreEqual(ProcessState.Running, pMonitor.GetProcessInformation().First().State,
                            "ProcessState1 assertion is wrong");
            Assert.AreEqual(ProcessState.NotRunning, pMonitor.GetProcessInformation().Last().State,
                            "ProcessState2 assertion is wrong");

            //Act
            demoProcess1.Kill();
            pMonitor.RefreshInformation();

            //Assert
            Assert.AreEqual(2, pMonitor.NbOfProcesses, "NbOfProcesses assertion is wrong");
            Assert.AreEqual(2, pMonitor.NbOfNotRunningProcesses, "NbOfNotRunningProcesses assertion is wrong");
            Assert.AreEqual(0, pMonitor.NbOfRunningProcesses, "NbOfRunningProcesses assertion is wrong");
            Assert.AreEqual(ProcessState.NotRunning, pMonitor.GetProcessInformation().First().State,
                            "ProcessState1 assertion is wrong");
            Assert.AreEqual(ProcessState.NotRunning, pMonitor.GetProcessInformation().Last().State,
                            "ProcessState2 assertion is wrong");
        }
Exemplo n.º 2
0
        public JsonResult GetProcessStatus()
        {
            //Instantiate and refresh information regarding the 3 processes (Notepad, Wordpad and Paint). The
            //information is taken from the Web.config file
            IProcessMonitor processMonitor = ProcessMonitorFactory.BuildDefaultOSProcessMonitor();

            IList <BasicProcessInformation> statusOfProcesses = processMonitor.GetProcessInformation();

            return(Json(statusOfProcesses, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        /// <summary>
        /// On Windows, interrogate the status of the Notepad process every 3 seconds. You can open and close
        /// Notepad in order to see how the program responds to your changes. We print the output on the console.
        /// </summary>
        static void Main()
        {
            System.Console.WriteLine("PMonitor Example - Console");
            IProcessMonitor pm = ProcessMonitorFactory.BuildDefaultOSProcessMonitor();

            while (true)
            {
                pm.RefreshInformation();
                BasicProcessInformation bpi = pm.GetProcessInformation().Single();

                System.Console.WriteLine("{0} Process {1} is {2}", DateTime.Now.ToString(CultureInfo.InvariantCulture), bpi.FriendlyName, bpi.State.ToString());

                Thread.Sleep(3000);
            }
        }
Exemplo n.º 4
0
        public void TheConstructorShouldInstantiateMonitorCorrectly()
        {
            //Act
            IProcessMonitor pMonitor = ProcessMonitorFactory.BuildDefaultOSProcessMonitor();

            //Assert
            Assert.AreEqual(2, pMonitor.NbOfProcesses, "NbOfProcesses assertion is wrong");
            Assert.AreEqual("PMonitor.DemoProcess1", pMonitor.GetProcessInformation().First().ProcessName,
                            "ProcessName1 assertion is wrong");
            Assert.AreEqual(ProcessState.NotRunning, pMonitor.GetProcessInformation().First().State,
                            "ProcessState1 assertion is wrong");
            Assert.AreEqual("PMonitor.DemoProcess2", pMonitor.GetProcessInformation().Last().ProcessName,
                            "ProcessName2 assertion is wrong");
            Assert.AreEqual(ProcessState.NotRunning, pMonitor.GetProcessInformation().Last().State,
                            "ProcessState2 assertion is wrong");
        }
Exemplo n.º 5
0
        /// <summary>
        /// On Windows, interrogate the status of the Notepad process every 3 seconds. You can open and close
        /// Notepad in order to see how the program responds to your changes. We print the output on the console.
        /// </summary>
        static void Main()
        {
            System.Console.WriteLine("PMonitor BoehmTrader - Console");
            IProcessMonitor pm = ProcessMonitorFactory.BuildDefaultOSProcessMonitor();

            while (true)
            {
                pm.RefreshInformation();
                BasicProcessInformation bpi = pm.GetProcessInformation().Single();

                if (numMonitoring % 10 == 0)
                {
                    System.Console.WriteLine("{0} Process {1} is {2}", DateTime.Now.ToString(CultureInfo.InvariantCulture), bpi.FriendlyName, bpi.State.ToString());
                }

                if (bpi.State == ProcessState.NotRunning)
                {
                    StartProcess();
                }

                Thread.Sleep(500);
                numMonitoring++;
            }
        }