Example #1
0
        public void NewMessage()
        {
            Iso8583MessageFormatter formatter = new Iso8583MessageFormatter();

            object message = formatter.NewMessage();

            Assert.IsTrue(message is Iso8583Message);
        }
Example #2
0
        public Posteo(String sIp, int iPuerto, int iTimeOut, int iGrabaLog, int iGrabaMsg, String sLlaveIzq, String sLlaveDer, Iso8583MessageFormatter formato)
        {
            this._sIp       = sIp;
            this._sLlaveIzq = sLlaveIzq;
            this._sLlaveDer = sLlaveDer;
            this._iPuerto   = iPuerto;
            this._iTimeOut  = iTimeOut;
            this._iGrabaLog = iGrabaLog;
            this._iGrabaMsg = iGrabaMsg;
            this._formato   = formato;
            ThreadStart theadStartPosteo = new ThreadStart(ejecucionPosteo);
            Thread      theadPosteo      = new Thread(theadStartPosteo);

            //theadPosteo.Priority = ThreadPriority.Highest;
            theadPosteo.Start();
        }
Example #3
0
        public void Clone()
        {
            string name        = "Formatter";
            string description = "ISO 8583 message formatter formatter";
            StringMessageHeaderFormatter headerFormatter =
                new StringMessageHeaderFormatter(new FixedLengthManager(2),
                                                 StringEncoder.GetInstance());
            StringFieldFormatter mtiFormatter =
                new StringFieldFormatter(-1, new FixedLengthManager(4),
                                         StringEncoder.GetInstance());
            Iso8583MessageFormatter formatter = new Iso8583MessageFormatter();

            // Set properties.
            formatter.Name                   = name;
            formatter.Description            = description;
            formatter.MessageHeaderFormatter =
                ( IMessageHeaderFormatter)headerFormatter;
            formatter.MessageTypeIdentifierFormatter = mtiFormatter;

            // Add field Formatters.
            for (int i = 0; i < _messageFormatterTests[0].Fields.Length; i++)
            {
                formatter.FieldFormatters.Add(_messageFormatter[_messageFormatterTests[0].Fields[i]]);
            }

            Iso8583MessageFormatter clonedFormatter =
                ( Iso8583MessageFormatter)formatter.Clone();

            Assert.IsNotNull(clonedFormatter);

            // Check properties.
            Assert.IsTrue(clonedFormatter.Name.Equals(name));
            Assert.IsTrue(clonedFormatter.Description.Equals(description));
            Assert.IsNotNull(formatter.Logger == clonedFormatter.Logger);
            Assert.IsNotNull(clonedFormatter.FieldFormatters);
            Assert.IsNotNull(clonedFormatter.MessageHeaderFormatter);
            Assert.IsTrue(formatter.MessageHeaderFormatter == headerFormatter);
            Assert.IsTrue(formatter.MessageTypeIdentifierFormatter == mtiFormatter);

            foreach (FieldFormatter fieldFormatter in formatter.FieldFormatters)
            {
                Assert.IsTrue(clonedFormatter.FieldFormatters.Contains(
                                  fieldFormatter.FieldNumber));
                Assert.IsTrue(clonedFormatter[fieldFormatter.FieldNumber] ==
                              fieldFormatter);
            }
        }
Example #4
0
 public Pos(String ip, int puerto, int timeout, String trama, int iGrabaLog, int iGrabaMsg)
 {
     this._ip         = ip;
     this._puerto     = puerto;
     this._timeoutPos = timeout;
     //this._talla=1;
     //this._Bitmap=2;
     this._trama     = trama;
     this._iGrabaLog = iGrabaLog;
     this._iGrabaMsg = iGrabaMsg;
     this._formato   = new Iso8583Bin1987MessageFormatter();
     if (trama.Length == _lengthTrama)
     {
         _ISOMsg = camposTramaIso(trama, _formato);
     }
     else
     {
         throw new Exception("Longitud de trama Plana de requerimiento no es valida");
     }
 }
        public void DoTest(Iso8583MessageFormatter formatter, string[] fieldValues,
                           FieldFormatter[] fieldFormatters,
                           Iso8583MessageFormatterTestConfig[] tests, bool partialWriting)
        {
            FormatterContext formatterContext = new FormatterContext(
                FormatterContext.DefaultBufferSize);
            ParserContext parserContext = new ParserContext(
                ParserContext.DefaultBufferSize);
            Iso8583Message messageToFormat;
            Iso8583Message parsedMessage;
            string         formattedData;

            // Add field Formatters.
            for (int i = 0; i < fieldFormatters.Length; i++)
            {
                if (fieldFormatters[i] != null)
                {
                    formatter.FieldFormatters.Add(fieldFormatters[i]);
                }
            }

            for (int i = 0; i < tests.Length; i++)
            {
                messageToFormat = new Iso8583Message(tests[i].MessageTypeIdentifier);
                formatterContext.Clear();
                parserContext.Clear();
                parsedMessage = null;
                formattedData = null;

                // Set header formatter.
                formatter.MessageHeaderFormatter = tests[i].HeaderFormatter;

                // Set message type identifier formatter.
                formatter.MessageTypeIdentifierFormatter = tests[i].MessageTypeIdentifierFormatter;

                // Set header.
                messageToFormat.Header = tests[i].Header;

                // Set message fields.
                for (int j = 0; j < tests[i].Fields.Length; j++)
                {
                    messageToFormat.Fields.Add(tests[i].Fields[j],
                                               fieldValues[tests[i].Fields[j] - 1]);
                }

                // Format message.
                formatter.Format(messageToFormat, ref formatterContext);
                formattedData = formatterContext.GetDataAsString();

                //Console.WriteLine( "Data:[" + formattedData + "]");

                // Check formatted data.
                Assert.IsTrue(tests[i].ExpectedFormattedData.Equals(formattedData));

                // Now parse to see if we get a copy of our message.
                if (partialWriting)
                {
                    for (int j = 0; j < formattedData.Length; j++)
                    {
                        parserContext.Write(formattedData.Substring(j, 1));
                        parsedMessage = ( Iso8583Message)formatter.Parse(ref parserContext);

                        // Message must be acquired only with the last char of formattedData.
                        if ((j + 1) == formattedData.Length)
                        {
                            Assert.IsNotNull(parsedMessage);
                        }
                        else
                        {
                            Assert.IsNull(parsedMessage);
                        }
                    }
                }
                else
                {
                    parserContext.Write(formattedData);
                    parsedMessage = ( Iso8583Message)formatter.Parse(ref parserContext);
                }

                // Parser data must be exhausted.
                Assert.IsTrue(parserContext.DataLength == 0);

                // Check parsed message.
                Assert.IsNotNull(parsedMessage);

                // Check header.
                if (tests[i].HeaderFormatter == null)
                {
                    Assert.IsNull(parsedMessage.Header);
                }
                else
                {
                    Assert.IsNotNull(parsedMessage.Header);

                    if (tests[i].Header == null)
                    {
                        Assert.IsTrue(string.Empty.Equals((( StringMessageHeader)
                                                           (parsedMessage.Header)).Value));
                    }
                    else
                    {
                        if ((( StringMessageHeader)(tests[i].Header)).Value == null)
                        {
                            Assert.IsTrue(string.Empty.Equals((( StringMessageHeader)
                                                               (parsedMessage.Header)).Value));
                        }
                        else
                        {
                            Assert.IsTrue((( StringMessageHeader)
                                           (messageToFormat.Header)).Value.Equals((( StringMessageHeader)
                                                                                   (parsedMessage.Header)).Value));
                        }
                    }
                }

                // Check message type identifier.
                Assert.IsTrue(messageToFormat.MessageTypeIdentifier ==
                              parsedMessage.MessageTypeIdentifier);

                // Check fields.
                Assert.IsTrue(messageToFormat.Fields.Count == parsedMessage.Fields.Count);
                Assert.IsTrue(messageToFormat.Fields.MaximumFieldNumber ==
                              parsedMessage.Fields.MaximumFieldNumber);
                for (int j = 0; j < tests[i].Fields.Length; j++)
                {
                    Assert.IsTrue(fieldValues[tests[i].Fields[j] - 1].Equals(
                                      (( StringField)(parsedMessage[tests[i].Fields[j]])).FieldValue));
                }
            }
        }
Example #6
0
        private Iso8583Message camposTramaIso(String trama, Iso8583MessageFormatter formato)
        {
            Iso8583Message    _ISOMsg;
            String            sInfoTrack2;
            String            sMontoServicio;
            String            sMontoPropina;
            String            sMontoCashOver;
            String            sInfoTrack1;
            String            sMesesGracia;
            String            sMontoBaseGravaIVA   = "";
            String            sMontoBaseNoGravaIVA = "";
            String            sTipoTarjeta;
            String            sTipoPlazoCredito;
            String            sModoEntrada;
            String            sCVV2;
            String            sMonto;
            String            sMontoIva;
            String            sNumeroAutorizacion;
            String            sNumeroLote;
            String            sMTI              = "";
            String            sTipoTransaccion  = "";
            CamposAdicionales camposAdicionales = new CamposAdicionales();

            _sTipoTransaccion    = trama.Substring(0, 2);
            sTipoTarjeta         = trama.Substring(2, 2);
            sTipoPlazoCredito    = trama.Substring(4, 4);
            sMesesGracia         = trama.Substring(8, 2);
            sInfoTrack2          = trama.Substring(10, 37).Trim();
            sModoEntrada         = trama.Substring(47, 3);
            sCVV2                = trama.Substring(50, 4).Trim();
            sMonto               = trama.Substring(54, 12);
            sMontoBaseGravaIVA   = trama.Substring(66, 12).Trim();
            sMontoBaseNoGravaIVA = trama.Substring(78, 12).Trim();
            sMontoIva            = trama.Substring(90, 12).Trim();
            sMontoServicio       = trama.Substring(102, 12).Trim();
            sMontoPropina        = trama.Substring(114, 12).Trim();
            sMontoCashOver       = trama.Substring(126, 12).Trim();
            _sSecuencial         = trama.Substring(138, 6);
            _sHora               = trama.Substring(144, 6);
            _sFecha              = trama.Substring(150, 8);
            sNumeroAutorizacion  = trama.Substring(158, 6).Trim();
            _sTerminalId         = trama.Substring(164, 8);
            _sMerchandId         = trama.Substring(172, 15);
            sNumeroLote          = trama.Substring(187, 6);
            sInfoTrack1          = trama.Substring(193, 99);
            _sMontoFijo          = trama.Substring(292, 12).Trim();
            _sNombreTarjeta      = "";
            sInfoTrack1          = sInfoTrack1.Trim();
            if (sMontoIva != null)
            {
                if (sMontoIva.Length > 0)
                {
                    camposAdicionales.setIVA(sMontoIva);
                }
            }
            if (sMontoServicio != null)
            {
                if (sMontoServicio.Length > 0)
                {
                    camposAdicionales.setServicios(sMontoServicio);
                }
            }
            if (sMontoPropina != null)
            {
                if (sMontoPropina.Length > 0)
                {
                    camposAdicionales.setPropina(sMontoPropina);
                }
            }
            if (_sMontoFijo != null)
            {
                if (_sMontoFijo.Length > 0)
                {
                    camposAdicionales.setMontoFijo(_sMontoFijo);
                }
            }
            if (sMontoCashOver != null)
            {
                if (sMontoCashOver.Length > 0)
                {
                    camposAdicionales.setCashOver(sMontoCashOver);
                }
            }
            if ((_sTipoTransaccion.CompareTo("01") == 0) || (_sTipoTransaccion.CompareTo("02") == 0))
            {
                sMTI             = "0200";
                sTipoTransaccion = "00";
            }
            else if (_sTipoTransaccion.CompareTo("03") == 0)
            {
                sMTI             = "0200";
                sTipoTransaccion = "20";
            }
            else if (_sTipoTransaccion.CompareTo("04") == 0)
            {
                sMTI             = "0400";
                sTipoTransaccion = "00";
            }
            _ISOMsg                       = new Iso8583Message();
            _ISOMsg.Formatter             = formato;
            _ISOMsg.MessageTypeIdentifier = Convert.ToInt32(sMTI);
            _ISOMsg.Fields.Add(3, sTipoTransaccion + sTipoTarjeta + "00");
            _ISOMsg.Fields.Add(113, sTipoPlazoCredito + sMesesGracia);
            sInfoTrack2 = sInfoTrack2.Trim();
            int posicion = sInfoTrack2.IndexOf("=");

            _sNumeroTarjeta = sInfoTrack2.Substring(0, posicion);
            _sNumeroTarjeta = protegeTarjeta(_sNumeroTarjeta);
            if (sModoEntrada.CompareTo("012") == 0)
            {
                _ISOMsg.Fields.Add(2, sInfoTrack2.Substring(0, posicion));
                _ISOMsg.Fields.Add(14, sInfoTrack2.Substring(posicion + 1));
            }
            else if (sModoEntrada.CompareTo("022") == 0)
            {
                _ISOMsg.Fields.Add(35, sInfoTrack2);
            }
            _ISOMsg.Fields.Add(22, sModoEntrada);
            if (sCVV2.Length > 0)
            {
                _ISOMsg.Fields.Add(48, sCVV2);
            }
            _ISOMsg.Fields.Add(4, sMonto);
            _ISOMsg.Fields.Add(114, camposAdicionales.toISOHiCC());
            _ISOMsg.Fields.Add(11, _sSecuencial);
            _ISOMsg.Fields.Add(12, _sHora);
            _ISOMsg.Fields.Add(13, _sFecha.Substring(4));
            sMontoBaseGravaIVA   = sMontoBaseGravaIVA.Trim();
            sMontoBaseNoGravaIVA = sMontoBaseNoGravaIVA.Trim();
            _ISOMsg.Fields.Add(119, UTILIDADES.zeropad(sMontoBaseGravaIVA, 12) + UTILIDADES.zeropad(sMontoBaseNoGravaIVA, 12));
            sNumeroAutorizacion = sNumeroAutorizacion.Trim();
            if (sNumeroAutorizacion.Length == 6)
            {
                _ISOMsg.Fields.Add(38, sNumeroAutorizacion);
            }
            _ISOMsg.Fields.Add(41, _sTerminalId);
            _ISOMsg.Fields.Add(42, _sMerchandId);
            if (sInfoTrack1.Length > 0)
            {
                _sNombreTarjeta = extraeTarjetaHabiente(sInfoTrack1);
                _ISOMsg.Fields.Add(45, sInfoTrack1);
            }
            _ISOMsg.Fields.Add(112, sNumeroLote);
            if (this._iGrabaMsg == 1)
            {
                UTILIDADES.mensaje("DEBUG : " + "Datos:" + _sSecuencial + "|" + _sTerminalId + "|" + _sMerchandId, "LogEvent", "log");
            }
            return(_ISOMsg);
        }