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(); } }
static void CopyCsvCompToPg(string csvPath, string schema = "raw_reports") { var tableName = Path.GetFileNameWithoutExtension(csvPath); tableName = tableName.Replace("report_", ""); tableName = tableName.Replace("trep_", ""); tableName = "acta_comp_" + tableName; tableName = tableName.Replace('.', '_'); using (ElecPgRepository dbRepo = new ElecPgRepository(StrCnn)) { dbRepo.CreatePgActaCompTable(tableName, schema); PathWriter = $"/Volumes/easystore/Temp/copy_{tableName}.txt"; WriterOpen(); WriteLine($"Database: durkteel"); WriteLine($"Tabla: {schema}.{tableName}"); WriteLine($"Copiando reporte: {csvPath}"); WriteLine("--------------------------------------------------------------"); int ret = dbRepo.CopyCsvCompToPg(csvPath, tableName); WriteLine($"Filas insertadas: {ret}"); WriteLine(""); WriterClose(); } }
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(); } }