/// ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- /// <name>SaveAthleteSeasonData</name> /// <date>30/03/15</date> /// <summary> /// Reads the athlete season details xml from file and decodes it. /// </summary> /// <param name="fileName">name of xml file</param> /// <returns>decoded athlete's details</returns> /// ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- public List <IAthleteSeasonDetails> LoadAthleteSeasonData( string fileName, IResultsConfigMngr resultsConfigurationManager) { List <IAthleteSeasonDetails> seasonDetails = new List <IAthleteSeasonDetails>(); try { XDocument reader = XDocument.Load(fileName); XElement rootElement = reader.Root; var athleteList = from Athlete in rootElement.Elements(c_athleteElement) select new { key = (int)Athlete.Attribute(c_keyAttribute), name = (string)Athlete.Attribute(c_nameAttribute), 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) } }, eventTimes = from EventTimes in Athlete.Elements(c_timesElement) select new { events = from Times in EventTimes.Elements(c_eventTimeElement) select new { time = (string)Times.Attribute(c_eventTimeAttribute), date = (string)Times.Attribute(c_eventDateAttribute) } }, mobTrophyPoints = from Points in Athlete.Elements(MobTrophyPointsElement) select new { point = from Point in Points.Elements(c_eventPointsElement) select new { finishing = (int)Point.Attribute(c_finishingPoints), position = (int)Point.Attribute(c_positionPoints), best = (int)Point.Attribute(c_bestPoints), date = (string)Point.Attribute(c_eventDateAttribute) } }, teamTrophyPoints = from Points in Athlete.Elements(TeamTrophyPointsElement) select new { point = from Point in Points.Elements(c_eventPointsElement) select new { teamTrophyPoint = (int)Point.Attribute(TeamTrophyPointsAttribute), date = (string)Point.Attribute(c_eventDateAttribute) } } }; foreach (var athlete in athleteList) { AthleteSeasonDetails athleteDetails = new AthleteSeasonDetails( athlete.key, athlete.name); foreach (var eventTms in athlete.eventTimes) { foreach (var times in eventTms.events) { athleteDetails.AddNewTime(new Appearances(new RaceTimeType(times.time), new DateType(times.date))); } } foreach (var points in athlete.mobTrophyPoints) { foreach (var point in points.point) { DateType eventDate = new DateType( point.date); CommonPoints commonPoints = new CommonPoints( point.finishing, point.position, point.best, eventDate); athleteDetails.Points.AddNewEvent(commonPoints); // TODO, should probably check that there are the correct number read from the xml file. // i.e. there is one for each event in the currently loaded season. // Will want to change it to proper serialisation at some point. } } foreach (var points in athlete.teamTrophyPoints) { foreach (var point in points.point) { DateType date = new DateType(point.date); IAthleteTeamTrophyPoints newEvent = new AthleteTeamTrophyPoints( point.teamTrophyPoint, date); athleteDetails.TeamTrophyPoints.AddNewEvent(newEvent); } } seasonDetails.Add(athleteDetails); } } catch (Exception ex) { this.logger.WriteLog("Error reading athlete data: " + ex.ToString()); seasonDetails = new List <IAthleteSeasonDetails>(); } return(seasonDetails); }
/// <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); }
/// ---------- ---------- ---------- ---------- ---------- ---------- /// <name>ReadCompleteSummaryData</name> /// <date>31/01/15</date> /// <summary> /// Reads the athlete details xml from file and decodes it. /// </summary> /// <param name="fileName">name of xml file</param> /// <returns>decoded summary data</returns> /// ---------- ---------- ---------- ---------- ---------- ---------- public ISummary ReadCompleteSummaryData(string fileName) { ISummary summaryData = null; if (!File.Exists(fileName)) { string error = $"Summary file missing, one created - {fileName}"; Messenger.Default.Send( new HandicapErrorMessage( error)); this.logger.WriteLog(error); SaveSummaryData(fileName, new Summary()); } try { XDocument reader = XDocument.Load(fileName); XElement rootElement = reader.Root; XElement TotalRunnersElement = rootElement.Element(c_RunnersLabel); XElement MaleRunnersElement = rootElement.Element(c_MaleRunnersLabel); XElement FemaleRunnersElement = rootElement.Element(c_FemaleRunnersLabel); XElement YBsElement = rootElement.Element(c_YBLabel); XElement PBsElement = rootElement.Element(c_PBLabel); XElement FirstTimersElement = rootElement.Element(c_FirstTimersLabel); XElement FastestElement = rootElement.Element(c_FastestLabel); XElement FastestBoysElement = FastestElement.Element(fastestBoysLabel); XElement FastestGirlsElement = FastestElement.Element(fastestGirlsLabel); summaryData = new Summary( (int)StringToIntConverter.ConvertStringToInt(MaleRunnersElement.Value), (int)StringToIntConverter.ConvertStringToInt(FemaleRunnersElement.Value), (int)StringToIntConverter.ConvertStringToInt(YBsElement.Value), (int)StringToIntConverter.ConvertStringToInt(PBsElement.Value), (int)StringToIntConverter.ConvertStringToInt(FirstTimersElement.Value)); var boysList = from Athlete in FastestBoysElement.Elements(timeLabel) select new { key = (string)Athlete.Attribute(keyLabel), name = (string)Athlete.Attribute(c_NameLabel), minutes = (int)Athlete.Attribute(c_MinutesLabel), seconds = (int)Athlete.Attribute(c_SecondsLabel), date = (string)Athlete.Attribute(dateLabel) }; foreach (var athlete in boysList) { summaryData.SetFastestBoy((int)StringToIntConverter.ConvertStringToInt(athlete.key), athlete.name, new TimeType(athlete.minutes, athlete.seconds), new DateType(athlete.date)); } var girlsList = from Athlete in FastestGirlsElement.Elements(timeLabel) select new { key = (string)Athlete.Attribute(keyLabel), name = (string)Athlete.Attribute(c_NameLabel), minutes = (int)Athlete.Attribute(c_MinutesLabel), seconds = (int)Athlete.Attribute(c_SecondsLabel), date = (string)Athlete.Attribute(dateLabel) }; foreach (var athlete in girlsList) { summaryData.SetFastestGirl((int)StringToIntConverter.ConvertStringToInt(athlete.key), athlete.name, new TimeType(athlete.minutes, athlete.seconds), new DateType(athlete.date)); } } catch (Exception ex) { this.logger.WriteLog("Error reading summary data: " + ex.ToString()); summaryData = new Summary(); } return(summaryData); }