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
/// comandos para acceder EvaPOS.
/// </summary>
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;
/// <summary>
/// Factory que retorna un directorio de comandos instanciado
......@@ -18,6 +19,8 @@ public class DirectorioCmdsFactory
return DispensaDirectorioCmdsGK.Dispensa();
case "gk_test":
return DispensaDirectorioCmdsGKPruebas.Dispensa();
case "posbc":
return DispensaDirectorioCmdPOSBC.Dispensa();
default:
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
/// <summary>
/// Objeto xml del mensaje, construido a partir del texto xml.
/// </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
{
get
......@@ -116,23 +120,25 @@ namespace EvaPosSrvResp
/// <summary>
/// Constructor genérico.
/// </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;
IdSesion = idSesion;
TipoMensaje = tipo;
TextoXML = textoXML;
MensajeXml = mensajeXml;
}
/// <summary>
/// Constructor usado para calcular Longitud del mensaje (encabezado + texto xml).
/// </summary>
public TramaSCO(Int32 idSesion, TipoMensaje tipo, string textoXML)
public TramaSCO(Int32 idSesion, TipoMensaje tipo, string textoXML,string mensajeXml)
{
IdSesion = idSesion;
TipoMensaje = tipo;
TextoXML = textoXML;
Longitud = Convert.ToUInt32(TextoEncabezado.Length + TextoXML.Length);
MensajeXml = mensajeXml;
}
}
......@@ -147,9 +153,10 @@ namespace EvaPosSrvResp
public Int32 SessionId { get; private set; }
public TipoMensaje MessageType { get; private set; }
public abstract string TextoXML { get; }
public string MensajeXml { get; }
public TramaSCO TramaSCO
{
get => new TramaSCO(SessionId, MessageType, TextoXML);
get => new TramaSCO(SessionId, MessageType, TextoXML, MensajeXml);
}
public Respuesta(int sessionId, TipoMensaje tipo)
......@@ -178,6 +185,7 @@ namespace EvaPosSrvResp
/// Retorna mensaje.
/// </summary>
public override string TextoXML { get => _mensaje; }
}
/// <summary>
......
......@@ -400,7 +400,9 @@ namespace EvaPosSCOSrv
log.Debug("Longitud mensaje: {long}", trama.Longitud);
// Extrae encabezado. String con patron soeps~<texto>~
//datos: es lo que tenemos que enviar al POSBC
string datos = Encoding.UTF8.GetString(buffer, 0, nroBytes);
trama.MensajeXml = datos;
int inicioXML = datos.IndexOf("<");
string parteEncabezado = datos.Substring(0, inicioXML);
log.Debug("Encabezado: {encabezado}", parteEncabezado);
......
{
"GatewayConfig": {
"POS": "gk",
"POS_comment": "Indicates the set of commands to instantiate, according to the type of POS: evapos, tests, gk, etc.",
"IpSCO": "127.0.0.1",
"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.1.9",
"IpSCO_comment": "SCO IP, local or remote",
"PortSCO": 6697,
"PortSCO": 6690,
"PortSCO_comment": "SCO IP Port",
"Language": "es",
"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