/// <summary> /// Obtiene los archivos desde el FTP, los guarda localmente y devuelve la estructura FileRef con la referencia a los archivos descargados /// </summary> /// <returns></returns> private IEnumerable <FileRef> ObtenerArchivosDesdeFTP() { var ftp = new SIR.Common.FTP.FTPClient( DAO.Config.Get("ftpHost", Logger)?.Value, DAO.Config.Get("ftpUsername", Logger)?.Value, DAO.Config.Get("ftpPassword", Logger)?.Value, DAO.Config.Get("ftpPort", Logger)?.Convert <int>() ?? 21, DAO.Config.Get("ftpEnableSsl", Logger)?.Convert <bool>() ?? false ); // Obtengo la configuración y obtengo la lista de archivos desde el FTP var ftpPath = DAO.Config.Get("ftpDir", Logger)?.Value; var files = ftp.GetFiles(ftpPath); // Verifico que pre-exista la carpeta local var localPath = DAO.Config.Get("localDir", Logger)?.Value; if (!System.IO.Directory.Exists(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, localPath))) { System.IO.Directory.CreateDirectory(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, localPath)); } // Sólo se procesan los archivos que cumplen cierto criterio según el nombre var validFile = new Regex(@"^REND?BCBA(029|999)\d{6}.txt$", RegexOptions.IgnoreCase); var tasks = new Queue <Task <Response <FileRef> > >(); foreach (var file in files.Where(f => validFile.IsMatch(f))) { tasks.Enqueue(new Task <Response <FileRef> >(ObtenerArchivoDesdeFTP, new { ftp, ftpPath, file, localPath })); } Logger.Info($"Se encontraron {tasks.Count} archivos a descargar desde el FTP."); // Descargo los archivos en paralelo y logueo los resultados. var results = new SIR.Common.Thread.TaskManager().ProcesarEnParalelo(tasks, 5); foreach (var res in results) { Logger.Log(res); } // Devuelvo sólo los archivos que no tuvieron problemas en procesarse return(results.Where(p => !p.ExistsErrorMessages).Select(p => p.Data)); }
internal void ProcesarRendicionDAI(DateTime fecha, int dias) { IList <DTO.StoredProcedures.RendicionPagos> pendientes = new DTO.StoredProcedures.RendicionPagos[0]; try { var deps = DAO.Config.Get("RendicionPagosDAIDependencias", Logger)?.Value; var parms = new SIR.Common.DAL.SP.Parameters() .AddParam("pFechaDesde", fecha.AddDays(-dias + 1)) .AddParam("pFechaHasta", fecha) .AddParam("pDependencias", deps.Split(',')); pendientes = DAO.ExecProcedure <DTO.StoredProcedures.RendicionPagos>("SIR.GETRENDPAGOSDAI", parms); } catch (Exception ex) { Logger.Error($"Error al obtener las boletas pendientes de notificación desde la base de datos.", ex); } var path = DAO.Config.Get("RendicionPagosDAIFilePath", Logger)?.Value; var tasks = new Queue <Task>(); for (var d = 1; d <= dias; d++) { var procFecha = fecha.AddDays(1 - d); var f = procFecha.ToString("ddMMyyyy"); var data = pendientes.Where(p => p.Fecha == f).ToArray(); tasks.Enqueue(new Task <bool>((obj) => { var _logger = (SIR.Common.Log.Logger)((dynamic)obj).Logger; var _fecha = (DateTime)((dynamic)obj).Fecha; var _path = (string)((dynamic)obj).Path; var _pagos = (DTO.StoredProcedures.RendicionPagos[])((dynamic)obj).Pagos; GenerarArchivoRendicion(_logger, _fecha, _path, _pagos); return(true); }, new { Logger, Fecha = procFecha, Path = path, Pagos = data })); } var async = new SIR.Common.Thread.TaskManager(); async.ProcesarEnParalelo(tasks, Config.RendicionesDAI_Paralelismo); }
internal void ProcesarNotificaciones(DateTime desde, DateTime hasta) { IList <DTO.StoredProcedures.Pendiente> pendientes = new DTO.StoredProcedures.Pendiente[0]; try { var parms = new SIR.Common.DAL.SP.Parameters() .AddParam("pFechaDesde", desde) .AddParam("pFechaHasta", hasta); pendientes = DAO.ExecProcedure <DTO.StoredProcedures.Pendiente>("SIR.GETBUIPENDNOTIF", parms); } catch (Exception ex) { Logger.Error($"Error al obtener las boletas pendientes de notificación desde la base de datos."); Logger.Error(ex); } var notificaciones = new Queue <Task>(); foreach (var notif in pendientes) { notificaciones.Enqueue(new Task <bool>((obj) => { var _logger = (SIR.Common.Log.Logger)((dynamic)obj).Logger; var _notif = (DTO.StoredProcedures.Pendiente)((dynamic)obj).notif; var _connector = (SIR.Common.Connector.VEPConnector)((dynamic)obj).connector; try { var res = _connector.NotificarPago(new VEP.Request.NotificarPagoRequest() { Numero = _notif.Numero, Traza = _notif.IdCobro, AConfirmar = _notif.AConfirmar }); _logger.Log(res); if (res.Success) { _logger.Info($"Se estableció la Traza {_notif.IdCobro} para la Boleta {_notif.Numero}({_notif.Id})"); } else { _logger.Error($"Ocurrió un error al establecer la Traza {_notif.IdCobro} para la Boleta {_notif.Numero}({_notif.Id})."); } if (res.Success && _notif.AConfirmar) { var baja = _connector.BajaFacturaPMC(new VEP.Request.BajaFacturaPMCRequest() { NroFactura = _notif.Numero, NroUsuario = string.Empty }); _logger.Log(baja); if (baja.Success) { _logger.Info($"Baja PMC para la boleta {_notif.Numero}({_notif.Id}): {baja.Data}"); } } } catch (Exception ex) { _logger.Error($"Error al procesar la Notificación de Pago de la Boleta {_notif.Numero}({_notif.Id})"); _logger.Error(ex); } return(true); }, new { notif, Logger, connector = this.VEPConnector })); } Logger.Info($"Se han encontrado {notificaciones.Count} Boletas a Notificar."); var async = new SIR.Common.Thread.TaskManager(); async.ProcesarEnParalelo(notificaciones, this.Config.NotificacionesBUI_Paralelismo); }
internal void ProcesarNotificacionesPE() { IList <DTO.StoredProcedures.PendientePE> pendientes = new DTO.StoredProcedures.PendientePE[0]; try { pendientes = DAO.ExecProcedure <DTO.StoredProcedures.PendientePE>("SIR.GETPAGOSBUIPENDPE", null); } catch (Exception ex) { Logger.Error($"Error al obtener los pagos de BUIs externos a PE desde la base de datos."); Logger.Error(ex); } var peUser = DAO.Config.Get("RecaudaUser", Logger)?.Value; var pePass = DAO.Config.Get("RecaudaPass", Logger)?.Value; var notificaciones = new Queue <Task>(); foreach (var notif in pendientes) { notificaciones.Enqueue(new Task <bool>((obj) => { var _logger = (SIR.Common.Log.Logger)((dynamic)obj).Logger; var _notif = (DTO.StoredProcedures.PendientePE)((dynamic)obj).notif; var _connector = (SIR.Common.Connector.RecaudaConnector)((dynamic)obj).connector; var _vepConnector = (SIR.Common.Connector.VEPConnector)((dynamic)obj).vepConnector; var _user = (string)((dynamic)obj).user; var _pass = (string)((dynamic)obj).pass; try { var res = _connector.NotificarPostbackBUI(new Recauda.Request.NotificarPostbackBUIRequest() { IdCobro = _notif.IdCobro, IdPostback = _notif.IdPostback, FechaPago = _notif.Fecha, NroBUI = _notif.Numero, User = _user, Pass = _pass }).Result; _logger.Log(res); if (res.Success && res.Data) { _logger.Info($"Se ha notificado el Pago de BUI a Pago Electrónico. Boleta:{_notif.Numero}({_notif.IdBoleta}), Cobro:{_notif.Fecha:dd/MM/yyyy HH:mm}({_notif.IdCobro})"); } else { _logger.Info($"Error al notificar pago de BUI a Pago Electrónico. Boleta:{_notif.Numero}({_notif.IdBoleta}), Cobro:{_notif.Fecha:dd/MM/yyyy HH:mm}({_notif.IdCobro})"); } } catch (Exception ex) { _logger.Error($"Error al procesar la Notificación de Pago de la Boleta:{notif.Numero}({notif.IdBoleta}), Cobro:{notif.Fecha:dd/MM/yyyy HH:mm}({notif.IdCobro})"); _logger.Error(ex); } return(true); }, new { notif, Logger, connector = this.RecaudaConnector, vepConnector = this.VEPConnector, user = peUser, pass = pePass })); } Logger.Info($"Se han encontrado {notificaciones.Count} Boletas a Informar al Sistema de Recaudaciones Electrónico."); var async = new SIR.Common.Thread.TaskManager(); async.ProcesarEnParalelo(notificaciones, this.Config.NotificacionesPE_Paralelismo); }
internal void ProcesarVencimientos() { IList <DTO.StoredProcedures.Pendiente> pendientes = new DTO.StoredProcedures.Pendiente[0]; try { pendientes = DAO.ExecProcedure <DTO.StoredProcedures.Pendiente>("SIR.GETBUIVENCIDAS", null); } catch (Exception ex) { Logger.Error($"Error al obtener las boletas pendientes de cancelación por vencimiento desde la base de datos."); Logger.Error(ex); } var notificaciones = new Queue <Task>(); foreach (var notif in pendientes) { notificaciones.Enqueue(new Task <bool>((obj) => { var _logger = (SIR.Common.Log.Logger)((dynamic)obj).Logger; var _notif = (DTO.StoredProcedures.Pendiente)((dynamic)obj).notif; var _connector = (SIR.Common.Connector.VEPConnector)((dynamic)obj).connector; try { var res = _connector.Cancelar(new VEP.Request.CancelarRequest() { Id = _notif.Id, Numero = _notif.Numero }); _logger.Log(res); if (res.Success) { _logger.Info($"Se Canceló la Boleta {_notif.Numero}({_notif.Id}) por Vencimiento de la misma"); } else { _logger.Error($"No se pudo cancelar la Boleta {_notif.Numero}({_notif.Id}) por Vencimiento de la misma"); } if (res.Success && _notif.AConfirmar) { var baja = _connector.BajaFacturaPMC(new VEP.Request.BajaFacturaPMCRequest() { NroFactura = _notif.Numero, NroUsuario = string.Empty }); _logger.Log(baja); if (baja.Success) { _logger.Info($"Baja PMC para la boleta {_notif.Numero}({_notif.Id}): {baja.Data}"); } } } catch (Exception ex) { _logger.Error($"Error al procesar la Cancelación de la Boleta {_notif.Numero}({_notif.Id}) por Vencimiento de la misma"); _logger.Error(ex); } return(true); }, new { notif, Logger, connector = this.VEPConnector })); } Logger.Info($"Se han encontrado {notificaciones.Count} Boletas a Cancelar por Vencimiento."); var async = new SIR.Common.Thread.TaskManager(); async.ProcesarEnParalelo(notificaciones, this.Config.Vencimientos_Paralelismo); }