public void ProcessUpdate(AthleteUpdate updateMessage)
        {
            lock (_lock)
            {
                if (updateMessage.UpdateType == AthleteRaceStatus.Registered)
                {
                    RegistrationUpdate temp = (RegistrationUpdate)updateMessage;
                    handler.AddAthlete(new Athlete(temp.BibNumber, temp.FirstName, temp.LastName, temp.Gender, temp.Age));
                }
                else
                {
                    handler.updateObservers(updateMessage);
                }
            }

            Console.WriteLine(updateMessage.ToString());
        }
 public void Update(AthleteUpdate update)
 {
     Console.WriteLine(prevUpdate);
     if (prevUpdate != "")
     {
         if (prevUpdate != $"{update.UpdateType}")
         {
             listView1.Items.Add(new ListViewItem(update.ToString()));
             prevUpdate = $"{update.UpdateType}";
         }
     }
     else
     {
         prevUpdate = $"{update.UpdateType}";
         listView1.Items.Add(new ListViewItem(update.ToString()));
     }
 }
        private void SimulateOneSecondOfData()
        {
            bool keepingGoing = true;

            while (keepingGoing && !_reader.EndOfStream)
            {
                var line = _reader.ReadLine();
                if (line == "---")
                {
                    keepingGoing = false;
                }
                else
                {
                    var message = AthleteUpdate.Create(line);
                    Handler.ProcessUpdate(message);
                }
            }
        }
示例#4
0
 //AthleteCollection athleteCollection = new AthleteCollection();
 public void ProcessUpdate(AthleteUpdate updateMessage)
 {
     // TODO: Do something to process the update message, depending on the concrete type of message
     if (updateMessage.UpdateType.ToString() == "Registered")
     {
         // AthleteCollection.UpdateAt
         lock (AthleteCollection.getAthleteCollection())
         {
             AthleteCollection.RegisterAthlete(updateMessage);
         }
     }
     if (updateMessage.UpdateType.ToString() == "OnCourse")
     {
         LocationUpdate temp = (LocationUpdate)updateMessage;
         AthleteCollection.UpdateAthlete(temp.BibNumber, temp.LocationOnCourse, temp.Timestamp, temp.UpdateType.ToString());
     }
     // TODO: Note that the console write line does below here
     Console.WriteLine(updateMessage.ToString());
 }
        private void AddAthlete(AthleteUpdate message)
        {
            RegistrationUpdate registrationMessage = new RegistrationUpdate();

            registrationMessage = (RegistrationUpdate)message;
            Athlete athlete = new Athlete();

            athlete.status       = registrationMessage.UpdateType.ToString();
            athlete.FirstName    = registrationMessage.FirstName;
            athlete.LastName     = registrationMessage.LastName;
            athlete.Gender       = registrationMessage.Gender;
            athlete.Age          = registrationMessage.Age;
            athlete.prevRaceTime = registrationMessage.Timestamp;
            athlete.Location     = 0;
            athlete.BibNumber    = message.BibNumber;
            athlete.updated      = true;

            athleteCollection.Add(message.BibNumber, athlete);
        }
示例#6
0
        private void CreateNewAthlete(AthleteUpdate updateMessage)
        {
            RegistrationUpdate regUpdate = (RegistrationUpdate)updateMessage;
            Athlete            ath       = new Athlete()
            {
                status            = updateMessage.UpdateType,
                timestamp         = updateMessage.Timestamp,
                bibNumber         = updateMessage.BibNumber,
                firstName         = regUpdate.FirstName,
                lastName          = regUpdate.LastName,
                gender            = regUpdate.Gender,
                age               = regUpdate.Age,
                locationOnCourse  = 0.0,
                officialStartTime = null,
                officialEndTime   = null
            };

            athletes.Add(ath);
            RefreshAthLists(new object(), new EventArgs());
        }
示例#7
0
        public void LocationUpdate_Create()
        {
            var locationUpdate = (LocationUpdate)AthleteUpdate.Create("OnCourse,47,8/15/2017 10:26:00 AM,680.067495971265");

            Assert.IsNotNull(locationUpdate);

            Assert.AreEqual(AthleteRaceStatus.OnCourse, locationUpdate.UpdateType);
            Assert.AreEqual(47, locationUpdate.BibNumber);
            Assert.AreEqual(new DateTime(2017, 8, 15, 10, 26, 0), locationUpdate.Timestamp);
            Assert.AreEqual(680.067495971265, locationUpdate.LocationOnCourse, 0.0001);

            try
            {
                var msg = AthleteUpdate.Create("OnCourse,47,8/15/2017 10:26:00 AM");
                Assert.Fail($"Exception expected when creating: msg={msg}");
            }
            catch { /* ignore */ }

            try
            {
                var msg = AthleteUpdate.Create("OnCourse,47");
                Assert.Fail($"Exception expected when creating: msg={msg}");
            }
            catch { /* ignore */ }

            try
            {
                var msg = AthleteUpdate.Create("OnCourse");
                Assert.Fail($"Exception expected when creating: msg={msg}");
            }
            catch { /* ignore */ }

            try
            {
                var msg = AthleteUpdate.Create("OnCourse,47,8/15/2017 10:26:00 AM,680.067495971265,bad");
                Assert.Fail($"Exception expected when creating: msg={msg}");
            }
            catch { /* ignore */ }
        }
        public void FinishedUpdate_Create()
        {
            var fUpdate = (FinishedUpdate)AthleteUpdate.Create("Finished,84,8/15/2017 2:34:00 PM,8/15/2017 2:33:45 PM");

            Assert.IsNotNull(fUpdate);

            Assert.AreEqual(AthleteRaceStatus.Finished, fUpdate.UpdateType);
            Assert.AreEqual(84, fUpdate.BibNumber);
            Assert.AreEqual(new DateTime(2017, 8, 15, 14, 34, 0), fUpdate.Timestamp);
            Assert.AreEqual(new DateTime(2017, 8, 15, 14, 33, 45), fUpdate.OfficialEndTime);

            try
            {
                var msg = AthleteUpdate.Create("Finished,84,8/15/2017 2:34:00 PM");
                Assert.Fail($"Exception expected when creating: msg={msg}");
            }
            catch { /* ignore */ }

            try
            {
                var msg = AthleteUpdate.Create("Finished,84");
                Assert.Fail($"Exception expected when creating: msg={msg}");
            }
            catch { /* ignore */ }

            try
            {
                var msg = AthleteUpdate.Create("Finished");
                Assert.Fail($"Exception expected when creating: msg={msg}");
            }
            catch { /* ignore */ }

            try
            {
                var msg = AthleteUpdate.Create("Finished,84,bad,8/15/2017 2:34:00 PM,8/15/2017 2:33:45 PM");
                Assert.Fail($"Exception expected when creating: msg={msg}");
            }
            catch { /* ignore */ }
        }
示例#9
0
        /// <summary>
        /// Update the values provided in updateMessage
        /// </summary>
        /// <param name="updateMessage">Contains updated values</param>
        public void updateStats(AthleteUpdate updateMessage)
        {
            status    = updateMessage.UpdateType;
            timestamp = updateMessage.Timestamp;
            switch (updateMessage.UpdateType)
            {
            case AthleteRaceStatus.Registered:
                // Do nothing
                break;

            case AthleteRaceStatus.DidNotStart:
                // Do nothing
                break;

            case AthleteRaceStatus.Started:
                StartedUpdate startUpdate = (StartedUpdate)updateMessage;
                officialStartTime = startUpdate.OfficialStartTime;
                break;

            case AthleteRaceStatus.OnCourse:
                LocationUpdate locUpdate = (LocationUpdate)updateMessage;
                locationOnCourse = locUpdate.LocationOnCourse;
                break;

            case AthleteRaceStatus.DidNotFinish:
                // Do nothing
                break;

            case AthleteRaceStatus.Finished:
                FinishedUpdate finishUpdate = (FinishedUpdate)updateMessage;
                officialEndTime = finishUpdate.OfficialEndTime;
                break;

            default:
                throw new ApplicationException("Invalid AthleteUpdate type");
            }
            notifyObservers();
        }
 public abstract void NotifyObservers(AthleteUpdate update);
示例#11
0
        public void RegistrationUpdate_Create()
        {
            RegistrationUpdate rUpdate = (RegistrationUpdate)AthleteUpdate.Create("Registered,14,8/15/2017 7:02:05 AM,Jane,Jones,F,16");

            Assert.IsNotNull(rUpdate);

            Assert.AreEqual(AthleteRaceStatus.Registered, rUpdate.UpdateType);
            Assert.AreEqual(14, rUpdate.BibNumber);
            Assert.AreEqual(new DateTime(2017, 8, 15, 7, 2, 5), rUpdate.Timestamp);
            Assert.AreEqual("Jane", rUpdate.FirstName);
            Assert.AreEqual("Jones", rUpdate.LastName);
            Assert.AreEqual("F", rUpdate.Gender);
            Assert.AreEqual(16, rUpdate.Age);

            try
            {
                var msg = AthleteUpdate.Create("Registered,14,8/15/2017 7:02:05 AM,Jane,Jones,F");
                Assert.Fail($"Exception expected when creating: msg={msg}");
            }
            catch { /* ignore */ }

            try
            {
                var msg = AthleteUpdate.Create("Registered,14,8/15/2017 7:02:05 AM,Jane,Jones");
                Assert.Fail($"Exception expected when creating: msg={msg}");
            }
            catch { /* ignore */ }

            try
            {
                var msg = AthleteUpdate.Create("Registered,14,8/15/2017 7:02:05 AM,Jane");
                Assert.Fail($"Exception expected when creating: msg={msg}");
            }
            catch { /* ignore */ }

            try
            {
                var msg = AthleteUpdate.Create("Registered,14,8/15/2017 7:02:05 AM");
                Assert.Fail($"Exception expected when creating: msg={msg}");
            }
            catch { /* ignore */ }

            try
            {
                var msg = AthleteUpdate.Create("Registered,14");
                Assert.Fail($"Exception expected when creating: msg={msg}");
            }
            catch { /* ignore */ }

            try
            {
                var msg = AthleteUpdate.Create("Registered");
                Assert.Fail($"Exception expected when creating: msg={msg}");
            }
            catch { /* ignore */ }

            try
            {
                var msg = AthleteUpdate.Create("Registered,14,8/15/2017 7:02:05 AM,Jane,Jones,F,16,bad");
                Assert.Fail($"Exception expected when creating: msg={msg}");
            }
            catch { /* ignore */ }
        }
示例#12
0
 public abstract void Process(AthleteUpdate updateMessage, Dictionary <int, Athlete> athleteList);
 public void Update(AthleteUpdate update)
 {
     listView1.Items.Add(new ListViewItem(update.ToString()));
     this.Refresh();
 }
 public void ProcessUpdate(AthleteUpdate updateMessage)
 {
     _receivedMessages.Add(updateMessage);
 }
示例#15
0
 public void Update(AthleteUpdate update)
 {
 }
示例#16
0
        public void ProcessUpdate(AthleteUpdate updateMessage)
        {
            string[] updateList = updateMessage.ToString().Split(',');

            if (updateMessage.GetType().ToString() == "RaceData.Messages.RegistrationUpdate")
            {
                AppLayer.RegistrationUpdate update = new AppLayer.RegistrationUpdate(updateList[0], updateList[1], updateList[2], updateList[3], updateList[4], updateList[5], updateList[6]);
                myRace.Athletes.Add(new Athlete(update.Status, update.BibNumber, update.FirstName, update.LastName, update.Gender, update.Age));

                foreach (Athlete thing in myRace.Athletes)
                {
                    if (thing.BibNumber == update.BibNumber)
                    {
                        foreach (Observer item in observersToAdd)
                        {
                            thing.RegisterObserver(item);
                        }
                        thing.NotifyObservers();
                        break;
                    }
                }
            }
            else if (updateMessage.GetType().ToString() == "RaceData.Messages.DidNotStartUpdate")
            {
                AppLayer.DidNotStartUpdate update = new AppLayer.DidNotStartUpdate(updateList[0], updateList[1], updateList[2]);
                foreach (Athlete thing in myRace.Athletes)
                {
                    if (thing.BibNumber == update.BibNumber)
                    {
                        thing.Status = RaceData.AthleteRaceStatus.DidNotStart;

                        thing.NotifyObservers();
                        break;
                    }
                }
            }
            else if (updateMessage.GetType().ToString() == "RaceData.Messages.StartedUpdate")
            {
                AppLayer.StartedUpdate update = new AppLayer.StartedUpdate(updateList[0], updateList[1], updateList[2], updateList[3]);
                foreach (Athlete thing in myRace.Athletes)
                {
                    if (thing.BibNumber == update.BibNumber)
                    {
                        thing.Status    = RaceData.AthleteRaceStatus.Started;
                        thing.startTime = update.OfficialStartTime;

                        thing.NotifyObservers();
                        break;
                    }
                }
            }
            else if (updateMessage.GetType().ToString() == "RaceData.Messages.LocationUpdate")
            {
                AppLayer.LocationUpdate update = new AppLayer.LocationUpdate(updateList[0], updateList[1], updateList[2], updateList[3]);
                foreach (Athlete thing in myRace.Athletes)
                {
                    if (thing.BibNumber == update.BibNumber)
                    {
                        thing.Status   = RaceData.AthleteRaceStatus.OnCourse;
                        thing.Location = update.Location;

                        thing.NotifyObservers();
                        break;
                    }
                }
            }
            else if (updateMessage.GetType().ToString() == "RaceData.Messages.DidNotFinishUpdate")
            {
                AppLayer.DidNotFinishUpdate update = new AppLayer.DidNotFinishUpdate(updateList[0], updateList[1], updateList[2]);
                foreach (Athlete thing in myRace.Athletes)
                {
                    if (thing.BibNumber == update.BibNumber)
                    {
                        thing.Status = RaceData.AthleteRaceStatus.DidNotFinish;

                        thing.NotifyObservers();
                        break;
                    }
                }
            }
            else if (updateMessage.GetType().ToString() == "RaceData.Messages.FinishedUpdate")
            {
                AppLayer.FinishedUpdate update = new AppLayer.FinishedUpdate(updateList[0], updateList[1], updateList[2], updateList[3]);
                foreach (Athlete thing in myRace.Athletes)
                {
                    if (thing.BibNumber == update.BibNumber)
                    {
                        thing.Status     = RaceData.AthleteRaceStatus.Finished;
                        thing.finishTime = update.OfficialEndTime;

                        thing.NotifyObservers();
                        break;
                    }
                }
            }
        }
示例#17
0
 public void ProcessUpdate(AthleteUpdate updateMessage)
 {
     UpdateAthlete(updateMessage);
     Console.WriteLine(updateMessage.ToString());
 }