示例#1
0
        static void Main(string[] args)
        {
            var log = new SIR.Common.Log.Logger("SIR.Sync", new Common.Log.LoggerConfig()
            {
                Console = new Common.Log.LoggerConfig.ConsoleConfig()
                {
                    ShowInConsole = true
                }
            });

            try
            {
                log.Info("== Inicio de Procesamiento de SIR.Sync ==");
                log.Info($"Version: {System.Reflection.Assembly.GetExecutingAssembly().GetName().Version}");
                log.Info($"Command: {AppDomain.CurrentDomain.FriendlyName} {string.Join(' ', args)}");

                var optionsRes = new ParseArgs().Parse <Arguments>(args);
                if (optionsRes.ExistsErrorMessages)
                {
                    log.Log(optionsRes);
                    Console.ReadLine();
                    return;
                }
                var options = optionsRes.Data;

                if (options.ShowHelp)
                {
                    Console.WriteLine("Listado de Parámetros válidos para la aplicación");
                    Console.WriteLine(new ParseArgs().GetHelpText <Arguments>());
                    return;
                }

                var config = Newtonsoft.Json.JsonConvert.DeserializeObject <Application>(System.IO.File.ReadAllText("SIR.Sync.Config.json"));

                if (options.ProcesarSync)
                {
                    var procesador = new BLL.ProcesadorSync(log, config);

                    procesador.ProcesarNotificaciones(options.FechaDesde, options.FechaHasta);
                    procesador.ProcesarAnulaciones(options.FechaDesde, options.FechaHasta);
                    procesador.ProcesarVencimientos();
                    procesador.ProcesarNotificacionesPE();
                }

                if (options.ProcesarRendicion)
                {
                    var procesador = new BLL.ProcesadorRendiciones(log, config);

                    procesador.ProcesarRendicionDAI(options.FechaRendicion, options.DiasRendicion);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
            finally
            {
                log.Info("== Fin de Procesamiento de SIR.Sync ==");
            }
        }
示例#2
0
        /// <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));
        }