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

Conexion con el POSBC

parent 9cdff4a9
......@@ -30,7 +30,7 @@ namespace EvaPosSrvResp
/// <summary>
/// Inicializar DTO adecuado al mensaje.
/// </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>
/// Retorna una "shallow copy" del objeto.
......@@ -107,6 +107,14 @@ namespace EvaPosSrvResp
/// <summary>
/// Propiedad que toma toda la trama xml que viene de chec, para asi enviarla al POSBC
/// </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
{
get
......@@ -120,25 +128,29 @@ namespace EvaPosSrvResp
/// <summary>
/// Constructor genérico.
/// </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;
IdSesion = idSesion;
TipoMensaje = tipo;
TextoXML = textoXML;
MensajeXml = mensajeXml;
BufferEntrada = bufferEntrada;
CantBytes = cantBytes;
}
/// <summary>
/// Constructor usado para calcular Longitud del mensaje (encabezado + texto xml).
/// </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;
TipoMensaje = tipo;
TextoXML = textoXML;
Longitud = Convert.ToUInt32(TextoEncabezado.Length + TextoXML.Length);
MensajeXml = mensajeXml;
BufferEntrada = bufferEntrada;
CantBytes = cantBytes;
}
}
......@@ -154,9 +166,11 @@ namespace EvaPosSrvResp
public TipoMensaje MessageType { get; private set; }
public abstract string TextoXML { get; }
public string MensajeXml { get; }
public byte[] BufferEntrada { get; private set; }
public int CantBytes { get; private set; }
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)
......
......@@ -13,6 +13,7 @@ using EvaPosSrvResp;
using EvaPosSrvAplicacion;
using EvaPOS_API_FRAME.RespuestasXML;
using EvaPOS_API_FRAME.Comandos;
using gatewayGK.POSBC;
namespace EvaPosSCOSrv
{
/// <summary>
......@@ -278,24 +279,45 @@ namespace EvaPosSCOSrv
// Lee longitud mensaje entrante, 4 bytes.
Log.Debug("Esperando mensaje...");
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;
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;
}
// 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)
else
{
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
// identifica comando que lo procesa, se ejecuta el comando
......@@ -491,7 +513,7 @@ namespace EvaPosSCOSrv
// valores inicializados en el DTO.
cmd = _comandos.ObtieneComando(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);
}
......
......@@ -2,7 +2,7 @@
"GatewayConfig": {
"POS": "posbc",
"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",
"PortSCO": 6690,
"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