Esempio n. 1
0
        /// <summary>
        /// Validates that the column header names match.
        /// </summary>
        /// <param name="fileFormat">The <see cref="FileFormatBase"/>.</param>
        /// <param name="record">The <see cref="FileRecord"/>.</param>
        void IFileRecord.OnRead(FileFormatBase fileFormat, FileRecord record)
        {
            var frr = CheckConfiguration(fileFormat, record);

            for (int i = 0; i < frr.Columns.Count; i++)
            {
                if (i >= record.Columns.Count)
                {
                    break;
                }

                if (StringComparer.OrdinalIgnoreCase.Compare(frr.Columns[i].Name, record.Columns[i]) != 0)
                {
                    record.Messages.Add(Entities.MessageType.Error, string.Format(System.Globalization.CultureInfo.InvariantCulture, "Column (position {0}) content '{1}' does not match the expected name '{2}'.", i + 1, record.Columns[i], frr.Columns[i].Name));
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Validates that the column header names match.
        /// </summary>
        /// <param name="fileFormat">The <see cref="FileFormatBase"/>.</param>
        /// <param name="record">The <see cref="FileRecord"/>.</param>
        void IFileRecord.OnRead(FileFormatBase fileFormat, FileRecord record)
        {
            var frr = CheckConfiguration(fileFormat, record);

            for (int i = 0; i < frr.Columns.Length; i++)
            {
                if (i >= record.Columns.Length)
                {
                    break;
                }

                if (StringComparer.OrdinalIgnoreCase.Compare(frr.Columns[i].Name, record.Columns[i]) != 0)
                {
                    record.Messages.Add(Entities.MessageType.Error, "Column (position {0}) content '{1}' does not match the expected name '{2}'.", i + 1, record.Columns[i], frr.Columns[i].Name);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Check the configuration is valid.
        /// </summary>
        private FileRecordReflector CheckConfiguration(FileFormatBase fileFormat, FileRecord record)
        {
            if (fileFormat.IsHierarchical)
            {
                throw new InvalidOperationException("The ColumnNameHeader cannot be used when the File Format is hierarchical.");
            }

            var frr = fileFormat.GetFileRecordReflector(fileFormat.ContentRowType);

            if (record.LineNumber != 1 || fileFormat.HeaderRowType == null || fileFormat.HeaderRowType != typeof(ColumnNameHeader))
            {
                throw new InvalidOperationException("The ColumnNameHeader can only be used for a Header row.");
            }

            if (record.Columns.Count != frr.Columns.Count)
            {
                record.Messages.Add(Entities.MessageType.Warning, "The number of Header columns '{0}' does not match that specified for the expected Content '{1}'.", record.Columns.Count, frr.Columns.Count);
            }

            return(frr);
        }
Esempio n. 4
0
        /// <summary>
        /// Writes the header record using the column names.
        /// </summary>
        /// <param name="fileFormat">The <see cref="FileFormatBase"/>.</param>
        /// <param name="record">The <see cref="FileRecord"/>.</param>
        void IFileRecord.OnWrite(FileFormatBase fileFormat, FileRecord record)
        {
            var frr = CheckConfiguration(fileFormat, record);
            var sb  = new StringBuilder();

            var cols = new List <string>();

            for (int i = 0; i < frr.Columns.Count; i++)
            {
                cols.Add(frr.Columns[i].Text);
            }

            record.Columns = cols;
            for (int i = 0; i < frr.Columns.Count; i++)
            {
                if (!fileFormat.WriteColumnToLineDataInternal(frr.Columns[i], record, i, sb))
                {
                    return;
                }
            }

            record.LineData = sb.ToString();
        }