コード例 #1
0
        /// <summary>
        /// Initialises a new instance of the <see cref="LabelGenerationViewModel"/> class.
        /// </summary>
        /// <param name="model">junior handicap model</param>
        /// <param name="normalisationConfigManager">normalisation configuration manager</param>
        /// <param name="seriesConfigManager">series configuration manager</param>
        /// <param name="logger">application logger</param>
        /// <param name="saveFolder">folder to save the output to</param>
        public LabelGenerationViewModel(
            IModel model,
            INormalisationConfigMngr normalisationConfigManager,
            ISeriesConfigMngr seriesConfigManager,
            IJHcLogger logger,
            string saveFolder)
        {
            this.model = model;
            this.seriesConfigManager = seriesConfigManager;
            this.logger = logger;
            SaveFolder  = saveFolder;
            NormalisationConfigType hcConfiguration =
                normalisationConfigManager.ReadNormalisationConfiguration();

            // TODO, this is repeated code, see HandicapWriter.cs
            foreach (AthleteDetails athlete in model.Athletes.AthleteDetails)
            {
                TimeType newHandicap = model.CurrentSeason.GetAthleteHandicap(athlete.Key, hcConfiguration);

                // Only look at active athletes.
                if (athlete.Active)
                {
                    List <string> runningNumbers = model.Athletes.GetAthleteRunningNumbers(athlete.Key);

                    // Use default handicap, if the athlete is not registered for the current season.
                    // TODO, I suspect this should never happen???
                    if (newHandicap == null)
                    {
                        newHandicap = athlete.RoundedHandicap;
                    }

                    // Ensure that the athlete is registered for the season.
                    if (runningNumbers.Count > 0)
                    {
                        AthleteLabel modelAthlete =
                            new AthleteLabel(
                                athlete.Name,
                                athlete.Club,
                                runningNumbers[0],
                                newHandicap,
                                athlete.Appearances == 0);
                        modelAthlete.AthleteLabelWidth  = A4Details.GetLabelWidth96DPI(NoColumns);
                        modelAthlete.AthleteLabelHeight = A4Details.GetLabelHeight96DPI(NoRows);
                        this.AthleteDetails.Add(modelAthlete);
                    }
                }
            }

            // Order the athletes alphabetically.
            this.AthleteDetails =
                this.AthleteDetails.OrderBy(athlete => athlete.Forename).ToList();
            this.AthleteDetails =
                this.AthleteDetails.OrderBy(athlete => athlete.Surname).ToList();

            this.saveDirectory = saveFolder;

            this.CreateRaceLabelsCommand  = new CreateAndSaveRaceLabelsCmd(this);
            this.CreateSpareLabelsCommand = new CreateAndSaveSpareLabelsCmd(this);
            this.CreateAllLabelsCommand   = new CreateAndSaveAllLabelsCmd(this);
        }
コード例 #2
0
        /// <summary>
        ///   Creates a new instance of the AthleteDetails class
        /// </summary>
        /// <param name="key">unique key</param>
        /// <param name="name">athlete's name</param>
        /// <param name="club">athlete's club</param>
        /// <param name="roundedHandicap">rounded handicap</param>
        /// <param name="sex">athlete's sex</param>
        /// <param name="birthYear">birth year, no longer recorded</param>
        /// <param name="birthMonth">birth month, no longer recorded</param>
        /// <param name="birthDay">birth day, no longer recorded</param>
        /// <param name="signedConsent">
        /// indicates whether the parental consent form has been signed
        /// </param>
        /// <param name="active">active</param>
        /// <param name="normalisationConfigManager">normalisation config manager</param>
        public AthleteDetails(
            int key,
            string name,
            string club,
            TimeType roundedHandicap,
            SexType sex,
            string birthYear,
            string birthMonth,
            string birthDay,
            bool signedConsent,
            bool active,
            INormalisationConfigMngr normalisationConfigManager)
        {
            this.Key  = key;
            this.Name = name;
            this.Club = club;
            this.PredeclaredHandicap = roundedHandicap;
            this.Sex           = sex;
            this.SignedConsent = signedConsent;
            this.Active        = active;

            this.RunningNumbers = new List <string>();
            this.Times          = new List <Appearances>();

            this.BirthDate =
                new DateOfBirth(
                    birthYear,
                    birthMonth,
                    birthDay);

            this.normalisationConfigMngr = normalisationConfigManager;
        }
コード例 #3
0
ファイル: PrimaryDisplayViewModel.cs プロジェクト: abs508/jHc
        /// <summary>
        /// Creates a new instance of the <see cref="PrimaryDisplayViewModel"/> class
        /// </summary>
        /// <param name="model">application model</param>
        /// <param name="businessLayerManager">business layer manager</param>
        /// <param name="normalisationConfigurationManager">normalisation configuration manager</param>
        /// <param name="resultsConfigurationManager">results configuration manager</param>
        /// <param name="seriesConfigurationManager">series configuration manager</param>
        /// <param name="generalIo">general IO manager</param>
        /// <param name="commonIo">Common IO manager</param>
        /// <param name="logger">application logger</param>
        public PrimaryDisplayViewModel(
            IModel model,
            IBLMngr businessLayerManager,
            INormalisationConfigMngr normalisationConfigurationManager,
            IResultsConfigMngr resultsConfigurationManager,
            ISeriesConfigMngr seriesConfigurationManager,
            IGeneralIo generalIo,
            ICommonIo commonIo,
            IJHcLogger logger)
        {
            this.logger = logger;
            this.logger.WriteLog("HandicapMainViewModel created");
            this.model = model;
            this.normalisationConfigManager  = normalisationConfigurationManager;
            this.resultsConfigurationManager = resultsConfigurationManager;
            this.seriesConfigManager         = seriesConfigurationManager;
            this.businessLayerManager        = businessLayerManager;
            this.generalIo       = generalIo;
            this.commonIo        = commonIo;
            this.isValidLocation = this.businessLayerManager.IsValid;

            Messenger.Default.Register <HandicapErrorMessage>(this, this.PopulateErrorInformation);
            Messenger.Default.Register <HandicapProgressMessage>(this, this.PopulateProgressInformation);
            Messenger.Default.Register <ValidLocationMessage>(this, this.InvalidLocationMessage);

            this.InitialiseViewModels();
            this.InitialiseOpenAppCommands();
        }
コード例 #4
0
 /// <summary>
 /// Initialises a new instance of the <see cref="DeleteResultsMngr"/> class.
 /// </summary>
 /// <param name="model">junior handicap model</param>
 /// <param name="normalisationConfigManager">normalisation config manager</param>
 /// <param name="logger">application logger</param>
 public DeleteResultsMngr(
     IModel model,
     INormalisationConfigMngr normalisationConfigManager,
     IJHcLogger logger)
     : base(model)
 {
     this.logger = logger;
     this.normalisationConfigMngr = normalisationConfigManager;
 }
コード例 #5
0
 /// <summary>
 /// Initialises a new instance of the <see cref="AthleteDataReader"/> class.
 /// </summary>
 /// <param name="normalisationConfigManager">Normalisation config manager</param>
 /// <param name="seriesConfigManager">series config manager</param>
 /// <param name="logger">application logger</param>
 public AthleteDataReader(
     INormalisationConfigMngr normalisationConfigManager,
     ISeriesConfigMngr seriesConfigManager,
     IJHcLogger logger)
 {
     this.logger = logger;
     this.normalisationConfigManager = normalisationConfigManager;
     this.seriesConfigManager        = seriesConfigManager;
 }
コード例 #6
0
ファイル: CalculateResultsMngr.cs プロジェクト: abs508/jHc
 /// <summary>
 /// Initialises a new instance of the <see cref="CalculateResultsMngr"/> class.
 /// </summary>
 /// <param name="model">junior handicap model</param>
 /// <param name="normalisationConfigurationManager">
 /// normalisation configuration manager
 /// </param>
 /// <param name="resultsConfigurationManager">
 /// results configuration manager
 /// </param>
 /// <param name="seriesConfigurationManager">
 /// series configuration manager
 /// </param>
 /// <param name="logger">application logger</param>
 public CalculateResultsMngr(
     IModel model,
     INormalisationConfigMngr normalisationConfigurationManager,
     IResultsConfigMngr resultsConfigurationManager,
     ISeriesConfigMngr seriesConfigurationManager,
     IJHcLogger logger)
     : base(model)
 {
     this.logger = logger;
     this.resultsConfiguration = resultsConfigurationManager;
     this.hcConfiguration      = normalisationConfigurationManager.ReadNormalisationConfiguration();
     this.seriesConfiguration  = seriesConfigurationManager.ReadSeriesConfiguration();
 }
コード例 #7
0
        /// <summary>
        /// Initialises a new instance of the <see cref="AthleteSummaryViewModel"/> class.
        /// </summary>
        /// <param name="model">junior handicap model</param>
        /// <param name="normalisationConfigManager">Normalisation configuration manager</param>
        /// <param name="resultsConfigurationManager">results configuration manager</param>
        public AthleteSummaryViewModel(
            IModel model,
            INormalisationConfigMngr normalisationConfigManager,
            IResultsConfigMngr resultsConfigurationManager)
        {
            this.model = model;
            this.normalisationConfigManager  = normalisationConfigManager;
            this.resultsConfigurationManager = resultsConfigurationManager;

            this.LoadAthleteInformation(model.Athletes.AthleteDetails);
            //model.AthletesCallback = new AthletesDelegate(AthleteInfoUpdated);

            this.athleteCollectionIndex = -1;

            string testString = this.AthleteSummaryKey;
        }
コード例 #8
0
 /// <summary>
 ///   Creates a new instance of the AthleteDetails class
 /// </summary>
 /// <param name="key">unique key</param>
 /// <param name="normalisationConfigManager">normalisation config manager</param>
 public AthleteDetails(
     int key,
     INormalisationConfigMngr normalisationConfigManager)
     : this(
         key,
         string.Empty,
         string.Empty,
         new TimeType(59, 59),
         SexType.NotSpecified,
         "1970",
         "1",
         "1",
         false,
         true,
         normalisationConfigManager)
 {
 }
コード例 #9
0
        /// <summary>
        /// Prevents a new instance of the HandicapModel class from being created.
        /// </summary>
        /// <param name="normalisationConfigMngr">Normalisation configuration manager</param>
        /// <param name="resultsConfigurationManager">Results configuration manager</param>
        /// <param name="athleteData">athlete data</param>
        /// <param name="clubData">club data</param>
        /// <param name="eventData">event data</param>
        /// <param name="summaryData">summary data</param>
        /// <param name="resultsTableReader">results table reader</param>
        /// <param name="seasonIo">season IO Manager</param>
        /// <param name="eventIo">event IO manager</param>
        /// <param name="rawEventIo">raw event IO manager</param>
        /// <param name="generalIo">general IO manager</param>
        /// <param name="logger">application logger</param>
        public Model(
            INormalisationConfigMngr normalisationConfigMngr,
            IResultsConfigMngr resultsConfigurationManager,
            IAthleteData athleteData,
            IClubData clubData,
            IEventData eventData,
            ISummaryData summaryData,
            IResultsTableReader resultsTableReader,
            ISeasonIO seasonIo,
            IEventIo eventIo,
            IRawEventIo rawEventIo,
            IGeneralIo generalIo,
            IJHcLogger logger)
        {
            this.normalisationConfigurationManager = normalisationConfigMngr;
            this.resultsConfigurationManager       = resultsConfigurationManager;
            this.athleteData = athleteData;
            this.clubData    = clubData;
            this.summaryData = summaryData;
            this.eventIo     = eventIo;
            this.seasonIo    = seasonIo;
            this.logger      = logger;

            // Setup local models.
            this.CurrentSeason =
                new Season(
                    resultsConfigurationManager,
                    this.athleteData,
                    this.clubData,
                    this.summaryData,
                    this.eventIo,
                    this.logger);
            this.CurrentEvent =
                new EventHC(
                    eventData,
                    this.summaryData,
                    resultsTableReader,
                    rawEventIo,
                    this.logger);
            this.Seasons       = seasonIo.GetSeasons();
            this.Athletes      = this.athleteData.ReadAthleteData();
            this.Clubs         = this.clubData.LoadClubData();
            this.GlobalSummary = this.summaryData.LoadSummaryData();

            Messenger.Default.Register <LoadNewSeriesMessage>(this, this.LoadNewSeries);
        }
コード例 #10
0
ファイル: BLMngr.cs プロジェクト: abs508/jHc
        /// <summary>
        /// Initialises a new instance of the <see cref="BLMngr"/> class.
        /// </summary>
        /// <param name="model">junior handicap model</param>
        /// <param name="normalisationConfigurationManager">the normalisation config manager</param>
        /// <param name="resultsConfigurationManager">the results config manager</param>
        /// <param name="seriesConfigurationManager">the series config manager</param>
        /// <param name="athleteData">athlete data</param>
        /// <param name="clubData">club data</param>
        /// <param name="eventData">event data</param>
        /// <param name="summaryData">summary data</param>
        /// <param name="seasonIO">season IO manager</param>
        /// <param name="eventIo">event IO manager</param>
        /// <param name="generalIo">general IO manager</param>
        /// <param name="logger">application logger</param>
        public BLMngr(
            IModel model,
            INormalisationConfigMngr normalisationConfigurationManager,
            IResultsConfigMngr resultsConfigurationManager,
            ISeriesConfigMngr seriesConfigurationManager,
            IAthleteData athleteData,
            IClubData clubData,
            IEventData eventData,
            ISummaryData summaryData,
            ISeasonIO seasonIO,
            IEventIo eventIo,
            IGeneralIo generalIo,
            IJHcLogger logger)
        {
            this.logger = logger;
            this.model  = model;
            this.normalisationConfigurationManager = normalisationConfigurationManager;
            this.resultsConfigurationManager       = resultsConfigurationManager;
            this.seriesConfigurationManager        = seriesConfigurationManager;
            this.athleteData        = athleteData;
            this.clubData           = clubData;
            this.eventData          = eventData;
            this.summaryData        = summaryData;
            this.seasonIO           = seasonIO;
            this.eventIo            = eventIo;
            this.generalIo          = generalIo;
            this.ModelRootDirectory = RootIO.LoadRootFile();
            this.currentSeason      = string.Empty;

            this.resultsCalculator =
                new CalculateResultsMngr(
                    this.model,
                    this.normalisationConfigurationManager,
                    this.resultsConfigurationManager,
                    this.seriesConfigurationManager,
                    this.logger);

            this.IsValid =
                this.generalIo.DataFolderExists && this.generalIo.ConfigurationFolderExists;

            Messenger.Default.Register <LoadNewSeasonMessage>(this, this.NewCurrentSeason);
            Messenger.Default.Register <LoadNewEventMessage>(this, this.NewCurrentEvent);
            Messenger.Default.Register <LoadNewSeriesMessage>(this, this.LoadNewSeries);
            Messenger.Default.Register <CreateNewSeriesMessage>(this, this.CreateNewSeries);
            Messenger.Default.Register <ReinitialiseRoot>(this, this.ReinitialiseRoot);
        }
コード例 #11
0
        /// <summary>
        /// Initialises a new instance of the <see cref="NormalisationConfigViewModel"/> class.
        /// </summary>
        /// <param name="normalisationConfigManager">normalisation config manager</param>
        /// <param name="logger">application logger</param>
        public NormalisationConfigViewModel(
            INormalisationConfigMngr normalisationConfigManager,
            IJHcLogger logger)
        {
            this.normalisationConfigManager = normalisationConfigManager;
            this.logger = logger;

            NormalisationConfigType config =
                this.normalisationConfigManager.ReadNormalisationConfiguration();

            useHandicap           = config.UseCalculatedHandicap;
            handicapTime          = config.HandicapTime.ToString();
            minimumHandicap       = config.MinimumHandicap.ToString();
            this.handicapInterval = config.HandicapInterval.ToString();

            useHandicapOrig           = UseHandicap;
            handicapTimeOrig          = HandicapTime;
            minimumHandicapOrig       = MinimumHandicap;
            this.handicapIntervalOrig = this.HandicapInterval;

            SaveCommand = new NormalisationConfigSaveCmd(this);
        }
コード例 #12
0
        /// <summary>
        /// Initialises a new instance of the <see cref="AthleteData"/> class.
        /// </summary>
        /// <param name="generalIo">general IO manager</param>
        /// <param name="logger">application logger</param>
        public AthleteData(
            IGeneralIo generalIo,
            INormalisationConfigMngr normalisationConfigManager,
            ISeriesConfigMngr seriesConfigManager,
            IJHcLogger logger)
        {
            this.generalIo = generalIo;
            this.logger    = logger;

            this.athleteDataReader =
                new AthleteDataReader(
                    normalisationConfigManager,
                    seriesConfigManager,
                    this.logger);
            this.athleteSeasonDataReader =
                new AthleteSeasonDataReader(
                    this.logger);

            string rootDirectory = RootIO.LoadRootFile();

            this.dataPath = $"{rootDirectory}{Path.DirectorySeparatorChar}{IOPaths.dataPath}{Path.DirectorySeparatorChar}";
            Messenger.Default.Register <ReinitialiseRoot>(this, this.ReinitialiseRoot);
        }
コード例 #13
0
        /// <summary>
        /// Write the handicaps to a file.
        /// </summary>
        /// <param name="model">junior handicap model</param>
        /// <param name="folder">output folder</param>
        /// <param name="normalisationConfigMngr">normalisation configuration manager</param>
        /// <param name="logger">application logger</param>
        /// <returns>success flag</returns>
        public static bool WriteHandicapTable(
            IModel model,
            string folder,
            INormalisationConfigMngr normalisationConfigMngr,
            IJHcLogger logger)
        {
            bool success = true;

            Messenger.Default.Send(
                new HandicapProgressMessage(
                    "Printing handicap."));

            try
            {
                NormalisationConfigType hcConfiguration =
                    normalisationConfigMngr.ReadNormalisationConfiguration();

                using (StreamWriter writer = new StreamWriter(Path.GetFullPath(folder) +
                                                              Path.DirectorySeparatorChar +
                                                              model.CurrentSeason.Name +
                                                              model.CurrentEvent.Name +
                                                              ResultsPaths.handicapTable +
                                                              ResultsPaths.csvExtension))
                {
                    List <AthleteDetails> athletes = new List <AthleteDetails>(model.Athletes.AthleteDetails);
                    athletes = athletes.OrderBy(athlete => athlete.Forename).ToList();
                    athletes = athletes.OrderBy(athlete => athlete.Surname).ToList();

                    foreach (AthleteDetails athlete in athletes)
                    {
                        if (!athlete.Active)
                        {
                            continue;
                        }

                        string number =
                            model.Athletes.GetAthleteRunningNumber(
                                athlete.Key);
                        TimeType newHandicap =
                            model.CurrentSeason.GetAthleteHandicap(
                                athlete.Key,
                                hcConfiguration);
                        string consented =
                            athlete.SignedConsent
                            ? "Y"
                            : string.Empty;

                        // Use default handicap, if the athlete is not registered for the current season.
                        if (newHandicap == null)
                        {
                            newHandicap = athlete.RoundedHandicap;
                        }

                        string entryString = athlete.Name +
                                             ResultsPaths.separator +
                                             number +
                                             ResultsPaths.separator +
                                             newHandicap +
                                             ResultsPaths.separator +
                                             athlete.Club +
                                             ResultsPaths.separator +
                                             consented;

                        writer.WriteLine(entryString);
                    }
                    success = true;
                }
            }
            catch (Exception ex)
            {
                logger.WriteLog("Error, failed to print handicap: " + ex.ToString());

                Messenger.Default.Send(
                    new HandicapErrorMessage(
                        "Failed to print handicap"));

                success = false;
            }

            return(success);
        }