コード例 #1
0
        /// <summary>
        /// Analiza la información contenida en un contexto de analisis y
        /// construcción de mensajes, y construye en base a ella un nuevo
        /// campo para el que el formateador se ha construido.
        /// </summary>
        /// <param name="parserContext">
        /// Es el contexto de analisis y construcción y construcción de mensajes.
        /// </param>
        /// <returns>
        /// El nuevo campo contruido a partir de la información contenida en
        /// el contexto de análisis y construcción de mensajes.
        /// </returns>
        public override Field Parse(ref ParserContext parserContext)
        {
            // If MinValue, at this moment the length hasn't been decoded.
            if (parserContext.DecodedLength == int.MinValue)
            {
                if (!_lengthManager.EnoughData(ref parserContext))
                {
                    // Insufficient data to parse length, return null.
                    return(null);
                }

                // Save length in parser context just in case field value
                // can't be parsed at this time (more data needed).
                parserContext.DecodedLength =
                    _lengthManager.ReadLength(ref parserContext);
            }

            if (parserContext.DataLength < _encoder.GetEncodedLength(
                    parserContext.DecodedLength))
            {
                // Insufficient data to parse field value, return null.
                return(null);
            }

            // Create the new messaging component with parsing context data.
            string fieldValue;

            if (_padding == null)
            {
                fieldValue = _encoder.Decode(ref parserContext, parserContext.DecodedLength);
            }
            else
            {
                fieldValue = _padding.RemovePad(_encoder.Decode(ref parserContext,
                                                                parserContext.DecodedLength));
            }

            if (_validator != null)
            {
                _validator.Validate(fieldValue);
            }

            StringField field = new StringField(FieldNumber, fieldValue);

            _lengthManager.ReadLengthTrailer(ref parserContext);

            return(field);
        }
コード例 #2
0
        /// <summary>
        /// Analiza la información contenida en un contexto de analisis y
        /// construcción de mensajes, y construye en base a ella un nuevo
        /// cabezal para el que el formateador se ha construido.
        /// </summary>
        /// <param name="parserContext">
        /// Es el contexto de analisis y construcción y construcción de mensajes.
        /// </param>
        /// <returns>
        /// El nuevo cabezal contruido a partir de la información contenida en
        /// el contexto de análisis y construcción de mensajes.
        /// </returns>
        public virtual MessageHeader Parse(ref ParserContext parserContext)
        {
            // If zero, at this moment the length hasn't been decoded.
            if (parserContext.DecodedLength == int.MinValue)
            {
                if (!_lengthManager.EnoughData(ref parserContext))
                {
                    // Insufficient data to parse length, return null.
                    return(null);
                }

                // Save length in parser context just in case field value
                // can't be parsed at this time (more data needed).
                parserContext.DecodedLength =
                    _lengthManager.ReadLength(ref parserContext);
            }

            if (parserContext.DataLength < _encoder.GetEncodedLength(
                    parserContext.DecodedLength))
            {
                // Insufficient data to parse field value, return null.
                return(null);
            }

            // Create the new messaging component with parsing context data.
            StringMessageHeader header;

            if (_padding == null)
            {
                header = new StringMessageHeader(_encoder.Decode(
                                                     ref parserContext, parserContext.DecodedLength));
            }
            else
            {
                header = new StringMessageHeader(_padding.RemovePad(
                                                     _encoder.Decode(ref parserContext,
                                                                     parserContext.DecodedLength)));
            }

            _lengthManager.ReadLengthTrailer(ref parserContext);

            return(header);
        }