Commit 7bba23e7 authored by Brayan Sarmiento's avatar Brayan Sarmiento
Browse files

Creacion todos los comandos para el POSBC

parent 7be3dce9
......@@ -23,7 +23,7 @@ namespace EvaPOS_API_FRAME.Comandos
/// </summary>
public AddReceiptLinesRequest Request { get; private set; }
/// <summary>
/// Procesa y responde ReportStatusEventsRequest.
/// Procesa y responde AddReceiptLines.
/// </summary>
public Respuestas Ejecutar()
......
using EvaPOS_API_FRAME.DTO;
using EvaPosSrvResp;
using gatewayGK.Infraestructura;
using gatewayGK.POSBC;
using GatewaySCO;
using Microsoft.Extensions.Configuration;
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;
using EvaPOS_API_FRAME.Comandos;
using EvaPosSrvDTO;
namespace gatewayGK.ComandosPruebas
{
///<summary>
/// Procesa el comando cuando se va a reimprimir una transacción
/// </summary>
public class ReprintReceiptsPosbcCmd : IComando
{
public string Referencia { get; set; } = "scsns:ReprintReceipts";
/// <summary>
/// DTO con solicitud.
/// </summary>
public ReprintReceiptsRequestDTO Request { get; private set; }
/// <summary>
/// Procesa y responde del evento reimprimir.
/// </summary>
///
public Respuestas Ejecutar()
{
IConfiguration configBuilder = ConfigurationHelper.Configuration;
string direccionIpPosbc = configBuilder["posbc:DireccionIpPosbc"];
string puertoPosbcString = configBuilder["posbc:PuertoPosbc"];
int puertoPosbcInt = int.Parse(puertoPosbcString);
Log.Information($"Inicio del comando QueryStatus para realizar conexión con el POSBC");
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
Log.Information($"Cantidad de bytes recibido desde CHEC: {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), puertoPosbcInt);
//Conectar al endpoint
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC...");
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000; // en milisegundos
// 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;
if (socket.Poll(5000000, SelectMode.SelectRead)) // 5 segundos en microsegundos
{
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]);
}
}
else
{
// Tiempo de espera agotado
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Log.Information($"XML de respuesta recibido por parte del POSBC:{result}");
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();
}
public IComando CreaCopia()
{
return (ReprintReceiptsPosbcCmd)this.MemberwiseClone();
}
public void CargaDTO(DTOBase reprintReceiptsDTO)
{
Request = (ReprintReceiptsRequestDTO)reprintReceiptsDTO;
}
}
}
using EvaPOS_API_FRAME.DTO;
using EvaPosSrvResp;
using gatewayGK.Infraestructura;
using gatewayGK.POSBC;
using GatewaySCO;
using Microsoft.Extensions.Configuration;
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;
using EvaPOS_API_FRAME.Comandos;
using EvaPosSrvDTO;
namespace gatewayGK.ComandosPruebas
{
///<summary>
/// Comando para cancelar una transacción
/// </summary>
public class VoidTransactionPosbcCmd : IComando
{
public string Referencia { get; set; } = "scsns:VoidTransaction";
/// <summary>
/// DTO con solicitud.
/// </summary>
public VoidTransactionDTO Request { get; private set; }
/// <summary>
/// Procesa y responde VoidTransactionRequest.
/// </summary>
public Respuestas Ejecutar()
{
IConfiguration configBuilder = ConfigurationHelper.Configuration;
string direccionIpPosbc = configBuilder["posbc:DireccionIpPosbc"];
string puertoPosbcString = configBuilder["posbc:PuertoPosbc"];
int puertoPosbcInt = int.Parse(puertoPosbcString);
Log.Information($"Inicio del comando VoidTransaction para realizar conexión con el POSBC");
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
Log.Information($"Cantidad de bytes recibido desde CHEC: {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), puertoPosbcInt);
//Conectar al endpoint
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC...");
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000; // en milisegundos
// 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;
if (socket.Poll(5000000, SelectMode.SelectRead)) // 5 segundos en microsegundos
{
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]);
}
}
else
{
// Tiempo de espera agotado
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Log.Information($"XML de respuesta recibido por parte del POSBC:{result}");
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();
}
public IComando CreaCopia()
{
return (VoidTransactionPosbcCmd)this.MemberwiseClone();
}
public void CargaDTO(DTOBase voidTransactionDTO)
{
Request = (VoidTransactionDTO)voidTransactionDTO;
}
}
}
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace gatewayGK.Infraestructura
{
public static class ConfigurationHelper
{
public static IConfiguration Configuration { get; private set; }
static ConfigurationHelper()
{
Configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.Build();
}
}
}
using gatewayGK.POSBC;
using gatewayGK.ComandosPruebas;
using gatewayGK.POSBC;
using Serilog;
using System;
using System.Collections.Generic;
......@@ -26,6 +27,21 @@ namespace gatewayGK.Infraestructura
.AgregaCmd(new InitializeRequestPosbcCmd())
.AgregaCmd(new QueryStatusRequestPosbcCmd())
.AgregaCmd(new ReportStatusEventsRequestPosbcCmd())
.AgregaCmd(new TerminateRequestPosbcCmd())
.AgregaCmd(new AddItemRequestPosbcCmd())
.AgregaCmd(new AddReceiptLinesRequestPosbcCmd())
.AgregaCmd(new AddTenderDebitPosbcCmd())
.AgregaCmd(new CancelActionPosbcCmd())
.AgregaCmd(new ErrorPosbcCmd())
.AgregaCmd(new GetTotalsRequestPosbcCmd())
.AgregaCmd(new PrintCurrentReceiptsRequestPosbcCmd())
.AgregaCmd(new RemoveReceiptLinesPosbcCmd())
.AgregaCmd(new ReprintReceiptsPosbcCmd())
.AgregaCmd(new SignOffResponsePosbcCmd())
.AgregaCmd(new SuspendTransactionRequestPosbcCmd())
.AgregaCmd(new VoidTransactionPosbcCmd())
.AgregaCmd(new AddCustomerBirthdatePosbcCmd())
.AgregaCmd(new AddCustomerPosbcCmd())
.DirectorioCmds;
}
}
......
using EvaPOS_API_FRAME.DTO;
using EvaPosSrvResp;
using gatewayGK.Infraestructura;
using GatewaySCO;
using Microsoft.Extensions.Configuration;
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;
using EvaPOS_API_FRAME.Comandos;
using EvaPosSrvDTO;
namespace gatewayGK.POSBC
{
///<summary>
/// Comando para la construcción de la logica "Restricción de edad"
/// </summary>
public class AddCustomerBirthdatePosbcCmd : IComando
{
public string Referencia { get; set; } = "scsns:AddCustomerBirthdate";
/// <summary>
/// DTO con solicitud.
/// </summary>
public AddCustomerBirthdateRequest Request { get; private set; }
/// <summary>
/// Procesa y responde AddCustomerBirthdateRequest.
/// </summary>
public Respuestas Ejecutar()
{
IConfiguration configBuilder = ConfigurationHelper.Configuration;
string direccionIpPosbc = configBuilder["posbc:DireccionIpPosbc"];
string puertoPosbcString = configBuilder["posbc:PuertoPosbc"];
int puertoPosbcInt = int.Parse(puertoPosbcString);
Log.Information($"Inicio del comando QueryStatus para realizar conexión con el POSBC");
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
Log.Information($"Cantidad de bytes recibido desde CHEC: {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), puertoPosbcInt);
//Conectar al endpoint
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC...");
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000; // en milisegundos
// 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;
if (socket.Poll(5000000, SelectMode.SelectRead)) // 5 segundos en microsegundos
{
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]);
}
}
else
{
// Tiempo de espera agotado
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Log.Information($"XML de respuesta recibido por parte del POSBC:{result}");
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();
}
public IComando CreaCopia()
{
return (AddCustomerBirthdatePosbcCmd)this.MemberwiseClone();
}
public void CargaDTO(DTOBase addCustomerBirthdateRequest)
{
Request = (AddCustomerBirthdateRequest)addCustomerBirthdateRequest;
}
}
}
using EvaPOS_API_FRAME.DTO;
using EvaPosSrvResp;
using gatewayGK.Infraestructura;
using GatewaySCO;
using Microsoft.Extensions.Configuration;
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;
using EvaPOS_API_FRAME.Comandos;
using EvaPosSrvDTO;
namespace gatewayGK.POSBC
{
/// <summary>
/// Comando para agregar un cliente
/// </summary>
public class AddCustomerPosbcCmd : IComando
{
public string Referencia { get; set; } = "scsns:AddCustomer";
/// <summary>
/// DTO con solicitud.
/// </summary>
public AddCustomerRequest Request { get; set; }
/// <summary>
/// Procesa y responde AddCustomerRequest.
/// </summary>
public Respuestas Ejecutar()
{
IConfiguration configBuilder = ConfigurationHelper.Configuration;
string direccionIpPosbc = configBuilder["posbc:DireccionIpPosbc"];
string puertoPosbcString = configBuilder["posbc:PuertoPosbc"];
int puertoPosbcInt = int.Parse(puertoPosbcString);
Log.Information($"Inicio del comando AddCustomer para realizar conexión con el POSBC");
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
Log.Information($"Cantidad de bytes recibido desde CHEC: {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), puertoPosbcInt);
//Conectar al endpoint
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC...");
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000; // en milisegundos
// 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;
if (socket.Poll(5000000, SelectMode.SelectRead)) // 5 segundos en microsegundos
{
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]);
}
}
else
{
// Tiempo de espera agotado
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Log.Information($"XML de respuesta recibido por parte del POSBC:{result}");
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();
}
public IComando CreaCopia()
{
return (AddCustomerPosbcCmd)this.MemberwiseClone();
}
public void CargaDTO(DTOBase addCustomerRequest)
{
Request = (AddCustomerRequest)addCustomerRequest;
}
}
}
using EvaPOS_API_FRAME.DTO;
using EvaPosSrvDTO;
using EvaPosSrvResp;
using gatewayGK.Infraestructura;
using GatewaySCO;
using Microsoft.Extensions.Configuration;
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;
namespace gatewayGK.POSBC
{
///<summary>
/// Procesa solicitudes del primer item agregado.
/// </summary>
public class AddItemRequestPosbcCmd : IComando
{
public string Referencia { get; set; } = "scsns:AddItem";
/// <summary>
/// DTO con solicitud.
/// </summary>
public AddItemRequestDTO Request { get; private set; }
/// <summary>
/// Procesa y responde ReportStatusEventsRequest.
/// </summary>
public Respuestas Ejecutar()
{
IConfiguration configBuilder = ConfigurationHelper.Configuration;
string direccionIpPosbc = configBuilder["posbc:DireccionIpPosbc"];
string puertoPosbcString = configBuilder["posbc:PuertoPosbc"];
int puertoPosbcInt = int.Parse(puertoPosbcString);
Log.Information($"Inicio del comando AddItem para realizar conexión con el POSBC");
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
Log.Information($"Tamaño del buffer recibido desde CHEC: {bufferRecibido}");
Log.Information($"Cantidad de bytes recibido desde CHEC: {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), puertoPosbcInt);
//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}");
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000;
// 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;
if (socket.Poll(5000000, SelectMode.SelectRead))
{
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]);
}
}
else
{
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Log.Information($"XML de respuesta recibido por parte del POSBC:{result}");
Entorno<EntornoPOSBC>.Instancia.get().BufferSalida = data;
// Cerrar el socket
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);
}
return new Respuestas();
}
public IComando CreaCopia()
{
return (AddItemRequestPosbcCmd)this.MemberwiseClone();
}
public void CargaDTO(DTOBase addItemRequestDTO)
{
Request = (AddItemRequestDTO)addItemRequestDTO;
}
}
}
using EvaPOS_API_FRAME.DTO;
using EvaPosSrvDTO;
using EvaPosSrvResp;
using gatewayGK.Infraestructura;
using GatewaySCO;
using Microsoft.Extensions.Configuration;
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;
namespace gatewayGK.POSBC
{
///<summary>
/// Procesa el salto del empaque del producto
/// </summary>
public class AddReceiptLinesRequestPosbcCmd : IComando
{
public string Referencia { get; set; } = "scsns:AddReceiptLines";
/// <summary>
/// DTO con solicitud.
/// </summary>
public AddReceiptLinesRequest Request { get; private set; }
/// <summary>
/// Procesa y responde AddReceiptLines.
/// </summary>
public Respuestas Ejecutar()
{
IConfiguration configBuilder = ConfigurationHelper.Configuration;
string direccionIpPosbc = configBuilder["posbc:DireccionIpPosbc"];
string puertoPosbcString = configBuilder["posbc:PuertoPosbc"];
int puertoPosbcInt = int.Parse(puertoPosbcString);
Log.Information($"Inicio del comando AddReceiptLinesRequest para realizar conexión con el POSBC");
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
Log.Information($"Cantidad de bytes recibido desde CHEC: {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), puertoPosbcInt);
//Conectar al endpoint
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC...");
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000; // en milisegundos
// 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;
if (socket.Poll(5000000, SelectMode.SelectRead)) // 5 segundos en microsegundos
{
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]);
}
}
else
{
// Tiempo de espera agotado
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Log.Information($"XML de respuesta recibido por parte del POSBC:{result}");
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);
}
return new Respuestas();
}
public IComando CreaCopia()
{
return (AddReceiptLinesRequestPosbcCmd)this.MemberwiseClone();
}
public void CargaDTO(DTOBase addReceiptLinesRequest)
{
Request = (AddReceiptLinesRequest)addReceiptLinesRequest;
}
}
}
using EvaPOS_API_FRAME.Comandos;
using EvaPOS_API_FRAME.DTO;
using EvaPosSrvDTO;
using EvaPosSrvResp;
using gatewayGK.Infraestructura;
using GatewaySCO;
using Microsoft.Extensions.Configuration;
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;
namespace gatewayGK.POSBC
{
///<summary>
/// Procesa solicitudes del pago
/// </summary>
public class AddTenderDebitPosbcCmd : IComando
{
public string Referencia { get; set; } = "scsns:AddTender";
/// <summary>
/// DTO con solicitud.
/// </summary>
public AddTenderRequest Request { get; private set; }
/// <summary>
/// Procesa y responde eventos del pago con tarjeta de debito
/// </summary>
///
public Respuestas Ejecutar()
{
IConfiguration configBuilder = ConfigurationHelper.Configuration;
string direccionIpPosbc = configBuilder["posbc:DireccionIpPosbc"];
string puertoPosbcString = configBuilder["posbc:PuertoPosbc"];
int puertoPosbcInt = int.Parse(puertoPosbcString);
Log.Information($"Inicio del comando AddTender para realizar conexión con el POSBC");
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
Log.Information($"Cantidad de bytes recibido desde CHEC: {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), puertoPosbcInt);
//Conectar al endpoint
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC...");
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000; // en milisegundos
// 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;
if (socket.Poll(5000000, SelectMode.SelectRead)) // 5 segundos en microsegundos
{
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]);
}
}
else
{
// Tiempo de espera agotado
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Log.Information($"XML de respuesta recibido por parte del POSBC:{result}");
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();
}
public IComando CreaCopia()
{
return (AddTenderDebitPosbcCmd)this.MemberwiseClone();
}
public void CargaDTO(DTOBase AddTenderRequestDebitDTO)
{
Request = (AddTenderRequest)AddTenderRequestDebitDTO;
}
}
}
using EvaPosSrvResp;
using gatewayGK.Infraestructura;
using GatewaySCO;
using Microsoft.Extensions.Configuration;
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;
using static EvaPOS_API_FRAME.DTO.CancelActionDTO;
using EvaPOS_API_FRAME.Comandos;
using EvaPosSrvDTO;
namespace gatewayGK.POSBC
{
/// <summary>
/// Comando para cancelar acción en el Datafóno
/// </summary>
public class CancelActionPosbcCmd : IComando
{
public string Referencia { get; set; } = "scsns:CancelAction";
/// <summary>
/// DTO con la solicitud de referencia.
/// </summary>
public CancelActionRequest Request { get; private set; }
/// <summary>
/// Procesa y responde el evento Request.
/// </summary>
public Respuestas Ejecutar()
{
IConfiguration configBuilder = ConfigurationHelper.Configuration;
string direccionIpPosbc = configBuilder["posbc:DireccionIpPosbc"];
string puertoPosbcString = configBuilder["posbc:PuertoPosbc"];
int puertoPosbcInt = int.Parse(puertoPosbcString);
Log.Information($"Inicio del comando QueryStatus para realizar conexión con el POSBC");
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
Log.Information($"Cantidad de bytes recibido desde CHEC: {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), puertoPosbcInt);
//Conectar al endpoint
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC...");
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000; // en milisegundos
// 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;
if (socket.Poll(5000000, SelectMode.SelectRead)) // 5 segundos en microsegundos
{
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]);
}
}
else
{
// Tiempo de espera agotado
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Log.Information($"XML de respuesta recibido por parte del POSBC:{result}");
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();
}
public IComando CreaCopia()
{
return (CancelActionPosbcCmd)MemberwiseClone();
}
public void CargaDTO(DTOBase CancelActionDTO)
{
Request = (CancelActionRequest)CancelActionDTO;
}
}
}
using EvaPosSrvDTO;
using EvaPosSrvResp;
using gatewayGK.Infraestructura;
using GatewaySCO;
using Microsoft.Extensions.Configuration;
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;
using EvaPOS_API_FRAME.Comandos;
namespace gatewayGK.POSBC
{
/// <summary>
/// Comando para procesar situaciones de error.
/// </summary>
public class ErrorPosbcCmd : IComando
{
/// <summary>
/// Referencia del mensaje.
/// </summary>
public string Referencia { get; set; } = "error";
/// <summary>
/// Campo ErrorDTO
/// </summary>
public ErrorDTO? Error { get; private set; }
/// <summary>
/// Constructor desde un DTO con mensaje de texto.
/// </summary>
public Respuestas Ejecutar()
{
IConfiguration configBuilder = ConfigurationHelper.Configuration;
string direccionIpPosbc = configBuilder["posbc:DireccionIpPosbc"];
string puertoPosbcString = configBuilder["posbc:PuertoPosbc"];
int puertoPosbcInt = int.Parse(puertoPosbcString);
Log.Information($"Inicio del comando QueryStatus para realizar conexión con el POSBC");
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
Log.Information($"Cantidad de bytes recibido desde CHEC: {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), puertoPosbcInt);
//Conectar al endpoint
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC...");
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000; // en milisegundos
// 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;
if (socket.Poll(5000000, SelectMode.SelectRead)) // 5 segundos en microsegundos
{
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]);
}
}
else
{
// Tiempo de espera agotado
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Log.Information($"XML de respuesta recibido por parte del POSBC:{result}");
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();
}
/// <summary>
/// Retorna copia del comando.
/// </summary>
public IComando CreaCopia()
{
return (ErrorPosbcCmd)this.MemberwiseClone();
}
public void CargaDTO(DTOBase errorDTO)
{
Error = (ErrorDTO)errorDTO;
}
}
}
using EvaPOS_API_FRAME.DTO;
using EvaPosSrvResp;
using gatewayGK.Infraestructura;
using GatewaySCO;
using Microsoft.Extensions.Configuration;
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;
using EvaPOS_API_FRAME.Comandos;
using EvaPosSrvDTO;
namespace gatewayGK.POSBC
{
///<summary>
/// Comando que procesa el estado de pagar venta
/// </summary>
public class GetTotalsRequestPosbcCmd : IComando
{
public string Referencia { get; set; } = "scsns:GetTotals";
/// <summary>
/// DTO con solicitud.
/// </summary>
public GetTotalsRequest Request { get; private set; }
/// <summary>
/// Procesa y responde GetTotalsRequest.
/// </summary>
public Respuestas Ejecutar()
{
IConfiguration configBuilder = ConfigurationHelper.Configuration;
string direccionIpPosbc = configBuilder["posbc:DireccionIpPosbc"];
string puertoPosbcString = configBuilder["posbc:PuertoPosbc"];
int puertoPosbcInt = int.Parse(puertoPosbcString);
Log.Information($"Inicio del comando GetTotals para realizar conexión con el POSBC");
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
Log.Information($"Cantidad de bytes recibido desde CHEC: {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), puertoPosbcInt);
//Conectar al endpoint
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC...");
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000; // en milisegundos
// 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;
if (socket.Poll(5000000, SelectMode.SelectRead)) // 5 segundos en microsegundos
{
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]);
}
}
else
{
// Tiempo de espera agotado
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Log.Information($"XML de respuesta recibido por parte del POSBC:{result}");
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();
}
public IComando CreaCopia()
{
return (GetTotalsRequestPosbcCmd)this.MemberwiseClone();
}
public void CargaDTO(DTOBase getTotalsRequestDTO)
{
Request = (GetTotalsRequest)getTotalsRequestDTO;
}
}
}
using EvaPosSrvDTO;
using EvaPosSrvResp;
using gatewayGK.Infraestructura;
using GatewaySCO;
using Microsoft.Extensions.Configuration;
using Serilog;
using System;
using System.Collections.Generic;
......@@ -30,26 +32,33 @@ namespace gatewayGK.POSBC
/// </summary>
public Respuestas Ejecutar()
{
string direccionIpPosbc = "127.0.0.1";
int puerto = 6697;
IConfiguration configBuilder = ConfigurationHelper.Configuration;
string direccionIpPosbc = configBuilder["posbc:DireccionIpPosbc"];
string puertoPosbcString = configBuilder["posbc:PuertoPosbc"];
int puertoPosbcInt = int.Parse(puertoPosbcString);
string xmlData = Request.mensajeXml;
Log.Information($"Inicio del comando InitializeRequest para realizar conexión con el POSBC");
Log.Information($"Dirección IP del servidor POSBC {direccionIpPosbc}, Puerto de conexión: {puertoPosbcInt}");
// Convertir la trama XML a bytes
byte[] dataToSend = Encoding.UTF8.GetBytes(xmlData);
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
Log.Information($"Tamaño del buffer recibido desde CHEC: {bufferRecibido}");
Log.Information($"Cantidad de bytes recibido desde CHEC: {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);
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(direccionIpPosbc), puertoPosbcInt);
//Conectar al endpoint
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC");
Log.Information("Conectandose al servidor POSBC...");
// Enviar los datos
......@@ -57,28 +66,18 @@ namespace gatewayGK.POSBC
Log.Information($"Buffer de entrada enviado al servidor POSBC {bufferRecibido}");
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 10000;
socket.ReceiveTimeout = 5000;
// 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;
try
if (socket.Poll(5000000, SelectMode.SelectRead))
{
bytesLeidos = socket.Receive(bufferSalida, 0, bufferSalida.Length, SocketFlags.None);
}
catch (SocketException ex)
{
if (ex.SocketErrorCode == SocketError.TimedOut)
{
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
//Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0
if (bytesLeidos == 0 || bytesLeidos == 1)
......@@ -93,11 +92,19 @@ namespace gatewayGK.POSBC
receivedBytes.Add(bufferSalida[i]);
}
}
else
{
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Log.Information($"XML de respuesta recibido por parte del POSBC:{result}");
Entorno<EntornoPOSBC>.Instancia.get().BufferSalida = data;
// Cerrar el socket
......
using EvaPOS_API_FRAME.DTO;
using EvaPosSrvResp;
using gatewayGK.Infraestructura;
using GatewaySCO;
using Microsoft.Extensions.Configuration;
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;
using EvaPOS_API_FRAME.Comandos;
using EvaPosSrvDTO;
namespace gatewayGK.POSBC
{
///<summary>
/// Comando que procesa las solicitudes de la impresora
///</summary>
public class PrintCurrentReceiptsRequestPosbcCmd : IComando
{
public string Referencia { get; set; } = "scsns:PrintCurrentReceipts";
/// <summary>
/// DTO con solicitud.
/// </summary>
public PrintCurrentReceiptsRequest Request { get; private set; }
/// <summary>
/// Procesa y responde eventos de la impresora dependiendo al id
/// </summary>
public Respuestas Ejecutar()
{
IConfiguration configBuilder = ConfigurationHelper.Configuration;
string direccionIpPosbc = configBuilder["posbc:DireccionIpPosbc"];
string puertoPosbcString = configBuilder["posbc:PuertoPosbc"];
int puertoPosbcInt = int.Parse(puertoPosbcString);
Log.Information($"Inicio del comando PrintCurrentReceipts para realizar conexión con el POSBC");
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
Log.Information($"Cantidad de bytes recibido desde CHEC: {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), puertoPosbcInt);
//Conectar al endpoint
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC...");
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000; // en milisegundos
// 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;
if (socket.Poll(5000000, SelectMode.SelectRead)) // 5 segundos en microsegundos
{
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]);
}
}
else
{
// Tiempo de espera agotado
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Log.Information($"XML de respuesta recibido por parte del POSBC:{result}");
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();
}
public IComando CreaCopia()
{
return (PrintCurrentReceiptsRequestPosbcCmd)this.MemberwiseClone();
}
public void CargaDTO(DTOBase printCurrentReceiptsRequestDTO)
{
Request = (PrintCurrentReceiptsRequest)printCurrentReceiptsRequestDTO;
}
}
}
......@@ -10,6 +10,8 @@ using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using gatewayGK.Infraestructura;
using Microsoft.Extensions.Configuration;
namespace gatewayGK.POSBC
{
......@@ -31,25 +33,33 @@ namespace gatewayGK.POSBC
public Respuestas Ejecutar()
{
string direccionIpPosbc = "127.0.0.1";
int puerto = 6697;
IConfiguration configBuilder = ConfigurationHelper.Configuration;
string direccionIpPosbc = configBuilder["posbc:DireccionIpPosbc"];
string puertoPosbcString = configBuilder["posbc:PuertoPosbc"];
int puertoPosbcInt = int.Parse(puertoPosbcString);
Log.Information($"Inicio del comando QueryStatus para realizar conexión con el POSBC");
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
Log.Information($"Cantidad de bytes recibido desde CHEC: {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);
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(direccionIpPosbc), puertoPosbcInt);
//Conectar al endpoint
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC");
Log.Information("Conectandose al servidor POSBC...");
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
Log.Information($"Buffer de entrada enviado al servidor POSBC {bufferRecibido}");
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000; // en milisegundos
......@@ -61,18 +71,9 @@ namespace gatewayGK.POSBC
while (true)
{
int bytesLeidos = 0;
try
if (socket.Poll(5000000, SelectMode.SelectRead)) // 5 segundos en microsegundos
{
bytesLeidos = socket.Receive(bufferSalida, 0, bufferSalida.Length, SocketFlags.None);
}
catch(SocketException ex)
{
if (ex.SocketErrorCode == SocketError.TimedOut)
{
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
//Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0
if (bytesLeidos == 0 || bytesLeidos == 1)
......@@ -87,11 +88,20 @@ namespace gatewayGK.POSBC
receivedBytes.Add(bufferSalida[i]);
}
}
else
{
// Tiempo de espera agotado
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Log.Information($"XML de respuesta recibido por parte del POSBC:{result}");
Entorno<EntornoPOSBC>.Instancia.get().BufferSalida = data;
socket.Shutdown(SocketShutdown.Both);
......
using EvaPosSrvResp;
using gatewayGK.Infraestructura;
using GatewaySCO;
using Microsoft.Extensions.Configuration;
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;
using static EvaPOS_API_FRAME.DTO.RemoveReceiptLinesDTO;
using EvaPOS_API_FRAME.Comandos;
using EvaPosSrvDTO;
namespace gatewayGK.POSBC
{
public class RemoveReceiptLinesPosbcCmd : IComando
{
/// <summary>
/// Comando que procesa la solicitud de CHEC "Saltar a la bolsa"
/// </summary>
public string Referencia { get; set; } = "scsns:RemoveReceiptLines";
/// <summary>
/// DTO con solicitud.
/// </summary>
public RemoveReceiptLinesRequest Request { get; private set; }
/// <summary>
/// Procesa y responde ReportStatusEventsRequest.
/// </summary>
public Respuestas Ejecutar()
{
IConfiguration configBuilder = ConfigurationHelper.Configuration;
string direccionIpPosbc = configBuilder["posbc:DireccionIpPosbc"];
string puertoPosbcString = configBuilder["posbc:PuertoPosbc"];
int puertoPosbcInt = int.Parse(puertoPosbcString);
Log.Information($"Inicio del comando QueryStatus para realizar conexión con el POSBC");
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
Log.Information($"Cantidad de bytes recibido desde CHEC: {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), puertoPosbcInt);
//Conectar al endpoint
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC...");
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000; // en milisegundos
// 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;
if (socket.Poll(5000000, SelectMode.SelectRead)) // 5 segundos en microsegundos
{
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]);
}
}
else
{
// Tiempo de espera agotado
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Log.Information($"XML de respuesta recibido por parte del POSBC:{result}");
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();
}
public IComando CreaCopia()
{
return (RemoveReceiptLinesPosbcCmd)this.MemberwiseClone();
}
public void CargaDTO(DTOBase removeReceiptLinesRequest)
{
Request = (RemoveReceiptLinesRequest)removeReceiptLinesRequest;
}
}
}
......@@ -11,6 +11,8 @@ using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using gatewayGK.Infraestructura;
using Microsoft.Extensions.Configuration;
namespace gatewayGK.POSBC
{
......@@ -31,17 +33,25 @@ namespace gatewayGK.POSBC
///
public Respuestas Ejecutar()
{
string direccionIpPosbc = "127.0.0.1";
int puerto = 6697;
IConfiguration configBuilder = ConfigurationHelper.Configuration;
string direccionIpPosbc = configBuilder["posbc:DireccionIpPosbc"];
string puertoPosbcString = configBuilder["posbc:PuertoPosbc"];
int puertoPosbcInt = int.Parse(puertoPosbcString);
Log.Information($"Inicio del comando ReportStatusEvents para realizar conexión con el POSBC");
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
Log.Information($"Cantidad de bytes recibido desde CHEC: {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);
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(direccionIpPosbc), puertoPosbcInt);
//Conectar al endpoint
socket.Connect(endPoint);
......@@ -49,7 +59,7 @@ namespace gatewayGK.POSBC
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
Log.Information($"Buffer de entrada enviado al servidor POSBC {bufferRecibido}");
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000; // en milisegundos
......@@ -62,18 +72,9 @@ namespace gatewayGK.POSBC
{
int bytesLeidos = 0;
try
{
bytesLeidos = socket.Receive(bufferSalida, 0, bufferSalida.Length, SocketFlags.None);
}
catch (SocketException ex)
{
if (ex.SocketErrorCode == SocketError.TimedOut)
if (socket.Poll(5000000, SelectMode.SelectRead)) // 5 segundos en microsegundos
{
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
//Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0
if (bytesLeidos == 0 || bytesLeidos == 1)
{
......@@ -87,11 +88,20 @@ namespace gatewayGK.POSBC
receivedBytes.Add(bufferSalida[i]);
}
}
else
{
// Tiempo de espera agotado
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Log.Information($"XML de respuesta recibido por parte del POSBC:{result}");
Entorno<EntornoPOSBC>.Instancia.get().BufferSalida = data;
socket.Shutdown(SocketShutdown.Both);
......
using EvaPOS_API_FRAME.DTO;
using EvaPosSrvResp;
using gatewayGK.Infraestructura;
using GatewaySCO;
using Microsoft.Extensions.Configuration;
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;
using EvaPOS_API_FRAME.Comandos;
using EvaPosSrvDTO;
namespace gatewayGK.POSBC
{
///<summary>
/// Procesa solicitudes del SignOff
/// </summary>
public class SignOffResponsePosbcCmd : IComando
{
public string Referencia { get; set; } = "scsns:SignOff";
/// <summary>
/// DTO con solicitud.
/// </summary>
public SignOffRequestDTO Request { get; private set; }
/// <summary>
/// Procesa y responde SignOffRequest.
/// </summary>
public Respuestas Ejecutar()
{
IConfiguration configBuilder = ConfigurationHelper.Configuration;
string direccionIpPosbc = configBuilder["posbc:DireccionIpPosbc"];
string puertoPosbcString = configBuilder["posbc:PuertoPosbc"];
int puertoPosbcInt = int.Parse(puertoPosbcString);
Log.Information($"Inicio del comando SignOff para realizar conexión con el POSBC");
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
Log.Information($"Cantidad de bytes recibido desde CHEC: {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), puertoPosbcInt);
//Conectar al endpoint
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC...");
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000; // en milisegundos
// 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;
if (socket.Poll(5000000, SelectMode.SelectRead)) // 5 segundos en microsegundos
{
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]);
}
}
else
{
// Tiempo de espera agotado
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Log.Information($"XML de respuesta recibido por parte del POSBC:{result}");
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();
}
public IComando CreaCopia()
{
return (SignOffResponsePosbcCmd)this.MemberwiseClone();
}
public void CargaDTO(DTOBase signOffResponseDTO)
{
Request = (SignOffRequestDTO)signOffResponseDTO;
}
}
}
using EvaPOS_API_FRAME.DTO;
using EvaPosSrvResp;
using gatewayGK.Infraestructura;
using GatewaySCO;
using Microsoft.Extensions.Configuration;
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;
using EvaPOS_API_FRAME.Comandos;
using EvaPosSrvDTO;
namespace gatewayGK.POSBC
{
///<summary>
/// Comando para suspender transacción
/// </summary>
public class SuspendTransactionRequestPosbcCmd : IComando
{
public string Referencia { get; set; } = "scsns:Suspend";
/// <summary>
/// DTO con solicitud.
/// </summary>
public SuspendTransactionRequest Request { get; private set; }
/// <summary>
/// Procesa y responde SuspendTransactionRequest.
/// </summary>
public Respuestas Ejecutar()
{
IConfiguration configBuilder = ConfigurationHelper.Configuration;
string direccionIpPosbc = configBuilder["posbc:DireccionIpPosbc"];
string puertoPosbcString = configBuilder["posbc:PuertoPosbc"];
int puertoPosbcInt = int.Parse(puertoPosbcString);
Log.Information($"Inicio del comando Suspend para realizar conexión con el POSBC");
byte[] bufferRecibido = Entorno<EntornoPOSBC>.Instancia.get().BufferEntrada;
int cantBytes = Entorno<EntornoPOSBC>.Instancia.get().CantBytes;
Log.Information($"Cantidad de bytes recibido desde CHEC: {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), puertoPosbcInt);
//Conectar al endpoint
socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC...");
// Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None);
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000; // en milisegundos
// 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;
if (socket.Poll(5000000, SelectMode.SelectRead)) // 5 segundos en microsegundos
{
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]);
}
}
else
{
// Tiempo de espera agotado
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
byte[] data = receivedBytes.ToArray();
// Convertir el array de bytes a una cadena
string result = Encoding.UTF8.GetString(data);
Log.Information($"XML de respuesta recibido por parte del POSBC:{result}");
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();
}
public IComando CreaCopia()
{
return (SuspendTransactionRequestPosbcCmd)this.MemberwiseClone();
}
public void CargaDTO(DTOBase suspendTransactionRequest)
{
Request = (SuspendTransactionRequest)suspendTransactionRequest;
}
}
}
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