Esempio n. 1
0
        private string[] readNextLine()
        {
            string record = reader.ReadRecord();

            if (record.Length != schema.TotalWidth)
            {
                hasError = true;
                throw new FlatFileException(recordCount);
            }
            WindowCollection windows = schema.Windows;

            string[] values = new string[windows.Count];
            int      offset = 0;

            for (int index = 0; index != values.Length; ++index)
            {
                Window window = windows[index];
                string value  = record.Substring(offset, window.Width);
                if (window.Alignment == FixedAlignment.LeftAligned)
                {
                    value = value.TrimEnd(window.FillCharacter ?? options.FillCharacter);
                }
                else
                {
                    value = value.TrimStart(window.FillCharacter ?? options.FillCharacter);
                }
                values[index] = value;
                offset       += window.Width;
            }
            return(values);
        }
        private string[] partitionRecord(FixedLengthSchema schema, string record)
        {
            if (record.Length < schema.TotalWidth)
            {
                processError(new RecordProcessingException(metadata.RecordCount, Resources.FixedLengthRecordTooShort));
                return(null);
            }
            WindowCollection windows = schema.Windows;

            string[] values = new string[windows.Count - schema.ColumnDefinitions.MetadataCount];
            int      offset = 0;

            for (int index = 0; index != values.Length;)
            {
                var definition = schema.ColumnDefinitions[index];
                if (!(definition is IMetadataColumn metaColumn))
                {
                    Window window    = windows[index];
                    string value     = record.Substring(offset, window.Width);
                    var    alignment = window.Alignment ?? metadata.Options.Alignment;
                    if (alignment == FixedAlignment.LeftAligned)
                    {
                        value = value.TrimEnd(window.FillCharacter ?? metadata.Options.FillCharacter);
                    }
                    else
                    {
                        value = value.TrimStart(window.FillCharacter ?? metadata.Options.FillCharacter);
                    }
                    values[index] = value;
                    ++index;
                    offset += window.Width;
                }
            }
            return(values);
        }