Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }