/// <summary>
        /// Initializes a new instance of the <see cref="DelimitedValuesReader" /> class.
        /// </summary>
        /// <param name="source">
        /// The reader that provides input.
        /// </param>
        /// <param name="settings">
        /// Settings that customize the behavior of this instance.
        /// </param>
        public DelimitedValuesReader(TextReader source, DelimitedValuesReaderSettings?settings = null)
        {
            Guard.NotNull(source, nameof(source));

            this.settings = settings?.Clone() ?? new DelimitedValuesReaderSettings();
            this.source   = source;
            enumerator    = new DelimitedValuesEnumerator(this);
        }
コード例 #2
0
        private static Dictionary<int, CompetitionRunResult> ImportRunResultsFrom([NotNull] string path)
        {
            DateTime currentTimeUtc = SystemContext.UtcNow();
            var imported = new Dictionary<int, CompetitionRunResult>();

            using (var textReader = new StreamReader(path))
            {
                var settings = new DelimitedValuesReaderSettings { Culture = Settings.Default.ImportExportCulture };
                using (var valuesReader = new DelimitedValuesReader(textReader, settings))
                {
                    AssertRequiredColumnsExist(valuesReader);
                    bool hasOptionalColumns = ContainsOptionalColumnNames(valuesReader);

                    foreach (IDelimitedValuesReaderRow row in valuesReader)
                    {
                        try
                        {
                            CompetitionRunResult runResult = GetRunResultFrom(row, hasOptionalColumns, currentTimeUtc);
                            imported[runResult.Competitor.Number] = runResult;
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(
                                $"Failed to read import file at row {valuesReader.LineNumber}: {ex.Message}", ex);
                        }
                    }
                }
            }

            return imported;
        }