Ejemplo n.º 1
0
 /// <summary>
 /// Create a new athlete and add it to the athlete list.
 /// </summary>
 /// <param name="athleteName">name of the athlete</param>
 /// <param name="club">athlete's club</param>
 /// <param name="initialHandicapMinutes">initial handicap (minutes)</param>
 /// <param name="initialHandicapSeconds">initial handicap (seconds)</param>
 /// <param name="sex">athlete's sex</param>
 /// <param name="runningNumbers">collection of registed running numbers</param>
 /// <param name="birthYear">birth year, not used</param>
 /// <param name="birthMonth">birth month, not used</param>
 /// <param name="birthDay">birth day, not used</param>
 /// <param name="signedConsent">
 /// Indicates whether the parental consent form has been signed.
 /// </param>
 /// <param name="active">Indicates whether the athlete is currently active</param>
 public void CreateNewAthlete(
     string athleteName,
     string club,
     int initialHandicapMinutes,
     int initialHandicapSeconds,
     SexType sex,
     List <string> runningNumbers,
     string birthYear,
     string birthMonth,
     string birthDay,
     bool signedConsent,
     bool active)
 {
     Athletes.SetNewAthlete(
         new AthleteDetails(
             Athletes.NextKey,
             athleteName,
             club,
             new TimeType(initialHandicapMinutes, initialHandicapSeconds),
             sex,
             birthYear,
             birthMonth,
             birthDay,
             signedConsent,
             active,
             this.normalisationConfigurationManager)
     {
         RunningNumbers = runningNumbers
     });
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads the athlete details xml from file and decodes it.
        /// </summary>
        /// <param name="fileName">name of xml file</param>
        /// <returns>decoded athlete's details</returns>
        public Athletes ReadAthleteData(string fileName)
        {
            Athletes athleteData = new Athletes(this.seriesConfigManager);

            if (!File.Exists(fileName))
            {
                string error = string.Format("Athlete Data file missing, one created - {0}", fileName);
                Messenger.Default.Send(
                    new HandicapErrorMessage(
                        error));
                this.logger.WriteLog(error);
                SaveAthleteData(fileName, new Athletes(this.seriesConfigManager));
            }

            try
            {
                XDocument reader             = XDocument.Load(fileName);
                XElement  rootElement        = reader.Root;
                XElement  athleteListElement = rootElement.Element(c_athleteListLabel);

                var athleteList = from Athlete in athleteListElement.Elements(c_athleteLabel)
                                  select new
                {
                    key  = (string)Athlete.Attribute(c_keyLabel),
                    name = (string)Athlete.Attribute(c_nameLabel),
                    club = (string)Athlete.Attribute(c_clubLabel),
                    predeclaredHandicap = (string)Athlete.Attribute(predeclaredHandicapLabel),
                    sex            = (string)Athlete.Attribute(c_sexLabel),
                    signedConsent  = (string)Athlete.Attribute(SignedConsentAttribute),
                    active         = (string)Athlete.Attribute(activeLabel),
                    birthYear      = (string)Athlete.Attribute(birthYearAttribute),
                    birthMonth     = (string)Athlete.Attribute(birthMonthAttribute),
                    birthDay       = (string)Athlete.Attribute(birthDayAttribute),
                    runningNumbers = from RunningNumbers in Athlete.Elements(c_runningNumbersElement)
                                     select new
                    {
                        numbers = from Numbers in RunningNumbers.Elements(c_numberElement)
                                  select new
                        {
                            number = (string)Numbers.Attribute(c_numberAttribute)
                        }
                    },
                    timeList = from TimeList in Athlete.Elements(c_appearancesLabel)
                               select new
                    {
                        time = from Time in TimeList.Elements(c_timeLabel)
                               select new
                        {
                            time = (string)Time.Attribute(c_raceTimeLabel),
                            date = (string)Time.Attribute(c_raceDateLabel)
                        }
                    }
                };

                foreach (var athlete in athleteList)
                {
                    bool signedConsent = this.ConvertBool(athlete.signedConsent);
                    bool isActive      = this.ConvertBool(athlete.active);

                    int athleteKey =
                        (int)StringToIntConverter.ConvertStringToInt(
                            athlete.key);
                    TimeType athleteTime =
                        new TimeType(
                            athlete.predeclaredHandicap);
                    SexType            athleteSex         = StringToSexType.ConvertStringToSexType(athlete.sex);
                    List <Appearances> athleteAppearances = new List <Appearances>();

                    AthleteDetails athleteDetails =
                        new AthleteDetails(
                            athleteKey,
                            athlete.name,
                            athlete.club,
                            athleteTime,
                            athleteSex,
                            signedConsent,
                            isActive,
                            athleteAppearances,
                            athlete.birthYear,
                            athlete.birthMonth,
                            athlete.birthDay,
                            this.normalisationConfigManager);

                    foreach (var runningNumbers in athlete.runningNumbers)
                    {
                        foreach (var number in runningNumbers.numbers)
                        {
                            athleteDetails.AddNewNumber(number.number);
                        }
                    }

                    foreach (var raceTimeList in athlete.timeList)
                    {
                        foreach (var raceTime in raceTimeList.time)
                        {
                            athleteDetails.AddRaceTime(new Appearances(new RaceTimeType(raceTime.time),
                                                                       new DateType(raceTime.date)));
                        }
                    }

                    athleteData.SetNewAthlete(athleteDetails);
                }
            }
            catch (Exception ex)
            {
                this.logger.WriteLog("Error reading athlete data: " + ex.ToString());

                athleteData = new Athletes(this.seriesConfigManager);
            }

            return(athleteData);
        }