public override void insertarEnDB() { var lista = this.leerArchivo(_filename); clsRepo repo = new clsRepo(); /*System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); * stopWatch.Start();*/ Parallel.ForEach <string>(lista, linea => //foreach(string linea in lista) { /*commons.logger.Info("testing info"); * commons.logger.Warn("testing warning");*/ Dominio.Lastb lastb = getLastbLine(linea); if (lastb != null) { repo.Insertar <Dominio.Lastb>(lastb); } }); //Console.Write((stopWatch.ElapsedMilliseconds / 1000) + " segundos"); }
public Dominio.Lastb getLastbLine(string line) { Dominio.Lastb retorno; if (!esLineaLog(line)) { return(null); } retorno = new Dominio.Lastb(); string fecha = null; line = depurarFecha(line, out fecha); string[] arreglo = Regex.Split(line, " {2,}"); retorno.revision = commons.Revision_Actual; switch (arreglo.Length) { case 3: retorno.username = arreglo[0]; retorno.servicio = arreglo[1]; retorno.tiempoConexion = arreglo[2]; retorno.fecha = fecha; break; case 4: retorno.username = arreglo[0]; retorno.servicio = arreglo[1]; retorno.ip = arreglo[2]; retorno.tiempoConexion = arreglo[3]; //retorno.fecha = arreglo[3]; //retorno.fechaValue = null; retorno.fecha = fecha; break; case 5: retorno.username = arreglo[0]; retorno.servicio = arreglo[1]; retorno.ip = arreglo[2]; retorno.fecha = arreglo[3]; //retorno.fechaValue = null; retorno.tiempoConexion = arreglo[4]; break; case 6: retorno.username = arreglo[0]; retorno.servicio = arreglo[1]; retorno.ip = arreglo[2]; retorno.fecha = arreglo[3] + " " + arreglo[4];; //retorno.fechaValue = null; retorno.tiempoConexion = arreglo[5]; break; default: retorno = null; if (string.IsNullOrEmpty(line)) { Console.WriteLine("linea vacia"); } else { Console.WriteLine("error con la siguiente linea:\n" + line); } break; } return(retorno); }