Exemplo n.º 1
0
        static void BulkInsertCompCsvToPg(string compCsvName, string schema = "raw_reports")
        {
            var tableName = Path.GetFileNameWithoutExtension(compCsvName);

            tableName = tableName.Replace("report_", "");
            tableName = tableName.Replace("trep_", "");
            tableName = "acta_comp_" + tableName;
            tableName = tableName.Replace('.', '_');

            PathWriter = $"/Volumes/easystore/Temp/{tableName}.txt";
            WriterOpen();
            WriteLine($"Database: durkteel");
            WriteLine($"Tabla: {schema}.{tableName}");
            WriteLine($"Insertando reporte: {compCsvName}");
            WriteLine("--------------------------------------------------------------");

            var lines = CsvFile.ReadAllLines(compCsvName, 2);
            var actas = new List <PgActaComp>();

            foreach (var line in lines)
            {
                PgActaComp acta = CsvFile.GetPgActaComp(line);
                actas.Add(acta);
            }

            using (ElecPgRepository dbRepo = new ElecPgRepository(StrCnn))
            {
                dbRepo.CreatePgActaCompTable(tableName, schema);
                var result = dbRepo.InsertActasComp(actas, tableName, schema);
                WriteLine($"Actas insertadas: {result.Current.Count()}");
                WriterClose();
            }
        }
Exemplo n.º 2
0
        static void InsertCompCsvToPg(string compCsvName, string schema = "raw_reports")
        {
            var tableName = Path.GetFileNameWithoutExtension(compCsvName);

            tableName  = tableName.Replace("report_", "");
            tableName  = tableName.Replace("trep_", "");
            tableName  = "acta_comp_" + tableName;
            tableName  = tableName.Replace('.', '_');
            PathWriter = $"/Volumes/easystore/Temp/{tableName}.txt";
            WriterOpen();
            WriteLine($"Database: durkteel");
            WriteLine($"Tabla: {schema}.{tableName}");
            WriteLine($"Insertando reporte: {compCsvName}");
            WriteLine("--------------------------------------------------------------");
            using (ElecPgRepository dbRepo = new ElecPgRepository(StrCnn))
            {
                dbRepo.CreatePgActaCompTable(tableName, schema);
                var lines = CsvFile.ReadAllLines(compCsvName, 2);
                int i     = 0;
                foreach (var linea in lines)
                {
                    PgActaComp acta = CsvFile.GetPgActaComp(linea, compCsvName);
                    long       ret  = dbRepo.InsertPgActaComp(acta, tableName, schema);
                    if (ret == 1)
                    {
                        WriteLine($"Acta insertada: {++i}");
                    }
                    else
                    {
                        WriteLine($"Acta no insertada (ret={ret}): {++i}");
                    }
                }
                WriteLine("");
                WriterClose();
            }
        }