コード例 #1
0
ファイル: EzySystem.cs プロジェクト: waynenguyen/EzyGoEzy
        // 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();
        }
コード例 #2
0
ファイル: BusList.cs プロジェクト: waynenguyen/EzyGoEzy
        /****************************************************************************************************/
        // METHODS - MODIFIERS
        /****************************************************************************************************/

        // adds a new bus to the list
        public void Add(Bus newBus)
        {
            _busList.Add(newBus);
        }
コード例 #3
0
ファイル: EzySystem.cs プロジェクト: waynenguyen/EzyGoEzy
 // creates a bus object and adds it to the database
 public void CreateBus(string name, int frequency)
 {
     Bus newBus = new Bus(name, frequency);
     _busList.Add(newBus);
 }