Commit 61bc8558 authored by Brayan Sarmiento's avatar Brayan Sarmiento
Browse files

Inicio de creacion de los comandos para el posbc

parent 11b7efd5
...@@ -25,5 +25,10 @@ public static class Const ...@@ -25,5 +25,10 @@ public static class Const
/// comandos para acceder EvaPOS. /// comandos para acceder EvaPOS.
/// </summary> /// </summary>
public const string PosEvaPOS = "evapos"; public const string PosEvaPOS = "evapos";
/// <summary>
/// Configuración. Indica tipo de pos POSBC, para instanciar
/// comandos para acceder POSBC.
/// </summary>
public const string Posbc = "posbc";
} }
\ No newline at end of file
using gatewayGK.Infraestructura;
using GatewaySCO; using GatewaySCO;
/// <summary> /// <summary>
/// Factory que retorna un directorio de comandos instanciado /// Factory que retorna un directorio de comandos instanciado
...@@ -18,6 +19,8 @@ public class DirectorioCmdsFactory ...@@ -18,6 +19,8 @@ public class DirectorioCmdsFactory
return DispensaDirectorioCmdsGK.Dispensa(); return DispensaDirectorioCmdsGK.Dispensa();
case "gk_test": case "gk_test":
return DispensaDirectorioCmdsGKPruebas.Dispensa(); return DispensaDirectorioCmdsGKPruebas.Dispensa();
case "posbc":
return DispensaDirectorioCmdPOSBC.Dispensa();
default: default:
throw new ArgumentException("TipoPOS no válido", "tipoPOS"); throw new ArgumentException("TipoPOS no válido", "tipoPOS");
} }
......
using gatewayGK.POSBC;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace gatewayGK.Infraestructura
{
/// <summary>
/// Instancia directorio de comandos de POSBC con cada
/// uno de los comandos.
/// </summary>
public class DispensaDirectorioCmdPOSBC : IDispensaDirectorioCmds
{
/// <summary>
/// Retorna directorio de comandos instanciado y poblado de
/// comandos.
/// </summary>
///
public static CreaDirectorioCmds Dispensa()
{
Log.Information("Instancia comandos POSBC.");
return new IniciaDirectorioCmds()
.AgregaCmd(new InitializeRequestPosbcCmd())
.AgregaCmd(new QueryStatusRequestPosbcCmd())
.AgregaCmd(new ReportStatusEventsRequestPosbcCmd())
.DirectorioCmds;
}
}
}
using EvaPosSrvDTO;
using EvaPosSrvResp;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace gatewayGK.POSBC
{
public class InitializeRequestPosbcCmd : IComando
{
public string Referencia { get; set; } = "scsns:Initialize";
/// <summary>
/// DTO con solicitud.
/// </summary>
public InitializeRequestDTO Request { get; private set; }
/// <summary>
/// Nos traemos la trama de entrada
/// </summary>
public TramaSCO Trama { get; private set; }
/// <summary>
/// Procesa y responde InitializeRequest.
/// </summary>
public Respuestas Ejecutar()
{
string direccionIpPosbc = "192.168.1.18";
int puerto = 6697;
string xmlData = Trama.MensajeXml;
// Convertir la trama XML a bytes
byte[] dataToSend = Encoding.UTF8.GetBytes(xmlData);
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(dataToSend);
Log.Information($"Datos enviados al servidor POSBC {dataToSend}");
// Buffer para recibir la respuesta
byte[] buffer = new byte[1024];
int bytesReceived = socket.Receive(buffer);
// Convertir los datos recibidos a una cadena
string response = Encoding.UTF8.GetString(buffer, 0, bytesReceived);
Log.Information($"Respuesta recibida del POSBC {response}");
// Cerrar el socket
socket.Shutdown(SocketShutdown.Both);
socket.Close();
}
catch (Exception ex)
{
Log.Error("Error:", ex.Message);
}
return new Respuestas();
}
public IComando CreaCopia()
{
return (InitializeRequestPosbcCmd)this.MemberwiseClone();
}
public void CargaDTO(DTOBase initializeRequestDTO)
{
Request = (InitializeRequestDTO)initializeRequestDTO;
}
}
}
using EvaPOS_API_FRAME.DTO;
using EvaPosSrvDTO;
using EvaPosSrvResp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace gatewayGK.POSBC
{
/// <summary>
/// Procesa solicitudes de QueryStatusRequest.
/// </summary>
public class QueryStatusRequestPosbcCmd : IComando
{
public string Referencia { get; set; } = "scsns:QueryStatus";
/// <summary>
/// DTO con solicitud.
/// </summary>
public QueryStatusRequestDTO Request { get; private set; }
/// <summary>
/// Procesa y responde QueryStatusRequest.
/// </summary>
///
public Respuestas Ejecutar()
{
return new Respuestas();
}
public IComando CreaCopia()
{
return (QueryStatusRequestPosbcCmd)this.MemberwiseClone();
}
public void CargaDTO(DTOBase queryStatusRequestDTO)
{
Request = (QueryStatusRequestDTO)queryStatusRequestDTO;
}
}
}
using EvaPOS_API_FRAME.DTO;
using EvaPosSrvDTO;
using EvaPosSrvResp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace gatewayGK.POSBC
{
///<summary>
/// Procesa solicitudes de ReportStatusEventsRequest.
/// </summary>
public class ReportStatusEventsRequestPosbcCmd : IComando
{
public string Referencia { get; set; } = "scsns:ReportStatusEvents";
/// <summary>
/// DTO con solicitud.
/// </summary>
public ReportStatusEventsRequestDTO Request { get; private set; }
/// <summary>
/// Procesa y responde ReportStatusEventsRequest.
/// </summary>
///
public Respuestas Ejecutar()
{
return new Respuestas();
}
public IComando CreaCopia()
{
return (ReportStatusEventsRequestPosbcCmd)this.MemberwiseClone();
}
public void CargaDTO(DTOBase reportStatusEventsRequestDTO)
{
Request = (ReportStatusEventsRequestDTO)reportStatusEventsRequestDTO;
}
}
}
...@@ -103,6 +103,10 @@ namespace EvaPosSrvResp ...@@ -103,6 +103,10 @@ namespace EvaPosSrvResp
/// <summary> /// <summary>
/// Objeto xml del mensaje, construido a partir del texto xml. /// Objeto xml del mensaje, construido a partir del texto xml.
/// </summary> /// </summary>
public string MensajeXml { get; set; }
/// <summary>
/// Propiedad que toma toda la trama xml que viene de chec, para asi enviarla al POSBC
/// </summary>
public XmlDocument ContenidoXML public XmlDocument ContenidoXML
{ {
get get
...@@ -116,23 +120,25 @@ namespace EvaPosSrvResp ...@@ -116,23 +120,25 @@ namespace EvaPosSrvResp
/// <summary> /// <summary>
/// Constructor genérico. /// Constructor genérico.
/// </summary> /// </summary>
public TramaSCO(UInt32 longitud, Int32 idSesion, TipoMensaje tipo, string textoXML) public TramaSCO(UInt32 longitud, Int32 idSesion, TipoMensaje tipo, string textoXML,string mensajeXml)
{ {
Longitud = longitud; Longitud = longitud;
IdSesion = idSesion; IdSesion = idSesion;
TipoMensaje = tipo; TipoMensaje = tipo;
TextoXML = textoXML; TextoXML = textoXML;
MensajeXml = mensajeXml;
} }
/// <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) public TramaSCO(Int32 idSesion, TipoMensaje tipo, string textoXML,string mensajeXml)
{ {
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;
} }
} }
...@@ -147,9 +153,10 @@ namespace EvaPosSrvResp ...@@ -147,9 +153,10 @@ namespace EvaPosSrvResp
public Int32 SessionId { get; private set; } public Int32 SessionId { get; private set; }
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 TramaSCO TramaSCO public TramaSCO TramaSCO
{ {
get => new TramaSCO(SessionId, MessageType, TextoXML); get => new TramaSCO(SessionId, MessageType, TextoXML, MensajeXml);
} }
public Respuesta(int sessionId, TipoMensaje tipo) public Respuesta(int sessionId, TipoMensaje tipo)
...@@ -178,6 +185,7 @@ namespace EvaPosSrvResp ...@@ -178,6 +185,7 @@ namespace EvaPosSrvResp
/// Retorna mensaje. /// Retorna mensaje.
/// </summary> /// </summary>
public override string TextoXML { get => _mensaje; } public override string TextoXML { get => _mensaje; }
} }
/// <summary> /// <summary>
......
...@@ -400,7 +400,9 @@ namespace EvaPosSCOSrv ...@@ -400,7 +400,9 @@ namespace EvaPosSCOSrv
log.Debug("Longitud mensaje: {long}", trama.Longitud); log.Debug("Longitud mensaje: {long}", trama.Longitud);
// Extrae encabezado. String con patron soeps~<texto>~ // Extrae encabezado. String con patron soeps~<texto>~
//datos: es lo que tenemos que enviar al POSBC
string datos = Encoding.UTF8.GetString(buffer, 0, nroBytes); string datos = Encoding.UTF8.GetString(buffer, 0, nroBytes);
trama.MensajeXml = datos;
int inicioXML = datos.IndexOf("<"); int inicioXML = datos.IndexOf("<");
string parteEncabezado = datos.Substring(0, inicioXML); string parteEncabezado = datos.Substring(0, inicioXML);
log.Debug("Encabezado: {encabezado}", parteEncabezado); log.Debug("Encabezado: {encabezado}", parteEncabezado);
......
{ {
"GatewayConfig": { "GatewayConfig": {
"POS": "gk", "POS": "posbc",
"POS_comment": "Indicates the set of commands to instantiate, according to the type of POS: evapos, tests, gk, etc.", "POS_comment": "Indicates the set of commands to instantiate, according to the type of POS: evapos, tests, gk,posbc etc.",
"IpSCO": "127.0.0.1", "IpSCO": "192.168.1.9",
"IpSCO_comment": "SCO IP, local or remote", "IpSCO_comment": "SCO IP, local or remote",
"PortSCO": 6697, "PortSCO": 6690,
"PortSCO_comment": "SCO IP Port", "PortSCO_comment": "SCO IP Port",
"Language": "es", "Language": "es",
"Language_comment": "Language code as needed by the POS application" "Language_comment": "Language code as needed by the POS application"
......
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