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
Hide whitespace changes
Inline
Side-by-side
gatewayGK/ComandosPruebas/AddReceiptLinesRequestCmd.cs
View file @
7bba23e7
...
...
@@ -23,7 +23,7 @@ namespace EvaPOS_API_FRAME.Comandos
/// </summary>
public
AddReceiptLinesRequest
Request
{
get
;
private
set
;
}
/// <summary>
/// Procesa y responde
ReportStatusEventsRequ
es
t
.
/// Procesa y responde
AddReceiptLin
es.
/// </summary>
public
Respuestas
Ejecutar
()
...
...
gatewayGK/ComandosPruebas/ReprintReceiptsPosbcCmd.cs
0 → 100644
View file @
7bba23e7
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
;
}
}
}
gatewayGK/ComandosPruebas/VoidTransactionPosbcCmd.cs
0 → 100644
View file @
7bba23e7
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
;
}
}
}
gatewayGK/Infraestructura/ConfigurationHelper.cs
0 → 100644
View file @
7bba23e7
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
();
}
}
}
gatewayGK/Infraestructura/DispensaDirectorioCmdPOSBC.cs
View file @
7bba23e7
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
;
}
}
...
...
gatewayGK/POSBC/AddCustomerBirthdatePosbcCmd.cs
0 → 100644
View file @
7bba23e7
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
;
}
}
}
gatewayGK/POSBC/AddCustomerPosbcCmd.cs
0 → 100644
View file @
7bba23e7
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
;
}
}
}
gatewayGK/POSBC/AddItemRequestPosbcCmd.cs
0 → 100644
View file @
7bba23e7
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
;
}
}
}
gatewayGK/POSBC/AddReceiptLinesRequestPosbcCmd.cs
0 → 100644
View file @
7bba23e7
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
;
}
}
}
gatewayGK/POSBC/AddTenderDebitPosbcCmd.cs
0 → 100644
View file @
7bba23e7
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
;
}
}
}
gatewayGK/POSBC/CancelActionPosbcCmd.cs
0 → 100644
View file @
7bba23e7
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
;
}
}
}
gatewayGK/POSBC/ErrorPosbcCmd.cs
0 → 100644
View file @
7bba23e7
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
;
}
}
}
gatewayGK/POSBC/GetTotalsRequestPosbcCmd.cs
0 → 100644
View file @
7bba23e7
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
;
}
}
}
gatewayGK/POSBC/InitializeRequestPosbcCmd.cs
View file @
7bba23e7
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
),
puerto
PosbcInt
);
//Conectar al endpoint
socket
.
Connect
(
endPoint
);
Log
.
Information
(
"Conectandose al servidor POSBC"
);
Log
.
Information
(
"Conectandose al servidor POSBC
...
"
);
// Enviar los datos
...
...
@@ -57,47 +66,45 @@ namespace gatewayGK.POSBC
Log
.
Information
(
$"Buffer de entrada enviado al servidor POSBC
{
bufferRecibido
}
"
);
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket
.
ReceiveTimeout
=
10
000
;
socket
.
ReceiveTimeout
=
5
000
;
// 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
)
//Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0
if
(
bytesLeidos
==
0
||
bytesLeidos
==
1
)
{
Log
.
Information
(
"Tiempo de espera agotado. No se recibieron más datos."
);
// 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
]);
}
}
//Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0
if
(
bytesLeidos
==
0
||
bytesLeidos
==
1
)
else
{
// El socket se ha cerrado
Log
.
Information
(
"Tiempo de espera agotado. No se recibieron más datos."
);
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
);
Log
.
Information
(
$"XML de respuesta recibido por parte del POSBC:
{
result
}
"
);
Entorno
<
EntornoPOSBC
>.
Instancia
.
get
().
BufferSalida
=
data
;
// Cerrar el socket
...
...
gatewayGK/POSBC/PrintCurrentReceiptsRequestPosbcCmd.cs
0 → 100644
View file @
7bba23e7
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
;
}
}
}
gatewayGK/POSBC/QueryStatusRequestPosbcCmd.cs
View file @
7bba23e7
...
...
@@ -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
),
puerto
PosbcInt
);
//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,37 +71,37 @@ 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
)
//Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0
if
(
bytesLeidos
==
0
||
bytesLeidos
==
1
)
{
Log
.
Information
(
"Tiempo de espera agotado. No se recibieron más datos."
);
// 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
]);
}
}
//Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0
if
(
bytesLeidos
==
0
||
bytesLeidos
==
1
)
else
{
// El socket se ha cerrado
// Tiempo de espera agotado
Log
.
Information
(
"Tiempo de espera agotado. No se recibieron más datos."
);
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
);
Log
.
Information
(
$"XML de respuesta recibido por parte del POSBC:
{
result
}
"
);
Entorno
<
EntornoPOSBC
>.
Instancia
.
get
().
BufferSalida
=
data
;
socket
.
Shutdown
(
SocketShutdown
.
Both
);
...
...
gatewayGK/POSBC/RemoveReceiptLinesPosbcCmd.cs
0 → 100644
View file @
7bba23e7
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
;
}
}
}
gatewayGK/POSBC/ReportStatusEventsRequestPosbcCmd.cs
View file @
7bba23e7
...
...
@@ -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
),
puerto
PosbcInt
);
//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,36 +72,36 @@ namespace gatewayGK.POSBC
{
int
bytesLeidos
=
0
;
try
bytesLeidos
=
socket
.
Receive
(
bufferSalida
,
0
,
bufferSalida
.
Length
,
SocketFlags
.
None
);
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
)
//Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0
if
(
bytesLeidos
==
0
||
bytesLeidos
==
1
)
{
Log
.
Information
(
"Tiempo de espera agotado. No se recibieron más datos."
);
// 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
]);
}
}
//Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0
if
(
bytesLeidos
==
0
||
bytesLeidos
==
1
)
else
{
// El socket se ha cerrado
// Tiempo de espera agotado
Log
.
Information
(
"Tiempo de espera agotado. No se recibieron más datos."
);
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
);
Log
.
Information
(
$"XML de respuesta recibido por parte del POSBC:
{
result
}
"
);
Entorno
<
EntornoPOSBC
>.
Instancia
.
get
().
BufferSalida
=
data
;
socket
.
Shutdown
(
SocketShutdown
.
Both
);
...
...
gatewayGK/POSBC/SignOffResponsePosbcCmd.cs
0 → 100644
View file @
7bba23e7
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
;
}
}
}
gatewayGK/POSBC/SuspendTransactionRequestPosbcCmd.cs
0 → 100644
View file @
7bba23e7
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
;
}
}
}
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