Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Brayan Sarmiento
API-Gateway-CHEC
Commits
7bba23e7
Commit
7bba23e7
authored
Jun 14, 2024
by
Brayan Sarmiento
Browse files
Creacion todos los comandos para el POSBC
parent
7be3dce9
Changes
24
Show whitespace changes
Inline
Side-by-side
gatewayGK/POSBC/TerminateRequestPosbcCmd.cs
0 → 100644
View file @
7bba23e7
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
;
using
gatewayGK.Infraestructura
;
using
Microsoft.Extensions.Configuration
;
namespace
gatewayGK.POSBC
{
/// <summary>
/// Comando para cerrar la lane
/// </summary>
public
class
TerminateRequestPosbcCmd
:
IComando
{
public
string
Referencia
{
get
;
set
;
}
=
"scsns:Terminate"
;
/// <summary>
/// DTO con solicitud.
/// </summary>
public
TerminateRequestDTO
Destroy
{
get
;
private
set
;
}
/// <summary>
/// Procesa y responde el evento Terminar.
/// </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 Terminate 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
(
TerminateRequestPosbcCmd
)
this
.
MemberwiseClone
();
}
public
void
CargaDTO
(
DTOBase
terminateRequest
)
{
Destroy
=
(
TerminateRequestDTO
)
terminateRequest
;
}
}
}
gatewayGK/Program.cs
View file @
7bba23e7
...
@@ -4,6 +4,7 @@ using EvaPosSCOSrv;
...
@@ -4,6 +4,7 @@ using EvaPosSCOSrv;
using
EvaPosSrvAplicacionImp
;
using
EvaPosSrvAplicacionImp
;
using
EvaPosSrvRespImp
;
using
EvaPosSrvRespImp
;
using
gatewayGK.POSBC
;
using
gatewayGK.POSBC
;
using
gatewayGK.Infraestructura
;
namespace
GatewaySCO
namespace
GatewaySCO
{
{
...
@@ -24,10 +25,7 @@ namespace GatewaySCO
...
@@ -24,10 +25,7 @@ namespace GatewaySCO
// TODO - opción de incluir la activación en la cadena de configuración.
// TODO - opción de incluir la activación en la cadena de configuración.
// Instancia objeto de configuración, usa proveedor json y variables ambiente.
// Instancia objeto de configuración, usa proveedor json y variables ambiente.
IConfigurationRoot
configBuilder
=
new
ConfigurationBuilder
()
IConfiguration
configBuilder
=
ConfigurationHelper
.
Configuration
;
.
AddJsonFile
(
"appsettings.json"
)
.
AddEnvironmentVariables
()
.
Build
();
// TODO Sacar la ruta de logs del objeto de configuración adecuadamente.
// TODO Sacar la ruta de logs del objeto de configuración adecuadamente.
string
?
rutaLogs
=
configBuilder
[
"Serilog:WriteTo:1:Args:path"
];
string
?
rutaLogs
=
configBuilder
[
"Serilog:WriteTo:1:Args:path"
];
...
...
gatewayGK/Servidor/EvaPosSrvSCO.cs
View file @
7bba23e7
...
@@ -294,6 +294,7 @@ namespace EvaPosSCOSrv
...
@@ -294,6 +294,7 @@ namespace EvaPosSCOSrv
Array
.
Copy
(
bufferEntrada
,
datosRecibidos
,
bytesLeidos
);
Array
.
Copy
(
bufferEntrada
,
datosRecibidos
,
bytesLeidos
);
//Revisamos que xml envio Chec
//Revisamos que xml envio Chec
string
resultadoXml
=
Encoding
.
UTF8
.
GetString
(
bufferEntrada
);
string
resultadoXml
=
Encoding
.
UTF8
.
GetString
(
bufferEntrada
);
Log
.
Information
(
$"XML de entrada enviado por CHEC:
{
resultadoXml
}
"
);
bufferEntrada
=
datosRecibidos
;
bufferEntrada
=
datosRecibidos
;
}
}
else
else
...
@@ -329,25 +330,25 @@ namespace EvaPosSCOSrv
...
@@ -329,25 +330,25 @@ namespace EvaPosSCOSrv
IComando
cmd
=
_presentacion
.
Entrada
(
msj
);
IComando
cmd
=
_presentacion
.
Entrada
(
msj
);
//Enviamos la respuesta del pinpad primero del datafono antes de que entre al comando procesar
//Enviamos la respuesta del pinpad primero del datafono antes de que entre al comando procesar
if
(
cmd
.
Referencia
==
"scsns:AddTender"
)
//
if (cmd.Referencia == "scsns:AddTender")
{
//
{
Respuestas
respuestaDatafono
=
EjecutarProcesarDatafonoDirecto
();
//
Respuestas respuestaDatafono = EjecutarProcesarDatafonoDirecto();
foreach
(
var
respuesta
in
respuestaDatafono
)
//
foreach (var respuesta in respuestaDatafono)
{
//
{
Log
.
Debug
(
"Respuesta del pinpad del datafono"
);
//
Log.Debug("Respuesta del pinpad del datafono");
var
bufferSalida
=
_sesion
.
Salida
(
respuesta
.
TramaSCO
);
//
var bufferSalida = _sesion.Salida(respuesta.TramaSCO);
socket
.
Send
(
bufferSalida
,
0
,
bufferSalida
.
Length
,
SocketFlags
.
None
);
//
socket.Send(bufferSalida, 0, bufferSalida.Length, SocketFlags.None);
Log
.
Information
(
"Bytes enviados {bytes}"
,
bufferSalida
.
Length
);
//
Log.Information("Bytes enviados {bytes}", bufferSalida.Length);
}
//
}
}
//
}
respuestas
=
_aplicacion
.
Procesar
(
cmd
);
respuestas
=
_aplicacion
.
Procesar
(
cmd
);
//TODO - Logica para mandar la respuesta del POSBC
//TODO - Logica para mandar la respuesta del POSBC
if
(
entornoApi
==
"posbc"
)
if
(
entornoApi
==
"posbc"
)
{
{
byte
[]
bufferSalidaRecibido
=
Entorno
<
EntornoPOSBC
>.
Instancia
.
get
().
BufferSalida
;
byte
[]
bufferSalidaRecibido
=
Entorno
<
EntornoPOSBC
>.
Instancia
.
get
().
BufferSalida
;
socket
.
Send
(
bufferSalidaRecibido
,
0
,
bufferSalidaRecibido
.
Length
,
SocketFlags
.
None
);
socket
.
Send
(
bufferSalidaRecibido
,
0
,
bufferSalidaRecibido
.
Length
,
SocketFlags
.
None
);
Log
.
Information
(
"Bytes enviados {bytes} del servidor POSBC"
,
bufferSalidaRecibido
.
Length
);
Log
.
Information
(
"Bytes enviados {bytes} del servidor
de
POSBC
a CHEC
"
,
bufferSalidaRecibido
.
Length
);
}
}
else
else
{
{
...
@@ -362,9 +363,6 @@ namespace EvaPosSCOSrv
...
@@ -362,9 +363,6 @@ namespace EvaPosSCOSrv
socket
.
Send
(
bufferSalida
,
0
,
bufferSalida
.
Length
,
SocketFlags
.
None
);
socket
.
Send
(
bufferSalida
,
0
,
bufferSalida
.
Length
,
SocketFlags
.
None
);
Log
.
Information
(
"Bytes enviados {bytes}"
,
bufferSalida
.
Length
);
Log
.
Information
(
"Bytes enviados {bytes}"
,
bufferSalida
.
Length
);
}
}
}
log
.
Information
(
"Fin del ciclo, se enviaron {nro} respuestas"
,
respuestas
.
Count
);
log
.
Information
(
"Fin del ciclo, se enviaron {nro} respuestas"
,
respuestas
.
Count
);
if
(
cmd
.
Referencia
==
"scsns:Terminate"
)
if
(
cmd
.
Referencia
==
"scsns:Terminate"
)
...
@@ -373,6 +371,8 @@ namespace EvaPosSCOSrv
...
@@ -373,6 +371,8 @@ namespace EvaPosSCOSrv
break
;
break
;
}
}
}
}
}
catch
(
SocketException
ex
)
catch
(
SocketException
ex
)
{
{
if
(
ex
.
SocketErrorCode
==
SocketError
.
ConnectionAborted
)
if
(
ex
.
SocketErrorCode
==
SocketError
.
ConnectionAborted
)
...
...
gatewayGK/appsettings.json
View file @
7bba23e7
...
@@ -45,7 +45,7 @@
...
@@ -45,7 +45,7 @@
{
{
"Name"
:
"File"
,
"Name"
:
"File"
,
"Args"
:
{
"Args"
:
{
"path"
:
"logs
/
scogateway-log.txt"
,
"path"
:
"
C:
\\
ApiGateway
\\
logs
\\
scogateway-log.txt"
,
"rollingInterval"
:
"Day"
"rollingInterval"
:
"Day"
}
}
}
}
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment