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

        // adds a new bus stop with name
        public void Add(BusStop newBusStop)
        {
            //string temp = newBusStop.GetName();
            //BusStop newBusStop2 = new BusStop(temp);
            _busStopList.Add(newBusStop);
        }
コード例 #3
0
ファイル: EzySystem.cs プロジェクト: waynenguyen/EzyGoEzy
 // creates a bus stop object and adds it to the database
 public void CreateBusStop(string name, double coordinateX, double coordinateY)
 {
     BusStop newBusStop = new BusStop(name);
     newBusStop.SetCoordinates(coordinateX, coordinateY);
     _busStopList.Add(newBusStop);
 }