Exemple #1
0
        private void SourceBeforeProcessDataRow(ProcessRowEventArgs <ParserContext20> e)
        {
            e.Context.CurrentDataRow20 = new DataRow20 {
                Row = e.Row
            };
            e.Context.DataRows.Add(e.Context.CurrentDataRow20);
            var kvp = FindDataRowProcessorDefinition(_fileProcessorDefinition, e);

            var hasValidDataType = ValidateDataRowProcessorDefinition(e, kvp.Value, kvp.Key);

            if (!hasValidDataType)
            {
                e.Context.UndecodedDataRows.Add(e.Context.CurrentDataRow20);
                return;
            }

            var lineType = $"Data Row '{e.Context.CurrentDataRow20.DataType}'";
            var hasValidateNumerOfFields = ParsedDataProcessorHelper.ValidateNumerOfFields(lineType, e.Row, kvp.Value.RowProcessorDefinition);

            if (!hasValidateNumerOfFields)
            {
                e.Context.UndecodedDataRows.Add(e.Context.CurrentDataRow20);
                return;
            }

            e.Context.DecodedDataRows.Add(e.Context.CurrentDataRow20);
        }
        private void SourceBeforeProcessRow(object sender, ProcessRowEventArgs <ParserContext10> e)
        {
            DataProcessorGlobal.Debug($"Processing Row. Index: {e.Row.Index}, Raw Data: '{e.Row.Raw}'");

            string lineType;
            RowProcessorDefinition rowProcessorDefinition;

            if (IsHeaderRow(e.Row))
            {
                lineType = "Header Row";
                rowProcessorDefinition = _fileProcessorDefinition.HeaderRowProcessorDefinition;
                e.Context.Header       = e.Row;
                ParsedDataProcessorHelper.ValidateNumerOfFields(lineType, e.Row, rowProcessorDefinition);
                return;
            }

            if (IsTrailerRow(e.Context.IsCurrentRowTheLast))
            {
                lineType = "Trailer Row";
                rowProcessorDefinition = _fileProcessorDefinition.TrailerRowProcessorDefinition;
                e.Context.Trailer      = e.Row;
                ParsedDataProcessorHelper.ValidateNumerOfFields(lineType, e.Row, rowProcessorDefinition);
                return;
            }

            lineType = "Data Row";
            rowProcessorDefinition = _fileProcessorDefinition.DataRowProcessorDefinition;
            e.Context.DataRows.Add(e.Row);
            ParsedDataProcessorHelper.ValidateNumerOfFields(lineType, e.Row, rowProcessorDefinition);
        }
Exemple #3
0
        private static void ValidateProcessorDefinition(FileProcessorDefinition20 processorDefinition)
        {
            if (processorDefinition is null)
            {
                throw new ArgumentNullException(nameof(processorDefinition));
            }

            ParsedDataProcessorHelper.ValidateRowProcessorDefinition("Header", processorDefinition.HeaderRowProcessorDefinition);
            ParsedDataProcessorHelper.ValidateRowProcessorDefinition("Trailer", processorDefinition.TrailerRowProcessorDefinition);
            ValidateDataRowProcessorDefinitions(processorDefinition);
        }
        private void AfterProcessHeaderRow(ProcessRowEventArgs <ParserContext10> e)
        {
            if (!IsValidRow(e))
            {
                e.Context.Errors.Add("Header row is invalid");
                return;
            }

            if (_fileProcessorDefinition.CreateRowJsonEnabled)
            {
                ParsedDataProcessorHelper.SetJson(e.Row, _fileProcessorDefinition.HeaderRowProcessorDefinition.FieldProcessorDefinitions);
            }
        }
        private void AfterProcessDataRow(ProcessRowEventArgs <ParserContext10> e)
        {
            if (!IsValidRow(e))
            {
                e.Context.InvalidDataRows.Add(e.Row);
                return;
            }

            if (_fileProcessorDefinition.CreateRowJsonEnabled)
            {
                ParsedDataProcessorHelper.SetJson(e.Row, _fileProcessorDefinition.DataRowProcessorDefinition.FieldProcessorDefinitions);
            }
        }
Exemple #6
0
        private static void ValidateFieldRules(Field field, IFieldRule[] fieldRules)
        {
            if (fieldRules == null || fieldRules.Length == 0)
            {
                return;
            }

            var tempValidationResultType = field.ValidationResult;

            foreach (var fieldRule in fieldRules)
            {
                ProcessRule(field, fieldRule);
                tempValidationResultType = ParsedDataProcessorHelper.GetMaxValidationResult(tempValidationResultType, field.ValidationResult);
            }

            field.ValidationResult     = tempValidationResultType;
            field.Row.ValidationResult = ParsedDataProcessorHelper.GetMaxValidationResult(field.Row.ValidationResult, field.ValidationResult);
        }
        private void SourceAfterProcessRow(object sender, ProcessRowEventArgs <ParserContext10> e)
        {
            e.Context.ValidationResult = ParsedDataProcessorHelper.GetMaxValidationResult(e.Context.ValidationResult, e.Row.ValidationResult);
            if (e.Context.ValidationResult == ValidationResultType.Critical)
            {
                e.Context.IsAborted = true;
            }

            if (IsHeaderRow(e.Row))
            {
                AfterProcessHeaderRow(e);
                return;
            }

            if (IsTrailerRow(e.Context.IsCurrentRowTheLast))
            {
                AfterProcessTrailerRow(e);
                return;
            }

            AfterProcessDataRow(e);
        }
Exemple #8
0
        private static void DecodeField(string fieldName, string description, Field field, IFieldDecoder fieldDecoder)
        {
            DataProcessorGlobal.Debug($"Decoding Field: {fieldName}, Raw Value: '{field.Raw}'");
            fieldDecoder.Decode(field);

            if (field.ValidationResult == ValidationResultType.Valid)
            {
                return;
            }

            field.Row.ValidationResult = ParsedDataProcessorHelper.GetMaxValidationResult(field.Row.ValidationResult, field.ValidationResult);
            var message = $"Invalid {description} '{field.Raw}'";

            if (field.ValidationResult == ValidationResultType.Warning)
            {
                field.Row.Warnings.Add(message);
            }
            else
            {
                field.Row.Errors.Add(message);
            }
        }
        private void SourceProcessField(object sender, ProcessFieldEventArgs <ParserContext10> e)
        {
            if (e.Field.Row.ValidationResult == ValidationResultType.Critical)
            {
                return;
            }

            FieldProcessorDefinition fieldProcessorDefinition;

            if (e.Field.Row.Index == 0 && _hasHeader)
            {
                fieldProcessorDefinition = _fileProcessorDefinition.HeaderRowProcessorDefinition.FieldProcessorDefinitions[e.Field.Index];
            }
            else if (e.Context.IsCurrentRowTheLast && _hasTrailer)
            {
                fieldProcessorDefinition = _fileProcessorDefinition.TrailerRowProcessorDefinition.FieldProcessorDefinitions[e.Field.Index];
            }
            else
            {
                fieldProcessorDefinition = _fileProcessorDefinition.DataRowProcessorDefinition.FieldProcessorDefinitions[e.Field.Index];
            }

            ParsedDataProcessorHelper.ProcessField(fieldProcessorDefinition.Description, e.Field, fieldProcessorDefinition);
        }
Exemple #10
0
 private void BeforeProcessTrailerRow(ProcessRowEventArgs <ParserContext20> e)
 {
     e.Context.Trailer = e.Row;
     ParsedDataProcessorHelper.ValidateNumerOfFields("Trailer Row", e.Row, _fileProcessorDefinition.TrailerRowProcessorDefinition);
 }