예제 #1
0
        /**********************************************************************
         ***********************************************************************
         * draw on canvas */
        void PaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            //canvas object
            info = e.Info; //
            SKSurface surface = e.Surface;

            canvas = surface.Canvas;


            //Important! Otherwise the drawing will look messed up in iOS
            if (canvas != null)
            {
                canvas.Clear();
            }

            CalculateNeededVariables();
            MakeSKPaint();

            /*********************HERE GOES THE DRAWING************************/
            /*important: the coordinate system starts in the upper left corner*/
            WriteInitialMemoryFragmentationOnCanvas();
            float relativeFragmentSize = DrawMemory();

            AllocationStrategiesAlgorithm.Status status = AllocationStrategiesAlgorithm.GetStatus();
            if (status == AllocationStrategiesAlgorithm.Status.searching || status == AllocationStrategiesAlgorithm.Status.successfull)
            {
                DrawRedArrow(relativeFragmentSize);


                int promIndex = AllocationStrategiesAlgorithm.GetMostPromisingIndex();
                if (promIndex != -1)
                {
                    DrawGrayArrow(promIndex, relativeFragmentSize);
                }
            }


            //execute all drawing actions
            canvas.Flush();
        }
예제 #2
0
        /**********************************************************************
         *********************************************************************/
        async void B_Next_Clicked(object sender, EventArgs e)
        {
            AllocationStrategiesAlgorithm.Status status = AllocationStrategiesAlgorithm.GetStatus();

            // if new memory request was made
            if (b_Next.Text == "Confirm")
            {
                // if the memory request is valid
                if (ValidateMemoryRequestInput(e_MemoryRequest.Text))
                {
                    b_Next.Text = "Next";

                    // disable memory request entry and indicate that it's accepted
                    e_MemoryRequest.IsEnabled       = false;
                    e_MemoryRequest.BackgroundColor = Color.FromRgba(172, 255, 47, 30);

                    // enable restart button
                    b_Restart.IsEnabled = true;

                    // check first if memory is already full before you make a new request
                    if (AllocationStrategiesAlgorithm.MemoryIsFull())
                    {
                        await DisplayAlert("Alert", "Out of memory! Please restart.", "OK");

                        b_Next.Text = "Confirm";
                        e_MemoryRequest.IsEnabled       = true; // enable memory request entry
                        e_MemoryRequest.BackgroundColor = Color.White;
                        e_MemoryRequest.Text            = "";
                    }
                    else
                    {
                        AllocationStrategiesAlgorithm.Start(Int32.Parse(e_MemoryRequest.Text));
                    }
                }
                // otherwise wait until a valid memory request is made by the user
                else
                {
                    e_MemoryRequest.BackgroundColor = Color.FromRgba(238, 130, 238, 30);
                }
            }
            else
            {
                //Debug.WriteLine("next button text");

                // start or still searching
                if (status == AllocationStrategiesAlgorithm.Status.searching || status == AllocationStrategiesAlgorithm.Status.start)
                {
                    Debug.WriteLine("start or Still searching ");
                    AllocationStrategiesAlgorithm.Next();
                    status = AllocationStrategiesAlgorithm.GetStatus();
                    if (status == AllocationStrategiesAlgorithm.Status.successfull)
                    {
                        b_Next.Text = "Allocate";
                    }
                    else if (status == AllocationStrategiesAlgorithm.Status.unsuccessfull)
                    {
                        b_Next.Text = "Confirm";
                        e_MemoryRequest.IsEnabled       = true; // enable memory request entry
                        e_MemoryRequest.BackgroundColor = Color.White;
                        e_MemoryRequest.Text            = "";
                        await DisplayAlert("Alert", "Memory request was unsuccessfull.", "OK");
                    }
                }
                //sth found
                else if (status == AllocationStrategiesAlgorithm.Status.successfull)
                {
                    //Debug.WriteLine("Sth found");
                    AllocationStrategiesAlgorithm.UpdateAllFragmentsList();
                    b_Next.Text = "Confirm";
                    e_MemoryRequest.IsEnabled       = true; // enable memory request entry
                    e_MemoryRequest.BackgroundColor = Color.White;
                    e_MemoryRequest.Text            = "";
                }

                /*
                 * else if (status == AllocationStrategiesAlgorithm.Status.unsuccessfull)
                 * {
                 *  b_Next.Text = "Confirm";
                 *  e_MemoryRequest.IsEnabled = true; // enable memory request entry
                 *  e_MemoryRequest.BackgroundColor = Color.White;
                 *  e_MemoryRequest.Text = "";
                 *  await DisplayAlert("Alert", "Memory request was unsuccessfull.", "OK");
                 *
                 * }*/
            }
            AllocationStrategiesDraw.Paint();
        }