Ejemplo n.º 1
0
        private void printClock(int cycle, ProcessProfile p, int rmax)
        {
            //BUG - decimal places will not print
            //decimal dpercentCPU = (p.CPUBurstCount / p.CPUBurstTime)*100;
            //string percentCPU = string.Format("{0:0.##}", dpercentCPU.ToString());

            Console.WriteLine(cycle + " | P" + p.processNo + " | " + p.CPUBurstCount + "/" + p.CPUBurstTime + " PRIORITY: " + p.Priority); /*+ " | " + percentCPU + "%");*/
        }
        //interpret will read into the CSV
        private Boolean interpret(string path)
        {
            //referring to StackOverflow tutorial on reading CSV
            using (TextFieldParser parser = new TextFieldParser(@path))
            {
                parser.TextFieldType = FieldType.Delimited;
                parser.SetDelimiters(",");
                while (!parser.EndOfData)
                {
                    //for each column
                    int csvCounter = 0;
                    //Processing row
                    string[] fields = parser.ReadFields();
                    foreach (string field in fields)
                    {
                        switch (csvCounter)
                        {
                        //Priority Column
                        case 0:
                            csvCounter++;
                            LPriority.Add(System.Convert.ToInt32(field));
                            //VERBOSE: Console.Write("Row Parsed: " + field);
                            break;

                        //Submission Time Column
                        case 1:
                            csvCounter++;
                            LSubmissionTime.Add(System.Convert.ToInt32(field));
                            //VERBOSE: Console.Write("," + field);
                            break;

                        //CPU Burst Time Column
                        case 2:
                            csvCounter = 0;
                            LCPUBurstTime.Add(System.Convert.ToInt32(field));
                            //VERBOSE: Console.WriteLine("," + field);
                            break;
                        }
                    }
                }
            }

            //process the seperated values into one ProcessProfile object
            for (int i = 0; i < LPriority.Count; i++)
            {
                ProcessProfile pp = new ProcessProfile(LPriority[i], LSubmissionTime[i], LCPUBurstTime[i]);

                pp.processNo = i;

                //drop it into the list of profiles
                listOfProfiles.Add(pp);
            }

            return(true);
        }