Beispiel #1
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);
        }
        /// <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);
        }