示例#1
0
        public static void AddTransactionSetDetails(this InterchangeErrors errors, int tsNumber, string idCode, string ctrlNumber, bool updateExisting)
        {
            if (errors == null)
            {
                throw new ArgumentNullException("errors");
            }

            TransactionSetErrors transactionSetErrors = new TransactionSetErrors(tsNumber, idCode, ctrlNumber, new EdiSectionErrors());

            FunctionalGroupErrors functionalGroupErrors;

            if (errors.FunctionalGroupErrors.Count == 0)
            {
                // TODO: Handle this error condition properly - Need to consider scenario where ST segment appear before GS
                // this should be error since TransactionSetDetails should be added only after functionalGroup

                functionalGroupErrors = errors.CreateNewFunctionalGroupErrorInfo(-1, "---", "----");
            }
            else
            {
                functionalGroupErrors = errors.FunctionalGroupErrors.Last();
            }

            if (functionalGroupErrors.TransactionSetErrors.Count > 0 && updateExisting == true)
            {
                functionalGroupErrors.TransactionSetErrors.Clear();
            }

            functionalGroupErrors.TransactionSetErrors.Add(transactionSetErrors);
        }
示例#2
0
        public static void AddFieldError(this InterchangeErrors errors, string segmentName, string fieldName, int errorCode, string errorDescription, int segmentNo,
                                         int positionInSegment, string fieldValue, long startIndex, long endIndex, EdiErrorType errorType)
        {
            if (errors == null)
            {
                throw new ArgumentNullException("errors");
            }

            int    positionInField = -1;
            int    repetitionCount = 0;
            string refDesignator   = "";

            if (errors == null)
            {
                throw new ArgumentNullException("errors");
            }

            FieldError fieldError = new FieldError(string.Format("{0}-{1}", segmentName, fieldName), positionInSegment, positionInField,
                                                   repetitionCount, errorCode, errorDescription, segmentNo,
                                                   fieldValue, refDesignator, startIndex, endIndex, errorType);

            EdiSectionErrors ediSectionErrors = GetEdiSectionErrors(errors, segmentName);

            ediSectionErrors.FieldErrorList.Add(fieldError);
        }
示例#3
0
        public static void AddGenericError(this InterchangeErrors errors, string segmentName, int errorCode, string errorDescription, int segmentNo,
                                           long startIndex, long endIndex)
        {
            if (errors == null)
            {
                throw new ArgumentNullException("errors");
            }

            GenericError genericError = new GenericError(errorCode, errorDescription, segmentNo, segmentName, startIndex, endIndex);

            EdiSectionErrors ediSectionErrors = GetEdiSectionErrors(errors, segmentName);

            ediSectionErrors.GenericErrorList.Add(genericError);
        }
示例#4
0
        public static void AddSegmentError(this InterchangeErrors errors, string segmentName, int errorCode, string errorDescription,
                                           int segmentNumber, long startIndex, long endIndex, EdiErrorType errorType)
        {
            if (errors == null)
            {
                throw new ArgumentNullException("errors");
            }

            string       explicitLoopId = "";
            SegmentError segmentError   = new SegmentError(segmentName, segmentNumber, errorCode, errorDescription,
                                                           explicitLoopId, startIndex, endIndex, errorType);

            EdiSectionErrors ediSectionErrors = GetEdiSectionErrors(errors, segmentName);

            ediSectionErrors.SegmentErrorList.Add(segmentError);
        }
示例#5
0
        public static void AddFunctionalGroupDetails(this InterchangeErrors errors, int groupNumber, string idCode, string ctrlNumber, bool updateExisting)
        {
            if (errors == null)
            {
                throw new ArgumentNullException("errors");
            }

            FunctionalGroupErrors functionalGroupErrors = new FunctionalGroupErrors(groupNumber, idCode, ctrlNumber);

            if (errors.FunctionalGroupErrors.Count > 0 && updateExisting == true)
            {
                errors.FunctionalGroupErrors.Clear();
            }

            errors.FunctionalGroupErrors.Add(functionalGroupErrors);
        }
示例#6
0
        private static EdiSectionErrors GetEdiSectionErrors(InterchangeErrors errors, string segmentName)
        {
            EdiSectionErrors ediSectionErrors;

            switch (segmentName.ToUpper())
            {
            case "ISA":
            case "IEA":
                ediSectionErrors = errors.IsaIeaErrorList;
                break;

            case "GS":
            case "GE":
                // FunctionalGroupErrors will have at least 1 element when GS segment is parsed.
                // If we encounter error during GS segment itself then add error in ISaIeaErrorList
                if (errors.FunctionalGroupErrors.Count == 0)
                {
                    ediSectionErrors = errors.IsaIeaErrorList;
                }
                else
                {
                    ediSectionErrors = errors.FunctionalGroupErrors.Last().GsGeErrorList;
                }
                break;

            default:
                // FunctionalGroupErrors will have at least 1 element when GS segment is parsed.
                // Similararly TransactionSetErrors will have at least 1 element when ST segment is parsed.
                // If we encounter error during any segment and then check the order in reverse way
                if (errors.FunctionalGroupErrors.Count == 0)
                {
                    ediSectionErrors = errors.IsaIeaErrorList;
                }
                else if (errors.FunctionalGroupErrors.Last().TransactionSetErrors.Count == 0)
                {
                    ediSectionErrors = errors.FunctionalGroupErrors.Last().GsGeErrorList;
                }
                else
                {
                    ediSectionErrors = errors.FunctionalGroupErrors.Last().TransactionSetErrors.Last().TsErrorList;
                }
                break;
            }

            return(ediSectionErrors);
        }
        /// <summary>
        /// Construct DocumentFragment for leaf node parent and then create and attach leaf nodes to it.
        /// </summary>
        /// <param name="pluglet"></param>
        /// <param name="segmentDetails"></param>
        /// <param name="internalSegment"></param>
        /// <param name="ediDelimiters"></param>
        /// <param name="segmentStartIndex"></param>
        /// <param name="segmentEndIndex"></param>
        /// <param name="ediErrors"></param>
        /// <param name="error"></param>
        /// <returns></returns>
        public static DocumentFragment ConstructDocumentFragment(this IPluglet pluglet, string[] segmentDetails, bool internalSegment, Delimiters ediDelimiters,
                                                                 int segmentSeqNumber, long segmentStartIndex, long segmentEndIndex, ref InterchangeErrors ediErrors, out string error)
        {
            if (pluglet == null)
            {
                throw new ArgumentNullException("pluglet");
            }

            if (segmentDetails == null)
            {
                throw new ArgumentNullException("segmentDetails");
            }

            LoggerFactory.Logger.Info("PlugletExtensions.ConstructDocumentFragment", "Constructing {0} instance", pluglet.Tag);

            if (pluglet.Children == null)
            {
                error = string.Format("Pluglet {0} does not have childrens", pluglet.Name);
                return(null);
            }

            // -1 is required since SegmentDetails[0] is the SegmentName
            if (pluglet.Children.Count < segmentDetails.Length - 1)
            {
                error = string.Format("Document has {1} data elements, it is less than segment children count {2} as described in Spec",
                                      pluglet.Name, pluglet.Children.Count, segmentDetails.Length);
                return(null);
            }

            error = string.Empty;
            ++pluglet.CurrentOccurrences;
            DocumentFragment documentFragment = new DocumentFragment()
            {
                Pluglet        = pluglet,
                Children       = new List <IDocumentFragment>(),
                SequenceNumber = segmentSeqNumber,
                StartOffset    = segmentStartIndex,
                EndOffset      = segmentEndIndex,
            };

            int plugletNum = 0;
            DocumentFragment dataFragment;
            IPluglet         plugletChild;
            bool             validateValue;

            long currentSegmentFieldStartIndex = segmentStartIndex;

            //SegmentNum start from 1 since SegmentDetails[0] is Segment name
            int segmentNum = 1;

            // if this is internal segment (composite segment - segment handing data and segment as children) then
            // start segmentDetails from 0
            if (internalSegment == true)
            {
                segmentNum = 0;
            }

            EdiErrorType errorType = pluglet.IsIgnore ? EdiErrorType.Warning : EdiErrorType.Error;

            for (; segmentNum < segmentDetails.Length; segmentNum++, plugletNum++)
            {
                if (segmentNum != 0)
                {
                    currentSegmentFieldStartIndex += segmentDetails[segmentNum - 1].Length + 1;
                }

                validateValue = false;
                plugletChild  = pluglet.Children[plugletNum];

                if (plugletChild.PlugletType == PlugletType.Data)
                {
                    dataFragment = new DocumentFragment()
                    {
                        Parent  = documentFragment,
                        Pluglet = plugletChild,
                        Value   = segmentDetails[segmentNum],

                        /*SequenceNumber = segmentSeqNumber,
                         * StartOffset = currentSegmentFieldStartIndex,
                         * EndOffset = currentSegmentFieldStartIndex + segmentDetails[segmentNum].Length,*/
                    };

                    validateValue = true;
                }
                else if (plugletChild.PlugletType == PlugletType.Segment)
                {
                    if (string.IsNullOrEmpty(segmentDetails[segmentNum]) == false)
                    {
                        string segmentError = string.Empty;

                        string [] internalSegmentDetails = segmentDetails[segmentNum].Split((char)ediDelimiters.ComponentSeperator);

                        dataFragment = plugletChild.ConstructDocumentFragment(internalSegmentDetails, true, ediDelimiters, segmentSeqNumber, currentSegmentFieldStartIndex,
                                                                              currentSegmentFieldStartIndex + segmentDetails[segmentNum].Length, ref ediErrors, out segmentError);

                        if (string.IsNullOrEmpty(segmentError) == false)
                        {
                            if (string.IsNullOrEmpty(error) == true)
                            {
                                error = string.Format("ConstructDocumentSegmentInstance: Pluglet {0}: ", pluglet.Name);
                            }

                            error = string.Format("{0} Error constructing {1}: {2}", error, plugletChild.Name, segmentError);
                        }
                    }
                    else
                    {
                        dataFragment = new DocumentFragment()
                        {
                            Parent  = documentFragment,
                            Pluglet = plugletChild,
                            Value   = segmentDetails[segmentNum],
                        };
                    }
                }
                else
                {
                    error = string.Format("ConstructDocumentSegmentInstance: Error constructing SegmentInstance. Pluglet {0} is of type {1}",
                                          pluglet.Name, plugletChild.Name);
                    return(null);
                }

                if (validateValue == true && plugletChild.DataType != null && string.IsNullOrEmpty(segmentDetails[segmentNum]) == false)
                {
                    FieldError fieldError = plugletChild.DataType.ValidateValue(new StringBuilder(segmentDetails[segmentNum]));
                    if (fieldError != null)
                    {
                        if (string.IsNullOrEmpty(error) == true)
                        {
                            error = string.Format("ConstructDocumentSegmentInstance: Pluglet {0}: ", pluglet.Name);
                        }

                        error = string.Format("{0} Error data validation failed {1}: {2} ({3})", error, plugletChild.Name, fieldError.Description, fieldError.DataValue);

                        ediErrors.AddFieldError(segmentDetails[0], plugletChild.Tag, fieldError.ErrorCode, fieldError.Description, segmentSeqNumber, segmentNum, segmentDetails[segmentNum], currentSegmentFieldStartIndex,
                                                currentSegmentFieldStartIndex + segmentDetails[segmentNum].Length - 1, errorType);
                    }
                }

                //TODO: Add validation (extension method)
                documentFragment.Children.Add(dataFragment);

                if (string.IsNullOrEmpty(segmentDetails[segmentNum]) && plugletChild.IsMandatory == true)
                {
                    if (string.IsNullOrEmpty(error) == true)
                    {
                        error = string.Format("ConstructDocumentSegmentInstance: Pluglet {0}: ", pluglet.Name);
                    }

                    error = string.Format("{0} Child {1} is mandatory but missing", error, plugletChild.Name);

                    ediErrors.AddFieldError(segmentDetails[0], plugletChild.Tag, X12ErrorCode.DeMandatoryDataElementMissingCode,
                                            X12ErrorCode.GetDataElementErrorDescription(X12ErrorCode.DeMandatoryDataElementMissingCode), segmentSeqNumber, segmentNum, string.Empty,
                                            currentSegmentFieldStartIndex, currentSegmentFieldStartIndex, errorType);
                }
            }

            for (; segmentNum <= pluglet.Children.Count; segmentNum++, plugletNum++)
            {
                plugletChild = pluglet.Children[plugletNum];
                if (plugletChild.IsMandatory == true)
                {
                    if (string.IsNullOrEmpty(error) == true)
                    {
                        error = string.Format("ConstructDocumentSegmentInstance: Pluglet {0}: ", pluglet.Name);
                    }

                    error = string.Format("{0} Child {1} is mandatory but missing", error, plugletChild.Name);

                    ediErrors.AddFieldError(segmentDetails[0], plugletChild.Tag, X12ErrorCode.DeMandatoryDataElementMissingCode,
                                            X12ErrorCode.GetDataElementErrorDescription(X12ErrorCode.DeMandatoryDataElementMissingCode), segmentSeqNumber, segmentNum, string.Empty,
                                            currentSegmentFieldStartIndex, currentSegmentFieldStartIndex, errorType);
                }
            }

            return(documentFragment);
        }
示例#8
0
 public static void AddGenericError(this InterchangeErrors errors, string segmentName, int errorCode, string errorDescription, int segmentNo)
 {
     errors.AddGenericError(segmentName, errorCode, errorDescription, segmentNo, -1, -1);
 }