private void ImportPilot(string[] record) { if (Competitions.Count() == 0) { throw new InvalidOperationException("Pilot import is not allowed when no competitions are defined"); } var number = int.Parse(record[1]); Pilot pilot; if (Pilots.Any(p => p.Number == number)) { pilot = Pilots.First(p => p.Number == number); } else { if (Tasks.Count() > 0) { throw new InvalidOperationException("Cannot add pilots when there are tasks defined"); } pilot = new Pilot() { Number = number }; Pilots.Add(pilot); } pilot.Name = record[2].Trim(); pilot.Country = (record.Length > 3) ? record[3].Trim() : ""; pilot.Balloon = (record.Length > 4) ? record[4].Trim() : ""; }
private void ImportResult(string[] record) { var auto = record[1].ToUpper().Trim() == "AUTO"; var taskNumber = int.Parse(record[2]); if (!Tasks.Any(t => t.Number == taskNumber)) { throw new InvalidOperationException("Inexistent task " + taskNumber.ToString()); } var pilotNumber = int.Parse(record[3]); if (!Pilots.Any(p => p.Number == pilotNumber)) { throw new InvalidOperationException("Inexistent pilot " + pilotNumber.ToString()); } var task = Tasks.First(t => t.Number == taskNumber); var pilotResult = task.PilotResults.First(pr => pr.Pilot.Number == pilotNumber); var result = auto ? pilotResult.AutoResultInfo : pilotResult.ManualResultInfo; var measure = ResultInfo.ParseMeasure(record[4]); var measurePenalty = ResultInfo.ParseMeasure(record[5]); var taskScorePenalty = int.Parse(record[6]); var competitionScorePenalty = int.Parse(record[7]); var infringedRules = record[8].Trim(); if (result.Measure != measure || result.MeasurePenalty != measurePenalty || result.TaskScorePenalty != taskScorePenalty || result.CompetitionScorePenalty != competitionScorePenalty || result.InfringedRules != infringedRules) { result.Measure = measure; result.MeasurePenalty = measurePenalty; result.TaskScorePenalty = taskScorePenalty; result.CompetitionScorePenalty = competitionScorePenalty; result.InfringedRules = infringedRules; task.Phases |= (auto ? CompletedPhases.AutoResults : CompletedPhases.ManualResults); task.ComputeScores(); } }