コード例 #1
0
        static void BulkInsertTrepCsvToPg(string trepCsvName, string schema = "raw_reports")
        {
            var tableName = Path.GetFileNameWithoutExtension(trepCsvName);

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

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

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

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

            using (ElecPgRepository dbRepo = new ElecPgRepository(StrCnn))
            {
                dbRepo.CreatePgActaTrepTable(tableName, schema);
                var result = dbRepo.InsertActasTrep(actas, tableName, schema);
                WriteLine($"Actas insertadas: {result.Current.Count()}");
                WriterClose();
            }
        }
コード例 #2
0
        static void InsertTrepCsvToPg(string trepCsvName, string schema = "raw_reports")
        {
            var tableName = Path.GetFileNameWithoutExtension(trepCsvName);

            tableName  = tableName.Replace("report_", "");
            tableName  = tableName.Replace("trep_", "");
            tableName  = "acta_trep_" + tableName;
            tableName  = tableName.Replace('.', '_');
            PathWriter = $"/Volumes/easystore/Temp/{tableName}.txt";
            WriterOpen();
            WriteLine($"Database: durkteel");
            WriteLine($"Tabla: {schema}.{tableName}");
            WriteLine($"Insertando reporte: {trepCsvName}");
            WriteLine("--------------------------------------------------------------");
            var lines = CsvFile.ReadAllLines(trepCsvName, 2);
            int i     = 0;

            using (ElecPgRepository dbRepo = new ElecPgRepository(StrCnn))
            {
                dbRepo.CreatePgActaTrepTable(tableName, schema);
                foreach (var linea in lines)
                {
                    PgActaTrep acta = CsvFile.GetPgActaTrep(linea, trepCsvName);
                    long       ret  = dbRepo.InsertPgActaTrep(acta, tableName, schema);
                    if (ret == 1)
                    {
                        WriteLine($"Acta insertada: {++i}");
                    }
                    else
                    {
                        WriteLine($"Acta no insertada (ret={ret}): {++i}");
                    }
                }
                WriteLine("");
                WriterClose();
            }
        }