Пример #1
0
        public bool SortMovingTrams(TramLocation location)
        {
            SortingAlgoritm sorter      = new SortingAlgoritm(AllTracks, repo);
            List <Tram>     movingTrams = repo.GetAllTramsWithLocation(location);

            if (movingTrams.Count != 0)
            {
                for (int i = 0; i < movingTrams.Count; i++)
                {
                    BeheerTram beheerTram = BeheerTram.ToBeheerTram(movingTrams[i]);
                    if (location == TramLocation.ComingIn)
                    {
                        if (movingTrams[i].DepartureTime == null)
                        {
                            GetExitTime(beheerTram);
                        }
                        SortTram(sorter, beheerTram);
                    }
                    else if (location == TramLocation.GoingOut)
                    {
                        beheerTram.EditTramLocation(TramLocation.Out);
                        movingTrams[i] = beheerTram;
                        repo.EditTram(movingTrams[i]);
                        repo.WipeSectorByTramId(movingTrams[i].Number);
                    }
                }
                FetchUpdates();
                return(true);
            }
            return(false);
        }
Пример #2
0
        private bool SortMovingTrams(TramLocation location)
        {
            var movingTrams = _repo.GetAllTramsWithLocation(location);

            if (movingTrams.Count != 0)
            {
                UpdateTracks();
                var sorter = new TramSortingAlgoritm(_allTracks, _repo);
                for (var i = 0; i < movingTrams.Count; i++)
                {
                    var beheerTram = BeheerTram.ToBeheerTram(movingTrams[i]);
                    if (location == TramLocation.ComingIn)
                    {
                        if (beheerTram.DepartureTime == null)
                        {
                            beheerTram.EditTramDepartureTime(GetExitTime(beheerTram));
                        }
                        sorter.AssignTramLocation(beheerTram);
                    }
                    else if (location == TramLocation.GoingOut)
                    {
                        beheerTram.EditTramLocation(TramLocation.Out);
                        movingTrams[i] = beheerTram;
                        _repo.EditTram(movingTrams[i]);
                        _repo.WipeSectorByTramId(movingTrams[i].Number);
                        Console.WriteLine($"Tram {beheerTram.Number} left the remise.");
                    }
                }
                return(true);
            }
            return(false);
        }
Пример #3
0
 public BeheerSector Assign(BeheerSector sector, BeheerTram tram)
 {
     sector.SetOccupyingTram(tram);
     repo.EditTram(tram);
     repo.EditSector(sector);
     return(sector);
 }
Пример #4
0
        public void ToggleDisabled(string trams)
        {
            var iTrams = Parse(trams);

            foreach (var tram in AllTrams)
            {
                var pos = Array.IndexOf(iTrams, tram.Key);
                if (pos != -1)
                {
                    if (tram.Value.Status == TramStatus.Defect)
                    {
                        tram.Value.EditTramStatus(TramStatus.Idle);
                        _repo.EditTram(tram.Value);
                    }
                    else
                    {
                        tram.Value.EditTramStatus(TramStatus.Defect);
                        _repo.EditTram(tram.Value);
                    }
                }
            }
            Update();
        }
Пример #5
0
        public void EditTram()
        {
            var tram = _logisticRepository.GetTram(1);

            Assert.IsNotNull(tram);

            var newTram = BeheerTram.ToBeheerTram(tram);

            newTram.EditTramStatus(TramStatus.Cleaning);
            newTram.EditTramDepartureTime(new DateTime(2017, 6, 15, 08, 0, 0, DateTimeKind.Unspecified));
            newTram.EditTramLocation(TramLocation.Out);

            _logisticRepository.EditTram(newTram);

            var fetchTram = _logisticRepository.GetTram(1);

            Assert.IsNotNull(fetchTram);

            Assert.AreEqual(JsonConvert.SerializeObject(newTram), JsonConvert.SerializeObject(fetchTram));
        }
Пример #6
0
        public void AssignTramLocation(BeheerTram tram)
        {
            tram.EditTramLocation(TramLocation.In);

            //With a service needed, put on the first free slot
            if (tram.Status == TramStatus.Cleaning || tram.Status == TramStatus.Maintenance ||
                tram.Status == TramStatus.CleaningMaintenance)
            {
                foreach (Track track in _allTracks.Where(track => track.Type == TrackType.Service))
                {
                    for (var i = 0; i < track.Sectors.Count; i++)
                    {
                        if (track.Sectors[i].OccupyingTram == null && track.Sectors[i].Status == SectorStatus.Open)
                        {
                            var beheerSector = BeheerSector.ToBeheerSector(track.Sectors[i]);
                            track.Sectors[i] = Assign(beheerSector, tram);
                            Console.WriteLine("Moved tram {0} to track: {1}, sector: {2} ({3})", tram.Number,
                                              beheerSector.TrackNumber, beheerSector.Number + 1, tram.Status);
                            return;
                        }
                    }
                }
            }

            //Put tram on track thats connected to the line the tram is on
            foreach (var track in _allTracks.Where(track => track.Line == tram.Line && track.Type == TrackType.Normal))
            {
                for (var i = 0; i < track.Sectors.Count - 1; i++)
                {
                    if (track.Sectors[i].OccupyingTram == null && track.Sectors[i].Status == SectorStatus.Open)
                    {
                        var beheerSector = BeheerSector.ToBeheerSector(track.Sectors[i]);
                        track.Sectors[i] = Assign(beheerSector, tram);
                        Console.WriteLine("Moved tram {0} to track: {1}, sector: {2}", tram.Number,
                                          beheerSector.TrackNumber, beheerSector.Number + 1);
                        return;
                    }

                    if (track.Sectors[i].Status == SectorStatus.Occupied &&
                        track.Sectors[i].OccupyingTram.DepartureTime < tram.DepartureTime)
                    {
                        if (track.Sectors[i + 1].Status == SectorStatus.Open)
                        {
                            var beheerSector = BeheerSector.ToBeheerSector(track.Sectors[i + 1]);
                            track.Sectors[i + 1] = Assign(beheerSector, tram);
                            Console.WriteLine("Moved tram {0} to track: {1}, sector: {2}", tram.Number,
                                              beheerSector.TrackNumber, beheerSector.Number + 1);
                            return;
                        }
                    }
                }
            }

            //If not successful put tram on any other normal track (that doesn't have another line connected to it)
            foreach (var track in _allTracks.Where(track => track.Type == TrackType.Normal))
            {
                for (var i = 0; i < track.Sectors.Count - 1; i++)
                {
                    if (track.Sectors[0].OccupyingTram == null && track.Sectors[0].Status == SectorStatus.Open)
                    {
                        var beheerSector = BeheerSector.ToBeheerSector(track.Sectors[i]);
                        track.Sectors[i] = Assign(beheerSector, tram);
                        Console.WriteLine("Moved tram {0} to track: {1}, sector: {2}", tram.Number,
                                          beheerSector.TrackNumber, beheerSector.Number + 1);
                        return;
                    }
                    else if (track.Sectors[i].Status == SectorStatus.Occupied &&
                             track.Sectors[i].OccupyingTram.DepartureTime < tram.DepartureTime)
                    {
                        if (track.Sectors[i + 1].Status == SectorStatus.Open)
                        {
                            var beheerSector = BeheerSector.ToBeheerSector(track.Sectors[i + 1]);
                            track.Sectors[i + 1] = Assign(beheerSector, tram);
                            Console.WriteLine("Moved tram {0} to track: {1}, sector: {2}", tram.Number,
                                              beheerSector.TrackNumber, beheerSector.Number + 1);
                            return;
                        }
                    }
                }
            }

            //If not successful put on an exit line
            foreach (var track in _allTracks.Where(track => track.Type == TrackType.Exit))
            {
                for (var i = 0; i < track.Sectors.Count - 1; i++)
                {
                    if (track.Sectors[0].OccupyingTram == null && track.Sectors[0].Status == SectorStatus.Open)
                    {
                        var beheerSector = BeheerSector.ToBeheerSector(track.Sectors[i]);
                        track.Sectors[i] = Assign(beheerSector, tram);
                        Console.WriteLine("Moved tram {0} to track: {1}, sector: {2}", tram.Number,
                                          beheerSector.TrackNumber, beheerSector.Number + 1);
                        return;
                    }
                    else if (track.Sectors[i].Status == SectorStatus.Occupied &&
                             track.Sectors[i].OccupyingTram.DepartureTime < tram.DepartureTime)
                    {
                        if (track.Sectors[i + 1].Status == SectorStatus.Open)
                        {
                            var beheerSector = BeheerSector.ToBeheerSector(track.Sectors[i + 1]);
                            track.Sectors[i + 1] = Assign(beheerSector, tram);
                            Console.WriteLine("Moved tram {0} to track: {1}, sector: {2}", tram.Number,
                                              beheerSector.TrackNumber, beheerSector.Number + 1);
                            return;
                        }
                    }
                    else if (track.Sectors[i].Status == SectorStatus.Occupied &&
                             track.Sectors[0].OccupyingTram.DepartureTime == null)
                    {
                        if (track.Sectors[i + 1].Status == SectorStatus.Open)
                        {
                            var beheerSector = BeheerSector.ToBeheerSector(track.Sectors[i + 1]);
                            track.Sectors[i + 1] = Assign(beheerSector, tram);
                            Console.WriteLine("Moved tram {0} to track: {1}, sector: {2}", tram.Number,
                                              beheerSector.TrackNumber, beheerSector.Number + 1);
                            return;
                        }
                    }
                }
            }

            //If not successful let user place tram
            tram.EditTramLocation(TramLocation.NotAssigned);
            _repo.EditTram(tram);
            Console.WriteLine($"Could not move tram {tram.Number}, please move manually.");
        }