public static void ExportTo([NotNull] string path, [NotNull] [ItemNotNull] IEnumerable<CompetitionRunResult> runResults) { Guard.NotNullNorEmpty(path, nameof(path)); Guard.NotNull(runResults, nameof(runResults)); using (var textWriter = new StreamWriter(path)) { var settings = new DelimitedValuesWriterSettings { Culture = Settings.Default.ImportExportCulture }; using (var valuesWriter = new DelimitedValuesWriter(textWriter, ExportColumnNames, settings)) { foreach (CompetitionRunResult runResult in runResults) { using (IDelimitedValuesWriterRow row = valuesWriter.CreateRow()) { row.SetCell(ImportExportColumns.CompetitorNumber, runResult.Competitor.Number); row.SetCell(ImportExportColumns.HandlerName, runResult.Competitor.HandlerName); row.SetCell(ImportExportColumns.DogName, runResult.Competitor.DogName); row.SetCell(ImportExportColumns.CountryCode, runResult.Competitor.CountryCode); if (runResult.Timings != null) { SetTimeElapsedSinceStart(row, ImportExportColumns.IntermediateTime1, runResult, runResult.Timings.IntermediateTime1); SetTimeElapsedSinceStart(row, ImportExportColumns.IntermediateTime2, runResult, runResult.Timings.IntermediateTime2); SetTimeElapsedSinceStart(row, ImportExportColumns.IntermediateTime3, runResult, runResult.Timings.IntermediateTime3); SetTimeElapsedSinceStart(row, ImportExportColumns.FinishTime, runResult, runResult.Timings.FinishTime); } if (runResult.HasCompleted) { row.SetCell(ImportExportColumns.FaultCount, runResult.FaultCount); row.SetCell(ImportExportColumns.RefusalCount, runResult.RefusalCount); row.SetCell(ImportExportColumns.IsEliminated, runResult.IsEliminated); row.SetCell(ImportExportColumns.Placement, runResult.PlacementText); } } } } } }
/// <summary> /// Initializes a new instance of the <see cref="DelimitedValuesWriter" /> class. /// </summary> /// <param name="target"> /// The writer to write output to. /// </param> /// <param name="columnNames"> /// The column name, used to identify cell values. /// </param> /// <param name="settings"> /// Settings that customize the behavior of this instance. /// </param> public DelimitedValuesWriter(TextWriter target, ICollection <string> columnNames, DelimitedValuesWriterSettings?settings = null) { Guard.NotNull(target, nameof(target)); AssertValidColumnNames(columnNames); this.target = target; innerColumnNames = columnNames.ToList(); this.settings = settings?.Clone() ?? new DelimitedValuesWriterSettings(); effectiveCulture = this.settings.Culture ?? CultureInfo.InvariantCulture; effectiveFieldSeparator = GetEffectiveFieldSeparator(); charactersThatRequireEscaping = new[] { '\r', '\n', effectiveFieldSeparator, this.settings.TextQualifier }; }