diff --git a/CLAUDE.md b/CLAUDE.md index a3c14fa..1467d1b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -93,8 +93,10 @@ transferencias siempre, sin depender de `Notificacion`. Detalle y tabla en `TotalDetalle_Parcial`/`_Invoice`/`SerieOrigen` y un `if` vacío en `CreateHojaRuta`) y se agregaron comentarios en Picking, Recibo, `ConnectionServiceLayer`, `CreditNotesRepository`, `InvoiceRepository` y - `RepositoryWrapper`. Sigue pendiente: código comentado, `Login`/`LoginPost` - duplicados y `PatchAsyncSBA`. + `RepositoryWrapper`. Además se unificó `LoginPost()` en `Login()` (eran idénticos; + las 4 llamadas a `LoginPost` ahora llaman a `Login`). Sigue pendiente: código + comentado, `PatchAsyncSBA` y la redundancia de las transferencias automáticas + (3 copias en Picking/Recibo) y de los métodos POST/PATCH del cliente. - Sin probar contra SAP: confirmar con la factura 292410 que SAP devuelve `BaseType`/`BaseEntry` en las líneas y `BatchNumbers` en las de la Entrega. @@ -148,7 +150,7 @@ Picking, columna `HORA` en `B_Log`. Lo que **no** se trajo: `Chatbots` y - `BE_ResultadoTransaccion.NombreEstacion`: setter con recursión infinita (bomba de tiempo; hoy nada lo asigna). - `ConnectionServiceLayer.PatchAsyncSBA`: con un `204` real devuelve `null` - sin marcar éxito. `Login()`/`LoginPost()` duplicados. + sin marcar éxito. - El cliente HTTP `bypass-ssl-validation` acepta cualquier certificado TLS hacia el Service Layer (se quitó el método `ValidarCertificado`, que no se usaba). - `appsettings.json` (fuera de git, en `.gitignore`) contiene credenciales diff --git a/Net.Connection.ServiceLayer/ConnectionServiceLayer.cs b/Net.Connection.ServiceLayer/ConnectionServiceLayer.cs index d7ac5ff..767ccca 100644 --- a/Net.Connection.ServiceLayer/ConnectionServiceLayer.cs +++ b/Net.Connection.ServiceLayer/ConnectionServiceLayer.cs @@ -136,95 +136,6 @@ namespace Net.Connection.ServiceLayer return _responseLoginServiceLayer; } } - // Igual que Login(); duplicado historico (candidato a unificar) - public async Task LoginPost() - { - try - { - // CONSTRUIMOS LA URL DE LA ACCIÓN - var urlBuilder_ = new StringBuilder(); - urlBuilder_.Append(_url != null ? _url.TrimEnd('/') : "") - .Append("/Login"); - var url_ = urlBuilder_.ToString(); - - // RECUPERAMOS EL HttpClient - - var client_ = _httpClient.CreateClient("bypass-ssl-validation"); - - - using (var request_ = new HttpRequestMessage()) - { - /////////////////////////////////////// - // CONSTRUIMOS LA PETICIÓN (REQUEST) // - /////////////////////////////////////// - // DEFINIMOS EL Content CON EL OBJETO A ENVIAR SERIALIZADO. - request_.Content = new StringContent("{\"CompanyDB\":\"" + _company + "\",\"Password\":\"" + _password + "\",\"UserName\":\"" + _user + "\"}"); - //request_.Content = new StringContent("{\"CompanyDB\":\"" + _company + "\",\"Password\":\"" + _password + "\",\"UserName\":\"" + _user + "\",\"Language\":\"" + _language + "\"}"); - - // DEFINIMOS EL ContentType, EN ESTE CASO ES "application/json" - request_.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); - request_.Headers.Add("cache-control", "no-cache"); - - // DEFINIMOS EL MÉTODO HTTP - request_.Method = new HttpMethod("POST"); - - // DEFINIMOS LA URI - request_.RequestUri = new Uri(url_, System.UriKind.RelativeOrAbsolute); - - // DEFINIMOS EL Accept, EN ESTE CASO ES "application/json" - request_.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json")); - - ///////////////////////////////////////// - // CONSTRUIMOS LA RESPUESTA (RESPONSE) // - ///////////////////////////////////////// - // Utilizamos ConfigureAwait(false) para evitar el DeadLock. - var response_ = await client_.SendAsync(request_).ConfigureAwait(false); - - // OBTENEMOS EL Content DEL RESPONSE como un String - // Utilizamos ConfigureAwait(false) para evitar el DeadLock. - var responseText_ = await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - - // SI ES LA RESPUESTA ESPERADA !! ... - if (response_.StatusCode == System.Net.HttpStatusCode.OK) // 200 - { - // DESERIALIZAMOS Content DEL RESPONSE - _responseLoginServiceLayer = JsonConvert.DeserializeObject(responseText_); - _responseLoginServiceLayer.ServicioActivo = true; - _responseLoginServiceLayer.MensajeLogin = "Autenticación Correcta"; - return _responseLoginServiceLayer; - } - else - // SI NO SE ESTÁ AUTORIZADO ... - if (response_.StatusCode == System.Net.HttpStatusCode.Unauthorized) // 401 - { - _responseLoginServiceLayer = JsonConvert.DeserializeObject(responseText_); - _responseLoginServiceLayer.ServicioActivo = false; - _responseLoginServiceLayer.MensajeLogin = "401 Unauthorized. Las credenciales de acceso del usuario son incorrectas."; - return _responseLoginServiceLayer; - } - else - // CUALQUIER OTRA RESPUESTA ... - if (response_.StatusCode != System.Net.HttpStatusCode.OK && // 200 - response_.StatusCode != System.Net.HttpStatusCode.NoContent) // 204 - { - _responseLoginServiceLayer = JsonConvert.DeserializeObject(responseText_); - _responseLoginServiceLayer.ServicioActivo = false; - _responseLoginServiceLayer.MensajeLogin = "401 Unauthorized. Las credenciales de acceso del usuario son incorrectas."; - return _responseLoginServiceLayer; - } - - // RETORNAMOS EL OBJETO POR DEFECTO ESPERADO - return _responseLoginServiceLayer; - } - - } - catch (Exception ex) - { - _responseLoginServiceLayer.ServicioActivo = false; - _responseLoginServiceLayer.MensajeLogin = ex.Message.ToString(); - return _responseLoginServiceLayer; - } - } // GET al Service Layer. dinamico = true: la respuesta es una sola entidad (ej. Invoices(123)); false: coleccion { value: [...] } public async Task> GetAsync(string Query, int maxpagesize,bool dinamico = false) { @@ -394,7 +305,7 @@ namespace Net.Connection.ServiceLayer if (_responseLoginServiceLayer.error.code.ToString() == "301") { - await LoginPost(); + await Login(); } goto band; @@ -528,7 +439,7 @@ namespace Net.Connection.ServiceLayer if (_responseLoginServiceLayer.error.code.ToString() == "301") { - await LoginPost(); + await Login(); } goto band; @@ -657,7 +568,7 @@ namespace Net.Connection.ServiceLayer if (_responseLoginServiceLayer.error.code.ToString() == "301") { - await LoginPost(); + await Login(); } goto band; @@ -783,7 +694,7 @@ namespace Net.Connection.ServiceLayer if (_responseLoginServiceLayer.error.code.ToString() == "301") { - await LoginPost(); + await Login(); goto band; } }