"gatewayGK/ComandosPruebas/AddCustomerBirthdateCmd.cs" did not exist on "2e963f0b67bfa3a2ff9a6fcee6cd1fed06d8f656"
Commit dbe4bfb5 authored by Brayan Sarmiento's avatar Brayan Sarmiento
Browse files

Conexion Posbc -> ApiGateway

parent e59eba09
......@@ -17,6 +17,10 @@ namespace gatewayGK.POSBC
/// <summary>
/// Propiedad que toma el buffer de entrada de CHEC para enviarselo al POSBC
/// </summary>
public byte[] BufferSalida { get; set; } = new byte[0];
/// <summary>
/// Propiedad que toma el buffer de salida del POSBC para mandarselo a chec
/// </summary>
public int CantBytes { get; set; } = 0;
/// <summary>
/// Propiedad que toma la cantidad de bytes que vienen de CHEC
......
......@@ -44,7 +44,6 @@ namespace gatewayGK.POSBC
{
// Crear un socket TCP/IP
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// Configurar el endpoint (IP y puerto)
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(direccionIpPosbc), puerto);
......@@ -52,20 +51,57 @@ namespace gatewayGK.POSBC
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC");
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
Log.Information($"Datos enviados al servidor POSBC {dataToSend}");
Log.Information($"Buffer de entrada enviado al servidor POSBC {bufferRecibido}");
// Buffer para recibir la respuesta - Revisar cual es la mejor manera de recibir ese
List<byte> receivedBytes = new List<byte>();
byte[] bufferSalida = new byte[1024];
while (true)
{
int bytesLeidos = 0;
bytesLeidos = socket.Receive(bufferSalida, 0, bufferSalida.Length, SocketFlags.None);
//Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0
if (bytesLeidos == 0 || bytesLeidos == 1)
{
// El socket se ha cerrado
break;
}
// Buffer para recibir la respuesta
byte[] buffer = new byte[1024];
int bytesReceived = socket.Receive(buffer);
// Añadir los bytes leídos a la lista
for (int i = 0; i < bytesLeidos; i++)
{
receivedBytes.Add(bufferSalida[i]);
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Entorno<EntornoPOSBC>.Instancia.get().BufferSalida = data;
// Convertir los datos recibidos a una cadena
string response = Encoding.UTF8.GetString(buffer, 0, bytesReceived);
Log.Information($"Respuesta recibida del POSBC {response}");
//buffer de salida del POSBC
//byte[] bufferSalida = new byte[3048];
//int bytesLeidos = 0;
//bytesLeidos = socket.Receive(bufferSalida, bytesLeidos, bufferSalida.Length, SocketFlags.None);
//string pasarXml = Encoding.UTF8.GetString(bufferSalida, 0, bytesLeidos);
//Log.Information($"Xml Armado {pasarXml}");
//byte[] datosRecibidos = new byte[bytesLeidos];
//// Copiar los datos recibidos al nuevo array
//Array.Copy(bufferSalida, datosRecibidos, bytesLeidos);
//// Convertir los datos recibidos a una cadena
//bufferSalida = datosRecibidos;
////string response = Encoding.UTF8.GetString(buffer, 0, bytesReceived);
//Log.Information($"buffer de salida recibido del POSBC {bufferSalida}");
//Entorno<EntornoPOSBC>.Instancia.get().BufferSalida = bufferSalida;
// Cerrar el socket
socket.Shutdown(SocketShutdown.Both);
socket.Close();
......@@ -80,7 +116,7 @@ namespace gatewayGK.POSBC
{
Log.Error("Error:", ex.Message);
}
//Esto como se manejara?
return new Respuestas();
}
......
using EvaPOS_API_FRAME.DTO;
using EvaPosSrvDTO;
using EvaPosSrvResp;
using GatewaySCO;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;
......@@ -23,9 +27,73 @@ namespace gatewayGK.POSBC
/// <summary>
/// Procesa y responde QueryStatusRequest.
/// </summary>
///
public Respuestas Ejecutar()
{
string direccionIpPosbc = "127.0.0.1";
int puerto = 6697;
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
try
{
// Crear un socket TCP/IP
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// Configurar el endpoint (IP y puerto)
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(direccionIpPosbc), puerto);
//Conectar al endpoint
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC");
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
Log.Information($"Buffer de entrada enviado al servidor POSBC {bufferRecibido}");
// Buffer para recibir la respuesta - Revisar cual es la mejor manera de recibir ese
List<byte> receivedBytes = new List<byte>();
byte[] bufferSalida = new byte[1024];
while (true)
{
int bytesLeidos = 0;
bytesLeidos = socket.Receive(bufferSalida, 0, bufferSalida.Length, SocketFlags.None);
//Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0
if (bytesLeidos == 0 || bytesLeidos == 1)
{
// El socket se ha cerrado
break;
}
// Añadir los bytes leídos a la lista
for (int i = 0; i < bytesLeidos; i++)
{
receivedBytes.Add(bufferSalida[i]);
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Entorno<EntornoPOSBC>.Instancia.get().BufferSalida = data;
socket.Shutdown(SocketShutdown.Both);
socket.Close();
}
catch (SocketException ex)
{
Log.Error($"Error de Socket: {ex.Message}");
Log.Error($"Código de error de Socket: {ex.SocketErrorCode}");
Log.Error(ex.StackTrace);
}
catch (Exception ex)
{
Log.Error("Error:", ex.Message);
}
//Esto como se manejara?
return new Respuestas();
}
......
using EvaPOS_API_FRAME.DTO;
using EvaPosSrvDTO;
using EvaPosSrvResp;
using GatewaySCO;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;
......@@ -26,6 +30,69 @@ namespace gatewayGK.POSBC
///
public Respuestas Ejecutar()
{
string direccionIpPosbc = "127.0.0.1";
int puerto = 6697;
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
try
{
// Crear un socket TCP/IP
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// Configurar el endpoint (IP y puerto)
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(direccionIpPosbc), puerto);
//Conectar al endpoint
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC");
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
Log.Information($"Buffer de entrada enviado al servidor POSBC {bufferRecibido}");
// Buffer para recibir la respuesta - Revisar cual es la mejor manera de recibir ese
List<byte> receivedBytes = new List<byte>();
byte[] bufferSalida = new byte[1024];
while (true)
{
int bytesLeidos = 0;
bytesLeidos = socket.Receive(bufferSalida, 0, bufferSalida.Length, SocketFlags.None);
//Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0
if (bytesLeidos == 0 || bytesLeidos == 1)
{
// El socket se ha cerrado
break;
}
// Añadir los bytes leídos a la lista
for (int i = 0; i < bytesLeidos; i++)
{
receivedBytes.Add(bufferSalida[i]);
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Entorno<EntornoPOSBC>.Instancia.get().BufferSalida = data;
socket.Shutdown(SocketShutdown.Both);
socket.Close();
}
catch (SocketException ex)
{
Log.Error($"Error de Socket: {ex.Message}");
Log.Error($"Código de error de Socket: {ex.SocketErrorCode}");
Log.Error(ex.StackTrace);
}
catch (Exception ex)
{
Log.Error("Error:", ex.Message);
}
//Esto como se manejara?
return new Respuestas();
}
......
......@@ -56,7 +56,7 @@ namespace GatewaySCO
Entorno<EntornoGK>.Instancia.get().ConfigGk = configGk;
Log.Information($"GK {Entorno<EntornoGK>.Instancia.get().UrlBase}");
}
if(config.POS == "posbc")
if(config.POS == "posbc" || config.POS == "pruebas")
{
Entorno<EntornoPOSBC>.Instancia.set(new EntornoPOSBC());
Log.Information($"Inicio del entorno POSBC");
......
......@@ -14,6 +14,7 @@ using EvaPosSrvAplicacion;
using EvaPOS_API_FRAME.RespuestasXML;
using EvaPOS_API_FRAME.Comandos;
using gatewayGK.POSBC;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace EvaPosSCOSrv
{
/// <summary>
......@@ -291,6 +292,8 @@ namespace EvaPosSCOSrv
byte[] datosRecibidos = new byte[bytesLeidos];
// Copiar los datos recibidos al nuevo array
Array.Copy(bufferEntrada, datosRecibidos, bytesLeidos);
//Revisamos que xml envio Chec
string resultadoXml = Encoding.UTF8.GetString(bufferEntrada);
bufferEntrada = datosRecibidos;
}
else
......@@ -339,6 +342,15 @@ namespace EvaPosSCOSrv
}
respuestas = _aplicacion.Procesar(cmd);
//TODO - Logica para mandar la respuesta del POSBC
if(entornoApi == "posbc")
{
byte[] bufferSalidaRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferSalida;
socket.Send(bufferSalidaRecibido, 0, bufferSalidaRecibido.Length, SocketFlags.None);
Log.Information("Bytes enviados {bytes} del servidor POSBC", bufferSalidaRecibido.Length);
}
else
{
Log.Debug("Respuestas de cmd ref '{cmd}' : {nroRespuestas}", cmd.Referencia, respuestas.Count);
// Enviando respuestas.
......@@ -350,6 +362,8 @@ namespace EvaPosSCOSrv
socket.Send(bufferSalida, 0, bufferSalida.Length, SocketFlags.None);
Log.Information("Bytes enviados {bytes}", bufferSalida.Length);
}
}
log.Information("Fin del ciclo, se enviaron {nro} respuestas", respuestas.Count);
......
......@@ -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": "192.168.168.135",
"IpSCO": "10.89.81.102",
"IpSCO_comment": "SCO IP, local or remote",
"PortSCO": 6690,
"PortSCO_comment": "SCO IP Port",
......@@ -24,6 +24,10 @@
"BusinessUnitGroupID": "1000",
"TillID": "103"
},
"posbc": {
"DireccionIpPosbc": "127.0.0.1",
"PuertoPosbc": "6697"
},
"Serilog": {
"Using": [
"Serilog.Sinks.Console",
......
......@@ -29,4 +29,6 @@
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>
</Project>
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