Exemple #1
0
        /// <summary>
        /// Writes the indexed <paramref name="column"/> from the <paramref name="record"/> to the line data <see cref="StringBuilder"/>.
        /// </summary>
        /// <param name="fcr">The corresponding <see cref="FileColumnReflector"/> configuration.</param>
        /// <param name="record">The related <see cref="FileRecord"/>.</param>
        /// <param name="column">The column index.</param>
        /// <param name="sb">The line data <see cref="StringBuilder"/>.</param>
        /// <returns><c>true</c> indicates that the column write was successful; otherwise, <c>false</c>.</returns>
        protected override bool WriteColumnToLineData(FileColumnReflector fcr, FileRecord record, int column, StringBuilder sb)
        {
            Check.NotNull(fcr, nameof(fcr));
            Check.NotNull(sb, nameof(sb));

            // Get the string value and correct the width if needed.
            var str = column > Check.NotNull(record, nameof(record)).Columns.Count ? null : record.Columns[column];

            if (string.IsNullOrEmpty(str))
            {
                sb.Append(PaddingChar, fcr.FileColumn.Width);
            }
            else
            {
                // Validate/correct the string value to ensure column width conformance.
                if (!fcr.StringWidthCorrector(record, ref str))
                {
                    return(false);
                }

                sb.Append(str.PadRight(fcr.FileColumn.Width, PaddingChar));
            }

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NumberConverter{T}"/> class.
        /// </summary>
        public NumberConverter()
        {
            _typeCode = FileColumnReflector.GetTypeCode(typeof(T));
            switch (_typeCode)
            {
            case TypeCode.Decimal:
            case TypeCode.Double:
            case TypeCode.Int16:
            case TypeCode.Int32:
            case TypeCode.Int64:
            case TypeCode.Single:
            case TypeCode.Byte:
            case TypeCode.SByte:
            case TypeCode.UInt16:
            case TypeCode.UInt32:
            case TypeCode.UInt64:
                break;

            default:
                throw new InvalidOperationException("Type T must be a numeric Type.");
            }
        }
Exemple #3
0
        /// <summary>
        /// Writes the indexed <paramref name="column"/> from the <paramref name="record"/> to the line data <see cref="StringBuilder"/>.
        /// </summary>
        /// <param name="fcr">The corresponding <see cref="FileColumnReflector"/> configuration.</param>
        /// <param name="record">The related <see cref="FileRecord"/>.</param>
        /// <param name="column">The column index.</param>
        /// <param name="sb">The line data <see cref="StringBuilder"/>.</param>
        /// <returns><c>true</c> indicates that the column write was successful; otherwise, <c>false</c>.</returns>
        protected override bool WriteColumnToLineData(FileColumnReflector fcr, FileRecord record, int column, StringBuilder sb)
        {
            // Delimit each column.
            if (column > 0)
            {
                sb.Append(Delimiter);
            }

            // Get the string value and correct the width if needed.
            var str = column > record.Columns.Length ? null : record.Columns[column];

            // Override if it is the hierarchy column.
            if (HierarchyColumnIndex.HasValue && HierarchyColumnIndex.Value == column)
            {
                str = record.RecordIdentifier;
            }

            // Where null this means there is nothing specific to write.
            if (string.IsNullOrEmpty(str))
            {
                return(true);
            }

            // Validate/correct the string value to ensure column width conformance.
            if (!fcr.StringWidthCorrector(record, ref str))
            {
                return(false);
            }

            // Check if the column content contains the delimiter and handle accordingly.
            var qualify = fcr.PropertyTypeCode == TypeCode.String && TextQualifier != NoCharacter && !TextQualifierOnlyWithDelimiterOnWrite;

            if (str.IndexOf(Delimiter) >= 0)
            {
                if (TextQualifier == NoCharacter)
                {
                    record.Messages.Add(MessageType.Error, "Text delimiter character found inside column text; no text qualifier has been specified and would result in errant record.");
                    return(false);
                }
                else
                {
                    qualify = true;
                }
            }

            // Double qualify a qualifier inside of the text.
            if (TextQualifier != NoCharacter)
            {
                if (!qualify && str.IndexOf(TextQualifier) >= 0)
                {
                    qualify = true;
                }

                if (qualify)
                {
                    str = str.Replace(TextQualifier.ToString(), new string(TextQualifier, 2));
                }
            }

            if (qualify)
            {
                sb.Append(TextQualifier);
            }

            sb.Append(str);

            if (qualify)
            {
                sb.Append(TextQualifier);
            }

            return(true);
        }
Exemple #4
0
 /// <summary>
 /// Writes the indexed <paramref name="column"/> from the <paramref name="record"/> to the line data <see cref="StringBuilder"/>.
 /// </summary>
 /// <param name="fcr">The corresponding <see cref="FileColumnReflector"/> configuration.</param>
 /// <param name="record">The related <see cref="FileRecord"/>.</param>
 /// <param name="column">The column index.</param>
 /// <param name="sb">The line data <see cref="StringBuilder"/>.</param>
 /// <returns><c>true</c> indicates that the column write was successful; otherwise, <c>false</c>.</returns>
 /// <remarks>Implementers must use <see cref="FileColumnReflector"/> <see cref="FileColumnReflector.StringWidthCorrector(FileRecord, ref string)"/> to
 /// validate and correct the column string prior to updating the line data to ensure that the configured file and column formatting rules are adhered to.</remarks>
 protected abstract bool WriteColumnToLineData(FileColumnReflector fcr, FileRecord record, int column, StringBuilder sb);
Exemple #5
0
 /// <summary>
 /// Writes the indexed <paramref name="column"/> from the <paramref name="record"/> to the line data <see cref="StringBuilder"/>.
 /// </summary>
 /// <param name="fcr">The corresponding <see cref="FileColumnReflector"/> configuration.</param>
 /// <param name="record">The related <see cref="FileRecord"/>.</param>
 /// <param name="column">The column index.</param>
 /// <param name="sb">The line data <see cref="StringBuilder"/>.</param>
 /// <returns><c>true</c> indicates that the column write was successful; otherwise, <c>false</c>.</returns>
 /// <remarks>Implementers must use <see cref="FileColumnReflector"/> <see cref="FileColumnReflector.StringWidthCorrector(FileRecord, ref string)"/> to
 /// validate and correct the column string prior to updating the line data to ensure that the configured file and column formatting rules are adhered to.</remarks>
 internal bool WriteColumnToLineDataInternal(FileColumnReflector fcr, FileRecord record, int column, StringBuilder sb)
 {
     return(WriteColumnToLineData(fcr, record, column, sb));
 }