Example #1
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("");
        }
Example #2
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");
         }
     }
 }