예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="X12SegmentParser"/> class.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <param name="loadSegmentSpec">if <c>true</c> then load spec for each segment (slower)</param>
 /// <param name="throwExceptionOnSyntaxErrors">if set to <c>true</c> [throw exception on syntax errors].</param>
 /// <exception cref="System.ArgumentNullException">reader</exception>
 public X12SegmentParser(X12TextReader reader, bool loadSegmentSpec = true, bool throwExceptionOnSyntaxErrors = true)
 {
     if (reader == null) throw new ArgumentNullException("reader");
     ThrowExceptionOnSyntaxErrors = throwExceptionOnSyntaxErrors;
     Reader = reader;
     Interchange = reader.IsaSegment;
     _delimiterSet = Reader.Delimiters;
     _loadSegmentSpec = loadSegmentSpec;
 }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="X12TextReader"/> class.
        /// </summary>
        /// <param name="input">The TextReader containing the X12 data to read.</param>
        /// <exception cref="ArgumentException"/>
        public X12TextReader(TextReader input)
        {
            if (input == null) throw new ArgumentNullException("input");
            _reader = input;
            _stringBuilder = new ThreadLocal<StringBuilder>(() => new StringBuilder(32));

            var header = ReadX12Header();
            Delimiters = new X12DelimiterSet(header);
            IsaSegment = new X12Interchange(new string(header), Delimiters);
        }
예제 #3
0
        private X12Segment CreateSegment(string segment)
        {
            var id = segment.Substring(0, segment.IndexOf(_delimiterSet.ElementSeparator));
            _indexCounter++;
            Counter++;

            switch (id)
            {
                case "ISA": // Interchange Start
                    if (Interchange != null)
                        ParseError(segment, "Only one ISA segment is allowed.");
                    _delimiterSet = new X12DelimiterSet(segment.ToCharArray());
                    return (_parentSegment = Interchange = new X12Interchange(segment, _delimiterSet));

                case "GS": // Function Group Start
                    if (Interchange == null)
                        ParseError(segment, "Segment '{0}' cannot occur before an ISA segment.", segment);
                    return (_parentSegment = FunctionalGroup = new X12FunctionalGroup(segment, _delimiterSet, Interchange));

                case "ST": // Start Transaction Set
                    if (FunctionalGroup == null)
                        ParseError(segment, "segment '{0}' cannot occur without a preceding GS segment.", segment);
                    TransactionSet = new X12TransactionSet(segment, _delimiterSet, FunctionalGroup);
                    if (FunctionalGroup != null) TransactionSet.Specification =
                        SpecificationLocator.FindTransactionSpec(TransactionSet.IdentifierCode, FunctionalGroup.VersionIdentifierCode);
                    _indexCounter = 0;
                    return _parentSegment = TransactionSet;

                case "SE": // End Transaction Set
                    if (TransactionSet == null)
                        ParseError(segment, "Segment '{0}' does not have a matching ST segment preceding it.", segment);
                    _parentSegment = FunctionalGroup;
                    return new X12TransactionSetTrailer(segment, _delimiterSet, TransactionSet);

                case "GE": // End Functional Specification
                    if (FunctionalGroup == null)
                        ParseError(segment, "Segment '{0}' does not have a matching GS segment precending it.", segment);
                    _parentSegment = Interchange;
                    return new X12FunctionalGroupTrailer(segment, _delimiterSet, FunctionalGroup);

                case "ISE": // End Interchange
                    if (Interchange == null)
                        ParseError(segment, "Segment '{0}' does not have a matching ISA segment preceding it.", segment);
                    _parentSegment = null;
                    return new X12InterchangeTrailer(segment, _delimiterSet, Interchange);

                default:
                    var spec = (_loadSegmentSpec && FunctionalGroup != null)
                                    ? SpecificationLocator.GetSegmentSpec(FunctionalGroup.VersionIdentifierCode, id)
                                    : null;
                    return new X12Segment(segment, _delimiterSet, spec, _parentSegment);
            }
        }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="X12Interchange"/> class.
 /// </summary>
 /// <param name="isaSegment">The isa segment.</param>
 /// <param name="delimiterSet">The delimiter set.</param>
 public X12Interchange(string isaSegment, X12DelimiterSet delimiterSet)
     : base(isaSegment, delimiterSet)
 {
     // ISA Segment is fixed size so trim each element field
     for (var i = 0; i < Elements.Length; i++) Elements[i] = Elements[i].TrimEnd();
 }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="X12TransactionSet" /> class.
 /// </summary>
 /// <param name="segment">The segment.</param>
 /// <param name="delimiterSet">The delimiter set.</param>
 /// <param name="parentFunctionalGroup">The parent functional group.</param>
 public X12TransactionSet(string segment, X12DelimiterSet delimiterSet, X12FunctionalGroup parentFunctionalGroup)
     : base(segment, delimiterSet, null, parentFunctionalGroup)
 {
     ParentFunctionalGroup = parentFunctionalGroup;
 }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="X12FunctionalGroup" /> class.
 /// </summary>
 /// <param name="gsSegment">The gs segment.</param>
 /// <param name="delimiterSet">The delimiter set.</param>
 /// <param name="parentInterchange">The parent interchange.</param>
 public X12FunctionalGroup(string gsSegment, X12DelimiterSet delimiterSet, X12Interchange parentInterchange)
     : base(gsSegment, delimiterSet, null, parentInterchange)
 {
     ParentInterchange = parentInterchange;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="X12FunctionalGroupTrailer" /> class.
 /// </summary>
 /// <param name="gsSegment">The gs segment.</param>
 /// <param name="delimiterSet">The delimiter set.</param>
 /// <param name="parentFunctionalGroup">The parent functional group.</param>
 public X12FunctionalGroupTrailer(string gsSegment, X12DelimiterSet delimiterSet, X12FunctionalGroup parentFunctionalGroup)
     : base(gsSegment, delimiterSet)
 {
     ParentFunctionalGroup = parentFunctionalGroup;
 }