Exemple #1
0
        public override void Process(AthleteUpdate updateMessage, Dictionary <int, Athlete> athleteList)
        {
            RegistrationUpdate regUpdate    = updateMessage as RegistrationUpdate;
            Athlete            MyNewAthlete = new Athlete(regUpdate.BibNumber, regUpdate.FirstName, regUpdate.LastName, regUpdate.Gender, regUpdate.Age);

            athleteList.Add(MyNewAthlete.BibNumber, MyNewAthlete);
            //Console.WriteLine(updateMessage.ToString());
        }
        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());
        }
        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);
        }
Exemple #4
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;
                    }
                }
            }
        }