Ejemplo n.º 1
0
        /// <summary>
        /// Get the <see cref="FileRecordReflector"/> for the specified <see cref="Type"/>.
        /// </summary>
        /// <param name="type">The <see cref="Type"/>.</param>
        /// <returns>The <see cref="FileRecordReflector"/>.</returns>
        public FileRecordReflector GetFileRecordReflector(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (_cache.ContainsKey(type))
            {
                return(_cache[type]);
            }

            var frf = new FileRecordReflector(type, this);

            lock (_lock)
            {
                if (_cache.ContainsKey(type))
                {
                    return(_cache[type]);
                }

                _cache.Add(type, frf);
                return(frf);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Compose the underlying children records.
 /// </summary>
 private void ComposeChildren(List <FileRecord> records, FileRecordReflector frf, FileRecord current)
 {
     foreach (var child in frf.Children)
     {
         var obj = child.GetValue(current.Value);
         if (child.IsCollection)
         {
             foreach (var item in (System.Collections.IEnumerable)obj)
             {
                 ComposeRecord(records, child.PropertyType, current.Level + 1, child.RecordIdentifier, item, true);
             }
         }
         else
         {
             ComposeRecord(records, child.PropertyType, current.Level + 1, child.RecordIdentifier, obj, true);
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Validates the record column count against the configuration (see <see cref="FileRecordReflector"/>).
        /// </summary>
        /// <param name="record">The <see cref="FileRecord"/>.</param>
        /// <param name="frr">The <see cref="FileRecordReflector"/>.</param>
        protected void ValidateColumnCount(FileRecord record, FileRecordReflector frr)
        {
            if (ColumnCountValidation == ColumnCountValidation.None || record.Columns.Length == frr.Columns.Length)
            {
                return;
            }

            if (record.Columns.Length < frr.Columns.Length)
            {
                switch (ColumnCountValidation)
                {
                case ColumnCountValidation.LessThanError:
                case ColumnCountValidation.LessAndGreaterThanError:
                    record.Messages.Add(MessageType.Error, LessColumnsThanExpectedFormat, record.Columns.Length, frr.Columns.Length);
                    break;

                case ColumnCountValidation.LessThanWarning:
                case ColumnCountValidation.LessAndGreaterThanWarning:
                    record.Messages.Add(MessageType.Warning, LessColumnsThanExpectedFormat, record.Columns.Length, frr.Columns.Length);
                    break;
                }
            }
            else
            {
                switch (ColumnCountValidation)
                {
                case ColumnCountValidation.GreaterThanError:
                case ColumnCountValidation.LessAndGreaterThanError:
                    record.Messages.Add(MessageType.Error, GreaterColumnsThanExpectedFormat, record.Columns.Length, frr.Columns.Length);
                    break;

                case ColumnCountValidation.GreaterThanWarning:
                case ColumnCountValidation.LessAndGreaterThanWarning:
                    record.Messages.Add(MessageType.Warning, GreaterColumnsThanExpectedFormat, record.Columns.Length, frr.Columns.Length);
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Validates the record column count against the configuration (see <see cref="FileRecordReflector"/>).
        /// </summary>
        /// <param name="record">The <see cref="FileRecord"/>.</param>
        /// <param name="frr">The <see cref="FileRecordReflector"/>.</param>
        protected void ValidateColumnCount(FileRecord record, FileRecordReflector frr)
        {
            if (ColumnCountValidation == ColumnCountValidation.None || Check.NotNull(record, nameof(record)).Columns.Count == Check.NotNull(frr, nameof(frr)).Columns.Count)
            {
                return;
            }

            if (record.Columns.Count < frr.Columns.Count)
            {
                switch (ColumnCountValidation)
                {
                case ColumnCountValidation.LessThanError:
                case ColumnCountValidation.LessAndGreaterThanError:
                    record.Messages.Add(MessageType.Error, LessColumnsThanExpectedFormat, record.Columns.Count, frr.Columns.Count);
                    break;

                case ColumnCountValidation.LessThanWarning:
                case ColumnCountValidation.LessAndGreaterThanWarning:
                    record.Messages.Add(MessageType.Warning, LessColumnsThanExpectedFormat, record.Columns.Count, frr.Columns.Count);
                    break;
                }
            }
            else
            {
                switch (ColumnCountValidation)
                {
                case ColumnCountValidation.GreaterThanError:
                case ColumnCountValidation.LessAndGreaterThanError:
                    record.Messages.Add(MessageType.Error, GreaterColumnsThanExpectedFormat, record.Columns.Count, frr.Columns.Count);
                    break;

                case ColumnCountValidation.GreaterThanWarning:
                case ColumnCountValidation.LessAndGreaterThanWarning:
                    record.Messages.Add(MessageType.Warning, GreaterColumnsThanExpectedFormat, record.Columns.Count, frr.Columns.Count);
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Perform the initial configuration.
        /// </summary>
        private void InitialConfiguration()
        {
            if (_fileFormat.FileValidation.HasFlag(FileValidation.MustHaveHeaderRow) && _fileFormat.HeaderRowType == null)
            {
                throw new InvalidOperationException("FileFormat specifies FileValidation with MustHaveHeaderRow; no corresponding HeaderRowType specified.");
            }

            if (_fileFormat.FileValidation.HasFlag(FileValidation.MustHaveTrailerRow) && _fileFormat.TrailerRowType == null)
            {
                throw new InvalidOperationException("FileFormat specifies FileValidation with MustHaveTrailerRow; no corresponding TrailerRowType specified.");
            }

            _contentReflector = _fileFormat.GetFileRecordReflector(_fileFormat.ContentRowType);
            if (_fileFormat.ContentValidator != null)
            {
                _contentReflector.SetValidator(_fileFormat.ContentValidator);
            }

            _hasHierarchy = _fileFormat.IsHierarchical && _contentReflector.Children.Length > 0;
            if (_hasHierarchy)
            {
                _hierarchy = FileRecordHierarchyItem.GetHierarchy(_fileFormat);
            }
        }