ajustado APIService e fixação Ntrip na base

This commit is contained in:
Diego Freitas 2026-09-25 15:57:48 -03:00
parent 19392738f7
commit c9c1d37df8
2 changed files with 36 additions and 34 deletions

View File

@ -5,6 +5,7 @@ using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
namespace AgroBase.Services
@ -26,28 +27,7 @@ namespace AgroBase.Services
return "https://zendioninc.com.br/agrobase/downloads";
}
}
private static bool _hasInternet
{
get
{
try
{
using (var client = new WebClient())
{
using (client.OpenRead("https://zendioninc.com.br/"))
{
return true;
}
}
}
catch
{
return false;
}
}
}
public static bool HasInternet { get; set; }
public static bool HasInternetNow() => _hasInternet;
public static async Task IniciarRotinasAsync()
{
@ -64,9 +44,42 @@ namespace AgroBase.Services
tmrMonitoramento.Start();
}
private static readonly HttpClient _internetClient = new HttpClient { Timeout = TimeSpan.FromSeconds(3) };
public static async Task<bool> HasInternetNowAsync(CancellationToken ct = default)
{
try
{
var request =
new HttpRequestMessage(
HttpMethod.Get,
"https://zendioninc.com.br/"
);
var response =
await _internetClient.SendAsync(
request,
HttpCompletionOption.ResponseHeadersRead,
ct
).ConfigureAwait(false);
/*
* Qualquer resposta HTTP significa que DNS,
* TCP e HTTPS chegaram ao servidor.
*/
return true;
}
catch
{
return false;
}
}
private static async Task tmrMonitoramento_Tick()
{
HasInternet = HasInternetNow();
HasInternet =
await HasInternetNowAsync()
.ConfigureAwait(false);
}
// Método para GET

View File

@ -2062,21 +2062,13 @@ namespace OperationControl.Services
private async Task AplicarCorrecaoRTK_NtripAsync(CancellationToken ct)
{
if (!IsConnected || !APIService.HasInternet)
if (!IsConnected)
return;
double backoffSeconds = 1.0;
while (!ct.IsCancellationRequested && CorrecaoRTK_Ntrip)
{
if (!APIService.HasInternet)
{
Ntrip_Conectado = false;
LimparNtripAtivo();
await Task.Delay(TimeSpan.FromSeconds(2), ct).ConfigureAwait(false);
continue;
}
List<NtripProviderConfig> providers = ObterSequenciaProvedoresNtrip();
if (providers.Count == 0)
@ -3796,9 +3788,6 @@ namespace OperationControl.Services
Func<Task> stopNtrip = null,
CancellationToken ct = default)
{
if (!APIService.HasInternetNow())
return false;
await ConfigurarComoRoverParadoAsync(portaUsb, portaEntrada, ct)
.ConfigureAwait(false);