コード例 #1
0
        private void Show_processData(process p, bool f)
        {
            if (f)
            {
                lbl_start.Show();
                lbl_start_v.Show();
                lbl_name.Show();
                lbl_name_v.Show();
                lbl_size.Show();
                lbl_size_v.Show();
                lbl_end.Show();
                lbl_end_v.Show();


                lbl_start_v.Text = p.start.ToString();

                lbl_name_v.Text = p.name;

                lbl_size_v.Text = p.size.ToString();

                lbl_end_v.Text = p.end.ToString();
                return;
            }
            lbl_start.Hide();
            lbl_start_v.Hide();
            lbl_name.Hide();
            lbl_name_v.Hide();
            lbl_size.Hide();
            lbl_size_v.Hide();
            lbl_end.Hide();
            lbl_end_v.Hide();
        }
コード例 #2
0
        private void update_process_list()
        {
            processes.Clear();

            for (int i = 0; i < process_number; i++)
            {
                process proc = new process();
                proc.name        = process_lbl[i].Text;
                proc.size        = Convert.ToInt16(process_size[i].Text);
                proc.method      = alocating_Algorithm[i].Text;
                proc.process_lbl = process_lbl[i];
                processes.Add(proc);
            }
        }
コード例 #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            process p = new process();

            Show_processData(p, false);
            new_ps++;
            MemoryLayout mem = new MemoryLayout();

            mem = this;
            AddProcess new_processForm = new AddProcess(ref mem, new_ps);

            new_processForm.ShowDialog();
            draw_process();
        }
コード例 #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            process p_new = new process();
            Label   lbl   = new Label();

            lbl.Text          = "New P" + new_ps.ToString();
            p_new.size        = Convert.ToInt16(textBox1.Text);
            p_new.method      = comboBox1.Text;
            p_new.process_lbl = lbl;
            p_new.name        = p_new.process_lbl.Text;
            //  p_new.waiting = lbl;
            //memFormHandler.inrement_y += 15;
            memFormHandler.procs.Add(p_new);
            this.Close();
        }
コード例 #5
0
        private void label_Click(object sender, EventArgs e)
        {
            Label clickedLabel = sender as Label;

            process p = new process();

            if (clickedLabel != null)
            {
                // If the clicked label is black, the player clicked
                // an icon that's already been revealed --
                // ignore the click
                if (clickedLabel.BackColor == Color.Red)
                {
                    Show_processData(p, false);
                    p            = clicked_process.Pop();
                    label16.Text = (Convert.ToInt16(label16.Text) - 1).ToString();
                    if (p.size > 10)
                    {
                        clickedLabel.BackColor = Color.Green;
                    }
                    else
                    {
                        clickedLabel.BackColor = Color.Blue;
                    }
                }
                else
                {
                    for (int i = 0; i < procs.Count; i++)
                    {
                        if (procs[i].name == clickedLabel.Name)
                        {
                            clicked_process.Push(procs[i]);
                            label16.Text = (Convert.ToInt16(label16.Text) + 1).ToString();
                            Show_processData(procs[i], true);
                            break;
                        }
                    }

                    clickedLabel.BackColor = Color.Red;
                }
            }
        }
コード例 #6
0
        //  Panel panel1 = new Panel();
        public MemoryLayout(ref Form1 form1Handler, int mem_size, List <hole> holes, List <process> procs)
        {
            InitializeComponent();
            this.holes        = holes;
            this.procs        = procs;
            this.mem_size     = mem_size;
            this.firstFormRef = form1Handler;
            panel1.AutoScroll = true;
            label1.Text       = mem_size.ToString();
            process p = new process();

            Show_processData(p, false);



            // panel1.CausesValidation = false;
            label1.Font = new Font("Tahoma", 5, FontStyle.Regular);
            draw_holes();
            // SendLabelsToBack();
            draw_process();
        }
コード例 #7
0
 public segment(process parent_process, int size, Color color)
 {
     this.size           = size;
     this.parent_process = parent_process;
     this.color          = parent_process.get_color();
 }
コード例 #8
0
        private void add_to_memory(object sender, EventArgs e, Label lbl, process p)
        {
            Button b = sender as Button;

            //sorting descendingly according to size:: try ex p=50,100,200 ;holes sizes=300,100,100;it will not work
            ////// p.segments_sort_desc();///ES2L FEEHA
            //renew the holes list and current process in memory Clear the memory panel and then draw it again
            if (p.get_size() > memory.get_total_empty_space())
            {
                MessageBox.Show("Process" + p.get_index().ToString() + " cannot be added to memory");
                return;
            }
            //Colning the memory because the defalult assign is by referance in c# ex:memory temp=memory => if we change temp the memory will change  due to copying by referrence

            if (firstfit.Checked == true)
            {
                memory temp = memory.copy();
                foreach (segment s in p.get_segments())
                {
                    int success = 0;
                    foreach (hole h in temp.get_holes())
                    {
                        if (h.get_size() >= s.get_size())
                        {
                            hole np = new hole(s.get_size(), h.get_start_location());
                            np.set_color(s.get_color());
                            np.set_text(s.get_text());
                            temp.add_process(np);

                            h.set_size(h.get_size() - s.get_size());
                            h.set_start_location(h.get_start_location() + s.get_size());
                            success = 1;
                            break;
                        }
                    }
                    if (success == 0)
                    {
                        MessageBox.Show("Process cannot be added to memory");
                        return;
                    }
                }
                memory = temp;
                lst_memory.Controls.Clear();
                memory_draw();
                /*if added successfully  remove the process from wait list*/
                b.Enabled   = false;
                lbl.Enabled = false;
                b.Hide();
                lbl.Hide();
                /**END OF FIRST FIT*/
            }
            else if (bestfit.Checked == true)
            {
                memory      temp  = memory;
                bool        check = false;
                List <bool> x     = new List <bool>();
                for (int i = 0; i < temp.get_number_holes_after_merge(); i++)
                {
                    x.Add(true);
                }

                temp.arrange_memory_ascending_size();
                foreach (segment s in p.get_segments())
                {
                    int i = 0;
                    foreach (hole h in temp.get_holes())
                    {
                        if (x[i])
                        {
                            if (s.get_size() > h.get_size())
                            {
                                check = false; continue;
                            }
                            else
                            {
                                x[i]  = false;
                                check = true;
                                break;
                            }
                        }
                        i++;
                    }
                }
                if (check)
                {
                    foreach (segment s in p.get_segments())
                    {
                        foreach (hole h in temp.get_holes())
                        {
                            if (s.get_size() > h.get_size())
                            {
                                continue;
                            }
                            else
                            {
                                hole get_in = new hole(s.get_size(), h.get_start_location());
                                get_in.set_color(s.get_color());
                                get_in.set_text(s.get_text());
                                h.set_size(h.get_size() - s.get_size());
                                h.set_start_location(h.get_start_location() + s.get_size());

                                temp.add_process(get_in);
                                break;
                            }
                        }
                    }
                    temp.merge_holes();
                }
                else
                {
                    MessageBox.Show("Process cannot be added to memory");
                    return;
                }
                memory = temp;
                lst_memory.Controls.Clear();
                memory_draw();
                b.Enabled   = false;
                lbl.Enabled = false;
                b.Hide();
                lbl.Hide();
            }
            else if (worstfit.Checked == true)
            {
                memory      temp  = memory;
                bool        check = false;
                List <bool> x     = new List <bool>();
                for (int i = 0; i < temp.get_number_holes_after_merge(); i++)
                {
                    x.Add(true);
                }

                temp.arrange_memory_descending_size();
                foreach (segment s in p.get_segments())
                {
                    int i = 0;
                    foreach (hole h in temp.get_holes())
                    {
                        if (x[i])
                        {
                            if (s.get_size() > h.get_size())
                            {
                                check = false; continue;
                            }
                            else
                            {
                                x[i]  = false;
                                check = true;
                                break;
                            }
                        }
                        i++;
                    }
                }
                if (check)
                {
                    foreach (segment s in p.get_segments())
                    {
                        foreach (hole h in temp.get_holes())
                        {
                            if (s.get_size() > h.get_size())
                            {
                                continue;
                            }
                            else
                            {
                                hole get_in = new hole(s.get_size(), h.get_start_location());
                                get_in.set_color(s.get_color());
                                get_in.set_text(s.get_text());
                                h.set_size(h.get_size() - s.get_size());
                                h.set_start_location(h.get_start_location() + s.get_size());

                                temp.add_process(get_in);
                                break;
                            }
                        }
                    }
                    temp.merge_holes();
                }
                else
                {
                    MessageBox.Show("Process cannot be added to memory");
                    return;
                }
                memory = temp;
                lst_memory.Controls.Clear();
                memory_draw();
                b.Enabled   = false;
                lbl.Enabled = false;
                b.Hide();
                lbl.Hide();
            }
        }
コード例 #9
0
        private void panel2_Paint(object sender, PaintEventArgs e)
        {
            process p = new process();

            Show_processData(p, false);
        }
コード例 #10
0
        private void groupBox3_Enter(object sender, EventArgs e)
        {
            process p = new process();

            Show_processData(p, false);
        }
コード例 #11
0
        private void MemoryLayout_Click(object sender, EventArgs e)
        {
            process p = new process();

            Show_processData(p, false);
        }
コード例 #12
0
        private void label3_Click(object sender, EventArgs e)
        {
            process p = new process();

            Show_processData(p, false);
        }
コード例 #13
0
        private void button4_Click(object sender, EventArgs e)
        {
            process proc = new process();

            Show_processData(proc, false);
            while (clicked_process.Count != 0)
            {
                proc = clicked_process.Pop();

                hole           h = new hole();
                List <process> same_hole_procs;
                h = holes.Find(x => x.hole_lbl.Text.Contains(proc.allocated_hole_name));
                same_hole_procs = new List <process>(procs.FindAll(x => x.allocated_hole_name.Contains(h.hole_lbl.Text.ToString())).OrderByDescending(n => n.start));

                if (h.end != proc.start && (same_hole_procs.Count != clicked_process.Count + 1))//there is another processes allocated under than process
                {
                    //get all processes allocated in that hole and shift them to the bottom of the hole

                    h.end += proc.size;

                    bool flag = false;
                    for (int i = 0; i < same_hole_procs.Count; i++)
                    {
                        if (same_hole_procs[i] == proc)
                        {
                            flag = true;
                            procs.Remove(proc);
                            continue;
                        }
                        if (flag)
                        {
                            same_hole_procs[i].end       += proc.size;
                            same_hole_procs[i].start      = same_hole_procs[i].end - same_hole_procs[i].size;
                            same_hole_procs[i].rearranged = true;
                            draw_process();
                        }
                    }


                    h.size += proc.size;
                }

                else
                {
                    h.size += proc.size;
                    h.end  += proc.size;
                    procs.Remove(proc);
                }
                this.panel1.Controls.Remove(proc.process_lbl);
                this.panel1.Controls.Remove(proc.start_lbl);
                this.panel1.Controls.Remove(proc.end_lbl);
                label16.Text = (Convert.ToInt16(label16.Text) - 1).ToString();
            }

            if (waiting_procs > 0)
            {
                //  waiting_procs-=clicked_process.Count;

                // draw_holes();

                draw_process();
            }
            if (waiting_procs == 0)
            {
                panel2.Controls.Clear();
            }
        }
コード例 #14
0
        private void draw_process()
        {
            Label start = new Label();
            Label end   = new Label();

            for (int i = 0; i < procs.Count; i++)
            {
                process current     = procs[i];
                bool    IsAlocated  = false;
                int     scale_width = Scale(current.size);
                if (current.IsAllocated && current.rearranged == false)
                {
                    continue;
                }

                else if (current.IsAllocated && current.rearranged == true)
                {
                    panel1.Controls.Remove(current.process_lbl);
                    panel1.Controls.Remove(current.start_lbl);
                    panel1.Controls.Remove(current.end_lbl);


                    Point pt    = new Point(45, Scale(current.start));
                    Point lbl_p = new Point(20, Scale(current.start));
                    start = creat_lable(current.start, lbl_p.X, lbl_p.Y);
                    end   = creat_lable(current.end, lbl_p.X, lbl_p.Y + (Scale(current.size) - 8));

                    start.BackColor = Color.DimGray;
                    end.BackColor   = Color.DimGray;
                    start.ForeColor = Color.GreenYellow;
                    end.ForeColor   = Color.GreenYellow;
                    start.Name      = current.name;
                    end.Name        = current.name;
                    start.Font      = new Font("Tahoma", 5, FontStyle.Regular);
                    end.Font        = new Font("Tahoma", 5, FontStyle.Regular);


                    if (current.size <= 10)
                    {
                        current.process_lbl.BackColor = Color.Blue;
                    }
                    else
                    {
                        current.process_lbl.BackColor = Color.Green;
                    }

                    current.process_lbl.ForeColor = Color.Black;
                    current.process_lbl.Location  = pt;
                    current.process_lbl.Height    = scale_width;
                    current.process_lbl.Width     = 155;
                    current.process_lbl.TextAlign = ContentAlignment.TopCenter;
                    current.start_lbl             = start;
                    current.end_lbl = end;
                    panel1.Controls.Add(current.process_lbl);
                    panel1.Controls.Add(start);
                    panel1.Controls.Add(end);
                    start.BringToFront();
                    end.BringToFront();
                    start.Invalidate();
                    end.Invalidate();
                    current.process_lbl.Name = current.name;
                    current.process_lbl.BringToFront();
                    current.process_lbl.Invalidate();

                    //current.process_lbl.Click += new System.EventHandler(this.label_Click);
                    // current.process_lbl.Leave += new System.EventHandler(this.label_leave);
                    current.rearranged = false;
                    continue;
                }


                if (current.method == "First Fit")
                {
                    holes.Sort();
                }
                else if (current.method == "Best Fit")
                {
                    holes = new List <hole>(holes.OrderBy(x => x.size).ToList());
                }
                else //worst fit method
                {
                    holes = new List <hole>(holes.OrderByDescending(x => x.size).ToList());
                }

                for (int j = 0; j < holes.Count; j++)
                {
                    hole current_hole = holes[j];
                    if (current_hole.size == 0)
                    {
                        continue;
                    }
                    if (current_hole.size >= current.size)
                    {
                        if (current.waiting != null)
                        {
                            panel2.Controls.Remove(current.waiting);
                            //current.waiting = null;
                            waiting_procs--;
                            inrement_y -= 15;
                        }
                        IsAlocated          = true;
                        current.start       = current_hole.end - current.size;
                        current.end         = current_hole.end;
                        current.IsAllocated = IsAlocated;
                        Point pt    = new Point(45, Scale(current.start));
                        Point lbl_p = new Point(20, Scale(current.start));
                        start = creat_lable(current.start, lbl_p.X, lbl_p.Y);
                        end   = creat_lable(current.end, lbl_p.X, lbl_p.Y + (Scale(current.size) - 8));

                        start.BackColor = Color.DimGray;
                        end.BackColor   = Color.DimGray;
                        start.ForeColor = Color.GreenYellow;
                        end.ForeColor   = Color.GreenYellow;
                        start.Name      = current.name;
                        end.Name        = current.name;
                        start.Font      = new Font("Tahoma", 5, FontStyle.Regular);
                        end.Font        = new Font("Tahoma", 5, FontStyle.Regular);


                        if (current.size <= 10)
                        {
                            current.process_lbl.BackColor = Color.Blue;
                        }
                        else
                        {
                            current.process_lbl.BackColor = Color.Green;
                        }

                        current.process_lbl.ForeColor = Color.Black;
                        current.process_lbl.Location  = pt;
                        current.process_lbl.Height    = scale_width;
                        current.process_lbl.Width     = 155;
                        current.process_lbl.TextAlign = ContentAlignment.TopCenter;
                        current.start_lbl             = start;
                        current.end_lbl = end;

                        current_hole.size -= current.size;      //Scale(scale_width);


                        current_hole.end -= current.size;

                        panel1.Controls.Add(current.process_lbl);
                        panel1.Controls.Add(start);
                        panel1.Controls.Add(end);
                        start.BringToFront();
                        end.BringToFront();
                        start.Invalidate();
                        end.Invalidate();
                        current.allocated_hole_name = current_hole.hole_lbl.Text;
                        current.process_lbl.BringToFront();
                        current.process_lbl.Invalidate();
                        current.process_lbl.Name   = current.name;
                        current.process_lbl.Click += new System.EventHandler(this.label_Click);
                        current.process_lbl.Leave += new System.EventHandler(this.label_leave);



                        break;
                    }
                }



                if (!current.IsAllocated)
                {
                    Label waiting_lbl = new Label();
                    waiting_lbl      = creat_lable(current.name + " with size = " + current.size + "->" + current.method, 6, 27 + inrement_y);
                    waiting_lbl.Name = current.name;
                    if (current.waiting == null)
                    {
                        current.waiting = waiting_lbl;
                    }
                    if (!panel2.Controls.Contains(current.waiting))
                    {
                        panel2.Controls.Add(current.waiting);
                        waiting_procs++;
                        inrement_y += 15;
                    }
                }
            }
        }