示例#1
0
        public void ManageReport(BusReportMsg busReportMsg)
        {
            UserInfoSet userInfoSet = new UserInfoSet();

            //only registered user will be handled
            foreach (ulong userPhoneAddr in busReportMsg.cellPhoneAddrSet)
            {
                //he or she is a registered user
                if (AccountManager.ContainsUser(userPhoneAddr))
                {
                    lock (AccountManager.UserBase[userPhoneAddr])
                    {
                        TripRecord aTripRecord = new TripRecord();
                        aTripRecord.busLine  = busReportMsg.busLine;
                        aTripRecord.isBoard  = busReportMsg.isBoard;
                        aTripRecord.stopName = busReportMsg.stopName;
                        aTripRecord.time     = busReportMsg.time;
                        TripManager.AddTripRecord(userPhoneAddr, aTripRecord);
                        UserInfo aUserInfo;
                        AccountManager.QueryUser(userPhoneAddr, out aUserInfo);
                        userInfoSet.Add(aUserInfo);
                    }
                    Console.WriteLine("Server has received MSG. BUSLINE={0}, userId={1}\n", busReportMsg.busLine, userPhoneAddr);
                }
            }

            //Charge users
            AccountManager.ChargeUsers(busReportMsg, userInfoSet);
        }
示例#2
0
 public static void AddTripRecord(ulong userPhoneAddr, TripRecord tripRecord)
 {
     lock (tripBase)
     {
         if (!tripBase.ContainsKey(userPhoneAddr))
         {
             tripBase.Add(userPhoneAddr, new TripInfo()
             {
                 userCellPhoneAddr = userPhoneAddr, tripRecords = new List <TripRecord>()
             });
         }
         tripBase[userPhoneAddr].tripRecords.Add(tripRecord);
         SaveTripBase();
     }
 }
示例#3
0
        public static void LoadTripBase()
        {
            StreamReader sr        = null;
            string       aTripLine = "";

            try
            {
                sr       = new StreamReader(@"Trips.txt");
                tripBase = new Dictionary <ulong, TripInfo>();
                while ((aTripLine = sr.ReadLine()) != null)
                {
                    List <TripRecord> tripRecords = new List <TripRecord>();
                    //Console.WriteLine(aUser);
                    string     userCellPhoneAddr = aTripLine.Substring(0, aTripLine.IndexOf(","));
                    string[]   records           = aTripLine.Substring(aTripLine.IndexOf("(") + 1, aTripLine.IndexOf(")") - aTripLine.IndexOf("(") - 1).Split(';');
                    TripRecord aTripRecord       = new TripRecord();
                    foreach (string aRecord in records)
                    {
                        string[] recordItems = aRecord.Split(',');
                        aTripRecord.time     = DateTime.Parse(recordItems.ElementAt(0));
                        aTripRecord.busLine  = recordItems.ElementAt(1);
                        aTripRecord.isBoard  = bool.Parse(recordItems.ElementAt(2));
                        aTripRecord.stopName = recordItems.ElementAt(3);
                        tripRecords.Add(aTripRecord);
                    }
                    TripInfo tripInfo = new TripInfo();
                    tripInfo.userCellPhoneAddr = ulong.Parse(userCellPhoneAddr);
                    tripInfo.tripRecords       = tripRecords;
                    tripBase.Add(tripInfo.userCellPhoneAddr, tripInfo);
                }
            }
            catch
            {
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }
        }