Ejemplo n.º 1
0
        public void check_fifo(RAM_var mem, ref string d, int P)
        {
            int ind;

            if (fifo.Count != 0)
            {
                int    i = 0;
                string nom;
                while (true)
                {
                    switch (P)
                    {
                    case 0:
                        ind = mem.firts_fit(fifo[i].Get_taille());
                        nom = "First Fit";
                        break;

                    case 1:
                        ind = mem.best_fit(fifo[i].Get_taille());
                        nom = "Best Fit";
                        break;

                    case 2:
                        ind = mem.worst_fit(fifo[i].Get_taille());
                        nom = "Worst Fit";
                        break;

                    case 3:
                        ind = mem.Next_fit(fifo[i].Get_taille());
                        nom = "Next Fit";
                        break;

                    default:
                        ind = mem.firts_fit(fifo[i].Get_taille());
                        nom = "First Fit";
                        break;
                    }
                    if (ind >= 0)
                    {
                        d += ">>>> le processus " + fifo[i].name + "  est ajouter a l'emplacement <" + ind + "> avec l'algorithme de :  <<" + nom + ">>\n\n";
                        corriger_prt(ind, mem.allocation_process(ind, fifo[i].Get_id(), fifo[i].Get_taille())); execute_process(fifo[i].Get_id(), ind);
                    }
                    else
                    {
                        break;
                    }
                    i++;
                    if (i >= fifo.Count)
                    {
                        break;
                    }
                }
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if ((temp.Text != null) && (taille.Text != null))
            {
                int ind, f = 0;
                try
                {
                    f = Convert.ToInt32(taille.Text);
                    if (f > mem.capacite)
                    {
                        throw new Exception();
                    }
                    if (f < 0)
                    {
                        throw new FormatException();
                    }
                }
                catch (FormatException)
                {
                    Error.Text = "Taille Devrait etre un entier positive";

                    ColorAnimation myColorAnimation = new ColorAnimation(Colors.Red, Color.FromRgb(241, 239, 239), TimeSpan.FromMilliseconds(4000));
                    Error.Foreground.BeginAnimation(SolidColorBrush.ColorProperty, myColorAnimation);
                    return;
                }
                catch (Exception)
                {
                    Error.Text = "Taille plus grand que la capacité max de la mémoire";

                    ColorAnimation myColorAnimation = new ColorAnimation(Colors.Red, Color.FromRgb(241, 239, 239), TimeSpan.FromMilliseconds(4000));
                    Error.Foreground.BeginAnimation(SolidColorBrush.ColorProperty, myColorAnimation);
                    return;
                }
                finally
                {
                    ColorAnimation myColorAnimation = new ColorAnimation(Color.FromRgb(0, 255, 184), TimeSpan.FromMilliseconds(4000));
                }

                if (f < mem.capacite)
                {
                    /*taillebar.Fill = new SolidColorBrush(Color.FromRgb(10, 201, 1));
                     *                  tempbar.Fill = new SolidColorBrush(Color.FromRgb(10, 201, 1));*/
                    try
                    {
                        if ((Convert.ToInt32(temp.Text)) < 0)
                        {
                            throw new FormatException();
                        }
                        pro.ajout_process(name.Text, Convert.ToInt32(taille.Text), Convert.ToInt32(temp.Text) + 1);
                    }
                    catch (ArgumentNullException)
                    {
                        Error.Text = "ArgumentNullException";

                        return;
                    }
                    catch (ArithmeticException)
                    {
                        Error.Text = "Invalide type of taille or temp";
                        return;
                    }
                    catch (FormatException)
                    {
                        Error.Text = "Temp devrait etre un entier positive";
                        ColorAnimation myColorAnimation = new ColorAnimation(Colors.Red, Colors.Gray, TimeSpan.FromMilliseconds(2000));
                        Error.Foreground.BeginAnimation(SolidColorBrush.ColorProperty, myColorAnimation);
                        return;
                    }



                    if (T != 0)
                    {
                        Derl.Add("");
                        switch (P)
                        {
                        default:
                            ind = mem.firts_fit(Convert.ToInt32(taille.Text));
                            break;

                        case 0:
                            ind = mem.firts_fit(Convert.ToInt32(taille.Text));
                            break;

                        case 1:
                            ind = mem.best_fit(Convert.ToInt32(taille.Text));
                            break;

                        case 2:
                            ind = mem.worst_fit(Convert.ToInt32(taille.Text));
                            break;

                        case 3:
                            ind = mem.Next_fit(Convert.ToInt32(taille.Text));
                            break;
                        }

                        if (ind >= 0)
                        {
                            Derl[T - 1] += ">>>> le processus <" + name.Text + ">  est ajouter a lemplacement   <" + ind + "> Avec l'algorihtme de:  <<" + Enum.GetValues(AlgoR).GetValue(P) + ">>\n\n";
                            pro.corriger_prt(ind, mem.allocation_process(ind, pro.fifo.Count + pro.en_cours.Count, Convert.ToInt32(taille.Text))); pro.execute_process(pro.fifo.Count + pro.en_cours.Count, ind);
                        }
                    }
                    name.Text = "P" + (pro.fifo.Count + pro.en_cours.Count + 1).ToString();
                }
                else
                {
                    /*taillebar.Fill = new SolidColorBrush(Color.FromRgb(201, 10, 1));
                     *                  tempbar.Fill = new SolidColorBrush(Color.FromRgb(201, 10, 1));*/
                }
            }


            System.Timers.Timer timer = new System.Timers.Timer(500);
            timer.Start();
            timer.Elapsed += delegate(object sender1, ElapsedEventArgs ev) { Change_color(sender1, ev); };
        }