Ejemplo n.º 1
0
        /// <summary>
        /// Save the configuration data.
        /// </summary>
        /// <param name="fileName">file name</param>
        /// <param name="configData">configuration data</param>
        /// <returns>success flag</returns>
        public bool SaveResultsConfigData(
            string fileName,
            ResultsConfigType configData)
        {
            bool success = true;

            try
            {
                XDocument writer = new XDocument(
                    new XDeclaration("1.0", "uft-8", "yes"),
                    new XComment("Results Configuration XML"));
                XElement root = new XElement(rootElement);

                XElement racePoints =
                    new XElement(
                        racePointsElement,
                        new XAttribute(finishingPointsAttribute, configData.FinishingPoints),
                        new XAttribute(seasonBestAttribute, configData.SeasonBestPoints),
                        new XAttribute(scoringPositionAttribute, configData.NumberOfScoringPositions),
                        new XAttribute(excludeFirstTimersAttribute, configData.ExcludeFirstTimers),
                        new XAttribute(allResultsAttribute, configData.AllResults),
                        new XAttribute(scoresToCountAttribute, configData.ScoresToCount),
                        new XAttribute(scoresDescendingAttribute, configData.ScoresAreDescending));
                XElement clubPoints =
                    new XElement(
                        clubPointsElement,
                        new XAttribute(useTeamsAttribute, configData.UseTeams),
                        new XAttribute(teamFinishingPointsAttribute, configData.TeamFinishingPoints),
                        new XAttribute(teamSizeAttribute, configData.NumberInTeam),
                        new XAttribute(teamSeasonBestAttribute, configData.TeamSeasonBestPoints));
                XElement harmonyPoints =
                    new XElement(
                        harmonyPointsElement,
                        new XAttribute(harmonyTeamSizeAttribute, configData.NumberInHarmonyTeam),
                        new XAttribute(harmonyScoringAttribute, configData.HarmonyPointsScoring));

                root.Add(racePoints);
                root.Add(clubPoints);
                root.Add(harmonyPoints);

                writer.Add(root);
                writer.Save(fileName);
            }
            catch (Exception ex)
            {
                this.logger.WriteLog("Error writing Results Configuration data " + ex.ToString());
            }

            return(success);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates and saves a default results configuration file.
 /// </summary>
 /// <param name="resultsConfig">results configuration details</param>
 public void SaveResultsConfiguration(ResultsConfigType resultsConfig)
 {
     try
     {
         this.configurationReader.SaveResultsConfigData(
             this.generalIo.ResultsConfigurationFile,
             resultsConfig);
         this.ResultsConfigurationDetails = resultsConfig;
     }
     catch (Exception ex)
     {
         this.logger.WriteLog("Failed to save results config file: " + ex.ToString());
         Messenger.Default.Send(
             new HandicapErrorMessage(
                 "Error creating results config file"));
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Determine the new position points
        /// </summary>
        /// <returns></returns>
        private int CalculatePositionPoints()
        {
            // Get working set.
            List <int> points = new List <int>();

            foreach (CommonPoints common in this.AllPoints)
            {
                points.Add(common.PositionPoints);
            }

            // If all scores used, just return.
            ResultsConfigType resultsConfigurationDetails =
                this.resultsConfigurationManager.ResultsConfigurationDetails;

            if (resultsConfigurationDetails.AllResults)
            {
                return(this.SumCollection(points));
            }

            // Order scores to make analysis easier.
            points.Sort();

            if (this.resultsConfigurationManager.ResultsConfigurationDetails.ScoresAreDescending)
            {
                points.Reverse();
            }
            else
            {
                // Make up for shortfall in scores.
                while (points.Count < this.resultsConfigurationManager.ResultsConfigurationDetails.ScoresToCount)
                {
                    points.Add(this.resultsConfigurationManager.ResultsConfigurationDetails.MissingScore);
                }
            }

            // Get rid of non counting scores
            while (points.Count > this.resultsConfigurationManager.ResultsConfigurationDetails.ScoresToCount)
            {
                points.RemoveAt(points.Count);
            }

            return(this.SumCollection(points));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Load a new series into the model.
 /// </summary>
 /// <param name="message">load a new series</param>
 private void LoadNewSeries(LoadNewSeriesMessage message)
 {
     this.ResultsConfigurationDetails =
         this.configurationReader.LoadResultsConfigData(
             this.generalIo.ResultsConfigurationFile);
 }