/// <summary> /// It parses the MTI. /// </summary> /// <param name="message"> /// The message to be parsed. /// </param> /// <param name="parserContext"> /// It's the parser context. /// </param> /// <returns> /// true if the MTI was parsed, otherwise false. /// </returns> public override bool BeforeFieldsParsing(Message message, ref ParserContext parserContext) { Field mti = _mtiFormatter.Parse(ref parserContext); if (mti == null) { return(false); } try { (( Iso8583Message)(message)).MessageTypeIdentifier = Convert.ToInt32(mti.Value, CultureInfo.InvariantCulture); } catch { throw new MessagingException(SR.CantParseMti); } return(true); }
public void Parse() { ParserContext parseContext = new ParserContext( ParserContext.DefaultBufferSize); StringField field; StringFieldFormatter formatter; // Setup data for three complete fields an one with partial data. parseContext.Write("DATA 20 DATA TO BE PARSED009SOME DATA00"); // Test fixed length parse. formatter = new StringFieldFormatter(37, new FixedLengthManager(12), StringEncoder.GetInstance()); field = ( StringField)formatter.Parse(ref parseContext); Assert.IsNotNull(field); parseContext.ResetDecodedLength(); Assert.IsTrue(field.FieldValue.Equals("DATA")); // Test variable length parse with padding. formatter = new StringFieldFormatter(48, new VariableLengthManager(1, 20, StringLengthEncoder.GetInstance(99)), StringEncoder.GetInstance(), SpacePaddingLeft.GetInstance(false), string.Empty); field = ( StringField)formatter.Parse(ref parseContext); Assert.IsNotNull(field); parseContext.ResetDecodedLength(); Assert.IsTrue(field.FieldValue.Equals("DATA TO BE PARSED")); // Test variable length parse without padding. formatter = new StringFieldFormatter(48, new VariableLengthManager(1, 999, StringLengthEncoder.GetInstance(999)), StringEncoder.GetInstance()); field = ( StringField)formatter.Parse(ref parseContext); Assert.IsNotNull(field); parseContext.ResetDecodedLength(); Assert.IsTrue(field.FieldValue.Equals("SOME DATA")); // Test partial variable length parse without padding. field = ( StringField)formatter.Parse(ref parseContext); Assert.IsNull(field); parseContext.Write("9MORE D"); field = ( StringField)formatter.Parse(ref parseContext); Assert.IsNull(field); parseContext.Write("ATA"); field = ( StringField)formatter.Parse(ref parseContext); Assert.IsNotNull(field); parseContext.ResetDecodedLength(); Assert.IsTrue(field.FieldValue.Equals("MORE DATA")); // Test partial fixed parse with padding. formatter = new StringFieldFormatter(37, new FixedLengthManager(12), StringEncoder.GetInstance()); field = ( StringField)formatter.Parse(ref parseContext); Assert.IsNull(field); parseContext.Write("ONE MORE"); field = ( StringField)formatter.Parse(ref parseContext); Assert.IsNull(field); parseContext.Write(" "); field = ( StringField)formatter.Parse(ref parseContext); Assert.IsNotNull(field); parseContext.ResetDecodedLength(); Assert.IsTrue(field.FieldValue.Equals("ONE MORE")); // Test variable length header with zero length. formatter = new StringFieldFormatter(48, new VariableLengthManager(0, 999, StringLengthEncoder.GetInstance(999)), StringEncoder.GetInstance()); parseContext.Write("000"); field = ( StringField)formatter.Parse(ref parseContext); Assert.IsNotNull(field); parseContext.ResetDecodedLength(); Assert.IsNull(field.FieldValue); // Test fixed length parse with validation. formatter = new StringFieldFormatter(37, new FixedLengthManager(12), StringEncoder.GetInstance(), ZeroPaddingLeft.GetInstance(false, true), NumericValidator.GetInstance()); parseContext.Write("000000145000"); field = ( StringField)formatter.Parse(ref parseContext); Assert.IsNotNull(field); parseContext.ResetDecodedLength(); Assert.IsTrue(field.FieldValue.Equals("145000")); // Try with an invalid value. parseContext.Write("0000001450F0"); try { field = ( StringField)formatter.Parse(ref parseContext); Assert.Fail(); } catch (StringValidationException) { } // Test variable length parse with validation. parseContext.Clear(); parseContext.ResetDecodedLength(); formatter = new StringFieldFormatter(48, new VariableLengthManager(1, 999, StringLengthEncoder.GetInstance(999)), StringEncoder.GetInstance(), NumericValidator.GetInstance()); parseContext.Write("00532000"); field = ( StringField)formatter.Parse(ref parseContext); Assert.IsNotNull(field); parseContext.ResetDecodedLength(); Assert.IsTrue(field.FieldValue.Equals("32000")); // Try with an invalid value. parseContext.Write("005350F0"); try { field = ( StringField)formatter.Parse(ref parseContext); Assert.Fail(); } catch (StringValidationException) { } }
internal protected override string ParseValueText(string text) { return(formatter.Parse(text)); }