Is a free .NET Core (2.2) library to import or export data from fixed length, xml in strings. All configuration can be made using a Builder to describe a record.
This project is based on FileHelpers project.
https://www.nuget.org/packages/FileHelpers.Fluent/1.2.1.2
https://www.nuget.org/packages/FileHelpers.Fluent.Fixed/1.2.1.2
https://www.nuget.org/packages/FileHelpers.Fluent.Xml/1.0.0
- Fixed Layout Engine
- Basic type converters -
(January 12, 2019) - Read from files -
(January 12, 2019) - Write from files -
(January 12, 2019) - Fixed Layout Engine - Multiple Record Types -
(February 19, 2019) - Delimited layout Engine - (Delayed to April 16, 2019)
- Delimited layout Engine - Multiple Record Types - (Delayed to April 23, 2019)
- Fixed layout Engine - Master Detail - (Delayed to April 30, 2019)
- Delimited layout Engine - Master Detail - (Delayed to April 30, 2019)
- Xml layout Engine -
(March 17, 2019)
The code bellow will configure an FixedRecordDescriptor with 3 fields and transform a fixed string into an array of ExpandoObject's containing the following properties.
-
Name of string type
-
Doc of Int64 type
-
BirthDate of DateTime type
var descriptor = new FixedRecordDescriptor(); descriptor.AddField("Name") .SetLength(50) .SetTrimMode(TrimMode.Both); descriptor.AddField("Doc") .SetLength(14) .SetAlignMode(AlignMode.Left) .SetConverter(typeof(LongConverter)) .SetAlignChar('0'); descriptor.AddField("BirthDate") .SetLength(8) .SetConverter(typeof(DateTimeConverter)) .SetConverterFormat("yyyyMMdd"); var engine = new FluentFixedEngine(descriptor); var items = engine.ReadString("Harlen Naves 0000587065966319840330");
Will configure a FixedRecordDescriptor with 3 properties (Funtion, ArraySize and ArrayData). ArrayData field will represents an Array of objects described with a single property (DealId).
var descriptor = new FixedRecordDescriptor();
descriptor.AddField("Function")
.SetLength(3)
.SetAlignMode(AlignMode.Right)
.SetAlignChar('0');
descriptor.AddField("ArraySize")
.SetLength(4)
.SetAlignMode(AlignMode.Left)
.SetAlignChar('0')
.SetConverter(typeof(IntegerConverter));
var arrayDescriptor = descriptor.AddArray("ArrayData")
.SetArrayLength(500)
.SetArrayItemLength(10)
.SetAlign(true)
.SetAlignChar('0');
arrayDescriptor.AddField("DealId")
.SetLength(10)
.SetNullValue(string.Empty)
.SetAlignMode(AlignMode.Right)
.SetAlignChar('0');
var engine = new FluentFixedEngine(descriptor);
var items = engine.ReadString(
"0010025STOCKAPA17STOCKASS18STOCKASS17STOCKDIC18STOCKDIC17STOCKDIP18STOCKDIP17STOCKGOT18STOCKGOT17STOCKLUV18STOCKLUV17STOCKNOR18STOCKNOR17STOCKRIV18STOCKRIV17STOCKSUE18STOCKSUE17STOCKTRC18STOCKTRC17STOCKTRV18STOCKTRV17STOCKLAP18STOCKLAP17STOCKASC18STOCKASC17000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
All 0's will be ignored as an array item because the Align of field "ArrayData" is setted to true and AlignChar is '0'. If you want to consider all array positions just set Align of "ArrayData" as false.
The code bellow configures an FixedRecordDescriptor with 3 properties (Name, Doc and BirthDate) and Write all objects into an string. Every array position will be transformed into a single line.
var descriptor = new FixedRecordDescriptor();
descriptor.AddField("Name")
.SetLength(50)
.SetTrimMode(TrimMode.Both);
descriptor.AddField("Doc")
.SetLength(14)
.SetAlignMode(AlignMode.Left)
.SetAlignChar('0');
descriptor.AddField("BirthDate")
.SetLength(8)
.SetConverter(typeof(DateTimeConverter))
.SetConverterFormat("yyyyMMdd");
var engine = new FluentFixedEngine(descriptor);
var item = new ExpandoObject();
item.TryAdd("Name", "Harlen Naves");
item.TryAdd("Doc", 05870659663);
item.TryAdd("BirthDate", new DateTime(1984, 03, 30));
string line = engine.WriteString(new[] { item });
Will configure a FixedRecordDescriptor with 3 properties (Funtion, ArraySize and ArrayData). ArrayData field will represents an Array of objects described with a single property (DealId).
var descriptor = new FixedRecordDescriptor();
descriptor.AddField("Function")
.SetLength(3)
.SetAlignMode(AlignMode.Right)
.SetAlignChar('0');
descriptor.AddField("ArraySize")
.SetLength(4)
.SetAlignMode(AlignMode.Left)
.SetAlignChar('0')
.SetConverter(typeof(IntegerConverter));
var arrayDescriptor = descriptor.AddArray("ArrayData")
.SetArrayLength(500)
.SetArrayItemLength(10)
.SetAlign(true)
.SetAlignChar('0');
arrayDescriptor.AddField("DealId")
.SetLength(10)
.SetNullValue(string.Empty)
.SetAlignMode(AlignMode.Right)
.SetAlignChar('0');
FluentFixedEngine engine = descriptor.Build();
ExpandoObject item = new ExpandoObject();
item.TryAdd("Function", "001");
item.TryAdd("ArraySize", 25);
List<ExpandoObject> arrayData = new List<ExpandoObject>();
for (int i = 0; i < 25; i++)
{
ExpandoObject arrayItem = new ExpandoObject();
arrayItem.TryAdd("DealId", "STOCKASC" + i.ToString().PadLeft(2, '0'));
arrayData.Add(arrayItem);
}
item.TryAdd("ArrayData", arrayData);
string content = engine.WriteString(new[] { item });