Пример #1
0
        /****************************************************************************************************/
        // METHODS - MODIFIERS (Passenger)
        /****************************************************************************************************/

        // adds a passenger ID to the bus stop queue
        public void EnqueuePassenger(UserInQueue newUser)
        {
            _userQueue.Add(newUser);
            IncrementStatCounter();
        }
Пример #2
0
        // Loads the Bus Stop Data from a data file
        public void LoadBusStopList()
        {
            if (!File.Exists(_busStopListDataFile))
            {
                // throw "file does not exist error"
                return;
            }

            StreamReader fin = new StreamReader(_busStopListDataFile);

            while (!fin.EndOfStream)
            {
                string tempBuffer = fin.ReadLine();

                if (tempBuffer.Equals("$START BUSSTOPLIST$"))
                {
                    tempBuffer = fin.ReadLine();

                    while (!tempBuffer.Equals("$END BUSSTOPLIST$"))
                    {
                        // If end of bus stop list, break
                        //if (tempBuffer.Equals("$END BUSSTOPLIST$"))
                        //    break;

                        // Read data
                        tempBuffer = fin.ReadLine();

                        // Break if end of the bus stop list
                        if (tempBuffer.Equals("$END BUSSTOPLIST$"))
                        {
                            break;
                        }

                        if (tempBuffer.Equals("$$START BUSSTOP$$"))
                        {
                            tempBuffer = fin.ReadLine();
                            while (!tempBuffer.Equals("$$END BUSSTOP$$"))
                            {
                                // Read bus stop data
                                //tempBuffer = fin.ReadLine();

                                string[] busStopToken = tempBuffer.Split('%');

                                string tempBusStopName = busStopToken[0];
                                Boolean tempStatus = System.Convert.ToBoolean(busStopToken[1]);
                                int tempStatCounter = System.Convert.ToInt32(busStopToken[2]);
                                double tempCoordinateX = System.Convert.ToDouble(busStopToken[3]);
                                double tempCoordinateY = System.Convert.ToDouble(busStopToken[4]);

                                // create bus stop
                                BusStop tempBusStop = new BusStop(tempBusStopName);
                                tempBusStop.SetStatus(tempStatus);
                                tempBusStop.SetStatCounter(tempStatCounter);
                                tempBusStop.SetCoordinates(tempCoordinateX, tempCoordinateY);

                                // Read user queue
                                tempBuffer = fin.ReadLine();
                                if (tempBuffer.Equals("$$$START USERINQUEUE$$$"))
                                {
                                    tempBuffer = fin.ReadLine();
                                    while (!tempBuffer.Equals("$$$END USERINQUEUE$$$"))
                                    {
                                        string[] token = tempBuffer.Split('%');

                                        string tempMobileNum = token[0];
                                        string tempBusName = token[1];
                                        string tempNextStop = token[2];

                                        // add user
                                        UserInQueue tempUser = new UserInQueue(tempMobileNum, tempBusName);
                                        tempUser.UpdateNextStop(tempNextStop);

                                        tempBusStop.EnqueuePassenger(tempUser);

                                        // read next passenger
                                        tempBuffer = fin.ReadLine();
                                    }
                                }
                                else
                                {
                                    // throw "wrong format" exception
                                }

                                // Read Bus queue
                                tempBuffer = fin.ReadLine();
                                if (tempBuffer.Equals("$$$START BUSQUEUE$$$"))
                                {
                                    tempBuffer = fin.ReadLine();
                                    while (!tempBuffer.Equals("$$$END BUSQUEUE$$$"))
                                    {
                                        tempBusStop.EnqueueBus(tempBuffer);
                                        tempBuffer = fin.ReadLine();
                                    }
                                }
                                else
                                {
                                    // throw "wrong format" exception
                                }

                                // Read subscribe list
                                tempBuffer = fin.ReadLine();

                                if (tempBuffer.Equals("$$$START SUBSCRIBELIST$$$"))
                                {
                                    tempBuffer = fin.ReadLine();
                                    while (!tempBuffer.Equals("$$$END SUBSCRIBELIST$$$"))
                                    {
                                        tempBusStop.AddUserToSubscribeList(tempBuffer);
                                        tempBuffer = fin.ReadLine();
                                    }
                                }
                                else
                                {
                                    // throw "wrong format" exception
                                }

                                // add current bus stop to list
                                _busStopList.Add(tempBusStop);

                                // read next bus stop
                                tempBuffer = fin.ReadLine();
                            }
                        }
                        // read empty line
                        tempBuffer = fin.ReadLine();
                    }
                    // end of file
                }
                else
                {
                    // throw "file format is wrong" error
                }
            }
            fin.Close();
        }
Пример #3
0
        // Loads the Bus Data from a data file
        public void LoadBusList()
        {
            if (!File.Exists(_busListDataFile))
            {
                // throw "file does not exist error"
                return;
            }

            StreamReader fin = new StreamReader(_busListDataFile);

            while (!fin.EndOfStream)
            {
                string tempBuffer = fin.ReadLine();

                if (tempBuffer.Equals("$START BUSLIST$"))
                {
                    tempBuffer = fin.ReadLine();

                    while (!tempBuffer.Equals("$END BUSLIST$"))
                    {
                        // Read data
                        tempBuffer = fin.ReadLine();
                        
                        // If end of bus list, break
                        if (tempBuffer.Equals("$END BUSLIST$"))
                            break;

                        if (tempBuffer.Equals("$$START BUS$$"))
                        {
                            tempBuffer = fin.ReadLine();
                            while (!tempBuffer.Equals("$$END BUS$$"))
                            {
                                // Read bus data
                                //tempBuffer = fin.ReadLine();
                                string[] busToken = tempBuffer.Split('%');

                                string tempBusName = busToken[0];
                                string tempCurrentStop = busToken[1];
                                int tempFrequency = System.Convert.ToInt32(busToken[2]);
                                int tempStatCounter = System.Convert.ToInt32(busToken[3]);

                                // create bus
                                Bus tempBus = new Bus(tempBusName, tempFrequency);
                                tempBus.UpdateCurrentStop(tempCurrentStop);
                                tempBus.SetStatCounter(tempStatCounter);

                                // Read RouteList
                                tempBuffer = fin.ReadLine();
                                if (tempBuffer.Equals("$$$START ROUTELIST$$$"))
                                {
                                    tempBuffer = fin.ReadLine();

                                    while (!tempBuffer.Equals("$$$END ROUTELIST$$$"))
                                    {
                                        string[] token = tempBuffer.Split('%');

                                        string tempBusStop = token[0];
                                        int tempTravelTime = System.Convert.ToInt32(token[1]);

                                        // add route
                                        tempBus.AddRoute(tempBusStop, tempTravelTime);

                                        tempBuffer = fin.ReadLine();
                                    }
                                }
                                else
                                {
                                    // throw "wrong format" exception
                                }

                                // Read Passenger List
                                tempBuffer = fin.ReadLine();
                                if (tempBuffer.Equals("$$$START PASSENGERLIST$$$"))
                                {
                                    tempBuffer = fin.ReadLine();

                                    while (!tempBuffer.Equals("$$$END PASSENGERLIST$$$"))
                                    {
                                        string[] token = tempBuffer.Split('%');

                                        string tempMobileNum = token[0];
                                        string tempBusName2 = token[1];
                                        string tempNextStop = token[2];

                                        // enqueue user to bus
                                        UserInQueue tempUser = new UserInQueue(tempMobileNum, tempBusName2);
                                        tempUser.UpdateNextStop(tempNextStop);
                                        tempBus.EnqueueUser(tempUser);

                                        tempBuffer = fin.ReadLine();
                                    }
                                }
                                else
                                {
                                    // throw "wrong format" exception
                                }

                                // Read subscribe list
                                tempBuffer = fin.ReadLine();
                                if (tempBuffer.Equals("$$$START SUBSCRIBELIST$$$"))
                                {
                                    tempBuffer = fin.ReadLine();
                                    while (!tempBuffer.Equals("$$$END SUBSCRIBELIST$$$"))
                                    {
                                        tempBus.AddUserToSubscribeList(tempBuffer);

                                        tempBuffer = fin.ReadLine();
                                    }
                                }
                                else
                                {
                                    // throw "wrong format" exception
                                }

                                // add bus to current databases
                                _busList.Add(tempBus);
                                // read next bus in the list
                                tempBuffer = fin.ReadLine();
                            }
                        }
                        else
                        {
                            // throw "format error" exception
                        }

                        // read empty line
                        tempBuffer = fin.ReadLine();
                    }
                    // end of file
                }
                else
                {
                    // throw "file format is wrong" error
                }
                tempBuffer = fin.ReadLine();
            }
            fin.Close();
        }
Пример #4
0
        // enqueues a user to a bus stop
        public void EnqueueUserToBusStop(string mobileNum, string stop, string bus)
        {
            // check if bus stop is available
            // if available, enqueue user
            // otherwise, throw error exception "Bus Stop is currently not in operation."

            // get bus stop
            BusStop currentBusStop = _busStopList.FindBusStopWithBusStopName(stop);

            if (currentBusStop.GetStatus())
            {
                UserInQueue newUser = new UserInQueue(mobileNum, bus);
                newUser.UpdateNextStop(FindNextStop(bus, stop));
                currentBusStop.EnqueuePassenger(newUser);

                // update user object
                User tempUser = _userList.FindUserWithMobileNumber(mobileNum);
                tempUser.UpdateUserLocation(stop);
                tempUser.UpdateUserStatus(USER_STATUS.waiting);

                Bus thebus = _busList.FindBusWithBusName(bus);
                List<Route> busroute = thebus.GetRouteList();
                string tempsms1 = "At time " + _time + " you wait for bus " + thebus.GetName() + ". We want to notify you that these following bus stops" + " has/have been interrupted: ";
                List<string> busstopname = new List<string>();
                for (int k = 0; k < busroute.Count; k++)
                {

                    // check if busroute[k] is in the bus stop interrupt

                    if (_busStopList.FindBusStopWithBusStopName(busroute.ElementAt(k).GetBusStopName()).GetStatus() == false)
                    {
                        // send msg to user
                        busstopname.Add(busroute.ElementAt(k).GetBusStopName());
                    }
                }
                for (int k = 0; k < busstopname.Count; k++)
                {
                    tempsms1 = tempsms1 + " " + busstopname.ElementAt(k);
                }
                if (busstopname.Count > 0)
                {
                    _userList.FindUserWithMobileNumber(mobileNum).AddSMS(tempsms1);
                    SMS sms = new SMS(_time, tempsms1);
                    _systemsmslog.Add(sms);
                }
            }
            else
            {
                // throw "Bus Stop is currently not in operation."
            }
        }
Пример #5
0
        // locates a passenger
        public void LocatePassenger(string busName, UserInQueue user)
        {
            string currentstop = user.GetNextStop();
            string currentNextStop = _busList.FindBusWithBusName(busName).RetrieveNextStop(user.GetNextStop());

            // update passenger's location
            User tempUser = _userList.FindUserWithMobileNumber(user.GetMobileNum());
            //tempUser.UpdateUserLocation(currentstop);

            if (BusNameIsInBusInterruptList(busName, currentNextStop))
                return;

            //user.UpdateNextStop(currentNextStop);

            if (currentNextStop == null)
            {
                //List<string> temp = (_busStopList.FindBusStopWithBusStopName(_busList.FindBusWithBusName(busName).GetLastStop()).GetBusQueue());
                //if (temp.IndexOf(busName) != -1)
                if (currentstop == null)
                {
                    SMS newsms = new SMS(_time, "At time " + _time + " user " + tempUser.GetName() + " has been auto hopped off.");
                    _systemsmslog.Add(newsms);
                    _autohopofflist.Add(_userList.FindUserWithMobileNumber(user.GetMobileNum()).GetName());
                    _userList.FindUserWithMobileNumber(user.GetMobileNum()).AddSMS("At time " + _time + " you have been auto hopped off.");
                    DequeueUserFromBus(_userList.FindUserWithMobileNumber(user.GetMobileNum()).GetName(), busName, _busList.FindBusWithBusName(busName).GetLastStop());
                }
            }
        }
Пример #6
0
 // Enqueue user to the passenger list ie. passenger enters the bus
 public void EnqueueUser(UserInQueue newuser)
 {
     _passengerList.Add(newuser);
     IncerementStatCounter();
 }