Example #1
0
        /// <summary>
        /// Checks whether the record is valid when considered in context of the parent stack.
        /// </summary>
        private bool FindUpHierachy(FileRecordHierarchyItem item, FileRecord record)
        {
            if (item.Children.ContainsKey(record.RecordIdentifier))
            {
                return(true);
            }

            if (item.IsRoot)
            {
                return(false);
            }

            return(FindUpHierachy(item.Parent, record));
        }
Example #2
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);
            }
        }
Example #3
0
        /// <summary>
        /// Move/traverse up hierarchy for the item and confirm alignment with the hierarchy attribute configuration(s) and update the values accordingly.
        /// </summary>
        private FileRecordHierarchyLinker MoveUpHierarchy(FileRecordHierarchyLinker linker, FileRecordHierarchyItem from, FileRecordHierarchyItem to, FileRecord record, bool final = false)
        {
            if (from == null)
            {
                return(null);
            }

            if (!final && from == to)
            {
                return(linker);
            }

            foreach (var child in from.Children)
            {
                var fhr   = child.Value.HierarchyReflector;
                var fha   = child.Value.HierarchyReflector.FileHierarchy;
                var count = linker.GetChildCount(fhr.RecordIdentifier);

                // Validate alignment to configuration.
                if (fha.IsMandatory && count == 0)
                {
                    fhr.CreateErrorMessage(record, "{0} is required; no record found.");
                    continue;
                }

                // Minimum count check only honoured where at least one record found; otherwise, use IsMandatory to catch.
                if (fhr.IsCollection && count > 0 && fha.MinCount > 0 && count < fha.MinCount)
                {
                    fhr.CreateErrorMessage(record, "{0} must have at least {2} records(s); additional required.", fha.MinCount);
                }

                // Update the values as we move up the hierarchy.
                var vals = linker.GetChildValues(fhr.RecordIdentifier);
                fhr.SetValue(linker.Value, vals);
            }

            return(MoveUpHierarchy(linker.Parent, from.Parent, to, record, final));
        }