Exemple #1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        //[STAThread]
        static void Main(string[] args)
        {
            Console.WriteLine("Is running.");
            VolatileStanSequencer _sequencer;
            Socket        _socket;
            AddressFamily _family;

            _sequencer = new VolatileStanSequencer();
            Iso8583Message echoMsg = new Iso8583Message(800);

            echoMsg.Fields.Add(Field3ProcCode, "990000");
            DateTime transmissionDate = DateTime.Now;

            echoMsg.Fields.Add(Field7TransDateTime, string.Format("{0}{1}", string.Format("{0:00}{1:00}", transmissionDate.Month, transmissionDate.Day), string.Format("{0:00}{1:00}{2:00}", transmissionDate.Hour, transmissionDate.Minute, transmissionDate.Second)));
            echoMsg.Fields.Add(Field11Trace, _sequencer.Increment().ToString());
            echoMsg.Fields.Add(Field24Nii, "101");
            echoMsg.Fields.Add(Field41TerminalCode, "12131415");
            echoMsg.Fields.Add(Field42MerchantCode, "000000852963  ");
            IMessageFormatter _formatter = new Iso8583Bin1987MessageFormatter();

            //formatterContext.GetData();
            echoMsg.Formatter = _formatter;
            //echoMsg.Formatter.Format(echoMsg, ref formatterContext);

            byte[] bBufferRecive;
            byte[] bBuffer = echoMsg.GetBytes();
            byte[] bHeader = Hex2Byte("6000018000");
            int    iTalla  = bBuffer.Length + bHeader.Length;

            byte[] bTalla = Hex2Byte(Convert.ToString(iTalla, 16).PadLeft(4, '0'));
            _family = AddressFamily.InterNetwork;
            _socket = new Socket(_family, SocketType.Stream, ProtocolType.Tcp);
            _socket.Connect("192.168.123.39", 9004);
            _socket.Send(bTalla);
            _socket.Send(bHeader);
            _socket.Send(bBuffer);
            Console.WriteLine(Byte2Hex(bTalla) + Byte2Hex(bHeader) + Byte2Hex(bBuffer));
            _socket.ReceiveTimeout = 10000;
            bBufferRecive          = new byte[_socket.ReceiveBufferSize];
            _socket.Receive(bBufferRecive);
            Hashtable ISO = TransaformaIso(bBufferRecive);

            byte[] bBody = (byte[])ISO["Body"];
            //FormatterContext formatterContext = new FormatterContext(FormatterContext.DefaultBufferSize);
            //formatterContext.Write(bBody);
            ParserContext _parserContext = new ParserContext(bBody.Length);

            _parserContext.Initialize();
            _parserContext.ResizeBuffer(bBody.Length);
            _parserContext.Write(bBody);

            Iso8583Message echoMsgResp = (Iso8583Message)echoMsg.Formatter.Parse(ref _parserContext);

            //echoMsg.Formatter.Format(echoMsg, ref formatterContext);
            Console.WriteLine(Byte2Hex(bBody));
            Console.WriteLine(echoMsgResp.ToString());
            _socket.Close();
            Console.ReadLine();
        }
        public void ToStringMethod()
        {
            Iso8583Message message = new Iso8583Message(1220);

            // Add fields.
            for (int i = 0; i < _fields.Length; i++)
            {
                message.Fields.Add(_fields[i]);
            }

            message.Header = new StringMessageHeader("HEADER");

            string data = message.ToString();

            Assert.IsNotNull(data);
            Assert.IsTrue(data.Equals("H:HEADER,M:1220,0:[1,2,3,4,11,12,25,48,49,64],1:[],2:1,3:000000,4:000000000100,11:000015,12:010102,25:0,48:SOME DATA,49:840,64:FFFFFFFFFFFFFFFF"));
        }
        public bool Process(IMessageSource source, Message message)
        {
            try
            {
                string         postBridgeNodeIp = (source as ServerPeer).Channel.Name;
                Iso8583Message theMsg           = message as Iso8583Message;
                if (TheBridge.PostBridgeNodePeer != null && TheBridge.PostBridgeNodePeer.Channel != null &&
                    postBridgeNodeIp == TheBridge.PostBridgeNodePeer.Channel.Name && !theMsg.IsRequest())
                {
                    if (_theBridge.PosRequestPeer.IsConnected)
                    {
                        _theBridge.PosRequestPeer.Send(message);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                bool isSignOnMessage = false;
                new PANE.ERRORLOG.Error().LogInfo("Request message: " + theMsg.ToString());
                PostBridge.Server.Messages.Message requestMessage = MessageParser.Read(theMsg, out isSignOnMessage);
                if (requestMessage.Validate())
                {
                    Iso8583Message msg = requestMessage.Execute();
                    new PANE.ERRORLOG.Error().LogInfo("About to send Response message: " + msg.ToString());
                    source.Send(msg);

                    //If is first sign on message, send Keyexchange.
                    if (!PinConfigurationManager.FepConfig.KeyExchangeOnConnect && lastKeyExchangeDate.Date != DateTime.Today && isSignOnMessage)
                    {
                        new BasicServerPeerManager2().DoKeyExchange(null);
                        lastKeyExchangeDate = DateTime.Now;
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                new PANE.ERRORLOG.Error().LogToFile(e);
                Logger.Error(e);
                return(false);
            }
        }
Exemple #4
0
        public String EnvioRequerimiento()
        {
            String         _respuesta = "";
            String         sError     = "";
            String         sPosteo;
            String         sFileName;
            String         sFecha;
            ParserContext  parserContext;
            Hashtable      ISO;
            Iso8583Message isoMsgResp;
            Socket         socket;

            byte[] bBody;
            byte[] bBufferRecive;
            byte[] bBufferEnvio;
            int    iLargoBody;

            if (this._trama.Length != _lengthTrama)
            {
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("POS   : " + "Longitud de trama Plana de requerimiento no es valida", "LogEvent", "log");
                }
                return("");
            }
            if (this._iGrabaLog == 1)
            {
                UTILIDADES.mensaje("INPUT METODO : " + UTILIDADES.ProtegeTramaPlana(_trama), "LogTracer", "log");
            }
            try
            {
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Previo Socket", "LogEvent", "log");
                }
                socket = InicializaSocket();
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Despues Socket", "LogEvent", "log");
                }
            }
            catch (System.Net.Sockets.SocketException e)
            {
                sError += e.Message;
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("POS   : " + e.Message, "LogEvent", "log");
                }
                throw new Exception(sError);
            }
            try
            {
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Antes de ISO to BYTE", "LogEvent", "log");
                }
                bBufferEnvio = TransformaISOByte(_ISOMsg, "6000081000");
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Despues de ISO to BYTE", "LogEvent", "log");
                }
            }
            catch (Exception e)
            {
                sError += e.Message;
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("POS   : " + e.Message, "LogEvent", "log");
                }
                throw new Exception(sError);
            }
            try
            {
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Antes de Envio", "LogEvent", "log");
                }
                socket.Send(bBufferEnvio);
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Despues de Envio", "LogEvent", "log");
                }
                if (this._iGrabaLog == 1)
                {
                    UTILIDADES.mensaje("OUTPUT DLL   : " + _ISOMsg.ToString(), "LogTracer", "log");
                }
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "TimeOut Definido", "LogEvent", "log");
                }
                socket.ReceiveTimeout = Convert.ToInt32(_timeoutPos);
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "TimeOut Definido", "LogEvent", "log");
                }
                bBufferRecive = new byte[socket.ReceiveBufferSize];
                socket.Receive(bBufferRecive);
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Buffer recibido", "LogEvent", "log");
                }
                ISO = TransaformaIso(bBufferRecive);
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Transforma buffer ISO", "LogEvent", "log");
                }
                bBody         = (byte[])ISO["Body"];
                iLargoBody    = bBody.Length;
                parserContext = new ParserContext(iLargoBody);
                parserContext.Initialize();
                parserContext.ResizeBuffer(iLargoBody);
                parserContext.Write(bBody);
                isoMsgResp = (Iso8583Message)_ISOMsg.Formatter.Parse(ref parserContext);
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Finaliza buffer ISO", "LogEvent", "log");
                }
                if (this._iGrabaLog == 1)
                {
                    UTILIDADES.mensaje("INPUT DLL    : " + isoMsgResp.ToString(), "LogTracer", "log");
                }
            }
            catch (Exception e)
            {
                sError += e.Message;
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Excepcion :" + sError, "LogEvent", "log");
                }
                if (((Field)_ISOMsg.Fields[3]).Value.ToString().CompareTo("003000") == 0)
                {
                    try
                    {
                        if (this._iGrabaMsg == 1)
                        {
                            UTILIDADES.mensaje("DEBUG : " + "Inicia Posteo", "LogEvent", "log");
                        }
                        sPosteo = UTILIDADES.F3DESEncriptarBloque(UTILIDADES.padMultiplo(UTILIDADES.Byte2Hex(_ISOMsg.GetBytes()), 16, "1C"), _sLlaveKEKIzquierda, _sLlaveKEKDerecha);
                        if (this._iGrabaMsg == 1)
                        {
                            UTILIDADES.mensaje("DEBUG : " + "Finaliza cifrado", "LogEvent", "log");
                        }
                        sFecha = DateTime.Now.ToString("HHmmss");
                        String sRuta = UTILIDADES.AppPath(true) + "Saf\\";
                        if (this._iGrabaMsg == 1)
                        {
                            UTILIDADES.mensaje("DEBUG : " + "Valida Ruta de Posteo", "LogEvent", "log");
                        }
                        Directory.CreateDirectory(sRuta);
                        sFileName = Convert.ToString(_ISOMsg.MessageTypeIdentifier) + ((Field)_ISOMsg.Fields[11]).Value.ToString() + ((Field)_ISOMsg.Fields[41]).Value.ToString() + ((Field)_ISOMsg.Fields[112]).Value.ToString() + sFecha + ".saf";
                        //new GrabaArchivo(sFileName, sPosteo, false);
                        if (this._iGrabaMsg == 1)
                        {
                            UTILIDADES.mensaje("DEBUG : " + "Guarda Archivo de Posteo", "LogEvent", "log");
                        }
                        UTILIDADES.almacenarArchivo(sRuta, sFileName, false, sPosteo);
                        if (this._iGrabaMsg == 1)
                        {
                            UTILIDADES.mensaje("DEBUG : " + "Ejecuta Posteo", "LogEvent", "log");
                        }
                        new Posteo(_ip, _puerto, _timeoutPos, _iGrabaLog, _iGrabaMsg, _sLlaveKEKIzquierda, _sLlaveKEKDerecha, _formato);
                        if (this._iGrabaMsg == 1)
                        {
                            UTILIDADES.mensaje("DEBUG : " + "Finaliza Posteo", "LogEvent", "log");
                        }
                        if (socket != null)
                        {
                            socket.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        sError += "\t" + ex.Message;
                        if (this._iGrabaMsg == 1)
                        {
                            UTILIDADES.mensaje("POS   : " + ex.Message, "LogEvent", "log");
                        }
                    }
                }
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("POS   : " + e.Message, "LogEvent", "log");
                }
                throw new Exception(sError);
            }
            try
            {
                socket.Close();
            }
            catch (Exception e)
            {
                sError += e.Message;
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("POS   : " + e.Message, "LogEvent", "log");
                }
            }
            try
            {
                new Posteo(_ip, _puerto, _timeoutPos, _iGrabaLog, _iGrabaMsg, _sLlaveKEKIzquierda, _sLlaveKEKDerecha, _formato);
            }
            catch (Exception e)
            {
                sError += e.Message;
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("POS   : " + e.Message, "LogEvent", "log");
                }
            }
            try
            {
                _respuesta = camposTramaPlano(isoMsgResp);
            }
            catch (Exception e)
            {
                sError += e.Message;
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("POS   : " + e.Message, "LogEvent", "log");
                }
            }
            if (this._iGrabaLog == 1)
            {
                UTILIDADES.mensaje("OUTPUT METODO: " + _respuesta, "LogTracer", "log");
            }
            if (_respuesta.Length > 0)
            {
                return(_respuesta);
            }
            return("");
        }
Exemple #5
0
 private void ejecucionPosteo()
 {
     try
     {
         int           iLargoArchivo, iLargoBody;
         byte[]        bArchivo, bBufferEnvio, bBufferRecive, bBody;
         ParserContext parserContext;
         if (this._iGrabaMsg == 1)
         {
             UTILIDADES.mensaje("DEBUGP: " + "Valida Ruta de  Posteo", "LogEvent", "log");
         }
         String    _sRuta = UTILIDADES.AppPath(true) + "Saf\\";
         String [] files  = Directory.GetFiles(_sRuta, "*.saf");
         if (this._iGrabaMsg == 1)
         {
             UTILIDADES.mensaje("DEBUGP: " + "Optiene Archivos de Posteo", "LogEvent", "log");
         }
         Iso8583Message isoMsgReq, isoMsgResp;
         Socket         socket;
         Hashtable      ISO;
         String         resultado;
         foreach (String sFile in files)
         {
             try
             {
                 resultado           = "";
                 isoMsgReq           = new Iso8583Message();
                 isoMsgReq.Formatter = _formato;
                 bArchivo            = UTILIDADES.Hex2Byte(UTILIDADES.F3DESDencriptarBloque(UTILIDADES.leerArchivo("", sFile), _sLlaveIzq, _sLlaveDer));
                 if (this._iGrabaMsg == 1)
                 {
                     UTILIDADES.mensaje("DEBUGP: " + "Leer y decifra archivo:" + sFile, "LogEvent", "log");
                 }
                 iLargoArchivo = bArchivo.Length;
                 parserContext = new ParserContext(iLargoArchivo);
                 parserContext.Initialize();
                 parserContext.ResizeBuffer(iLargoArchivo);
                 parserContext.Write(bArchivo);
                 if (this._iGrabaMsg == 1)
                 {
                     UTILIDADES.mensaje("DEBUGP: " + "Convierte ISO", "LogEvent", "log");
                 }
                 isoMsgReq = (Iso8583Message)isoMsgReq.Formatter.Parse(ref parserContext);
                 isoMsgReq.MessageTypeIdentifier = 400;
                 bBufferEnvio = TransformaISOByte(isoMsgReq, "6000081000");
                 if (this._iGrabaMsg == 1)
                 {
                     UTILIDADES.mensaje("DEBUGP: " + "Inicia Socket", "LogEvent", "log");
                 }
                 socket = InicializaSocket();
                 if (this._iGrabaMsg == 1)
                 {
                     UTILIDADES.mensaje("DEBUGP: " + "Inicia Socket Terminado", "LogEvent", "log");
                 }
                 socket.Send(bBufferEnvio);
                 if (this._iGrabaMsg == 1)
                 {
                     UTILIDADES.mensaje("DEBUGP: " + "Envio de Buffer", "LogEvent", "log");
                 }
                 if (this._iGrabaLog == 1)
                 {
                     UTILIDADES.mensaje("OUTPUT DLL  P: " + isoMsgReq.ToString(), "LogTracer", "log");
                 }
                 socket.ReceiveTimeout = 10000;
                 if (this._iGrabaMsg == 1)
                 {
                     UTILIDADES.mensaje("DEBUGP: " + "Set TimeOut: 10000", "LogEvent", "log");
                 }
                 bBufferRecive = new byte[socket.ReceiveBufferSize];
                 socket.Receive(bBufferRecive);
                 if (this._iGrabaMsg == 1)
                 {
                     UTILIDADES.mensaje("DEBUGP: " + "Recibe Buffer", "LogEvent", "log");
                 }
                 ISO           = TransaformaIso(bBufferRecive);
                 bBody         = (byte[])ISO["Body"];
                 iLargoBody    = bBody.Length;
                 parserContext = new ParserContext(iLargoBody);
                 parserContext.Initialize();
                 parserContext.ResizeBuffer(iLargoBody);
                 parserContext.Write(bBody);
                 if (this._iGrabaMsg == 1)
                 {
                     UTILIDADES.mensaje("DEBUGP: " + "Convierte Buffer en ISO", "LogEvent", "log");
                 }
                 isoMsgResp = (Iso8583Message)isoMsgReq.Formatter.Parse(ref parserContext);
                 if (this._iGrabaLog == 1)
                 {
                     UTILIDADES.mensaje("INPUT DLL   P: " + isoMsgResp.ToString(), "LogTracer", "log");
                 }
                 resultado = ((Field)isoMsgResp.Fields[39]).Value.ToString();
                 if ((resultado.CompareTo("91") != 0) && ((resultado.CompareTo("27") != 0)))
                 {
                     if (this._iGrabaMsg == 1)
                     {
                         UTILIDADES.mensaje("DEBUGP: " + "Valida Respuesta ", "LogEvent", "log");
                     }
                     File.Delete(sFile);
                     if (this._iGrabaMsg == 1)
                     {
                         UTILIDADES.mensaje("DEBUGP: " + "Elimina: " + sFile, "LogEvent", "log");
                     }
                 }
                 try
                 {
                     socket.Close();
                     if (this._iGrabaMsg == 1)
                     {
                         UTILIDADES.mensaje("DEBUGP: " + "Cierra Socket ", "LogEvent", "log");
                     }
                 }
                 catch (Exception e)
                 {
                     if (this._iGrabaMsg == 1)
                     {
                         UTILIDADES.mensaje("POSTEO: " + e.Message, "LogEvent", "log");
                     }
                 }
             }
             catch (Exception e)
             {
                 if (this._iGrabaMsg == 1)
                 {
                     UTILIDADES.mensaje("POSTEO: " + e.Message, "LogEvent", "log");
                 }
             }
         }
     }
     catch (Exception e)
     {
         if (this._iGrabaMsg == 1)
         {
             UTILIDADES.mensaje("POSTEO: " + e.Message, "LogEvent", "log");
         }
     }
 }