/// <summary> /// .ctor. Must be inherited. /// </summary> /// <param name="encoder">The <see cref="IFileParserEncoder">IFileParserEncoder</see> instance to use for encoding.</param> /// <param name="type">The <see cref="System.Type">type</see> of data the field contains.</param> /// <param name="name">The <see cref="System.String">name</see> of the field.</param> /// <param name="startPosition">The starting position of this field in the <see cref="IFileRecord">record</see> expressed as an /// <see cref="System.UInt32">unsigned integer</see>.</param> /// <param name="length">The field length expressed as an <see cref="System.UInt32">unsigned integer</see>.</param> /// <param name="format">The <see cref="FileFieldDataFormat">format</see> of the field.</param> public FileFieldBase(IFileParserEncoder encoder, Type type, string name, uint startPosition, uint length, FileFieldDataFormat format) { Encoder = encoder; Type = type; Name = name; StartPosition = startPosition; Length = length; DataFormat = format; }
/// <summary> /// .ctor. Creates a new instance of FileField. /// </summary> /// <param name="encoder">The <see cref="IFileParserEncoder">IFileParserEncoder</see> instance to use for encoding.</param> /// <param name="type">The <see cref="System.Type">type</see> of data the field contains.</param> /// <param name="name">The <see cref="System.String">name</see> of the field.</param> /// <param name="startPosition">The starting position of this field in the <see cref="IFileRecord">record</see> /// expressed as an <see cref="System.UInt32">unsigned integer</see>.</param> /// <param name="length">The field length expressed as an <see cref="System.UInt32">unsigned integer</see>.</param> /// <param name="format">The <see cref="FileFieldDataFormat">format</see> of the field.</param> public FileField(IFileParserEncoder encoder, Type type, string name, uint startPosition, uint length, FileFieldDataFormat format) { if (format == FileFieldDataFormat.Table) { throw new InvalidOperationException($"{IO.FileParser.Properties.Resources.ResourceManager.GetString("UnsupportedType")} : {format}"); } Encoder = encoder; Type = type; Name = name; StartPosition = startPosition; Length = length; DataFormat = format; }
/// <summary> /// Gets the <see cref="IFileLayout">layout</see> relevant to this object. /// </summary> /// <param name="encoder">The <see cref="IFileParserEncoder">encoder</see> to use. If null, the default (EBCDIC 2 ASCII) is used.</param> /// <returns>A <see cref="IFileLayout">layout</see> matching this object's properties.</returns> public IFileLayout GetFileLayout(IFileParserEncoder encoder = null) { IFileParserEncoder defEncoder = encoder ?? FileParserEncoder.GetDefaultEncoder(); IFileLayout result = new FileLayout(defEncoder) { Name = Name, OpenAsText = OpenAsText, RecordLength = RecordLength }; if (OpenAsText) { result.FillCharacter = FillCharacter; result.TextLineTerminator = TextLineTerminator; } else { result.FillByte = FillByte; } if (HeaderFields != null && HeaderFields.Length > 0) { System.Collections.Generic.List <IFileField> fields = new System.Collections.Generic.List <IFileField>(); foreach (SerializableField field in HeaderFields.OrderBy(x => x.StartPosition)) { fields.Add(field.GetField(defEncoder)); } result.HeaderRecord = new FileRecord(fields.ToArray()); } if (FooterFields != null && FooterFields.Length > 0) { System.Collections.Generic.List <IFileField> fields = new System.Collections.Generic.List <IFileField>(); foreach (SerializableField field in FooterFields.OrderBy(x => x.StartPosition)) { fields.Add(field.GetField(defEncoder)); } result.FooterRecord = new FileRecord(fields.ToArray()); } if (MasterFields != null && MasterFields.Length > 0) { System.Collections.Generic.List <IFileField> fields = new System.Collections.Generic.List <IFileField>(); foreach (SerializableField field in MasterFields.OrderBy(x => x.StartPosition)) { fields.Add(field.GetField(defEncoder)); } result.MasterFields = fields.ToArray(); } return(result); }
/// <summary> /// Gets the <see cref="IFileField">IFileField</see> layout definition for this object. /// </summary> /// <param name="encoder">The <see cref="IFileParserEncoder">encoder</see> to use. If null, the default (EBCDIC 2 ASCII) is used.</param> /// <returns>An <see cref="IFileField">IFileField</see> object utilizing this object's layout.</returns> public IFileField GetField(IFileParserEncoder encoder = null) { if (DataFormat == FileFieldDataFormat.Table) { throw new System.InvalidOperationException( $"{IO.FileParser.Properties.Resources.ResourceManager.GetString("UnsupportedType")}"); } IFileParserEncoder defEncoder = encoder ?? FileParserEncoder.GetDefaultEncoder(); System.Type type = System.Type.GetType(Type); if (DataFormat == FileFieldDataFormat.String) { return(new FileField(defEncoder, type, Name, StartPosition, Length, DataFormat) { RightAlign = RightAlign, BoolAsString = BoolAsString, FillCharacter = FillCharacter }); } else if (type == typeof(System.DateTime) || type == typeof(System.DateTime?)) { return(new FileField(defEncoder, Name, StartPosition, Length, DataFormat, YearFirst) { RightAlign = RightAlign, BoolAsString = BoolAsString, FillByte = FillByte, YearFirst = YearFirst }); } else { return(new FileField(defEncoder, Name, StartPosition, Length, DataFormat, Precision) { RightAlign = RightAlign, BoolAsString = BoolAsString, FillByte = FillByte }); } }
/// <summary> /// .ctor. Must be inherited. User for <see cref="System.Boolean">boolean</see> types with a <see cref="System.String">string</see> output. /// </summary> /// <param name="encoder">The <see cref="IFileParserEncoder">IFileParserEncoder</see> instance to use for encoding.</param> /// <param name="name">The <see cref="System.String">name</see> of the field.</param> /// <param name="startPosition">The starting position of this field in the <see cref="IFileRecord">record</see> expressed as an /// <see cref="System.UInt32">unsigned integer</see>.</param> /// <param name="length">The field length expressed as an <see cref="System.UInt32">unsigned integer</see>.</param> /// <param name="showAs"> /// Identifies how the <see cref="System.Boolean">boolean</see> value will be represented as a <see cref="System.String">string</see>. /// Length of 1 will only return the first <see cref="System.Char">character</see> of the expected <see cref="System.String">string</see>. /// </param> public FileField(IFileParserEncoder encoder, string name, uint startPosition, uint length, BooleanStringRepresentation showAs) : base(encoder, name, startPosition, length, showAs) { }
/// <summary> /// .ctor. Creates a new instance of FileField. Used for <see cref="System.DateTime">Date</see> <see cref="System.Type">types</see>. /// </summary> /// <param name="encoder">The <see cref="IFileParserEncoder">IFileParserEncoder</see> instance to use for encoding.</param> /// <param name="name">The <see cref="System.String">name</see> of the field.</param> /// <param name="startPosition">The starting position of this field in the <see cref="IFileRecord">record</see> /// expressed as an <see cref="System.UInt32">unsigned integer</see>.</param> /// <param name="length">The field length expressed as an <see cref="System.UInt32">unsigned integer</see>.</param> /// <param name="format">The <see cref="FileFieldDataFormat">format</see> of the field.</param> /// <param name="yearFirst">If <see cref="System.Boolean">true</see> it assumes the year is the first part of the string. /// Default is <see cref="System.Boolean">false</see>. /// Note: If the <see cref="System.String">string</see> contains a parsable date character ( / or - ) it will attempt to use /// <see cref="System.DateTime.TryParse(string, out System.DateTime)">TryParse</see> and return any successful result. /// If <see cref="System.DateTime.TryParse(string, out System.DateTime)">TryParse</see> fails it proceeds on to /// <see cref="System.String">string</see> parsing. /// </param> /// <param name="required">If <see cref="System.Boolean">true</see>, throw a <see cref="FieldException"></see> on a null result.</param> public FileField(IFileParserEncoder encoder, string name, uint startPosition, uint length, FileFieldDataFormat format, bool yearFirst, bool required = false) : base(encoder, name, startPosition, length, format, yearFirst, required) { }
/// <summary> /// .ctor. Must be inherited. Used for <see cref="System.DateTime">Date</see> <see cref="System.Type">types</see>. /// </summary> /// <param name="encoder">The <see cref="IFileParserEncoder">IFileParserEncoder</see> instance to use for encoding.</param> /// <param name="name">The <see cref="System.String">name</see> of the field.</param> /// <param name="startPosition">The starting position of this field in the <see cref="IFileRecord">record</see> expressed as an /// <see cref="System.UInt32">unsigned integer</see>.</param> /// <param name="length">The field length expressed as an <see cref="System.UInt32">unsigned integer</see>.</param> /// <param name="format">The <see cref="FileFieldDataFormat">format</see> of the field.</param> /// <param name="yearFirst">If <see cref="System.Boolean">true</see> it assumes the year is the first part of the string. Default is /// <see cref="System.Boolean">false</see>. /// Note: If the <see cref="System.String">string</see> contains a parsable date character ( / or - ) it will attempt to use /// <see cref="System.DateTime.TryParse(string, out System.DateTime)">TryParse</see> and return any successful result. /// If <see cref="System.DateTime.TryParse(string, out System.DateTime)">TryParse</see> fails it proceeds on to /// <see cref="System.String">string</see> parsing. /// </param> /// <param name="required">If <see cref="System.Boolean">true</see>, throw a <see cref="FieldException"></see> on a null result.</param> public FileFieldBase(IFileParserEncoder encoder, string name, uint startPosition, uint length, FileFieldDataFormat format, bool yearFirst, bool required = false) : this(encoder, required ? typeof(DateTime) : typeof(DateTime?), name, startPosition, length, format) { YearFirst = yearFirst; }
/// <summary> /// .ctor. Creates a new instance of FileLayout. /// </summary> /// <param name="encoder">The <see cref="IFileParserEncoder">IFileParserEncoder</see> instance to use for encoding.</param> public FileLayout(IFileParserEncoder encoder) { Encoder = encoder; }
/// <summary> /// .ctor. Creates a new instance of FileTable. /// </summary> /// <param name="encoder">The <see cref="IFileParserEncoder">IFileParserEncoder</see> instance to use for encoding.</param> /// <param name="name">The <see cref="System.String">name</see> of the table.</param> /// <param name="startPosition">The starting position of this table in the <see cref="IFileRecord">record</see> /// expressed as an <see cref="System.UInt32">unsigned integer</see>.</param> /// <param name="length">The field (table) length expressed as an <see cref="System.UInt32">unsigned integer</see>.</param> public FileTable(IFileParserEncoder encoder, string name, uint startPosition, uint length) : this(encoder) { StartPosition = startPosition; Length = length; Name = name; }
/// <summary> /// .ctor. Creates a new instance of FileTable. /// </summary> /// <param name="encoder">The <see cref="IFileParserEncoder">IFileParserEncoder</see> instance to use for encoding.</param> public FileTable(IFileParserEncoder encoder) { records = new List <IFileRecord>(); Encoder = encoder; }
/// <summary> /// .ctor. Creates a new instance of FileRecord. /// </summary> /// <param name="encoder">The <see cref="IFileParserEncoder">IFileParserEncoder</see> instance to utilize for processing.</param> public FileRecord(IFileParserEncoder encoder) : base(encoder) { invalids = new List <FieldException>(); }
/// <summary> /// Gets a <see cref="IFileParser">file parser</see> object extracted from this layouts properties. /// </summary> /// <param name="encoder">The <see cref="IFileParserEncoder">encoder</see> to use. If null, the default (EBCDIC 2 ASCII) is used.</param> /// <returns>A <see cref="IFileParser">parser</see> derived from this object's properties.</returns> public IFileParser GetParser(IFileParserEncoder encoder = null) { return(new FileParser(GetFileLayout(encoder))); }
/// <summary> /// .ctor. Must be inherited. Used for numeric <see cref="System.Decimal">(decimal)</see> <see cref="System.Type">types</see>. /// </summary> /// <param name="encoder">The <see cref="IFileParserEncoder">IFileParserEncoder</see> instance to use for encoding.</param> /// <param name="name">The <see cref="System.String">name</see> of the field.</param> /// <param name="startPosition">The starting position of this field in the <see cref="IFileRecord">record</see> expressed as an /// <see cref="System.UInt32">unsigned integer</see>.</param> /// <param name="length">The field length expressed as an <see cref="System.UInt32">unsigned integer</see>.</param> /// <param name="format">The <see cref="FileFieldDataFormat">format</see> of the field.</param> /// <param name="precision">The precision of the expected resultant as <see cref="System.Int16"/>short. Default is 0. /// The limitation is from logical reasons.</param> /// <param name="required">If <see cref="System.Boolean">true</see>, throw a <see cref="FieldException"></see> on a null result.</param> public FileFieldBase(IFileParserEncoder encoder, string name, uint startPosition, uint length, FileFieldDataFormat format, short precision, bool required = false) : this(encoder, required ? typeof(decimal) : typeof(decimal?), name, startPosition, length, format) { Precision = precision; }
/// <summary> /// .ctor. Creates a new instance of FileParser. /// </summary> /// <param name="encoder">The <see cref="IFileParserEncoder">IFileParserEncoder</see> instance to use for encoding.</param> public FileParser(IFileParserEncoder encoder) : base(encoder) { records = new List <IFileRecord>(); }
/// <summary> /// .ctor. Must be inherited. /// </summary> /// <param name="encoder">The <see cref="IFileParserEncoder">IFileParserEncoder</see> instance to use for encoding.</param> public FileParserBase(IFileParserEncoder encoder) : this() { Layout = new FileLayout(encoder); }
/// <summary> /// .ctor. Must be inherited. /// </summary> /// <param name="encoder">The <see cref="IFileParserEncoder">IFileParserEncoder</see> instance to utilize for processing.</param> public FileRecordBase(IFileParserEncoder encoder) { Encoder = encoder; }
/// <summary> /// .ctor. Must be inherited. User for <see cref="System.Boolean">boolean</see> types with a <see cref="System.String">string</see> output. /// </summary> /// <param name="encoder">The <see cref="IFileParserEncoder">IFileParserEncoder</see> instance to use for encoding.</param> /// <param name="name">The <see cref="System.String">name</see> of the field.</param> /// <param name="startPosition">The starting position of this field in the <see cref="IFileRecord">record</see> expressed as an /// <see cref="System.UInt32">unsigned integer</see>.</param> /// <param name="length">The field length expressed as an <see cref="System.UInt32">unsigned integer</see>.</param> /// <param name="showAs"> /// Identifies how the <see cref="System.Boolean">boolean</see> value will be represented as a <see cref="System.String">string</see>. /// Length of 1 will only return the first <see cref="System.Char">character</see> of the expected <see cref="System.String">string</see>. /// </param> public FileFieldBase(IFileParserEncoder encoder, string name, uint startPosition, uint length, BooleanStringRepresentation showAs) : this(encoder, typeof(bool?), name, startPosition, length, FileFieldDataFormat.String) { BoolAsString = showAs; }