예제 #1
0
        public void Shutdown_AbortsAllProcesses()
        {
            var pm = new ProcessManager();

            pm.Initialize();
            pm.PostInitialize();
            var process1 = new ProcessStub(1);

            process1.Initialize();
            pm.AddProcess(process1);
            var process2 = new ProcessStub(2);

            process1.AttachChild(process2);
            var process3 = new ProcessStub(3);

            process3.Initialize();
            pm.AddProcess(process3);

            pm.Shutdown();

            Assert.IsEmpty(pm.Processes);
            Assert.IsTrue(process1.WasAborted);
            Assert.IsTrue(process2.WasAborted);
            Assert.IsTrue(process3.WasAborted);
        }
예제 #2
0
        public void AddProcess_RejectsDuplicateProcessId()
        {
            var pm = new ProcessManager();

            pm.Initialize();
            pm.PostInitialize();
            var process1 = new ProcessStub(1);

            process1.Initialize();
            var process2 = new ProcessStub(1);

            process2.Initialize();
            pm.AddProcess(process1);

            TestDelegate func = () => pm.AddProcess(process2);

            Assert.Throws <InvalidOperationException>(func);
            Assert.AreEqual(1, pm.Processes.Count);
        }
예제 #3
0
        public void GetProcesses_FindsProcessesByMostDerived()
        {
            var pm = new ProcessManager();

            pm.Initialize();
            pm.PostInitialize();
            var process1 = new ProcessStub(1);

            process1.Initialize();
            pm.AddProcess(process1);
            var process2 = new ProcessStub2(2);

            process2.Initialize();
            pm.AddProcess(process2);

            var result = pm.GetProcesses <ProcessStub2>().ToList();

            Assert.AreEqual(1, result.Count);
            Assert.IsNotNull(result.Single(p => ReferenceEquals(p, process2)));
        }
예제 #4
0
        public void AddProcess_HandlesNull()
        {
            var pm = new ProcessManager();

            pm.Initialize();
            pm.PostInitialize();

            TestDelegate func = () => pm.AddProcess(null);

            Assert.Throws <ArgumentNullException>(func);
            Assert.IsFalse(pm.Processes.Any());
        }
예제 #5
0
        public void AddProcess_AcceptsInitializedProcess()
        {
            var pm = new ProcessManager();

            pm.Initialize();
            pm.PostInitialize();
            var process = new ProcessStub(1);

            process.Initialize();

            pm.AddProcess(process);
        }
예제 #6
0
 public long AddProcess(ProcessObject process)
 {
     try
     {
         return(_processManager.AddProcess(process));
     }
     catch (Exception ex)
     {
         ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
예제 #7
0
        public void AddProcess_RejectsUnInitializedProcess()
        {
            var pm = new ProcessManager();

            pm.Initialize();
            pm.PostInitialize();
            var process = new ProcessStub(1);

            TestDelegate func = () => pm.AddProcess(process);

            Assert.Throws <InvalidOperationException>(func);
            Assert.IsFalse(pm.Processes.Any());
        }
예제 #8
0
        public void GetProcess_DoesNotFindNonExistingProcess()
        {
            var pm = new ProcessManager();

            pm.Initialize();
            pm.PostInitialize();
            var process = new ProcessStub(1);

            process.Initialize();
            pm.AddProcess(process);

            var result = pm.GetProcess(2);

            Assert.IsNull(result);
        }
예제 #9
0
        public void GetProcesses_DoesNotFindNonExisting()
        {
            var pm = new ProcessManager();

            pm.Initialize();
            pm.PostInitialize();
            var process1 = new ProcessStub(1);

            process1.Initialize();
            pm.AddProcess(process1);

            var result = pm.GetProcesses <ProcessStub2>().ToList();

            Assert.IsEmpty(result);
        }
예제 #10
0
        public void Update_DoesNotUpdatePausedProcess()
        {
            var pm = new ProcessManager();

            pm.Initialize();
            pm.PostInitialize();
            var process = new ProcessStub(1);

            process.Initialize();
            pm.AddProcess(process);
            const float time = 1.0f;

            pm.Update(time);

            Assert.AreEqual(0, process.DoUpdateCallCount);
        }
예제 #11
0
        public void GetProcess_FindsProcess()
        {
            var pm = new ProcessManager();

            pm.Initialize();
            pm.PostInitialize();
            var process = new ProcessStub(1);

            process.Initialize();
            pm.AddProcess(process);

            var result = pm.GetProcess(1);

            Assert.IsNotNull(result);
            Assert.AreSame(process, result);
        }
예제 #12
0
        public void Update_RemovesAbortedProcess()
        {
            var pm = new ProcessManager();

            pm.Initialize();
            pm.PostInitialize();
            var process = new ProcessStub(1);

            process.Initialize();
            pm.AddProcess(process);
            const float time = 1.0f;

            process.Abort();
            pm.Update(time);

            Assert.IsEmpty(pm.Processes);
        }
예제 #13
0
        public void Update_UpdatesRunningProcess()
        {
            var pm = new ProcessManager();

            pm.Initialize();
            pm.PostInitialize();
            var process = new ProcessStub(1);

            process.Initialize();
            pm.AddProcess(process);
            process.Resume();
            const float time = 1.0f;

            pm.Update(time);

            Assert.AreEqual(1, process.DoUpdateCallCount);
            Assert.AreEqual(time, process.LastUpdateDeltaTime);
        }
예제 #14
0
        public void Update_DoesNotActivateChildOnAbort()
        {
            var pm = new ProcessManager();

            pm.Initialize();
            pm.PostInitialize();
            var process1 = new ProcessStub(1);

            process1.Initialize();
            pm.AddProcess(process1);
            var process2 = new ProcessStub(2);

            process1.AttachChild(process2);
            const float time = 1.0f;

            process1.Abort();
            pm.Update(time);

            Assert.IsEmpty(pm.Processes);
            Assert.IsTrue(process2.WasAborted);
        }
예제 #15
0
        public void Update_AbortsChildThatFailsInitialization()
        {
            var pm = new ProcessManager();

            pm.Initialize();
            pm.PostInitialize();
            var process1 = new ProcessStub(1);

            process1.Initialize();
            pm.AddProcess(process1);
            var process2 = new ProcessStub(2, false);

            process1.AttachChild(process2);
            const float time = 1.0f;

            process1.Succeed();
            pm.Update(time);

            Assert.IsEmpty(pm.Processes);
            Assert.IsTrue(process2.WasAborted);
        }
        private void AddNewProcess(object sender, RoutedEventArgs e)
        {
            var newProcess = ValueNewProcess.Text;

            if (newProcess.Trim() == string.Empty)
            {
                MessageBox.Show(Properties.Resources.NameProcess, "", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var result = _manager.AddProcess(newProcess);

            ValueNewProcess.Text = string.Empty;
            if (result)
            {
                MessageBox.Show(Properties.Resources.Process + $" {newProcess} " + Properties.Resources.SuccessfullyCreated, "", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show(Properties.Resources.Process + $" {newProcess} " + Properties.Resources.AlredyCreated, "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #17
0
        public void Update_ActivatesUnInitializedChild()
        {
            var pm = new ProcessManager();

            pm.Initialize();
            pm.PostInitialize();
            var process1 = new ProcessStub(1);

            process1.Initialize();
            pm.AddProcess(process1);
            var process2 = new ProcessStub(2);

            process1.AttachChild(process2);
            const float time = 1.0f;

            process1.Succeed();
            pm.Update(time);

            Assert.AreEqual(1, pm.Processes.Count);
            Assert.IsNotNull(pm.Processes.Single(p => ReferenceEquals(p, process2)));
            Assert.IsTrue(process2.IsRunning);
        }
예제 #18
0
        public override void Update()
        {
            // update base
            UpdateWindow();
            base.Update();

            // update button positions
            int btnX = x + width - (btnLogon.width * 3) - 24;

            btnLogon.x = btnX; btnX += 100;
            btnLogon.y = y + height - btnLogon.height - 8;

            btnRestart.x = btnX; btnX += 100;
            btnRestart.y = y + height - btnRestart.height - 8;

            btnShutdown.x = btnX;
            btnShutdown.y = y + height - btnShutdown.height - 8;

            txtUser.x = x + 88;
            txtUser.y = y + 30;

            txtPass.x = x + 88;
            txtPass.y = y + 64;

            // update buttons
            if (!ProcessManager.IsInstanceOpen(Kernel.logon.invalidDialog.name))
            {
                btnLogon.Update();
                btnRestart.Update();
                btnShutdown.Update();
                txtUser.Update();
                txtPass.Update();
            }

            // power options
            if (btnRestart.down)
            {
                Sys.Power.Reboot();
            }
            if (btnShutdown.down)
            {
                Sys.Power.Shutdown();
            }

            // attempt login
            if (btnLogon.down && !btnLogon.clicked)
            {
                if (txtUser.text == Logon.username && txtPass.text == Logon.password)
                {
                    Kernel.shell = new Shell();
                    ProcessManager.AddProcess(Kernel.shell);
                    Kernel.logon.exitRequest = true;
                    exitRequest = true;
                }
                else
                {
                    Kernel.logon.InvalidLogin();
                }
                btnLogon.clicked = true;
            }
        }
예제 #19
0
        public override void Update()
        {
            timeLabel.text = Clock.FormattedTime;

            // toggle main menu
            if (menuBtn.down && !menuBtn.clicked)
            {
                menu.visible = !menu.visible; menuBtn.clicked = true;
            }

            // terminal
            if (menu.btnTerminal.down && !menu.btnTerminal.clicked)
            {
                ProcessManager.AddWindow(new Processes.Terminal(64, 64)); menu.btnTerminal.clicked = true; menu.visible = false;
            }

            // about
            if (menu.btnAbout.down && !menu.btnAbout.clicked)
            {
                ProcessManager.AddWindow(new Processes.AboutOS(64, 64)); menu.btnAbout.clicked = true; menu.visible = false;
            }

            // cli
            if (menu.btnCLI.down)
            {
                Kernel.RunTextMode();
            }

            // shutdown result
            if (shutdownDialog.result == DialogResult.yes)
            {
                Sys.Power.Shutdown();
            }
            if (shutdownDialog.result == DialogResult.no)
            {
                shutdownDialog.result = DialogResult.none; shutdownDialog.exitRequest = true;
            }

            // restart result
            if (restartDialog.result == DialogResult.yes)
            {
                Sys.Power.Reboot();
            }
            if (restartDialog.result == DialogResult.no)
            {
                restartDialog.result = DialogResult.none; restartDialog.exitRequest = true;
            }

            // logoff dialog
            if (logoffDialog.result == DialogResult.yes)
            {
                ProcessManager.windows.Clear();
                Kernel.logon = new Logon();
                ProcessManager.AddProcess(Kernel.logon);
                exitRequest = true;
            }
            if (logoffDialog.result == DialogResult.no)
            {
                logoffDialog.result = DialogResult.none; logoffDialog.exitRequest = true;
            }

            // confirm logoff
            if (menu.btnLogoff.down && !menu.btnLogoff.clicked)
            {
                if (!ProcessManager.IsInstanceOpen(logoffDialog.name) && !ProcessManager.IsInstanceOpen(restartDialog.name) && !ProcessManager.IsInstanceOpen(shutdownDialog.name))
                {
                    logoffDialog.exitRequest = false;
                    logoffDialog.moving      = false;
                    logoffDialog.result      = DialogResult.none;
                    ProcessManager.AddWindow(logoffDialog);
                }
                menu.btnLogoff.clicked = true;
                menu.visible           = false;
            }

            // confirm restart
            if (menu.btnRestart.down && !menu.btnRestart.clicked)
            {
                if (!ProcessManager.IsInstanceOpen(logoffDialog.name) && !ProcessManager.IsInstanceOpen(restartDialog.name) && !ProcessManager.IsInstanceOpen(shutdownDialog.name))
                {
                    restartDialog.exitRequest = false;
                    restartDialog.moving      = false;
                    restartDialog.result      = DialogResult.none;
                    ProcessManager.AddWindow(restartDialog);
                }
                menu.btnRestart.clicked = true;
                menu.visible            = false;
            }

            // confirm shutdown
            if (menu.btnOff.down && !menu.btnOff.clicked)
            {
                if (!ProcessManager.IsInstanceOpen(logoffDialog.name) && !ProcessManager.IsInstanceOpen(restartDialog.name) && !ProcessManager.IsInstanceOpen(shutdownDialog.name))
                {
                    shutdownDialog.exitRequest = false;
                    shutdownDialog.moving      = false;
                    shutdownDialog.result      = DialogResult.none;
                    ProcessManager.AddWindow(shutdownDialog);
                }
                menu.btnOff.clicked = true;
                menu.visible        = false;
            }

            // hide menu on click-away
            if (!menu.bounds.Contains(MSPS2.position) && !menuBtn.hover && !menu.hover)
            {
                if (MSPS2.state == Sys.MouseState.Left)
                {
                    menu.visible = false;
                }
            }
        }
예제 #20
0
 public void AddProcess(Process process, ResourceLimits rlimits)
 {
     processManager.AddProcess(process);
 }