Ejemplo n.º 1
0
        private void HandleInspection(FileInfo file, Sensores sensor)
        {
            DateTime fecha = DateTime.Parse(sensor.last_date_saved);

            #region Lectura de las filas del archivo
            DataTable csv = null;
            try
            {
                controllerLog.debug("Leyendo: " + file.FullName);
                csv = FilesHandler.FileToTable(file.FullName, ',');
            }
            catch (Exception ex)
            {
                controllerLog.stack("No fue posible leer: " + file.FullName, this, ex);
            }

            #endregion
            if (csv != null)
            {
                if (csv.Rows.Count > 0)
                {
                    int  filas  = 0;
                    bool creado = true;
                    foreach (DataRow Fila in csv.Rows)
                    {
                        humedad        = Fila[0].ToString();
                        temperatura    = Fila[1].ToString();
                        fecha_medicion = Convert.ToDateTime(Fila[4].ToString());
                        if (fecha_medicion > fecha)
                        {
                            filas++;
                            creado = Mediciones.createMeasure(sensor.id_sensor, temperatura, humedad, fecha_medicion);
                            if (!creado)
                            {
                                controllerLog.warning("La Fila con fecha " + fecha_medicion + " para sensor " + sensor.nombre + " NO se agregó a la BD");
                            }
                        }
                        else
                        {
                            //controllerLog.warning(file.FullName+"| la fila con fecha " + fecha_medicion + " NO se agregará a la BD");
                        }
                    }
                    if (filas > 0)
                    {
                        controllerLog.success("Registros Agregados: " + filas);
                    }
                    else
                    {
                        controllerLog.success("No se han registrado Nuevas Mediciones");
                    }

                    //Actualizo la fecha de la última lectura de las mediciones
                    controllerLog.info("---------------------------------------------");
                    controllerLog.info("Actualizando Ping de Sensor " + sensor.nombre);
                    Sensores.UpdatePing(sensor.nombre, fecha_medicion);
                    controllerLog.info("Ping Actualizado.");
                    controllerLog.info("---------------------------------------------");
                }
            }
        }
Ejemplo n.º 2
0
        private void CreateInspectionObject()
        {
            DataTable contenidoCsv = null;

            #region ABRE Y LEE TODAS LAS FILAS DEL ARCHIVO CSV
            try
            {
                rnsi.aoiLog.debug("Leyendo: " + csvFilePath.FullName);
                contenidoCsv = FilesHandler.FileToTable(csvFilePath.FullName, ',');
            }
            catch (Exception ex)
            {
                rnsi.aoiLog.stack("No fue posible leer: " + csvFilePath.FullName, this, ex);
            }
            #endregion

            // Solo si el archivo tiene al menos una fila de informacion
            if (contenidoCsv != null)
            {
                if (contenidoCsv.Rows.Count > 0)
                {
                    #region LEE COLUMNAS DE ARCHIVO CSV Y VALIDA BARCODE
                    DataRow info = contenidoCsv.Rows[0];

                    csvFile       = csvFilePath.Name;
                    csvDatetime   = csvFilePath.LastWriteTime;
                    csvDateSaved  = DateTime.Parse(info[15].ToString().Replace("U", ""));
                    csvDateCreate = DateTime.Parse(info[18].ToString().Replace("U", ""));

                    fecha = csvDatetime.ToString("yyyy-MM-dd");
                    hora  = csvDatetime.ToString("HH:mm:ss");

                    maquina  = info[5].ToString().Replace("\"", "").Trim();
                    programa = info[7].ToString().Replace("\"", "").Trim();

                    barcode = info[36].ToString().Replace("\"", "").Trim();

                    BarcodeValidate();

                    string panelNroReemp = info[38].ToString().Replace("\"", "").Trim();
                    if (!panelNroReemp.Equals(""))
                    {
                        panelNro = int.Parse(panelNroReemp);
                    }
                    #endregion

                    if (!barcode.Equals(""))
                    {
                        // Adjunto informacion de maquina
                        machine = Machine.list.Where(obj => obj.maquina == maquina).FirstOrDefault();
                        if (machine == null)
                        {
                            machine.LogBroadcast("warning",
                                                 string.Format("No existe la maquina: {0} en la base de datos MySQL", machine.maquina)
                                                 );
                        }
                        else
                        {
                            string proceso = "";
                            rnsi.DynamicTab(machine);
                            if (machine.proceso == "B")
                            {
                                proceso = "BPR";
                                barcode = barcode + "-B";
                            }
                            else
                            {
                                proceso = "SMT";
                            }

                            machine.LogBroadcast("info",
                                                 string.Format("{0} | Maquina {1} | Ultima inspeccion {2} | Proceso {3}",
                                                               machine.smd,
                                                               machine.line_barcode,
                                                               machine.ultima_inspeccion,
                                                               proceso
                                                               )
                                                 );

                            // Adjunto informacion del PCB usado para inspeccionar, contiene numero de bloques y block_id entre otros datos.
                            PcbInfo pcb_info = PcbInfo.list.Find(obj => obj.nombre.Equals(programa) && obj.tipoMaquina.Equals(rnsi.aoiConfig.machineNameKey));
                            if (pcb_info != null)
                            {
                                pcbInfo = pcb_info;
                            }

                            if (!Config.isByPassMode(machine))
                            {
                                // Adhiere las rutas a las carpetas de inspecciones
                                InspectionResult inspResult = new InspectionResult(this, rnsi);

                                if (inspResult.located)
                                {
                                    detailList = GetInspectionDetail(contenidoCsv);
                                    bloqueList = inspResult.GetBlockBarcodes(machine.proceso);

                                    MakeRevisionToAll();

                                    machine.LogBroadcast("info",
                                                         string.Format("Programa: [{0}] | Barcode: {1} | Bloques: {2}",
                                                                       programa,
                                                                       barcode,
                                                                       totalBloques
                                                                       )
                                                         );
                                }
                            }
                        }
                    }
                    else
                    {
                        rnsi.aoiLog.warning("El archivo no tiene codigo de panel");
                    }
                }
                else
                {
                    rnsi.aoiLog.warning("El archivo " + csvFilePath.FullName + " no tiene filas");
                }
            }
        }