Example #1
0
        /// <summary>pass in a whole segment (of type other than MSH), including message type
        /// at the start, according to encodingChars, and we'll parse the contents and
        /// put them in props.
        /// </summary>
        protected internal static void  parseSegmentWhole(System.Collections.Specialized.NameValueCollection props, System.Collections.IDictionary segmentId2nextRepIdx, System.Collections.ArrayList msgMask, NuGenEncodingCharacters encodingChars, System.String segment)
        {
            try
            {
                System.String segmentId = segment.Substring(0, (3) - (0));

                int currentSegmentRepIdx = 0;
                if (segmentId2nextRepIdx.Contains(segmentId))
                {
                    currentSegmentRepIdx = ((System.Int32)segmentId2nextRepIdx[segmentId]);
                }
                else
                {
                    currentSegmentRepIdx = 0;
                }
                segmentId2nextRepIdx[segmentId] = (System.Int32)(currentSegmentRepIdx + 1);

                // will only bother to parse this segment if any of it's contents will
                // be dumped to props.
                bool           parseThisSegment     = false;
                NuGenDatumPath segmentIdAsDatumPath = (new NuGenDatumPath()).add(segmentId);
                for (System.Collections.IEnumerator maskIt = msgMask.GetEnumerator(); !parseThisSegment && maskIt.MoveNext();)
                {
                    parseThisSegment = segmentIdAsDatumPath.startsWith((NuGenDatumPath)(maskIt.Current));
                }
                for (System.Collections.IEnumerator maskIt = msgMask.GetEnumerator(); !parseThisSegment && maskIt.MoveNext();)
                {
                    parseThisSegment = ((NuGenDatumPath)(maskIt.Current)).startsWith(segmentIdAsDatumPath);
                }

                if (parseThisSegment && (segment[3] == encodingChars.FieldSeparator))
                {
                    ER7SegmentHandler handler = new ER7SegmentHandler();
                    handler.m_props         = props;
                    handler.m_encodingChars = encodingChars;
                    handler.m_segmentId     = segmentId;
                    if (msgMask != null)
                    {
                        handler.m_msgMask = msgMask;
                    }
                    else
                    {
                        handler.m_msgMask = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
                        handler.m_msgMask.Add(new NuGenDatumPath());                         // everything will pass this
                        // (every DatumPath startsWith the zero-length DatumPath)
                    }
                    handler.m_segmentRepIdx = currentSegmentRepIdx;

                    System.Collections.ArrayList nodeKey = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
                    nodeKey.Add(0);
                    parseSegmentGuts(handler, segment.Substring(4), nodeKey);
                }
            }
            catch (System.NullReferenceException)
            {
            }
            catch (System.IndexOutOfRangeException)
            {
            }
        }
Example #2
0
        /// <summary>given segment, starting with "MSH", then encoding characters, etc...
        /// put MSH[0]-1[0]-1-1 (== MSH-1) and MSH[0]-2[0]-1-1 (== MSH-2) into props, if found,
        /// plus everything else found in 'segment'
        /// </summary>
        protected internal static bool parseMSHSegmentWhole(System.Collections.Specialized.NameValueCollection props, System.Collections.ArrayList msgMask, NuGenEncodingCharacters encodingChars, System.String segment)
        {
            bool ret = false;

            try
            {
                ER7SegmentHandler handler = new ER7SegmentHandler();
                handler.m_props         = props;
                handler.m_encodingChars = encodingChars;
                handler.m_segmentId     = "MSH";
                handler.m_segmentRepIdx = 0;
                if (msgMask != null)
                {
                    handler.m_msgMask = msgMask;
                }
                else
                {
                    handler.m_msgMask = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
                    handler.m_msgMask.Add(new NuGenDatumPath());                     // everything will pass this
                    // (every DatumPath startsWith the zero-length DatumPath)
                }

                encodingChars.FieldSeparator = segment[3];
                System.Collections.ArrayList nodeKey = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
                nodeKey.Add(0);
                handler.putDatum(nodeKey, System.Convert.ToString(encodingChars.FieldSeparator));
                encodingChars.ComponentSeparator    = segment[4];
                encodingChars.RepetitionSeparator   = segment[5];
                encodingChars.EscapeCharacter       = segment[6];
                encodingChars.SubcomponentSeparator = segment[7];
                nodeKey[0] = 1;
                handler.putDatum(nodeKey, encodingChars.ToString());

                if (segment[8] == encodingChars.FieldSeparator)
                {
                    ret = true;
                    // now -- we recurse
                    // through fields / field-repetitions / components / subcomponents.
                    nodeKey.Clear();
                    nodeKey.Add(2);
                    parseSegmentGuts(handler, segment.Substring(9), nodeKey);
                }
            }
            catch (System.IndexOutOfRangeException)
            {
            }
            catch (System.NullReferenceException)
            {
            }

            return(ret);
        }