Example #1
0
        /// <summary>Parses message and dumps contents to props, with keys in the
        /// ZYX[a]-b[c]-d-e style.
        /// </summary>
        public static bool parseMessage(System.Collections.Specialized.NameValueCollection props, System.Collections.ArrayList msgMask, System.String message)
        {
            bool ok = false;

            if (message != null)
            {
                if (props == null)
                {
                    props = new System.Collections.Specialized.NameValueCollection();
                }

                SupportClass.Tokenizer messageTokenizer = new SupportClass.Tokenizer(message, segmentSeparators);
                if (messageTokenizer.HasMoreTokens())
                {
                    System.String           firstSegment  = messageTokenizer.NextToken();
                    NuGenEncodingCharacters encodingChars = new NuGenEncodingCharacters('0', "0000");
                    if (parseMSHSegmentWhole(props, msgMask, encodingChars, firstSegment))
                    {
                        ok = true;
                        System.Collections.SortedList segmentId2nextRepIdx = new System.Collections.SortedList();
                        segmentId2nextRepIdx[new System.Text.StringBuilder("MSH").ToString()] = 1;
                        // in case we find another MSH segment, heh.
                        while (messageTokenizer.HasMoreTokens())
                        {
                            parseSegmentWhole(props, segmentId2nextRepIdx, msgMask, encodingChars, messageTokenizer.NextToken());
                        }
                    }
                }
            }
            return(ok);
        }
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);
        }
Example #3
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 #4
0
        private NuGenEncodingCharacters enc;         //used to check for content in parts of a message

        /// <summary>Creates a new instance of DefaultValidator </summary>
        public NuGenDefaultValidator()
        {
            enc = new NuGenEncodingCharacters('|', null);             //the | is assumed later -- don't change
        }