示例#1
0
        public void Run_Test()
        {
            Engine  engine  = new Engine();
            CheckIn checkIn = new CheckIn()
            {
                DestinationGate = 1, Status = BaggageStatus.Free
            };
            DropOff dropOff = new DropOff()
            {
                DestinationGate = 1, Status = BaggageStatus.Free,
            };
            MPA      mpa  = new MPA();
            DateTime date = new DateTime(2019, 6, 9, 16, 40, 0);

            Conveyor conveyor = new Conveyor(1, 1000)
            {
                DestinationGate = 1, Status = BaggageStatus.Free
            };


            engine.AddFlight(date, "bbb", 3, 1);
            engine.AddDispatcher();
            engine.AddCheckIn(checkIn);
            engine.AddConveyorPart(conveyor);

            engine.AddDropOff(dropOff);

            engine.LinkTwoNodes(checkIn, conveyor);
            engine.LinkTwoNodes(conveyor, dropOff);

            engine.Run();

            Assert.AreEqual(1, Convert.ToInt32(dropOff.baggages.Count));
        }
        public void ProcessBaggageTest_IfStatementElse()
        {
            MPA      mpa      = new MPA();
            Conveyor conveyor = new Conveyor(5, 6)
            {
                DestinationGate = 2
            };

            //Conveyor conveyornext = new Conveyor(5, 6) { DestinationGate = 2};
            conveyor.Status = BaggageStatus.Busy;
            Baggage baggage = new Baggage()
            {
                DestinationGate = 2
            };
            var var = 0;

            mpa.AddNextNode(conveyor);
            //mpa.AddNextNode(conveyornext);
            mpa.PassBaggage(baggage);

            if (mpa.NextNode.OnNodeStatusChangedToFree != null)
            {
                var = mpa.NextNode.OnNodeStatusChangedToFree.GetInvocationList().Length;
            }
            Assert.AreEqual(var, 1);
            //Assert.AreEqual(mpa.baggagesToWait.Count, 1);
        }
示例#3
0
        public void LinkTwoNodes_Test()
        {
            Engine  engine  = new Engine();
            CheckIn checkIn = new CheckIn()
            {
                DestinationGate = 1, Status = BaggageStatus.Free
            };
            DropOff dropOff = new DropOff()
            {
                DestinationGate = 1, Status = BaggageStatus.Free
            };
            MPA      mpa  = new MPA();
            DateTime date = new DateTime(2019, 6, 9, 14, 56, 0);

            Conveyor conveyor = new Conveyor(5, 1000)
            {
                DestinationGate = 1, Status = BaggageStatus.Free
            };

            Conveyor conveyor2 = new Conveyor(5, 1000)
            {
                DestinationGate = 1, Status = BaggageStatus.Free
            };
            Settings set = new Settings();

            engine.LinkTwoNodes(checkIn, conveyor);
            engine.LinkTwoNodes(conveyor, dropOff);

            //Assert.AreEqual(3,set.nextNodes.Count );
        }
        public void PassBaggage_Test()
        {
            Baggage baggage = new Baggage();
            MPA     mpa     = new MPA();

            mpa.PassBaggage(baggage);
            Assert.AreEqual(baggage, mpa.baggage);
        }
示例#5
0
        public bool AddMPA(GridTile firstTile, MPA mpa)
        {
            int cRange = TileVerticalCount / 4;
            int rRange = tileHorizontalCount / 4;

            if (CheckIfTilesAreEmpty(firstTile, cRange, rRange))
            {
                for (int i = firstTile.Column; i < firstTile.Column + cRange; i++)
                {
                    for (int y = firstTile.Row; y < firstTile.Row + rRange; y++)
                    {
                        MPATile  mpaTile = new MPATile(i, y, tileWidth, tileHeight);
                        GridTile temp    = FindTileInRowColumnCoordinates(i, y);
                        gridTiles.Remove(temp);
                        gridTiles.Add(mpaTile);
                        mpaTile.nodeInGrid = mpa;
                    }
                }
                return(true);
            }
            return(false);
        }
        public void AddNextNode_Test()
        {
            DropOff  drop     = new DropOff();
            MPA      mpa      = new MPA();
            Conveyor conveyor = new Conveyor(5, 6)
            {
                DestinationGate = 1
            };
            Conveyor conveyor2 = new Conveyor(5, 6)
            {
                DestinationGate = 1
            };
            Conveyor conveyor3 = new Conveyor(5, 6)
            {
                DestinationGate = 1
            };

            mpa.AddNextNode(conveyor);
            mpa.AddNextNode(conveyor2);
            mpa.AddNextNode(conveyor3);
            Assert.AreEqual(3, mpa.nextNodes.Count);
        }
示例#7
0
        public void Stop_Test()
        {
            Engine  engine  = new Engine();
            CheckIn checkIn = new CheckIn()
            {
                DestinationGate = 1, Status = BaggageStatus.Free
            };
            DropOff dropOff = new DropOff()
            {
                DestinationGate = 1, Status = BaggageStatus.Free,
            };
            MPA      mpa  = new MPA();
            DateTime date = new DateTime(2019, 6, 9, 16, 40, 0);

            Conveyor conveyor = new Conveyor(1, 1000)
            {
                DestinationGate = 1, Status = BaggageStatus.Free
            };


            engine.AddFlight(date, "bbb", 3, 1);
            engine.AddDispatcher();
            engine.AddCheckIn(checkIn);
            engine.AddConveyorPart(conveyor);

            engine.AddDropOff(dropOff);

            engine.LinkTwoNodes(checkIn, conveyor);
            engine.LinkTwoNodes(conveyor, dropOff);

            engine.Run();
            engine.Stop();
            //works with other components as well
            Assert.AreEqual(BaggageStatus.Free, conveyor.Status);
            Assert.AreEqual(BaggageStatus.Free, checkIn.Status);
            Assert.AreEqual(BaggageStatus.Free, dropOff.Status);
        }
示例#8
0
        public void Resume_Test()
        {
            Engine  engine  = new Engine();
            CheckIn checkIn = new CheckIn()
            {
                DestinationGate = 1, Status = BaggageStatus.Free
            };
            DropOff dropOff = new DropOff()
            {
                DestinationGate = 1, Status = BaggageStatus.Free,
            };
            MPA      mpa  = new MPA();
            DateTime date = new DateTime(2019, 6, 9, 16, 40, 0);

            Conveyor conveyor = new Conveyor(1, 1000)
            {
                DestinationGate = 1, Status = BaggageStatus.Free
            };


            engine.AddFlight(date, "bbb", 3, 1);
            engine.AddDispatcher();
            engine.AddCheckIn(checkIn);
            engine.AddConveyorPart(conveyor);

            engine.AddDropOff(dropOff);

            engine.LinkTwoNodes(checkIn, conveyor);
            engine.LinkTwoNodes(conveyor, dropOff);

            engine.Run();

            engine.Pause();
            engine.Resume();
            Assert.IsTrue(conveyor.timer.Enabled);
            Assert.IsTrue(engine.dispatcher.timers[0].Enabled);
        }
        public void ProcessBaggageTest_IfStatement()
        {
            MPA      mpa      = new MPA();
            Conveyor conveyor = new Conveyor(5, 6)
            {
                DestinationGate = 2
            };
            Conveyor conveyornext = new Conveyor(5, 6)
            {
                DestinationGate = 1
            };
            Baggage baggage = new Baggage()
            {
                DestinationGate = 1
            };

            mpa.AddNextNode(conveyor);
            mpa.AddNextNode(conveyornext);
            mpa.PassBaggage(baggage);

            Assert.AreEqual(mpa.NextNode, mpa.nextNodes[1]);
            Assert.AreEqual(BaggageStatus.Free, mpa.Status);
            Assert.AreEqual(null, mpa.baggage);
        }
示例#10
0
        public string LoadFromFile()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            try
            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    using (Stream stream = File.Open(ofd.FileName, FileMode.Open))
                    {
                        if (!ofd.FileName.Contains(".bin"))
                        {
                            var message = "Only .bin files supported";
                            return(message);
                        }
                        BinaryFormatter bin = new BinaryFormatter();
                        object          serializedObject     = bin.Deserialize(stream);
                        List <Object>   objectsToDeserialize = serializedObject as List <Object>;

                        checkIns        = (List <CheckIn>)objectsToDeserialize[0];
                        securities      = (List <Security>)objectsToDeserialize[1];
                        settings        = (Settings)objectsToDeserialize[2];
                        mainProcessArea = (MPA)objectsToDeserialize[3];
                        tiles           = (List <GridTile>)objectsToDeserialize[4];
                        flights         = (List <Flight>)objectsToDeserialize[5];
                        CreateDropOffsFromFile();
                        CreateConveyorsFromFile();
                    }
                }
            }
            catch (IOException)
            {
                throw;
            }
            return("");
        }
示例#11
0
        private void AnimationBox_MouseUp(object sender, MouseEventArgs e)
        {
            //if a conveyor has been built, there are a number of things that need checking
            if (buildModeActive && isBuildingConveyor)
            {
                Conveyor conveyor = new Conveyor(conveyorBuilding.Count, 0);
                engine.AddConveyorPart(conveyor);
                System.Diagnostics.Debug.WriteLine("uppress");
                int i = 0;

                /**
                 * //foreach tile in the newly build conveyor we:
                 * // add a node - the same node for all of course
                 * // assing positions to each tile in the conveyor
                 * // check if there are any tiles connected to the beginning and end of the conveyor
                 * //and automatically connect to them
                 * // for the other elements, auto connection checks and adding the node is performed on the mouse down event
                 * // the hature of the conveyor requires this different implementation
                 **/
                foreach (ConveyorTile t in conveyorBuilding)
                {
                    t.nodeInGrid     = conveyor;
                    t.PositionInLine = i;
                    if (t.PositionInLine == 0)
                    {
                        GridTile tt = thisGrid.AutoConnectToPrev(t, thisGrid.GetNeighboursIn4Directions);
                        //if the previous tile was a mpa
                        if (tt != null && tt is MPATile)
                        {
                            MPA tempMPA = tt.nodeInGrid as MPA;
                            tempMPA.AddNextNode(t.nodeInGrid as Conveyor);
                        }
                        else if (tt != null)
                        {
                            engine.LinkTwoNodes(tt.nodeInGrid, t.nodeInGrid);
                        }
                    }
                    i++;
                }
                conveyorBuilding.Last().isLastTile = true;

                GridTile temp = thisGrid.AutoConnectToNext(selectedTile, thisGrid.GetNeighboursIn4Directions);
                if (temp != null)
                {
                    engine.LinkTwoNodes(selectedTile.nodeInGrid, temp.nodeInGrid);
                    //setting the destination gate of the conveyor if it connects to any drop offs
                    if (temp is DropOffTile)
                    {
                        Conveyor selectedConveyor = selectedTile.nodeInGrid as Conveyor;
                        DropOff  selectedDropOff  = temp.nodeInGrid as DropOff;
                        selectedConveyor.DestinationGate = selectedDropOff.DestinationGate;
                    }
                }
            }

            // resetting all values needed to return the user to the state before the mouse down
            isConnectingTiles = false;
            if (selectedTile != null)
            {
                selectedTile.selected = false;
                selectedTile          = null;
            }
            isBuildingConveyor = false;
            conveyorBuilding.Clear();
        }
示例#12
0
        /**
         * // I intended to comment these methods to explain them
         * // I also hoped I would be able to make the code better
         * // I did not plan my time well
         * // - Boris Georgiev
         **/
        private void AnimationBox_MouseDown(object sender, MouseEventArgs e)
        {
            var      mouseClick = e as MouseEventArgs;
            GridTile t          = thisGrid.FindTileInPixelCoordinates(mouseClick.X, mouseClick.Y);

            SelectTile(t);

            if (buildModeActive)
            {
                //here we build the different elements
                if (t is EmptyTile && t.Unselectable == false && deleteMode == false)
                {
                    //because a single conveyor can consist of many tiles, we do not add the nodes when we begin building it, unlike the other elements
                    if (buildModeType == "Conveyor")
                    {
                        SelectTile(thisGrid.AddConveyorLineAtCoordinates(t));
                        conveyorBuilding.Add((ConveyorTile)selectedTile);

                        isBuildingConveyor = true;
                    }
                    else if (buildModeType == "CheckIn")
                    {
                        CheckIn checkin = new CheckIn();
                        SelectTile(thisGrid.AddCheckInAtCoordinates(t, checkin));
                        engine.AddCheckIn(checkin);
                        RefreshCheckInCombobox();

                        GridTile temp = thisGrid.AutoConnectToNext(selectedTile, thisGrid.GetBottomNeighbour);
                        if (temp != null)
                        {
                            engine.LinkTwoNodes(selectedTile.nodeInGrid, temp.nodeInGrid);
                        }
                    }
                    else if (buildModeType == "Security Scanner")
                    {
                        Security security = new Security();
                        SelectTile(thisGrid.AddSecurityAtCoordinates(t, security));
                        engine.AddSecurity(security);

                        GridTile temp = thisGrid.AutoConnectToPrev(selectedTile, thisGrid.GetNeighboursIn4Directions);
                        if (temp != null)
                        {
                            engine.LinkTwoNodes(temp.nodeInGrid, selectedTile.nodeInGrid);
                        }

                        temp = thisGrid.AutoConnectToNext(selectedTile, thisGrid.GetNeighboursIn4Directions);
                        if (temp != null)
                        {
                            engine.LinkTwoNodes(selectedTile.nodeInGrid, temp.nodeInGrid);
                        }
                    }
                    else if (buildModeType == "DropOff")
                    {
                        DropOff dropoff = new DropOff();
                        SelectTile(thisGrid.AddDropOffAtCoordinates(t, dropoff));
                        engine.AddDropOff(dropoff);
                        RefreshDropOffCombobox();
                        if (btnAddFlight.Enabled != true)
                        {
                            btnAddFlight.Enabled = true;
                        }

                        GridTile temp = thisGrid.AutoConnectToPrev(selectedTile, thisGrid.GetTopNeighbour);
                        if (temp != null)
                        {
                            engine.LinkTwoNodes(temp.nodeInGrid, selectedTile.nodeInGrid);
                            //each conveyor can contain the destination gate of the drop off it is connected too
                            //here we assign the destination gate to the previous conveyor
                            if (temp is ConveyorTile)
                            {
                                Conveyor selectedConveyor = temp.nodeInGrid as Conveyor;
                                DropOff  selectedDropOff  = selectedTile.nodeInGrid as DropOff;
                                selectedConveyor.DestinationGate = selectedDropOff.DestinationGate;
                            }
                        }
                    }

                    else if (buildModeType == "MPA")
                    {
                        MPA mpa = new MPA();
                        // AddMPA() first checks if there is available space to build it from the selected starting point
                        if (thisGrid.AddMPA(t, mpa))
                        {
                            engine.AddMPA(mpa);

                            SelectTile(thisGrid.FindTileInRowColumnCoordinates(t.Column, t.Row));
                            List <GridTile> tempMPA = thisGrid.GetMPA(selectedTile);
                            foreach (GridTile m in tempMPA)
                            {
                                GridTile temp = thisGrid.AutoConnectToPrev(m, thisGrid.GetNeighboursIn4Directions);
                                if (temp != null)
                                {
                                    engine.LinkTwoNodes(temp.nodeInGrid, m.nodeInGrid);
                                }
                                temp = thisGrid.AutoConnectToNext(m, thisGrid.GetNeighboursIn4Directions);
                                if (temp != null && temp.nodeInGrid is Conveyor)
                                {
                                    mpa.AddNextNode(temp.nodeInGrid as Conveyor);
                                }
                            }
                            // we disable the ability to create another MPA
                            rbMPA.Visible     = false;
                            rbCheckIn.Checked = true;
                        }
                    }
                }

                /**
                 * // isConnectingTiles is used in the MouseMove Event
                 * // since delete mode is enabled only if build mode is enabled,
                 * // we must ensure delete mode is not enabled when attempting to connect elements
                 **/
                else if (!(t is EmptyTile) && deleteMode == false)
                {
                    isConnectingTiles = true;
                }
                //here we delete tiles
                else if (!(t is EmptyTile) && deleteMode == true)
                {
                    if (t is ConveyorTile)
                    {
                        ConveyorTile first = thisGrid.RemoveConveyorLine(t);
                        engine.Remove(t.nodeInGrid);
                        if (engine.mainProcessArea != null)
                        {
                            //here we check if the main process area is linked to the deleted conveyor and remove any connections
                            foreach (Conveyor c in engine.mainProcessArea.nextNodes.ToList())
                            {
                                if (c == first.nodeInGrid)
                                {
                                    engine.mainProcessArea.nextNodes.Remove(c);
                                }
                            }
                        }
                    }
                    else if (t is MPATile)
                    {
                        thisGrid.RemoveMPA(t);
                        engine.Remove(t.nodeInGrid);
                        rbMPA.Visible = true;
                    }
                    else
                    {
                        engine.Remove(t.nodeInGrid);
                        thisGrid.RemoveNode(t);
                    }
                    RefreshCheckInCombobox();
                    RefreshDropOffCombobox();
                }
            }
            //getting information about the clicked tile when not building (buildModeActive == false)
            else
            {
                if (!(t is EmptyTile))
                {
                    Node n = thisGrid.ReturnNodeOnPosition(t);
                    lblNodeType.Text  = n.GetType().Name;
                    lblBagStatus.Text = n.Status.ToString();
                    if (t.nodeInGrid.NextNode == null)
                    {
                        lblNextNode.Text = "null";
                    }
                    else
                    {
                        lblNextNode.Text = t.nodeInGrid.NextNode.ToString();
                    }
                }
            }
            lblColRow.Text = t.Column + " " + t.Row;

            //accessing special options for dropoffs
            if (selectedTile is DropOffTile)
            {
                selectedDropOffForSettings = selectedTile.nodeInGrid as DropOff;
                cbCapacity.Text            = Convert.ToString(selectedDropOffForSettings.baggages.Capacity);
                cbEmployees.Text           = Convert.ToString(selectedDropOffForSettings.EmployeeSpeed);
                gbDropOffSettings.Text     = $"DropOff {selectedDropOffForSettings.DestinationGate} Settings";
                gbDropOffSettings.Visible  = true;
            }
            else
            {
                gbDropOffSettings.Visible = false;
            }
            animationBox.Invalidate();
        }
示例#13
0
 public void AddMPA(MPA mpa) => this.mainProcessArea = mpa;