From c750830c9d7d6ce1854eb54eb478e9af2525aaf1 Mon Sep 17 00:00:00 2001 From: Leandro Fernandes Vieira Date: Sun, 8 Oct 2023 21:17:38 -0300 Subject: [PATCH] done --- .../Reader/VariableLengthReaderBuilder.cs | 4 +- .../VariableLengthReaderSequentialBuilder.cs | 4 +- .../Writer/VariableLengthWriterBuilder.cs | 4 +- .../VariableLengthWriterSequentialBuilder.cs | 4 +- .../FileReader/FixedLengthReaderExtensions.cs | 31 +++++++++++- .../Extensions/FileReader/ReaderCommon.cs | 10 ++-- .../VariableLengthReaderExtensions.cs | 28 +++++++++-- .../VariableLengthReaderRawExtensions.cs | 50 +++++++++++++++++-- .../Extensions/FileWriter/WriterExtensions.cs | 26 ++++++++++ 9 files changed, 141 insertions(+), 20 deletions(-) diff --git a/RecordParser/Builders/Reader/VariableLengthReaderBuilder.cs b/RecordParser/Builders/Reader/VariableLengthReaderBuilder.cs index 7248eff..1c6e702 100644 --- a/RecordParser/Builders/Reader/VariableLengthReaderBuilder.cs +++ b/RecordParser/Builders/Reader/VariableLengthReaderBuilder.cs @@ -15,7 +15,7 @@ public interface IVariableLengthReaderBuilder /// /// Creates the reader object using the registered mappings. /// - /// The text (usually a character) that delimits collumns and separate values. + /// The text (usually a character) that delimits columns and separate values. /// Culture that will be used in the library internal default parsers functions. /// Function that generates an instance of . /// @@ -86,7 +86,7 @@ public IVariableLengthReaderBuilder DefaultTypeConvert(FuncSpanT ex) /// /// Creates the reader object using the registered mappings. /// - /// The text (usually a character) that delimits collumns and separate values. + /// The text (usually a character) that delimits columns and separate values. /// Culture that will be used in the library internal default parsers functions. /// Function that generates an instance of . /// diff --git a/RecordParser/Builders/Reader/VariableLengthReaderSequentialBuilder.cs b/RecordParser/Builders/Reader/VariableLengthReaderSequentialBuilder.cs index 9f30356..3f9b884 100644 --- a/RecordParser/Builders/Reader/VariableLengthReaderSequentialBuilder.cs +++ b/RecordParser/Builders/Reader/VariableLengthReaderSequentialBuilder.cs @@ -10,7 +10,7 @@ public interface IVariableLengthReaderSequentialBuilder /// /// Creates the reader object using the registered mappings. /// - /// The text (usually a character) that delimits collumns and separate values. + /// The text (usually a character) that delimits columns and separate values. /// Culture that will be used in the library internal default parsers functions. /// Function that generates an instance of . /// @@ -98,7 +98,7 @@ public IVariableLengthReaderSequentialBuilder DefaultTypeConvert(FuncSpanT /// /// Creates the reader object using the registered mappings. /// - /// The text (usually a character) that delimits collumns and separate values. + /// The text (usually a character) that delimits columns and separate values. /// Culture that will be used in the library internal default parsers functions. /// Function that generates an instance of . /// diff --git a/RecordParser/Builders/Writer/VariableLengthWriterBuilder.cs b/RecordParser/Builders/Writer/VariableLengthWriterBuilder.cs index cf42cc4..f52ee6c 100644 --- a/RecordParser/Builders/Writer/VariableLengthWriterBuilder.cs +++ b/RecordParser/Builders/Writer/VariableLengthWriterBuilder.cs @@ -14,7 +14,7 @@ public interface IVariableLengthWriterBuilder /// /// Creates the writer object using the registered mappings. /// - /// The text (usually a character) that delimits collumns and separate values. + /// The text (usually a character) that delimits columns and separate values. /// Culture that will be used in the library internal default parsers functions. /// /// Culture passed will not be applied in custom parser functions registered by the user (neither for member or type). @@ -134,7 +134,7 @@ public IVariableLengthWriterBuilder DefaultTypeConvert(FuncSpanTIntBool /// /// Creates the writer object using the registered mappings. /// - /// The text (usually a character) that delimits collumns and separate values. + /// The text (usually a character) that delimits columns and separate values. /// Culture that will be used in the library internal default parsers functions. /// /// Culture passed will not be applied in custom parser functions registered by the user (neither for member or type). diff --git a/RecordParser/Builders/Writer/VariableLengthWriterSequentialBuilder.cs b/RecordParser/Builders/Writer/VariableLengthWriterSequentialBuilder.cs index 09f08ee..cdb7699 100644 --- a/RecordParser/Builders/Writer/VariableLengthWriterSequentialBuilder.cs +++ b/RecordParser/Builders/Writer/VariableLengthWriterSequentialBuilder.cs @@ -10,7 +10,7 @@ public interface IVariableLengthWriterSequentialBuilder /// /// Creates the writer object using the registered mappings. /// - /// The text (usually a character) that delimits collumns and separate values. + /// The text (usually a character) that delimits columns and separate values. /// Culture that will be used in the library internal default parsers functions. /// /// Culture passed will not be applied in custom parser functions registered by the user (neither for member or type). @@ -74,7 +74,7 @@ public class VariableLengthWriterSequentialBuilder : IVariableLengthWriterSeq /// /// Creates the writer object using the registered mappings. /// - /// The text (usually a character) that delimits collumns and separate values. + /// The text (usually a character) that delimits columns and separate values. /// Culture that will be used in the library internal default parsers functions. /// /// Culture passed will not be applied in custom parser functions registered by the user (neither for member or type). diff --git a/RecordParser/Extensions/FileReader/FixedLengthReaderExtensions.cs b/RecordParser/Extensions/FileReader/FixedLengthReaderExtensions.cs index 6062f15..4d83d8b 100644 --- a/RecordParser/Extensions/FileReader/FixedLengthReaderExtensions.cs +++ b/RecordParser/Extensions/FileReader/FixedLengthReaderExtensions.cs @@ -8,14 +8,30 @@ namespace RecordParser.Extensions.FileReader { public class FixedLengthReaderOptions { + /// + /// Options to configure parallel processing + /// public ParallelOptions ParallelOptions { get; set; } + /// + /// Parse function which transforms text to object + /// public FuncSpanT Parser { get; set; } } public static class FixedLengthReaderExtensions { private const bool HasHeader = false; - + + /// + /// Reads the records (i.e., lines) from a fixed length file then parses each record + /// from text to object. + /// + /// type of objects read from file + /// fixed length file + /// options to configure the parsing + /// + /// Sequence of records. + /// public static IEnumerable GetRecords(this TextReader reader, FixedLengthReaderOptions options) { var func = () => new RowByLine(reader, Length); @@ -28,6 +44,19 @@ public static IEnumerable GetRecords(this TextReader reader, FixedLengthRe : GetRecordsSequential(parser, func, HasHeader); } + /// + /// Reads the records (i.e., lines) from a fixed length file. + /// The records are returned in the order they are in the file + /// + /// fixed length file + /// + /// Sequence of records. + /// + /// + /// The ReadOnlyMemory instances representing the records points to regions of the internal buffer used to read the file. + /// Store ReadOnlyMemory values will not hold record's values since the content of the buffer changes + /// as it goes forward through the file + /// public static IEnumerable> GetRecords(this TextReader reader) { return GetRecordsSequential((memory, i) => memory, () => new RowByLine(reader, Length), HasHeader); diff --git a/RecordParser/Extensions/FileReader/ReaderCommon.cs b/RecordParser/Extensions/FileReader/ReaderCommon.cs index 68381d2..2fe6c3f 100644 --- a/RecordParser/Extensions/FileReader/ReaderCommon.cs +++ b/RecordParser/Extensions/FileReader/ReaderCommon.cs @@ -10,25 +10,29 @@ public class ParallelOptions { /// /// Indicates if the processing should be performed - /// in a parallel instead of sequential. + /// in parallel instead of sequential. + /// Default value is true. /// public bool Enabled { get; set; } = true; /// /// Indicates if the original ordering of records must be maintained. + /// Default value is true. /// public bool EnsureOriginalOrdering { get; set; } = true; /// /// Maximum number of concurrently executing tasks /// that will be used to process the records. + /// Default value is null. /// - public int? MaxDegreeOfParallelism { get; set; } + public int? MaxDegreeOfParallelism { get; set; } = null; /// /// The CancellationToken to associate with the parallel processing. + /// Default value is null. /// - public CancellationToken? CancellationToken { get; set; } + public CancellationToken? CancellationToken { get; set; } = null; } internal static class ReaderCommon diff --git a/RecordParser/Extensions/FileReader/VariableLengthReaderExtensions.cs b/RecordParser/Extensions/FileReader/VariableLengthReaderExtensions.cs index 608b471..62f7e6d 100644 --- a/RecordParser/Extensions/FileReader/VariableLengthReaderExtensions.cs +++ b/RecordParser/Extensions/FileReader/VariableLengthReaderExtensions.cs @@ -9,14 +9,36 @@ namespace RecordParser.Extensions.FileReader { public class VariableLengthReaderOptions { - public bool HasHeader { get; set; } - public bool ContainsQuotedFields { get; set; } + /// + /// Indicates if there is a header record present in the reader's content. + /// If true, the first record (the header) will be skipped. + /// Default value is false, so nothing is skipped by default. + /// + public bool HasHeader { get; set; } = false; + /// + /// Indicates if there are any quoted field in the reader's content. + /// Default value is true. + /// + public bool ContainsQuotedFields { get; set; } = true; + /// + /// Options to configure parallel processing + /// public ParallelOptions ParallelOptions { get; set; } - // TODO create ParallelOptionsSafe } public static class VariableLengthReaderExtensions { + /// + /// Reads the records from a variable length file then parses each record + /// from text to object + /// + /// type of objects read from file + /// variable length file + /// parse reader + /// options to configure the parsing + /// + /// Sequence of records from the file + /// public static IEnumerable GetRecords(this TextReader stream, IVariableLengthReader reader, VariableLengthReaderOptions options) { Func func = options.ContainsQuotedFields diff --git a/RecordParser/Extensions/FileReader/VariableLengthReaderRawExtensions.cs b/RecordParser/Extensions/FileReader/VariableLengthReaderRawExtensions.cs index 7053b4c..f431910 100644 --- a/RecordParser/Extensions/FileReader/VariableLengthReaderRawExtensions.cs +++ b/RecordParser/Extensions/FileReader/VariableLengthReaderRawExtensions.cs @@ -16,14 +16,43 @@ namespace RecordParser.Extensions.FileReader public class VariableLengthReaderRawOptions { - public bool HasHeader { get; set; } - public bool ContainsQuotedFields { get; set; } - public bool Trim { get; set; } - + /// + /// Indicates if there is a header record present in the reader's content. + /// If true, the first record (the header) will be skipped. + /// Default value is false, so nothing is skipped by default. + /// + public bool HasHeader { get; set; } = false; + + /// + /// Indicates if there are any quoted field in the reader's content. + /// Default value is true. + /// + public bool ContainsQuotedFields { get; set; } = true; + + /// + /// Indicates if field's values should be trimmed. + /// Default value is false. + /// + public bool Trim { get; set; } = false; + + /// + /// Indicates how many columns each record has. + /// public int ColumnCount { get; set; } - // TODO change to char + + /// + /// The character that delimits columns and separate values. + /// public char Separator { get; set; } + + /// + /// Options to configure parallel processing + /// public ParallelOptions ParallelOptions { get; set; } + + /// + /// Factory for string pool instances. + /// public Func StringPoolFactory { get; set; } } @@ -62,6 +91,17 @@ private static Get BuildRaw(int collumnCount, bool hasTransform, bool trim) return final.Compile(); } + /// + /// Reads the records from a variable length file then parses each record + /// to object by accessing each field's value by index. + /// + /// type of objects read from file + /// variable length file + /// options to configure the parsing + /// parser that receives a function that returns field's value by index + /// + /// Sequence of records from the file + /// public static IEnumerable GetRecordsRaw(this TextReader stream, VariableLengthReaderRawOptions options, Func, T> reader) { var get = BuildRaw(options.ColumnCount, options.StringPoolFactory != null, options.Trim); diff --git a/RecordParser/Extensions/FileWriter/WriterExtensions.cs b/RecordParser/Extensions/FileWriter/WriterExtensions.cs index 2cb4832..a7e92de 100644 --- a/RecordParser/Extensions/FileWriter/WriterExtensions.cs +++ b/RecordParser/Extensions/FileWriter/WriterExtensions.cs @@ -8,17 +8,43 @@ namespace RecordParser.Extensions.FileWriter { using RecordParser.Extensions.FileReader; + /// + /// Delegate representing object to text convert method. + /// + /// Instance type + /// Instance that will be turn into text + /// Destination buffer + /// Count of chars written + /// + /// True if the writting was succeeded, otherwise false. + /// public delegate bool TryFormat(T instance, Span destination, out int charsWritten); public static class WriterExtensions { private const int initialPow = 10; + /// + /// Writes the elements of a sequence into the . + /// + /// Type of items in the sequence. + /// The TextWriter where the items will be written into. + /// Sequence of the elements. + /// Delegate that parses element into text. public static void Write(this TextWriter textWriter, IEnumerable items, TryFormat tryFormat) { Write(textWriter, items, tryFormat, new ParallelOptions()); } + + /// + /// Writes the elements of a sequence into the . + /// + /// Type of items in the sequence. + /// The TextWriter where the items will be written into. + /// Sequence of the elements. + /// Delegate that parses element into text. + /// Options to configure parallel processing. public static void Write(this TextWriter textWriter, IEnumerable items, TryFormat tryFormat, ParallelOptions options) { if (options.Enabled)