Primera versión estable compatible con linux de WSAsegasa
This commit is contained in:
@@ -1,23 +1,184 @@
|
||||
using bdAsegasa;
|
||||
using bdAsegasa.db;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualBasic;
|
||||
using Quartz;
|
||||
using Quartz.Impl;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Drawing.Text;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Services.Description;
|
||||
using tsUtilidades.SEPA_3414;
|
||||
using WSAsegasa;
|
||||
|
||||
namespace WSAsegasa
|
||||
{
|
||||
|
||||
public class Worker : BackgroundService
|
||||
{
|
||||
private readonly ILogger<Worker> _logger;
|
||||
|
||||
public Worker(ILogger<Worker> logger)
|
||||
public Worker(ILogger<Worker> logger, Configuracion Conf)
|
||||
{
|
||||
_logger = logger;
|
||||
Procesos.Conf = Conf;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
|
||||
|
||||
|
||||
|
||||
protected override async System.Threading.Tasks.Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
string Mensaje = "WSAsegasa. Versi<73>n: " + tsUtilidades.Utilidades.ExtraeValorCadena(Assembly.GetExecutingAssembly().FullName, "Version");
|
||||
try
|
||||
{
|
||||
if (_logger.IsEnabled(LogLevel.Information))
|
||||
|
||||
if (Procesos.Conf.HoraProcesosDiarios != null)
|
||||
{
|
||||
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
Mensaje += " Hora Procesos Programados: " + Procesos.Conf.HoraProcesosDiarios;
|
||||
CreaTareaProcesosDiarios();
|
||||
}
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
CreaTareaEnvioFacturas();
|
||||
|
||||
Logs.A<EFBFBD>adeLog(tsUtilidades.Enumeraciones.TipoLog.InicioServicio, "Inicio " + Mensaje);
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
if (_logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
_logger.LogInformation("Servicio en ejecuci<63>n: {time}", DateTimeOffset.Now);
|
||||
//Creo q aqui se deberia llamar a los servicios
|
||||
}
|
||||
Procesos.Procesar();
|
||||
await System.Threading.Tasks.Task.Delay(1000*60*5, stoppingToken);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// Logs.A<>adeLog(tsUtilidades.Enumeraciones.TipoLog.FinServicio, "Detenci<63>n " + Mensaje);
|
||||
// When the stopping token is canceled, for example, a call made from services.msc,
|
||||
// we shouldn't exit with a non-zero exit code. In other words, this is expected...
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "{Message}", ex.Message);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
public override async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
string Mensaje = "WSAsegasa. Versi<73>n: " + tsUtilidades.Utilidades.ExtraeValorCadena(Assembly.GetExecutingAssembly().FullName, "Version");
|
||||
Logs.A<EFBFBD>adeLog(tsUtilidades.Enumeraciones.TipoLog.FinServicio, "Finalizando " + Mensaje);
|
||||
|
||||
await base.StopAsync(cancellationToken);
|
||||
Logs.A<EFBFBD>adeLog(tsUtilidades.Enumeraciones.TipoLog.FinServicio, "Servicio Finalizado " + Mensaje);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void CreaTareaProcesosDiarios()
|
||||
{
|
||||
ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
|
||||
IScheduler scheduler = schedulerFactory.GetScheduler().Result;
|
||||
scheduler.Start().Wait();
|
||||
// Crear un trabajo
|
||||
IJobDetail job = JobBuilder.Create<TareasProgramadas>()
|
||||
.WithIdentity("TareasProgramadas", "Grupo1")
|
||||
.Build();
|
||||
// Crear un trigger que se ejecute diariamente a una hora espec<65>fica
|
||||
|
||||
|
||||
int Hora = int.Parse(Procesos.Conf.HoraProcesosDiarios.Split(":")[0]);
|
||||
int Minutos = int.Parse(Procesos.Conf.HoraProcesosDiarios.Split(":")[1]);
|
||||
ITrigger trigger = TriggerBuilder.Create()
|
||||
.WithIdentity("TareasProgramadas", "Grupo1")
|
||||
.StartAt(DateBuilder.TodayAt(Hora, Minutos, 0))
|
||||
.WithSimpleSchedule(x => x
|
||||
.WithIntervalInHours(24)
|
||||
.RepeatForever())
|
||||
.Build();
|
||||
|
||||
// Programar el trabajo con el trigger
|
||||
scheduler.ScheduleJob(job, trigger).Wait();
|
||||
}
|
||||
|
||||
private void CreaTareaEnvioFacturas()
|
||||
{
|
||||
ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
|
||||
IScheduler scheduler = schedulerFactory.GetScheduler().Result;
|
||||
scheduler.Start().Wait();
|
||||
// Crear un trabajo
|
||||
IJobDetail job = JobBuilder.Create<EnvioFacturas>()
|
||||
.WithIdentity("EnvioFacturas", "Grupo1")
|
||||
.Build();
|
||||
// Crear un trigger que se ejecute diariamente a una hora espec<65>fica
|
||||
|
||||
ITrigger trigger = TriggerBuilder.Create()
|
||||
.WithIdentity("EnvioFacturas", "Grupo1")
|
||||
.StartAt(DateBuilder.TodayAt(DateTime.Now.Hour, DateTime.Now.Minute, 0))
|
||||
.WithSimpleSchedule(x => x
|
||||
.WithIntervalInMinutes(15)
|
||||
.RepeatForever())
|
||||
.Build();
|
||||
|
||||
// Programar el trabajo con el trigger
|
||||
scheduler.ScheduleJob(job, trigger).Wait();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class TareasProgramadas : IJob
|
||||
{
|
||||
public Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
//var ch = bdTecnosis.db.chequeos;
|
||||
// var bd = bdTecnosis.tscTecnosis.NuevoContexto();
|
||||
//var c = bd.chequeos.FirstOrDefault(x => x.idChequeo == ch.idChequeo);
|
||||
//Comprobaciones.ChequeaColaCorreo(bd,c);
|
||||
//Comprobaciones.CompruebaReplica();
|
||||
//Aqui van los procesos y comprobaciones
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class EnvioFacturas : IJob
|
||||
{
|
||||
private static readonly SemaphoreSlim _semaforo = new SemaphoreSlim(1, 1);
|
||||
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
var cancellationToken = context.CancellationToken;
|
||||
|
||||
if (await _semaforo.WaitAsync(0, cancellationToken)) // no espera si est<73> ocupado
|
||||
{
|
||||
try
|
||||
{
|
||||
var ft = new ProcesosVeriFactuAsegasa();
|
||||
await ft.Iniciar(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.A<EFBFBD>adeLog(tsUtilidades.Enumeraciones.TipoLog.Fallo, ex.Message, ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_semaforo.Release();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var bd = tscgestionasegasa.NuevoContexto(Procesos.Conf.NombreConexionBD, true, false, true, "ProcesosVeriFactuTecnosis");
|
||||
var cvf = bd.enumeraciones.First(x => x.Codigo == "VF.CONF");
|
||||
if (DateTime.Now.Hour < cvf.ValorNumerico2.Value) Logs.A<EFBFBD>adeLog(tsUtilidades.Enumeraciones.TipoLog.Advertencia, "Bloqueo en EnvioFacturas");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user