Skip to content

Text Source

aprile.salvatore@gmail.com edited this page Feb 8, 2021 · 1 revision

This is a Source Task and allows to create an Text source work task. it's used to read information from text file and transform it into a transient object (for more details on Input/Output see How to work wiki page)

Input

Text Reader or filename. see below for more info about task configuration

Output

IEnumerable<IRow> result

This result represents an IEnumerable of IRow (for more details on Input/Output see How to work wiki page). The IEnumerable of IRow represents the read information from Text Reader/filename

How to use

The implementation of text source task is:

FlowBuilder builder = new FlowBuilder(_logger);
var flow = builder.Create("Text Source Work Task")
		  .Then(task => task.CreateTextSource()
			.From(filePath)
                        .ParseAsFixedColumns(fixColumn, false)
			.AddOtherField(() => "IsValid")
		  .Build())
	   .Build();
flow.Run();

Configuration

This task can be configurated in several way:

From(TextReader reader)

ITextSource From(TextReader reader);

you need to specify a text reader start to read a file. This field is Optional but you need to specify a text source (text reader or filename)

From(string file)

ITextSource From(string file);

you need to specify a filename to start to read a file. This field is Optional but you need to specify a text source (text reader or filename)

ParseAsFixedColumns

ITextSource ParseAsFixedColumns(int[] colWidths, bool useHeader);

This method is called to specify the witdh of the with a fixed length. You need to specify an array of number that represents the column width. the order of witdh specify the applied column: for example if you create an array int[3] {4,2,5}, the column 1 will have a width = 4, the column 2 will have a width = 2 and at the end the column 3 will have a wifth = 5. Moreover you can specify if the text contains an header.

This field is Optional but you need to specify a kind of parser (parser with fixed column or parser with a delimited char).

SkipWhen

ITextSource SkipWhen(Func<string, bool> func);

This is a function that is used to skip a row in base of a specific logic. This field is Optional

ParseAsDelimited(char delimiter, bool useHeader)

ITextSource ParseAsDelimited(char delimiter, bool useHeader);

This method is called to specify the delimiter char used in the text. Moreover you can specify if the text contains an header.

This field is Optional but you need to specify a kind of parser (parser with fixed column or parser with a delimited char).

ParseAsDelimited(char[] delimiters, bool useHeader)

ITextSource ParseAsDelimited(char[] delimiters, bool useHeader);

This method is called to specify the delimiter char array used in the text. You need to specify an array of different delimiter char. the order of delimiter specify the applied column: for example if you create an array char[3] {',','.',';'}, the column 1 will have as delimiter the "," char, the column 2 will have as delimiter the "." char and at the end the column 3 will have as delimiter the ";" char. Moreover you can specify if the text contains an header.

This field is Optional but you need to specify a kind of parser (parser with fixed column or parser with a delimited char).

ParseWith

ITextSource ParseWith(Func<string, IEnumerable<string>> lineSplitter, bool useHeader);

Specify a function that use a custom implementation to decide how to split the row. Moreover you can specify if the text contains an header. This field is Optional

AddOtherField

ITextSource AddOtherField(Func<string> fieldName);

This method allows to specify other adding field that will be inserted at the end of the IEnumerable<IRow> result object with null value. This feature is used to add a field that will be filled in the next specified task

Clone this wiki locally