Example #1
0
        // Loads the Bus Interrupt Data from a data file
        public void LoadBusInterruptList()
        {
            if (!File.Exists(_busInterruptListDataFile))
            {
                // throw "file does not exist error"
                return;
            }

            StreamReader fin = new StreamReader(_busInterruptListDataFile);

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

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

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

                        int tempTime = System.Convert.ToInt32(token[0]);
                        string tempBusName = token[1];
                        string tempNextStop = token[2];
                        string tempInterruptStop = token[3];

                        // create bus stop
                        BusInterrupt tempBusInterrupt = new BusInterrupt(tempTime, tempBusName, tempNextStop, tempInterruptStop);
                        _busInterruptList.Add(tempBusInterrupt);

                        // read next interrupt
                        tempBuffer = fin.ReadLine();
                    }
                }
            }
            fin.Close();
        }
Example #2
0
        /****************************************************************************************************/
        // METHODS - BUS INTERRUPTS
        /****************************************************************************************************/

        // sets a bus interrupt
        public void SetBusInterrupt(string busname, string nextstop)
        {
            Bus bus = _busList.FindBusWithBusName(busname);
            // send notification to user on the bus
            for (int i = 0; i < bus.GetPassengerList().Count; i++)
            {
                UserInQueue user = bus.GetPassengerList().ElementAt(i);
                User realuser = _userList.FindUserWithMobileNumber(user.GetMobileNum());
                realuser.AddSMS("At time " + _time + " this bus has been interrupted, and will be terminated at the next stop. Please alight at the next bus stop");
                string smsnews = "At time " + _time + " notification sent to user " + realuser.GetName() + " about bus " + bus.GetName() + " interruption";
                SMS sms = new SMS(_time, smsnews);
                _systemsmslog.Add(sms);
            }

            string interruptstop = bus.RetrievePreviousStop(nextstop);
            BusInterrupt ibus = new BusInterrupt(_time, busname, nextstop, interruptstop);

            _busInterruptList.Add(ibus);

            if (_busList.FindBusWithBusName(busname).GetPassengerList().Count > 0)
            {
                string currentstop = _busList.FindBusWithBusName(busname).RetrievePreviousStop(nextstop);

                for (int i = 0; i < _busList.FindBusWithBusName(busname).GetPassengerList().Count; i++)
                {
                    UserInQueue user = _busList.FindBusWithBusName(busname).GetPassengerList().ElementAt(i);
                    User user1 = _userList.FindUserWithMobileNumber(user.GetMobileNum());

                    DequeueUserFromBus(user1.GetName(), busname, currentstop);
                    EnqueueUserToBusStop(user1.GetMobileNum(), currentstop, busname);
                }
            }

            // notify user
            string message = "At " + _time + " bus " + busname + " has been interrupted.";
            NotifyBusSubscriber(busname, message);
            SMS systemmessage = new SMS(_time, message);
            _interruptlog.Add(systemmessage);
        }