Esempio n. 1
0
        private void UpdateReadyProcessesCurrentProcessDataGridView()
        {
            ClearCurrentProcessDataGridView();

            currentProcess = null;

            if (readyProcessesQueue.Count != 0)
            {
                SetCurrentProcessDataGridView();
            }
            else if (blockedProcessesList.Count == 0)
            {
                Queue <Process> suspendedProcessesQueue = JsonConvert.DeserializeObject <Queue <Process> >(File.ReadAllText("Procesos Suspendidos.txt"));

                if (suspendedProcessesQueue.Count != 0)
                {
                    return;
                }

                ButtonAddProcesses.Enabled = true;

                TimerProcessEstimatedTime.Enabled = false;

                using (FormProcessControlBlock processControlBlockForm = new FormProcessControlBlock(newProcessesQueue, readyProcessesQueue,
                                                                                                     currentProcess, blockedProcessesList, completedProcessesList, Convert.ToInt32(LabelCounterNumber.Text)))
                {
                    processControlBlockForm.ShowDialog();
                }
            }
        }
Esempio n. 2
0
        private void FormBatchProcessing_KeyDown(object sender, KeyEventArgs keyPressed)
        {
            if (TimerProcessEstimatedTime.Enabled == true)
            {
                if (keyPressed.KeyCode == Keys.P || keyPressed.KeyCode == Keys.M)
                {
                    TimerProcessEstimatedTime.Enabled = false;
                }
                else if (keyPressed.KeyCode == Keys.N)
                {
                    newProcessesQueue.Enqueue(GetNewProcess(globalProcessID++));

                    LabelNumOfRemainingNewProcesses.Text = newProcessesQueue.Count.ToString();

                    LabelNextNewProcessIDValue.Text   = newProcessesQueue.Peek().ID.ToString();
                    LabelNextNewProcessSizeValue.Text = newProcessesQueue.Peek().Size.ToString();
                }
                else if (keyPressed.KeyCode == Keys.T)
                {
                    TimerProcessEstimatedTime.Enabled = false;

                    using (FormProcessControlBlock processControlBlockForm = new FormProcessControlBlock(newProcessesQueue,
                                                                                                         readyProcessesQueue, currentProcess, blockedProcessesList, completedProcessesList, Convert.ToInt32(LabelCounterNumber.Text)))
                    {
                        if (processControlBlockForm.ShowDialog() == DialogResult.OK)
                        {
                            TimerProcessEstimatedTime.Enabled = true;
                        }
                    }
                }
                else if (keyPressed.KeyCode == Keys.S)
                {
                    if (blockedProcessesList.Count != 0)
                    {
                        Queue <Process> suspendedProcessesQueue = JsonConvert.DeserializeObject <Queue <Process> >(File.ReadAllText("Procesos Suspendidos.txt"));
                        Process         newSuspendedProcess     = blockedProcessesList[0];

                        if (suspendedProcessesQueue.Count == 0)
                        {
                            LabelNextSuspendedProcessIDValue.Text   = newSuspendedProcess.ID.ToString();
                            LabelNextSuspendedProcessSizeValue.Text = newSuspendedProcess.Size.ToString();
                        }

                        LabelNumOfRemainingSuspendedProcesses.Text = suspendedProcessesQueue.Count.ToString();

                        suspendedProcessesQueue.Enqueue(newSuspendedProcess);

                        RemoveMemoryDataGridViewProcess(newSuspendedProcess);
                        RemoveVirtualMemoryDataGridViewProcess(newSuspendedProcess);

                        globalMemory.Remove(newSuspendedProcess);
                        globalVirtualMemory.Remove(newSuspendedProcess);

                        blockedProcessesList.RemoveAt(0);
                        blockedProcessesDataTable.Rows[0].Delete();

                        File.WriteAllText("Procesos Suspendidos.txt", JsonConvert.SerializeObject(suspendedProcessesQueue, Formatting.Indented));
                    }
                }
                else if (keyPressed.KeyCode == Keys.R)
                {
                    Queue <Process> suspendedProcessesQueue = JsonConvert.DeserializeObject <Queue <Process> >(File.ReadAllText("Procesos Suspendidos.txt"));

                    if (suspendedProcessesQueue.Count != 0 && globalMemory.Add(suspendedProcessesQueue.Peek()))
                    {
                        DataRow blockedProcessesRow = blockedProcessesDataTable.NewRow();
                        Process newBlockedProcess   = suspendedProcessesQueue.Dequeue();

                        LabelNumOfRemainingSuspendedProcesses.Text = LabelNumOfRemainingSuspendedProcesses.Text = suspendedProcessesQueue.Count.ToString();

                        if (suspendedProcessesQueue.Count != 0)
                        {
                            LabelNextSuspendedProcessIDValue.Text   = suspendedProcessesQueue.Peek().ID.ToString();
                            LabelNextSuspendedProcessSizeValue.Text = suspendedProcessesQueue.Peek().Size.ToString();
                        }
                        else
                        {
                            LabelNextSuspendedProcessIDValue.Text   = "0";
                            LabelNextSuspendedProcessSizeValue.Text = "0";
                        }

                        blockedProcessesRow["ID"] = newBlockedProcess.ID;
                        blockedProcessesRow["TT"] = 0;

                        blockedProcessesDataTable.Rows.Add(blockedProcessesRow);

                        blockedProcessesList.Add(newBlockedProcess);

                        AddMemoryDataGridViewProcess(newBlockedProcess);
                        UpdateMemoryDataGridViewProcessColor(newBlockedProcess, Color.Purple);

                        File.WriteAllText("Procesos Suspendidos.txt", JsonConvert.SerializeObject(suspendedProcessesQueue, Formatting.Indented));
                    }
                }
                else if (keyPressed.KeyCode == Keys.U)
                {
                    List <int> processIndices;
                    int        frameIndex, virtualMemoryIndex;

                    foreach (Process readyProcess in readyProcessesQueue)
                    {
                        processIndices = globalMemory.FindIndices(readyProcess);

                        if (processIndices.Count != 1)
                        {
                            frameIndex         = processIndices[processIndices.Count - 1];
                            virtualMemoryIndex = globalVirtualMemory.AddFrame(new Frame(globalMemory.Frames[frameIndex]));

                            if (virtualMemoryIndex == -1)
                            {
                                return;
                            }

                            RemoveMemoryDataGridViewFrame(frameIndex);
                            globalMemory.RemoveFrame(frameIndex);

                            AddVirtualMemoryDataGridViewFrame(virtualMemoryIndex, Color.Blue);
                        }
                    }

                    foreach (Process blockedProcess in blockedProcessesList)
                    {
                        processIndices = globalMemory.FindIndices(blockedProcess);

                        if (processIndices.Count != 1)
                        {
                            frameIndex         = processIndices[processIndices.Count - 1];
                            virtualMemoryIndex = globalVirtualMemory.AddFrame(new Frame(globalMemory.Frames[frameIndex]));

                            if (virtualMemoryIndex == -1)
                            {
                                return;
                            }

                            RemoveMemoryDataGridViewFrame(frameIndex);
                            globalMemory.RemoveFrame(frameIndex);

                            AddVirtualMemoryDataGridViewFrame(virtualMemoryIndex, Color.Purple);
                        }
                    }
                }
                else if (currentProcess != null)
                {
                    if (keyPressed.KeyCode == Keys.I)
                    {
                        DataRow blockedProcessesRow = blockedProcessesDataTable.NewRow();

                        blockedProcessesRow["ID"] = currentProcess.ID;
                        blockedProcessesRow["TT"] = 0;

                        blockedProcessesDataTable.Rows.Add(blockedProcessesRow);

                        blockedProcessesList.Add(currentProcess);

                        UpdateMemoryDataGridViewProcessColor(currentProcess, Color.Purple);

                        if (readyProcessesQueue.Count != 0)
                        {
                            SetCurrentProcessDataGridView();
                        }
                        else
                        {
                            ClearCurrentProcessDataGridView();

                            currentProcess = null;
                        }
                    }
                    else if (keyPressed.KeyCode == Keys.E)
                    {
                        completedProcessesList.Add(currentProcess);

                        AddCompletedProcessToDataGridView(true);

                        UpdateReadyProcessesCurrentProcessDataGridView();
                    }
                }
            }
            else
            {
                if (keyPressed.KeyCode == Keys.C)
                {
                    TimerProcessEstimatedTime.Enabled = true;
                }
            }
        }