예제 #1
0
        /// <summary>
        /// Save the points table
        /// </summary>
        /// <param name="seasonName">season name</param>
        /// <param name="eventName">event name</param>
        /// <param name="resultsTable">points table</param>
        public bool SaveResultsTable(
            string seasonName,
            string eventName,
            List <IResultsTableEntry> resultsTable)
        {
            bool success = true;

            try
            {
                ResultsTableRoot rootElement = new ResultsTableRoot();

                XDocument writer = new XDocument(
                    new XDeclaration("1.0", "uft-8", "yes"),
                    new XComment("Results Table XML"));

                foreach (ResultsTableEntry entry in resultsTable)
                {
                    Row entryElement =
                        new Row(
                            entry.Key,
                            entry.Name,
                            entry.Club,
                            entry.Handicap.ToString(),
                            entry.Notes,
                            entry.ExtraInfo,
                            entry.Order,
                            entry.PB,
                            entry.SB,
                            entry.Points.ToString(),
                            entry.HarmonyPoints,
                            entry.RaceNumber,
                            entry.RunningOrder,
                            entry.Time.ToString(),
                            entry.Sex);

                    rootElement.Add(entryElement);
                }

                string fileName =
                    ResultsTableReader.GetPath(
                        seasonName,
                        eventName);
                XmlFileIo.WriteXml <ResultsTableRoot>(
                    rootElement,
                    fileName);
            }

            catch (XmlException ex)
            {
                this.logger.WriteLog($"Error writing results table file: {ex.XmlMessage}");
                success = false;
            }

            return(success);
        }
예제 #2
0
        /// <summary>
        /// Reads the athlete season details xml from file and decodes it.
        /// </summary>
        /// <param name="seasonName">season name</param>
        /// <param name="eventName">event name</param>
        /// <param name="date">event date</param>
        /// <returns>decoded athlete's details</returns>
        public IEventResults LoadResultsTable(
            string seasonName,
            string eventName,
            DateType date)
        {
            IEventResults    resultsTable = new EventResults();
            ResultsTableRoot deserialisedResultTable;
            string           resultsPath =
                ResultsTableReader.GetPath(
                    seasonName,
                    eventName);

            try
            {
                deserialisedResultTable =
                    XmlFileIo.ReadXml <ResultsTableRoot>(
                        resultsPath);
            }
            catch (XmlException ex)
            {
                this.logger.WriteLog(
                    $"Error reading the results table; {ex.XmlMessage}");

                return(resultsTable);
            }

            foreach (Row row in deserialisedResultTable)
            {
                RaceTimeType time =
                    new RaceTimeType(
                        row.Time);
                RaceTimeType handicap =
                    new RaceTimeType(
                        row.Handicap);
                CommonPoints points =
                    new CommonPoints(
                        row.Points,
                        date);
                int position = resultsTable.Entries.Count + 1;

                ResultsTableEntry rowEntry =
                    new ResultsTableEntry(
                        row.Key,
                        row.Name,
                        time,
                        row.Order,
                        row.RunningOrder,
                        handicap,
                        row.Club,
                        row.Sex,
                        row.Number,
                        points,
                        row.HarmonyPoints,
                        row.IsPersonalBest,
                        row.IsYearBest,
                        row.Notes,
                        row.ExtraInformation,
                        position);
                resultsTable.AddEntry(rowEntry);
            }

            return(resultsTable);
        }