Exemplo n.º 1
0
        public bool NotifyDeparture(String internationalID)
        {
            Plane            planeToSearch = new Plane(internationalID);
            TreeNode <Plane> planeFound    = WaitingPlanes.Find(planeToSearch);

            if (planeFound != null && planeFound.Data.Track != null)
            {
                planeFound.Data.SetDepartureTime(SystemTime);
                PlaneDepartures.Add("plane ID" + planeFound.Data.GetInternationalID() + " arrived from the track "
                                    + planeFound.Data.Track.GetName() + " " + planeFound.Data.GetDepartureTime().ToString());
                TrackType type = planeFound.Data.Track.GetLengthType();
                planeFound.Data.Track.DepartureHistory.Add(new PlaneShortInfo(planeFound.Data.GetInternationalID(),
                                                                              planeFound.Data.GetDepartureTime()));
                planeFound.Data.Track.SetPlane(null);
                planeFound.Data.Track = null;
                WaitingPlanes.Delete(planeFound.Data);


                foreach (Track track in type.Tracks)
                {
                    if (track.GetPlane() == null && type.WaitingPlanes.Root != null)
                    {
                        Plane plane = type.WaitingPlanes.DeleteMin();
                        plane.Track = track;
                        track.SetPlane(plane);
                        TrackAllocations.Add("plane ID" + plane.GetInternationalID() + " to the track " + track.GetName());
                        type.WaitingPlanesForSearch.Delete(plane);
                    }

                    if (waitingCount / TrackList.Count > 5)
                    {
                        int upperTypeIndex = TrackTypesLengthList.IndexOf(type.Length) + 1;
                        if (upperTypeIndex < TrackTypesLengthList.Count)
                        {
                            TrackType upperType = TrackTypes.Find(new TrackType(TrackTypesLengthList[upperTypeIndex])).Data;
                            foreach (Track tr in upperType.Tracks)
                            {
                                if (tr.GetPlane() == null)
                                {
                                    planeFound.Data.Track = tr;
                                    tr.SetPlane(planeFound.Data);
                                    TrackAllocations.Add("!!! plane ID" + planeFound.Data.GetInternationalID() + " to " + tr.GetName()
                                                         );
                                    break;
                                }
                            }
                        }
                    }
                }

                waitingCount--;
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        public void ReadFromFile()
        {
            SystemTime = DateTime.Parse(File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking\\PlaneDepartureTrackingMSTest\\SystemTime.txt"));


            String[] planes = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking" +
                                               "\\PlaneDepartureTrackingMSTest\\Planes.txt").Split('\n');
            int test = 0;

            for (int i = 0; i < planes.Length; i++)
            {
                String [] row = planes[i].Split(',');
                if (row.Length >= 6)
                {
                    test++;
                    Plane plane = new Plane(row[0], row[1], row[2],
                                            Double.Parse(row[3]),
                                            DateTime.Parse(row[4]),
                                            Double.Parse(row[6].Replace('.', ',')));
                    plane.SetTrackRequirementTime(DateTime.Parse(row[5]));
                    Planes.Add(plane);
                }
            }
            System.Windows.Forms.MessageBox.Show("" + test);


            String[] trackAllocations = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking\\PlaneDepartureTrackingMSTest\\TrackAllocations.txt").Split(',');
            for (int i = 0; i < trackAllocations.Length; i++)
            {
                String allocation = trackAllocations[i];
                TrackAllocations.Add(allocation);
            }

            ArrivedPlanes.SplayDisabled = true;
            String[] arrivedPlanes = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking" +
                                                      "\\PlaneDepartureTrackingMSTest\\ArrivedPlanes.txt").Split();
            foreach (String planeID in arrivedPlanes)
            {
                TreeNode <Plane> plane = Planes.Find(new Plane(planeID));
                if (plane != null)
                {
                    ArrivedPlanes.Add(plane.Data);
                }
            }
            ArrivedPlanes.SplayDisabled = false;

            String[] planeArrivals = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking\\PlaneDepartureTrackingMSTest\\PlaneArrivals.txt").Split(',');
            foreach (String arrival in planeArrivals)
            {
                PlaneArrivals.Add(arrival);
            }

            String[] planeDepartures = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking\\PlaneDepartureTrackingMSTest\\PlaneDepartures.txt").Split(',');
            foreach (String departure in planeDepartures)
            {
                PlaneDepartures.Add(departure);
            }

            String[] pairs = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking" +
                                              "\\PlaneDepartureTrackingMSTest\\TrackPlanes.txt").Split(',');
            foreach (String pair in pairs)
            {
                String[] splittedPair = pair.Split(':');
                if (splittedPair.Length == 2)
                {
                    String           trackName = splittedPair[0];
                    String           planeID   = splittedPair[1];
                    TreeNode <Plane> plane     = Planes.Find(new Plane(planeID));
                    TreeNode <Track> track     = Tracks.Find(new Track(trackName));
                    if (plane != null && track != null)
                    {
                        plane.Data.Track = track.Data;
                        track.Data.SetPlane(plane.Data);
                    }
                }
            }


            WaitingPlanes.SplayDisabled = true;
            String[] waitingPlanes = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking" +
                                                      "\\PlaneDepartureTrackingMSTest\\WaitingPlanes.txt").Split();
            foreach (String planeID in waitingPlanes)
            {
                TreeNode <Plane> plane = Planes.Find(new Plane(planeID));
                if (plane != null)
                {
                    WaitingPlanes.Add(plane.Data);
                }
            }
            WaitingPlanes.SplayDisabled = false;

            foreach (double length in TrackTypesLengthList)
            {
                TreeNode <TrackType> type = TrackTypes.Find(new TrackType(length));

                if (type != null)
                {
                    type.Data.WaitingPlanesForSearch.SplayDisabled = true;
                    String[] waitingPlanesForSearchTrack = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking" +
                                                                            "\\PlaneDepartureTrackingMSTest\\" +
                                                                            type.Data.Length
                                                                            + "WaitingPlanesForSearch.txt").Split();
                    foreach (String planeID in waitingPlanesForSearchTrack)
                    {
                        TreeNode <Plane> plane = Planes.Find(new Plane(planeID));
                        if (plane != null)
                        {
                            type.Data.WaitingPlanesForSearch.Add(plane.Data);
                        }
                    }
                    type.Data.WaitingPlanesForSearch.SplayDisabled = false;

                    String[] waitingPlanesTrack = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking" +
                                                                   "\\PlaneDepartureTrackingMSTest\\" +
                                                                   type.Data.Length
                                                                   + "WaitingPlanes.txt").Split();
                    foreach (String planeID in waitingPlanesTrack)
                    {
                        TreeNode <Plane> plane = Planes.Find(new Plane(planeID));
                        if (plane != null)
                        {
                            type.Data.WaitingPlanes.Add(plane.Data);
                        }
                    }
                    foreach (Track track in type.Data.Tracks)
                    {
                        String[] trackHistory = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking" +
                                                                 "\\PlaneDepartureTrackingMSTest\\" +
                                                                 track.GetName() +
                                                                 "History.txt").Split('\n');

                        foreach (String entry in trackHistory)
                        {
                            String[] splittedEntry = entry.Split(',');
                            if (splittedEntry.Length == 2)
                            {
                                track.DepartureHistory.Add(new PlaneShortInfo(splittedEntry[0],
                                                                              DateTime.Parse(splittedEntry[1])));
                            }
                        }
                    }
                }
            }

            waitingCount = Int32.Parse(File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking" +
                                                        "\\PlaneDepartureTrackingMSTest\\WaitingCount.txt"));
        }