Commit e59eba09 authored by Brayan Sarmiento's avatar Brayan Sarmiento
Browse files

Conexion con el POSBC

parent 9cdff4a9
...@@ -30,7 +30,7 @@ namespace EvaPosSrvResp ...@@ -30,7 +30,7 @@ namespace EvaPosSrvResp
/// <summary> /// <summary>
/// Inicializar DTO adecuado al mensaje. /// Inicializar DTO adecuado al mensaje.
/// </summary> /// </summary>
public DTOBase ObtieneDTO(int idSesion, TipoMensaje tipoMensaje, XmlElement docXml, string mensajeXml); public DTOBase ObtieneDTO(int idSesion, TipoMensaje tipoMensaje, XmlElement docXml, string mensajeXml, byte[] bufferEntrada, int cantBytes);
/// <summary> /// <summary>
/// Retorna una "shallow copy" del objeto. /// Retorna una "shallow copy" del objeto.
...@@ -107,6 +107,14 @@ namespace EvaPosSrvResp ...@@ -107,6 +107,14 @@ namespace EvaPosSrvResp
/// <summary> /// <summary>
/// Propiedad que toma toda la trama xml que viene de chec, para asi enviarla al POSBC /// Propiedad que toma toda la trama xml que viene de chec, para asi enviarla al POSBC
/// </summary> /// </summary>
public byte[] BufferEntrada { get; set; }
/// <summary>
/// Propiedad que toma el buffer de entrada de CHEC para enviarselo al POSBC
/// </summary>
public int CantBytes { get; set; }
/// <summary>
/// Propiedad que toma la cantidad de bytes que vienen de CHEC
/// </summary>
public XmlDocument ContenidoXML public XmlDocument ContenidoXML
{ {
get get
...@@ -120,25 +128,29 @@ namespace EvaPosSrvResp ...@@ -120,25 +128,29 @@ namespace EvaPosSrvResp
/// <summary> /// <summary>
/// Constructor genérico. /// Constructor genérico.
/// </summary> /// </summary>
public TramaSCO(UInt32 longitud, Int32 idSesion, TipoMensaje tipo, string textoXML,string mensajeXml) public TramaSCO(UInt32 longitud, Int32 idSesion, TipoMensaje tipo, string textoXML,string mensajeXml, byte[] bufferEntrada, int cantBytes)
{ {
Longitud = longitud; Longitud = longitud;
IdSesion = idSesion; IdSesion = idSesion;
TipoMensaje = tipo; TipoMensaje = tipo;
TextoXML = textoXML; TextoXML = textoXML;
MensajeXml = mensajeXml; MensajeXml = mensajeXml;
BufferEntrada = bufferEntrada;
CantBytes = cantBytes;
} }
/// <summary> /// <summary>
/// Constructor usado para calcular Longitud del mensaje (encabezado + texto xml). /// Constructor usado para calcular Longitud del mensaje (encabezado + texto xml).
/// </summary> /// </summary>
public TramaSCO(Int32 idSesion, TipoMensaje tipo, string textoXML,string mensajeXml) public TramaSCO(Int32 idSesion, TipoMensaje tipo, string textoXML,string mensajeXml, byte[] bufferEntrada, int cantBytes)
{ {
IdSesion = idSesion; IdSesion = idSesion;
TipoMensaje = tipo; TipoMensaje = tipo;
TextoXML = textoXML; TextoXML = textoXML;
Longitud = Convert.ToUInt32(TextoEncabezado.Length + TextoXML.Length); Longitud = Convert.ToUInt32(TextoEncabezado.Length + TextoXML.Length);
MensajeXml = mensajeXml; MensajeXml = mensajeXml;
BufferEntrada = bufferEntrada;
CantBytes = cantBytes;
} }
} }
...@@ -154,9 +166,11 @@ namespace EvaPosSrvResp ...@@ -154,9 +166,11 @@ namespace EvaPosSrvResp
public TipoMensaje MessageType { get; private set; } public TipoMensaje MessageType { get; private set; }
public abstract string TextoXML { get; } public abstract string TextoXML { get; }
public string MensajeXml { get; } public string MensajeXml { get; }
public byte[] BufferEntrada { get; private set; }
public int CantBytes { get; private set; }
public TramaSCO TramaSCO public TramaSCO TramaSCO
{ {
get => new TramaSCO(SessionId, MessageType, TextoXML, MensajeXml); get => new TramaSCO(SessionId, MessageType, TextoXML, MensajeXml, BufferEntrada, CantBytes);
} }
public Respuesta(int sessionId, TipoMensaje tipo) public Respuesta(int sessionId, TipoMensaje tipo)
......
...@@ -13,6 +13,7 @@ using EvaPosSrvResp; ...@@ -13,6 +13,7 @@ using EvaPosSrvResp;
using EvaPosSrvAplicacion; using EvaPosSrvAplicacion;
using EvaPOS_API_FRAME.RespuestasXML; using EvaPOS_API_FRAME.RespuestasXML;
using EvaPOS_API_FRAME.Comandos; using EvaPOS_API_FRAME.Comandos;
using gatewayGK.POSBC;
namespace EvaPosSCOSrv namespace EvaPosSCOSrv
{ {
/// <summary> /// <summary>
...@@ -278,24 +279,45 @@ namespace EvaPosSCOSrv ...@@ -278,24 +279,45 @@ namespace EvaPosSCOSrv
// Lee longitud mensaje entrante, 4 bytes. // Lee longitud mensaje entrante, 4 bytes.
Log.Debug("Esperando mensaje..."); Log.Debug("Esperando mensaje...");
var bufferLongitud = new byte[4]; var bufferLongitud = new byte[4];
//Entorno donde se encuentra la aplicacion
string entornoApi = Entorno<EntornoPOSBC>.Instancia.get().TipoEntorno;
//var bufferEntrada = new byte[1024];
byte[] bufferEntrada = new byte[1024];
int bytesLeidos = 0; int bytesLeidos = 0;
while (bytesLeidos < 4) if (entornoApi == "posbc")
{ {
bytesLeidos += socket.Receive(bufferLongitud, bytesLeidos, bufferLongitud.Length, SocketFlags.None); bytesLeidos = socket.Receive(bufferEntrada);
// Crear un nuevo array con el tamaño exacto de los datos recibidos
byte[] datosRecibidos = new byte[bytesLeidos];
// Copiar los datos recibidos al nuevo array
Array.Copy(bufferEntrada, datosRecibidos, bytesLeidos);
bufferEntrada = datosRecibidos;
} }
else
// Lee porción de datos del mensaje, hasta la longitud indicada en los 4 primeros bytes.
var longitudMensaje = LongitudMensaje(bufferLongitud);
Log.Debug("Longitud mensaje {long} - buffer longitud mensaje >>{buffer}<<", longitudMensaje, bufferLongitud);
if (longitudMensaje > LongMaxMensaje) throw new Exception($"Mensaje recibido de {longitudMensaje} bytes supera máximo permitido de {LongMaxMensaje} bytes.");
Log.Debug("Leyendo bytes con mensaje...");
var bufferEntrada = new byte[longitudMensaje];
bytesLeidos = 0;
while (bytesLeidos < longitudMensaje)
{ {
bytesLeidos += socket.Receive(bufferEntrada, bytesLeidos, bufferEntrada.Length, SocketFlags.None); while (bytesLeidos < 4)
{
bytesLeidos += socket.Receive(bufferLongitud, bytesLeidos, bufferLongitud.Length, SocketFlags.None);
}
// Lee porción de datos del mensaje, hasta la longitud indicada en los 4 primeros bytes.
var longitudMensaje = LongitudMensaje(bufferLongitud);
Log.Debug("Longitud mensaje {long} - buffer longitud mensaje >>{buffer}<<", longitudMensaje, bufferLongitud);
if (longitudMensaje > LongMaxMensaje) throw new Exception($"Mensaje recibido de {longitudMensaje} bytes supera máximo permitido de {LongMaxMensaje} bytes.");
Log.Debug("Leyendo bytes con mensaje...");
bufferEntrada = new byte[longitudMensaje];
bytesLeidos = 0;
while (bytesLeidos < longitudMensaje)
{
bytesLeidos += socket.Receive(bufferEntrada, bytesLeidos, bufferEntrada.Length, SocketFlags.None);
}
Log.Information("Bytes recibidos {bytes}", bytesLeidos);
} }
Log.Information("Bytes recibidos {bytes}", bytesLeidos);
Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada = bufferEntrada;
Entorno<EntornoPOSBC>.Instancia.get().CantBytes = bytesLeidos;
// Procesando entrada: se obtiene mensaje, con el cual se // Procesando entrada: se obtiene mensaje, con el cual se
// identifica comando que lo procesa, se ejecuta el comando // identifica comando que lo procesa, se ejecuta el comando
...@@ -491,7 +513,7 @@ namespace EvaPosSCOSrv ...@@ -491,7 +513,7 @@ namespace EvaPosSCOSrv
// valores inicializados en el DTO. // valores inicializados en el DTO.
cmd = _comandos.ObtieneComando(nodoRaiz.Name); cmd = _comandos.ObtieneComando(nodoRaiz.Name);
IAdaptadorDTO adaptador = _adaptadores.ObtieneAdaptador(nodoRaiz.Name); IAdaptadorDTO adaptador = _adaptadores.ObtieneAdaptador(nodoRaiz.Name);
DTOBase dto = adaptador.ObtieneDTO(mensaje.IdSesion, mensaje.TipoMensaje, docXml,mensaje.MensajeXml); DTOBase dto = adaptador.ObtieneDTO(mensaje.IdSesion, mensaje.TipoMensaje, docXml,mensaje.MensajeXml,mensaje.BufferEntrada,mensaje.CantBytes);
cmd.CargaDTO(dto); cmd.CargaDTO(dto);
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"GatewayConfig": { "GatewayConfig": {
"POS": "posbc", "POS": "posbc",
"POS_comment": "Indicates the set of commands to instantiate, according to the type of POS: evapos, tests, gk,posbc etc.", "POS_comment": "Indicates the set of commands to instantiate, according to the type of POS: evapos, tests, gk,posbc etc.",
"IpSCO": "10.89.81.101", "IpSCO": "192.168.168.135",
"IpSCO_comment": "SCO IP, local or remote", "IpSCO_comment": "SCO IP, local or remote",
"PortSCO": 6690, "PortSCO": 6690,
"PortSCO_comment": "SCO IP Port", "PortSCO_comment": "SCO IP Port",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment