/// <summary>
        /// Initialises a new instance of the <see cref="PositionEditorDialogViewModel"/> class.
        /// </summary>
        /// <param name="model">junior handicap model</param>
        /// <param name="commonIo">Common IO manager</param>
        public PositionEditorDialogViewModel(
            IModel model,
            ICommonIo commonIo)
        {
            this.model    = model;
            this.commonIo = commonIo;
            this.Barcodes = new ObservableCollection <PositionEditorRawItem>();
            this.MissingPositionTokens = new List <string>();
            this.barcodesIndex         = -1;

            this.OpenCommand =
                new SimpleCommand(
                    this.OpenFile,
                    this.CanOpenFile);
            this.SaveAsCommand =
                new SimpleCommand(
                    this.SaveAsFile,
                    this.CanSaveAsFile);

            this.UpCommand =
                new SimpleCommand(
                    this.MoveUp,
                    this.CanMoveUp);
            this.DeleteCommand =
                new SimpleCommand(
                    this.DeleteBarcode,
                    this.IsIndexValid);
            this.DownCommand =
                new SimpleCommand(
                    this.MoveDown,
                    this.CanMoveDown);
        }
Example #2
0
        /// <summary>
        /// Import the times from <paramref name="fileName"/>
        /// </summary>
        /// <param name="fileName">file containing times</param>
        /// <param name="commonIo">common IO manager</param>
        /// <returns>collection of race times.</returns>
        public static List <RaceTimeType> Import(
            string fileName,
            ICommonIo commonIo)
        {
            List <RaceTimeType> rawImportedTimes = new List <RaceTimeType>();
            List <string>       rawTimes         = commonIo.ReadFile(fileName);

            if (rawTimes == null ||
                rawTimes.Count == 0)
            {
                return(rawImportedTimes);
            }

            foreach (string line in rawTimes)
            {
                string rawTime = ImportParkrunTimerFactory.TranslateRawTime(line);

                List <int> timeDetails = ImportParkrunTimerFactory.TranslateTimeString(rawTime);

                if (timeDetails.Count != ImportParkrunTimerFactory.NumberOfSectionsInATime)
                {
                    continue;
                }

                rawImportedTimes.Add(
                    ImportParkrunTimerFactory.CalculateTime(
                        timeDetails[1],
                        timeDetails[2]));
            }

            return(rawImportedTimes);
        }
Example #3
0
        /// <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();
        }
Example #4
0
        /// <summary>
        /// Import the times from <paramref name="fileName"/>
        /// </summary>
        /// <param name="fileName">file containing times</param>
        /// <param name="commonIo">common Io manager</param>
        /// <returns>collection of race times.</returns>
        public static List <RaceTimeType> Import(
            string fileName,
            ICommonIo commonIo)
        {
            List <RaceTimeType> rawImportedTimes = new List <RaceTimeType>();
            List <string>       rawTimes         = commonIo.ReadFile(fileName);

            if (rawTimes == null ||
                rawTimes.Count < 3)
            {
                return(rawImportedTimes);
            }

            char splitChar = ',';

            for (int index = 2; index < rawTimes.Count; ++index)
            {
                string[] resultLine = rawTimes[index].Split(splitChar);
                if (resultLine.Length == 3)
                {
                    RaceTimeType time = new RaceTimeType(resultLine[2]);
                    rawImportedTimes.Add(time);
                }
            }

            return(rawImportedTimes);
        }
Example #5
0
        /// <summary>
        /// Import the times from <paramref name="fileName"/>
        /// </summary>
        /// <param name="fileName">file containing times</param>
        /// <param name="commonIo">common Io manager</param>
        /// <param name="logger">program logger</param>
        /// <returns>collection of race times.</returns>
        public static List <RawPositionResults> Import(
            string fileName,
            ICommonIo commonIo,
            IJHcLogger logger)
        {
            List <RawPositionResults> rawImportedPositions = new List <RawPositionResults>();
            List <string>             rawPositions         = commonIo.ReadFile(fileName);

            foreach (string positionAthleteData in rawPositions)
            {
                char splitChar = ',';

                string[] resultLine = positionAthleteData.Split(splitChar);

                // Ensure this line is not the first one and its valid.
                if (string.Equals(resultLine[0], StartString) ||
                    resultLine.Length != ImportParkrunPositionFactory.NumberOfSectionsInAValdEntry)
                {
                    continue;
                }

                // Ensure that the interesting data is not empty.
                if (string.IsNullOrEmpty(resultLine[0]) ||
                    string.IsNullOrEmpty(resultLine[1]) ||
                    !ResultsDecoder.IsPositionValue(resultLine[1]))
                {
                    continue;
                }

                int?position =
                    ResultsDecoder.ConvertPositionValue(
                        resultLine[1]);

                RawPositionResults result =
                    new RawPositionResults(
                        resultLine[0],
                        (int)position);

                rawImportedPositions.Add(result);
            }

            rawImportedPositions =
                rawImportedPositions
                .OrderBy(position => position.Position)
                .ToList();

            return(rawImportedPositions);
        }
Example #6
0
        /// <summary>
        /// Initialise a new instance of the <see cref="EventPaneViewModel"/> class.
        /// </summary>
        /// <param name="model">junior handicap model</param>
        /// <param name="businessLayerManager">business layer manager</param>
        /// <param name="generalIo">general IO manager</param>
        /// <param name="commonIo">common IO manager</param>
        /// <param name="logger">application logger</param>
        public EventPaneViewModel(
            IModel model,
            IBLMngr businessLayerManager,
            IGeneralIo generalIo,
            ICommonIo commonIo,
            IEventIo eventIo,
            IJHcLogger logger)
        {
            this.model = model;
            this.businessLayerManager = businessLayerManager;
            this.generalIo            = generalIo;
            this.commonIo             = commonIo;
            this.eventIo = eventIo;
            this.logger  = logger;

            this.seasonName = this.model.CurrentSeason.Name;

            // TODO, this.IsLocationValid has been copied from PrimaryDisplayViewModel. Can this be rationalised.
            NewEventCommand =
                new SimpleCommand(
                    this.EnableNewEventFields,
                    this.IsLocationValid);
            AddEventCommand =
                new SimpleCommand(
                    this.AddNewEvent,
                    this.NewEventValid);
            CancelEventCommand =
                new SimpleCommand(
                    this.CancelNewEventFields);

            OpenEventRawResultsDlgCommand =
                new SimpleCommand(
                    this.OpenEventRawResultsDialog,
                    this.IsLocationValid);
            OpenEventImportResultsDlgCommand =
                new SimpleCommand(
                    this.OpenEventImportResultsDialog,
                    this.IsLocationValid);
            CalculateResultsCommand =
                new SimpleCommand(
                    this.CalculateResults,
                    this.CanCalculateResults);

            this.InitialiseEventPane();

            Messenger.Default.Register <LoadNewSeasonMessage>(this, this.NewSeasonSelected);
        }
Example #7
0
        /// <summary>
        /// View model which manages raw results view.
        /// </summary>
        /// <param name="handicapEventModel">junior handicap model</param>
        /// <param name="athletesModel">athletes model</param>
        /// <param name="commonIo">common IO manager</param>
        /// <param name="logger">application logger</param>
        public EventRawResultsViewModel(
            IHandicapEvent handicapEventModel,
            Athletes athletesModel,
            ICommonIo commonIo,
            IJHcLogger logger)
        {
            this.handicapEventModel = handicapEventModel;
            this.athletesModel      = athletesModel;
            this.commonIo           = commonIo;
            this.logger             = logger;

            // Get the list of athletes registered for the current season from the Business layer.
            // This doesn't include the raw results, so read this directly from a file and add
            // to the the list.
            this.LoadRegisteredInformation(athletesModel.AthleteDetails);
            LoadRawEventResults();

            this.canSaveImported = false;
            this.importedState   = string.Empty;

            AddNewResultCommand =
                new SimpleCommand(
                    this.AddRawTimeCmd,
                    this.AddRawTimeCmdAvailable);
            SaveImportedResultsCommand =
                new SimpleCommand(
                    this.SaveImportResults,
                    this.CanSaveImported);
            SaveCommand =
                new SimpleCommand(
                    this.SaveRawResultsCmd,
                    this.SaveRawResultsCmdAvailable);
            ImportPositionsCommand =
                new SimpleCommand(
                    this.ImportPositionDataDialog);
            ImportTimesCommand =
                new SimpleCommand(
                    this.ImportTimesDataDialog);

            this.unregisteredAthletesIndex = -1;
        }
Example #8
0
        /// <summary>
        /// Import the times from <paramref name="fileName"/>
        /// </summary>
        /// <param name="fileName">file containing times</param>
        /// <param name="commonIo">common IO manager</param>
        /// <returns>collection of race times.</returns>
        public static List <RaceTimeType> Import(
            string fileName,
            ICommonIo commonIo)
        {
            List <RaceTimeType> rawImportedTimes = new List <RaceTimeType>();
            List <string>       rawTimes         = commonIo.ReadFile(fileName);

            if (rawTimes == null ||
                rawTimes.Count == 0)
            {
                return(rawImportedTimes);
            }

            foreach (string rawTime in rawTimes)
            {
                RaceTimeType time = new RaceTimeType(rawTime);
                rawImportedTimes.Add(time);
            }

            return(rawImportedTimes);
        }
        /// <summary>
        /// Import the times from <paramref name="fileName"/>
        /// </summary>
        /// <param name="fileName">file containing times</param>
        /// <param name="commonIo">common Io manager</param>
        /// <param name="logger">program logger</param>
        /// <returns>collection of race times.</returns>
        public static List <RawPositionResults> Import(
            string fileName,
            ICommonIo commonIo,
            IJHcLogger logger)
        {
            List <RawPositionResults> rawImportedPositions = new List <RawPositionResults>();
            List <List <string> >     rawPositions         = commonIo.ReadPairedStringListFomFile(fileName);

            foreach (List <string> positionAthleteData in rawPositions)
            {
                // Ensure 2 results present
                if (positionAthleteData.Count == 2)
                {
                    int?   position   = null;
                    string raceNumber = null;

                    string result1 = ResultsDecoder.OpnScannerResultsBarcode(positionAthleteData[0]);
                    string result2 = ResultsDecoder.OpnScannerResultsBarcode(positionAthleteData[1]);

                    UpdatePositionAthleteData(
                        result1,
                        ref position,
                        ref raceNumber);
                    UpdatePositionAthleteData(
                        result2,
                        ref position,
                        ref raceNumber);

                    if (position != null && raceNumber != null)
                    {
                        RawPositionResults results =
                            new RawPositionResults(
                                raceNumber,
                                (int)position);
                        rawImportedPositions.Add(results);
                    }
                    else
                    {
                        string errorString = $"Can't decode {positionAthleteData[0]}/{positionAthleteData[1]}";
                        HandicapProgressMessage message =
                            new HandicapProgressMessage(
                                errorString);

                        Messenger.Default.Send(
                            new HandicapProgressMessage(
                                errorString));

                        logger.WriteLog(errorString);
                    }
                }
                else
                {
                    string errorString = "Please check results, result/barcode pair invalid";
                    Messenger.Default.Send(
                        new HandicapProgressMessage(
                            errorString));
                    logger.WriteLog(errorString);
                }
            }

            rawImportedPositions =
                rawImportedPositions
                .OrderBy(position => position.Position)
                .ToList();

            return(rawImportedPositions);
        }