Esempio n. 1
0
        // notify a bus stop subscriber
        public void NotifyBusStopSubscriber(string busstopname, string message)
        {
            List<string> subscriber = _busStopList.FindBusStopWithBusStopName(busstopname).GetUserSubscribeList();

            for (int i = 0; i < subscriber.Count; i++)
            {
                _userList.FindUserWithMobileNumber(subscriber.ElementAt(i)).AddSMS(message);
                string smssystem = "At " + _time + "notification has been sent to user " + _userList.FindUserWithMobileNumber(subscriber.ElementAt(i)).GetName() + " because of bus stop " + busstopname + " interruption";
                SMS systemsms = new SMS(_time, smssystem);
                _systemsmslog.Add(systemsms);
            } 
        }
Esempio n. 2
0
        /****************************************************************************************************/
        // METHODS - PERSISTENCE (Load Data File Management)
        /****************************************************************************************************/

        // Loads the System Data from a data file
        public void LoadSystemData()
        {
            if (!File.Exists(_systemDataFile))
            {
                // throw "file does not exist error"
                return;
            }

            StreamReader fin = new StreamReader(_systemDataFile);

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

                if (tempBuffer.Equals("$START SYSTEMDATA$"))
                {
                    // Read in single data sets split with '%'
                    // FORMAT: T_VAL%T_COST%_time%_hasEvent
                    string tempData = fin.ReadLine();
                    string[] sysToken = tempData.Split('%');

                    T_VAL = System.Convert.ToInt32(sysToken[0]);
                    T_COST = System.Convert.ToInt32(sysToken[1]);
                    _time = System.Convert.ToInt32(sysToken[2]);
                    _hasEvent = System.Convert.ToBoolean(sysToken[3]);

                    // Read in Data
                    tempData = fin.ReadLine();

                    while (!tempData.Equals("$END SYSTEMDATA$"))
                    {
                        // read system sms log
                        if (tempData.Equals("$$START SYSTEMSMSLOG$$"))
                        {
                            tempData = fin.ReadLine();
                            while (!tempData.Equals("$$END SYSTEMSMSLOG$$"))
                            {
                                // Read sms log
                                // FORMAT: time%smsContent
                                string[] token = tempData.Split('%');

                                SMS tempSMS = new SMS(System.Convert.ToInt32(token[0]), token[1]);
                                _systemsmslog.Add(tempSMS);

                                tempData = fin.ReadLine();
                            }
                        }
                        else
                        {
                            // throw "format error" exception
                        }

                        // read interrupt log
                        tempData = fin.ReadLine();

                        if (tempData.Equals("$$START INTERRUPTLOG$$"))
                        {
                            tempData = fin.ReadLine();
                            while (!tempData.Equals("$$END INTERRUPTLOG$$"))
                            {
                                // Read interrupt log
                                // FORMAT: time%smsContent
                                string[] token = tempData.Split('%');

                                SMS tempInterrupt = new SMS(System.Convert.ToInt32(token[0]), token[1]);
                                _interruptlog.Add(tempInterrupt);

                                tempData = fin.ReadLine();
                            }
                        }
                        else
                        {
                            // throw "format error" exception
                        }

                        // read auto hopoff list
                        tempData = fin.ReadLine();

                        if (tempData.Equals("$$START AUTOHOPOFFLIST$$"))
                        {
                            tempData = fin.ReadLine();
                            while (!tempData.Equals("$$END AUTOHOPOFFLIST$$"))
                            {
                                // Read autohopoff list
                                // FORMAT: passenger
                                _autohopofflist.Add(tempData);

                                tempData = fin.ReadLine();
                            }
                        }
                        else
                        {
                            // throw "format error" exception
                        }

                        // read can hopoff now list
                        tempData = fin.ReadLine();

                        if (tempData.Equals("$$START CANHOPOFFNOWLIST$$"))
                        {
                            tempData = fin.ReadLine();
                            while (!tempData.Equals("$$END CANHOPOFFNOWLIST$$"))
                            {
                                // Read can hopoff now list
                                // FORMAT: passenger
                                _canhopoffnowlist.Add(tempData);

                                tempData = fin.ReadLine();
                            }
                        }
                        else
                        {
                            // throw "format error" exception
                        }

                        tempData = fin.ReadLine();
                    }

                    // end of file
                }
                else
                {
                    // throw "file format is wrong" error
                }
            }
            fin.Close();
        }
Esempio n. 3
0
        /****************************************************************************************************/
        // METHODS - BUS STOP INTERRUPTS
        /****************************************************************************************************/

        // Sets a bus stop's status to unavailable
        public List<string> SetBusStopInterrupt(string busStopName)
        {
            // get bus stop with bus stop name
            BusStop currentBusStop = _busStopList.FindBusStopWithBusStopName(busStopName);
            // set status of bus stop to unavailable
            currentBusStop.SetStatus(false);

            // update the status and location of all passengers
            for (int i = 0; i < currentBusStop.GetPassengerCount(); i++)
            {
                User tempUser = _userList.FindUserWithMobileNumber(currentBusStop.GetPassengerList()[i].GetMobileNum());
                tempUser.UpdateUserLocation(null);
                tempUser.UpdateUserStatus(USER_STATUS.inactive);
            }

            string message = "At " + _time + " bus stop " + busStopName + " has been under construction";
            NotifyBusStopSubscriber(busStopName, message);
            SMS systemmessage = new SMS(_time, message);
            _interruptlog.Add(systemmessage);

            // get current passengers in the bus stop
            List<UserInQueue> currentPassengers = new List<UserInQueue>();
            currentPassengers = currentBusStop.GetPassengerList();
            List<string> passengerList;
            passengerList = new List<string>();

            for (int i = 0; i < currentPassengers.Count(); i++)
            {
                passengerList.Add(currentPassengers[i].GetMobileNum());
            }

            // dequeue passengers from the bus stop
            currentBusStop.ClearUserQueue();

            return passengerList;
        }
Esempio n. 4
0
 // sets a bus stop to available again
 public void RemoveBusStopInterrupt(string busStopName)
 {
     // get bus stop with bus stop name
     BusStop currentBusStop = _busStopList.FindBusStopWithBusStopName(busStopName);
     // set the bus stop status to available
     currentBusStop.SetStatus(true);
     string message = "At " + _time + " bus stop" + busStopName + " is working again";
     NotifyBusStopSubscriber(busStopName, message);
     SMS systemmessage = new SMS(_time, message);
     _interruptlog.Add(systemmessage);
 }
Esempio n. 5
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);
        }
Esempio n. 6
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."
            }
        }
Esempio n. 7
0
        // deducts money from the indicated mode of payment
        private void DeductFromModeOfPayment(string mobileNum)
        {
            User currentuser = _userList.FindUserWithMobileNumber(mobileNum);

            if (currentuser.GetPaymentMode1() == PAYMENT_MODE.account)
            {
                if (currentuser.GetAccount() >= T_COST)
                {
                    currentuser.ReloadAccount(currentuser.GetAccount() - T_COST);

                    string temp = "At time " + _time + " " + currentuser.GetName() + " account balance has been deducted by " + T_COST;
                    currentuser.AddSMS("At time " + _time + " your account balance has been deducted by " + T_COST);

                    SMS tempSMS = new SMS(_time, temp);
                    _systemsmslog.Add(tempSMS);
                   

                    if (currentuser.GetAccount() < T_COST)
                    {
                        currentuser.AddSMS("At time " + _time + " your account balance is below the minimum fare cost which is " + T_COST + ". Please top-up before boarding the next bus.");
                        temp = "At time " + _time + " " + currentuser.GetName() + " account balance is below the minimum fare cost which is " + T_COST + ". Please top-up before boarding the next bus.";
                        SMS tempSMS1 = new SMS(_time, temp);
                        _systemsmslog.Add(tempSMS1);
                    }
                }
                else
                {
                    if (currentuser.GetPaymentMode2() == PAYMENT_MODE.credit)
                    {
                        currentuser.AddSMS("At time " + _time + " Your credit card has been deducted by " + T_COST);
                        string temp = "At time " + _time + " " + currentuser.GetName() + " credit card has been deducted by " + T_COST;
                        SMS tempSMS = new SMS(_time, temp);
                        _systemsmslog.Add(tempSMS);
                    }
                    else
                    {
                        currentuser.AddSMS("At time " + _time + " Your mobile account has been deducted by " + T_COST);
                        string temp = "At time " + _time + " " + currentuser.GetName() + " mobile account has been deducted by " + T_COST;
                        SMS tempSMS = new SMS(_time, temp);
                        _systemsmslog.Add(tempSMS);
                    }
                }
            }
            else if (currentuser.GetPaymentMode1() == PAYMENT_MODE.credit)
            {
                currentuser.AddSMS("At time " + _time + " Your credit card has been deducted by " + T_COST);                
                string temp = "At time " + _time + " " + currentuser.GetName() + " credit card has been deducted by " + T_COST;
                SMS tempSMS = new SMS(_time, temp);
                _systemsmslog.Add(tempSMS);
            }
            else
            {
                currentuser.AddSMS("At time " + _time + " Your mobile account has been deducted by " + T_COST);
                string temp = "At time " + _time + " " + currentuser.GetName() + " mobile account has been deducted by " + T_COST;
                SMS tempSMS = new SMS(_time, temp);
                _systemsmslog.Add(tempSMS);
            }
        }
Esempio n. 8
0
        // takes care of hopping on
        public List<string> GetWhoHasHopOn()
        {
            List<string> whohashopon = new List<string>();

            for (int i = 0; i < _busStopList.GetCount(); i++)
            {
                // we are now at bus stop i
                // we check for current passenger queue at bus stop i
                // then check if the desirable bus is at bus stop i
                List<UserInQueue> passengerqueue = _busStopList.At(i).GetPassengerList();
                List<string> busqueue = _busStopList.At(i).GetBusQueue();
                int j = 0;

                while (_busStopList.At(i).GetPassengerList().Count >0)
                {
                    if (j == _busStopList.At(i).GetPassengerList().Count)
                    {
                        break;
                    }

                    UserInQueue tempuserinqueue = passengerqueue.ElementAt(j);
                    string temp = tempuserinqueue.GetBusName();

                    if (busqueue.IndexOf(temp) != -1)
                    {
                        string mobilenum = tempuserinqueue.GetMobileNum();
                        string name = _userList.FindUserWithMobileNumber(mobilenum).GetName();

                        whohashopon.Add(name);
                        _userList.FindUserWithMobileNumber(_busStopList.At(i).GetPassengerList().ElementAt(j).GetMobileNum()).UpdateJourneyPlan(_busStopList.At(i).GetName(), temp, _time);

                        // update user location and status
                        _userList.FindUserWithMobileNumber(mobilenum).UpdateUserStatus(USER_STATUS.active);
                        //_userList.FindUserWithMobileNumber(mobilenum).UpdateUserLocation(temp);

                        _busList.FindBusWithBusName(temp).EnqueueUser(tempuserinqueue);
                        _busStopList.At(i).DequeuePassengerWithMobileNum(mobilenum);
                        
                        // We check for the expiry ticket here
                        if (_userList.FindUserWithMobileNumber(mobilenum).GetTicketExpiry() < _time)
                        {
                            // invalid ticket
                            // now we update the ticket
                            IssueNewTicket(mobilenum);
                            // then deduct money from the user
                            DeductFromModeOfPayment(mobilenum);
                        }
                        else
                        {
                            _userList.FindUserWithMobileNumber(mobilenum).AddSMS("At time " + _time + " you have hopped on bus " + _busList.FindBusWithBusName(temp).GetName() + " and your TVAL is still valid");
                            string smscontent = "At time " + _time + " " + name +  " have hopped on bus " + _busList.FindBusWithBusName(temp).GetName() + " and his/her TVAL is still valid";
                            SMS smsforuser = new SMS(_time, smscontent);
                            _systemsmslog.Add(smsforuser);
                        }


                        // We send notification if there's a bus stop in the waiting bus's route that has been interrupted
                        Bus bus = _busList.FindBusWithBusName(temp);
                        List<Route> busroute = bus.GetRouteList();
                        string tempsms1 = "At time " + _time + " you wait for bus " + bus.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);

                        j--;
                    }
                    j++;
                }
            }
            return whohashopon;
        }
Esempio n. 9
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());
                }
            }
        }