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
be61f482
Commit
be61f482
authored
Jun 17, 2024
by
Brayan Sarmiento
Browse files
Cambios Arquitectura POSBC
parent
7bba23e7
Changes
4
Hide whitespace changes
Inline
Side-by-side
gatewayGK/Program.cs
View file @
be61f482
...
...
@@ -5,6 +5,7 @@ using EvaPosSrvAplicacionImp;
using
EvaPosSrvRespImp
;
using
gatewayGK.POSBC
;
using
gatewayGK.Infraestructura
;
using
gatewayGK.Servidor
;
namespace
GatewaySCO
{
...
...
@@ -18,6 +19,7 @@ namespace GatewaySCO
{
Program
program
=
new
Program
();
program
.
ActivaServidor
(
args
);
}
public
Config
LeeConfiguracion
(
string
[]
args
)
...
...
@@ -58,9 +60,19 @@ namespace GatewaySCO
{
Entorno
<
EntornoPOSBC
>.
Instancia
.
set
(
new
EntornoPOSBC
());
Log
.
Information
(
$"Inicio del entorno POSBC"
);
Task
.
Run
(
async
()
=>
await
ActivaServidorPosbc
());
}
return
config
;
}
public
async
Task
ActivaServidorPosbc
()
{
IConfiguration
configBuilder
=
ConfigurationHelper
.
Configuration
;
Console
.
WriteLine
(
"*** Gateway SCO - POSBC ***"
);
PosbcServerConnect
servidor
=
new
PosbcServerConnect
();
// Lógica adicional para inicializar y activar el servidor POSBC
await
servidor
.
ActivaServidor
();
// Ejemplo de un método asincrónico para iniciar el servidor
}
public
void
ActivaServidor
(
string
[]
args
)
{
...
...
gatewayGK/Servidor/EvaPosSrvSCO.cs
View file @
be61f482
...
...
@@ -242,6 +242,8 @@ namespace EvaPosSCOSrv
}
}
//
/// <summary>
/// Retorna longitud del mensaje representada en los 4 primeros bytes del arreglo bytes de argumento.
/// </summary>
...
...
@@ -296,6 +298,9 @@ namespace EvaPosSCOSrv
string
resultadoXml
=
Encoding
.
UTF8
.
GetString
(
bufferEntrada
);
Log
.
Information
(
$"XML de entrada enviado por CHEC:
{
resultadoXml
}
"
);
bufferEntrada
=
datosRecibidos
;
Entorno
<
EntornoPOSBC
>.
Instancia
.
get
().
BufferEntrada
=
bufferEntrada
;
Entorno
<
EntornoPOSBC
>.
Instancia
.
get
().
CantBytes
=
bytesLeidos
;
}
else
{
...
...
@@ -320,9 +325,6 @@ namespace EvaPosSCOSrv
}
Entorno
<
EntornoPOSBC
>.
Instancia
.
get
().
BufferEntrada
=
bufferEntrada
;
Entorno
<
EntornoPOSBC
>.
Instancia
.
get
().
CantBytes
=
bytesLeidos
;
// Procesando entrada: se obtiene mensaje, con el cual se
// identifica comando que lo procesa, se ejecuta el comando
// y se retornarn respuestas al cliente que ha emitido el mensaje.
...
...
@@ -411,6 +413,7 @@ namespace EvaPosSCOSrv
}
}
/// <summary>
/// Clase que controla el nivel básico de entrada y salida de mensajes.
/// Extrae la información del mensaje, limpiando la información de control.
...
...
gatewayGK/Servidor/PosbcServerConnect.cs
0 → 100644
View file @
be61f482
using
EvaPosSCOSrv
;
using
Serilog.Events
;
using
Serilog
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Net.Sockets
;
using
System.Net
;
using
gatewayGK.Infraestructura
;
using
Microsoft.Extensions.Configuration
;
namespace
gatewayGK.Servidor
{
public
class
PosbcServerConnect
{
ILogger
log
=
Log
.
ForContext
<
ServidorSocket
>();
readonly
static
bool
_isDebug
=
Log
.
IsEnabled
(
LogEventLevel
.
Debug
);
/// <summary>
/// Longitud máxima de mensaje de entrada.
/// </summary>
public
const
Int32
LongMaxMensaje
=
1
_024
*
8
;
/// <summary>
/// Dirección ip para vincular el socket.
/// </summary>
public
string
Direccion
{
get
;
private
set
;
}
=
"127.0.0.1"
;
/// <summary>
/// Puerto a vincular socket.
/// </summary>
public
Int32
Puerto
{
get
;
private
set
;
}
=
6697
;
public
int
LongColaConexiones
{
get
;
private
set
;
}
=
10
;
/// <summary>
/// Fija timeout usado para enviar / recibir em modo sincrónico, en milisegundos.
/// Si el timeout se excede, se presenta una excepción.
/// Default a 5 segundos.
/// </summary>
public
int
TimeOutSincMs
{
get
;
private
set
;
}
=
3000
;
long
_numeroConexionesEntrantes
=
0
;
public
PosbcServerConnect
()
{
}
public
async
Task
ActivaServidor
()
{
IConfiguration
configBuilder
=
ConfigurationHelper
.
Configuration
;
string
direccion
=
configBuilder
[
"posbc:DireccionIpPosbc"
];
string
puertoPosbcString
=
configBuilder
[
"posbc:PuertoPosbc"
];
int
puerto
=
int
.
Parse
(
puertoPosbcString
);
IPEndPoint
ipEndPoint
=
new
(
IPAddress
.
Parse
(
direccion
),
puerto
);
int
cont
=
0
;
using
Socket
tcpSocket
=
new
(
ipEndPoint
.
AddressFamily
,
SocketType
.
Stream
,
ProtocolType
.
Tcp
);
await
tcpSocket
.
ConnectAsync
(
ipEndPoint
);
log
.
Information
(
"Posbc servidor socket en {ip} : {puerto}, proceso id {id}"
,
Direccion
,
Puerto
);
Socket
socketEntrada
;
try
{
while
(
true
)
{
log
.
Information
(
"Esperando conexión POSBC..."
);
}
}
catch
(
Exception
ex
)
{
log
.
Error
(
"Error : {error}"
,
ex
);
}
finally
{
tcpSocket
.
Close
();
}
}
}
}
gatewayGK/appsettings.json
View file @
be61f482
...
...
@@ -2,7 +2,7 @@
"GatewayConfig"
:
{
"POS"
:
"posbc"
,
"POS_comment"
:
"Indicates the set of commands to instantiate, according to the type of POS: evapos, tests, gk,posbc etc."
,
"IpSCO"
:
"1
0.89.81.102
"
,
"IpSCO"
:
"1
27.0.0.1
"
,
"IpSCO_comment"
:
"SCO IP, local or remote"
,
"PortSCO"
:
6690
,
"PortSCO_comment"
:
"SCO IP Port"
,
...
...
@@ -28,6 +28,9 @@
"DireccionIpPosbc"
:
"127.0.0.1"
,
"PuertoPosbc"
:
"6697"
},
"EntornoPOSBC"
:
{
"value"
:
"true"
},
"Serilog"
:
{
"Using"
:
[
"Serilog.Sinks.Console"
,
...
...
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