Example #1
0
        //Add new process inside our table (list) and Scheduler memory
        private void buttonInput_Click(object sender, EventArgs e)
        {
            var durationString    = textBoxDuration.Text;
            var arrivalTimeString = textBoxArrivalTime.Text;
            var priorityString    = textBoxPriority.Text;
            var burstTimeString   = textBoxBurstTime.Text;
            var ioTimeString      = textBoxIOTime.Text;

            string inputErrors = Input.CheckInputErrors(durationString, arrivalTimeString, priorityString, burstTimeString, ioTimeString);

            if (!String.IsNullOrEmpty(inputErrors))
            {
                MessageBox.Show(inputErrors);
            }
            else
            {
                int duration    = Int32.Parse(durationString);
                int arrivalTime = Int32.Parse(arrivalTimeString);
                int priority    = Int32.Parse(priorityString);
                int burstTime   = Int32.Parse(burstTimeString);
                int ioTime      = Int32.Parse(ioTimeString);

                if (ioTime == 0)
                {
                    burstTime       = duration;
                    burstTimeString = durationString;
                }

                Process newProcess = new Process(Global.Scheduler.ProcessesList.Count + 1, duration, arrivalTime, priority, burstTime, ioTime);
                Global.Scheduler.ProcessesList.Add(newProcess);

                Input.AddProcessToTable(dataGridViewProcessesList, newProcess.Id, durationString, arrivalTimeString, priorityString, burstTimeString, ioTimeString);
            }
        }
        private void buttonLoadFromFile_Click(object sender, EventArgs e)
        {
            string line;

            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter      = "Text files | *.txt";
            dialog.Multiselect = false;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                String path = dialog.FileName;
                using (StreamReader reader = new StreamReader(new FileStream(path, FileMode.Open), new UTF8Encoding()))
                {
                    while ((line = reader.ReadLine()) != null)
                    {
                        string[] bits = line.Split(' ');

                        var priorityString = "0";
                        int duration       = Int32.Parse(bits[1]);
                        int arrivalTime    = Int32.Parse(bits[0]);
                        int priority       = Int32.Parse(priorityString);
                        int burstTime      = Int32.Parse(bits[2]);
                        int ioTime         = Int32.Parse(bits[3]);

                        if (ioTime == 0)
                        {
                            burstTime = duration;
                            bits[2]   = bits[1];
                        }

                        Process newProcess = new Process(Global.Scheduler.ProcessesList.Count + 1, duration, arrivalTime, priority, burstTime, ioTime);
                        Global.Scheduler.ProcessesList.Add(newProcess);
                        Global.ProcessesInList.Add(CloneObject.CloneJson(newProcess));

                        Input.AddProcessToTable(dataGridViewProcessesList, newProcess.Id, bits[1], bits[0], priorityString, bits[2], bits[3]);
                    }

                    reader.Close();
                }
            }
        }