Esempio n. 1
0
        /// <summary>
        /// Lanzamiento del update
        /// </summary>
        private void lanzarUpdate()
        {
            try
            {
                actualProces = 0;
                actualProces++;
                // Create a new instance of our ProgressBar Delegate that points
                // to the ProgressBar's SetValue method.
                updatePbDelegate =
                    new UpdateProgressBarDelegate(pBar.SetValue);
                Dispatcher.Invoke(updatePbDelegate,
                System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, Convert.ToDouble(actualProces) });
                if (this.validacionBD() )
                if( this.checkSMS() != 0)
                {
                    this.addText("Comprobando la conectividad de la red\n");
                    if (NetworkInterface.GetIsNetworkAvailable())
                   {
                        this.addText("Conectividad de la red comprobada\n");
                        int numIntentos = 1;
                        int numIntentosMax = 1;
                        int tiempoEspera = 1 ;
                        //Obteniendo num maximo de intentos
                        try
                        {
                            numIntentosMax = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["NumReintentos"]);
                        }
                        catch(Exception ex)
                        {
                            this.addText("Formato de número de intentos invalido - " + ex.Message );
                             numIntentos = 1;
                        }
                        //Obteniendo tiempo de espera entre intentos
                        try
                        {
                            tiempoEspera = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SegsTiempoReintento"]);
                        }
                        catch(Exception ex2)
                        {
                            this.addText("Formato de tiempo de espera invalido - " + ex2.Message);
                             numIntentos = 1;
                        }
                        //Intentos de conexion
                        while (numIntentos <= numIntentosMax)
                        {
                            this.addText("Comprobando la conectividad de la carpeta de datos - intento "+numIntentos+" / "+numIntentosMax+"\n");
                            if (this.getStatusConn())
                            {
                                this.addText("Conectividad de la carpeta de datos comprobada\n");
                                this.addText("Iniciando sincronización de KPIs\n");

                                //--------- INI BZG - Elimina Carpeta temporal -------------
                                EliminaArchivosTemporales();
                                //--------- FIN BZG - Elimina Carpeta temporal -------------

                                //Sincronizando
                                //--------------   INI BZG ----------------
                                territorio = this.ValidaCambioTerritorio();
                                //--------------   FIN BZG ----------------
                                this.sincroniceKPIs();
                                this.sincroniceCatalogos();
                                DateTime stopTime = DateTime.Now;
                                double totalSeconds = (double)stopTime.Ticks / TimeSpan.TicksPerSecond;
                                string dateFormat = stopTime.ToString("yyyyMMddHHmmssffff");
                                long fecha_sin_int = Convert.ToInt64(dateFormat);
                                int duracion = 0;
                                Consultas c = new Consultas();
                                c.InsertVitacora(usuario, WindowsIdentity.GetCurrent().Name, DateTime.Now, versionCliente, duracion, null, territorio, fecha_sin_int, true);

                                if (this.getText().ToLower().Contains("error"))
                                {
                                    MessageBox.Show("El proceso de sincronización terminó con al menos un error. Favor de contactar a Help Desk.");
                                    //MessageBox.Show("El proceso de actualización terminó, pero se registró un problema, verifique el detalle de la ejecución.");
                                }
                                else
                                    MessageBox.Show("El proceso de sincronización de KPIs terminó exitosamente.");
                                    //MessageBox.Show("El proceso de actualización terminó, por favor verifique el log para constatar la ejecución del proceso");
                                string delay = System.Configuration.ConfigurationManager.AppSettings["SegsTiempoComprobacionConexion"];
                                try
                                {
                                    int delayNew = Convert.ToInt32(delay);
                                    delayNew = delayNew + 5;
                                    System.Threading.Thread.Sleep(delayNew * 1000);
                                }
                                catch (Exception)
                                {
                                }
                                this.reinitPrincipal();
                                break;
                            }
                            else
                            {
                                this.addText("No se encontró conexión con la carpeta de datos de aplicación " + System.Configuration.ConfigurationManager.AppSettings["CarpetaCompartida"] + "\n");
                                numIntentos++;
                                System.Threading.Thread.Sleep(tiempoEspera);
                            }
                        }
                        //Comprobando maximo de intentos
                        if (numIntentos > numIntentosMax)
                        {
                            this.addText("Los intentos de conectividad superaron el máximo de intentos "+numIntentos+"/"+numIntentosMax+"\n");
                        }
                   }
                    else
                    {
                        MessageBox.Show("No se encontró conexión de red disponible");
                    }
                }
                actualProces++;
                Dispatcher.Invoke(updatePbDelegate,
                System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, Convert.ToDouble(actualProces) });

            this.btnEjecutarEnabled(true);
            }
            catch (Exception ex3)
            {
                this.btnEjecutarEnabled(true);
                this.addText("Error en la ejecución de la actualización : " + ex3.Message);
                MessageBox.Show("Ocurrió un error en la ejecución de la actualización - " + ex3.Message);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Proceso de sincronizacion
        /// </summary>
        private void sincroniceKPIs()
        {
            bool local = true;
            this.addText("*****************  INICIANDO PROCESO DE SINCRONIZACIÓN DE KPIS  *****************\n");
            string compartida = System.Configuration.ConfigurationManager.AppSettings["CarpetaCompartida"];
            this.addText("Obteniendo archivos de la carpeta remota \n");
            string[] archivosTerritorio = this.obtenerArchivos(compartida,territorio+"*.zip");
            if (archivosTerritorio.Length == 0)
                this.addText("No se detectaron archivos en la carpeta remota\n");
            setMaxBar(archivosTerritorio.Length);
            Consultas c = new Consultas();
            foreach (string file in archivosTerritorio)
            {
                try
                {
                    FileInfo fkpi = new FileInfo(file);
                    string kpi = fkpi.Name.Substring(fkpi.Name.IndexOf("_") + 1, (fkpi.Name.LastIndexOf("_") - 1 - fkpi.Name.IndexOf("_")));
                    string date = file.Substring(file.LastIndexOf("_")+1, (file.Length-5 - file.LastIndexOf("_")));
                    long dateLong = -1;
                    try
                    {
                        dateLong = Convert.ToInt64(date);
                    }
                    catch { }
                    this.addText("Insertando registro en NMT_TMP_FILES para el KPI "+kpi+"\n");
                    c.InsertNMT_TMP_FILES(file,kpi,territorio,dateLong);
                }
                catch (Exception ex)
                {
                    this.addText("Error insertando registro en NMT_TMP_FILES para el KPI del archivo" + file + "\n" + ex.Message);
                }
                actualProces++;
                Dispatcher.Invoke(updatePbDelegate,
                System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, Convert.ToDouble(actualProces) });
            }
            this.addText("Seleccionando archivos a cargar\n");
            c.CompareNMT_TMP_FILES();
            DataTable kpis = new DataTable();
            kpis = c.SelectNMT_TMP_FILES().Tables[0];
            if (kpis.Rows.Count == 0)
                this.addText("No se detectaron archivos a cargar \n");
            foreach (DataRow g in kpis.Rows)
            {
                string file = (string)g["FULL_FILENAME"];
                string kpi = (string)g["FILENAME_KPI"];
                long dateLong = (long)g["FILENAME_DATE"];
                this.cargaCurrentFiles(file, kpi, territorio, dateLong);
            }
            this.addText("Seleccionando archivos con bit para carga en CURRENT FILES\n");
            DataTable kpisCurrent = new DataTable();
            kpisCurrent = c.SelectNMT_CURRENT_FILES().Tables[0];
            setMaxBar(kpisCurrent.Rows.Count);
            if (kpisCurrent.Rows.Count == 0)
                this.addText("No se detectaron archivos a cargar con bit en 1\n");
            foreach (DataRow g in kpisCurrent.Rows)
            {
                string file = (string)g["FULL_FILENAME"];
                string kpi = (string)g["FILENAME_KPI"];
                long dateLong = (long)g["FILENAME_DATE"];
                DateTime startTime = DateTime.Now;
                try
                {
                    this.addText("Realizando la extracción del .zip\n");
                    List<string> files = this.descomprimir(file);
                    this.addText("Homologando "+kpi+" \n");
                    bool exitoLectura = true;
                    try
                    {
                        string tabla = this.homologue(kpi);
                        DataTable datosTabla = new DataTable();
                        datosTabla = c.CreateTableKPITemp(tabla).Tables[0];
                        this.addText("Iniciando lectura de archivo\n");
                        StreamReader reader = null;
                        try
                        {
                            reader = new StreamReader(files[0]);
                            string line = string.Empty;
                            while ((line = reader.ReadLine()) != null)
                            {
                                try
                                {
                                    string[] valores = line.Split('|');
                                    int index = 0;
                                    string columns = "";
                                    string inserts = "";
                                    bool a = false;
                                    foreach (DataRow gdata in datosTabla.Rows)
                                    {
                                        string column = (string)gdata["COLUMN_NAME"];
                                        if (column == "Ciclo")
                                            a = true;
                                        string tipo = (string)gdata["TYPE_NAME"];
                                        columns += column + ",";
                                        string val = "";

                                        // --INI BZG ADECUACION COMILLAS
                                        if (tipo.ToLower().Contains("char")) val += "{\"}";
                                        // --FIN BZG ADECUACION COMILLAS
                                        if (index < valores.Length) val += valores[index];
                                        // --INI BZG ADECUACION COMILLAS
                                        if (tipo.ToLower().Contains("char")) val += "{\"}";
                                        // --FIN BZG ADECUACION COMILLAS
                                        if (a == true)
                                            val = val.Substring(0, 6);

                                        inserts += val + ",";
                                        index++;
                                        a = false;
                                    }
                                    try
                                    {
                                        c.ExecuteSQLNMT_TMP_FILES(tabla, columns.Remove(columns.Length - 1, 1), inserts.Remove(inserts.Length - 1, 1),local);
                                    }
                                   catch (Exception ex2)
                                    {
                                        this.addText("Error insertando los datos en la tabla temporal\n" + ex2.Message);
                                        this.addText("Registro " + inserts.Remove(inserts.Length - 1, 1) + "\n");
                                        exitoLectura = exitoLectura && false;
                                    }
                                }
                                catch (Exception ex3)
                                {
                                    this.addText("Error mapeando columnas de tabla con columnas del archivo\n" + ex3.Message);
                                    exitoLectura = exitoLectura && false;
                                }
                            }
                            reader.Close();
                        }
                        catch (Exception ex4)
                        {
                            this.addText("Error en la lectura del archivo "+file+"\n" + ex4.Message);
                            if (reader != null)
                                reader.Close();
                            exitoLectura = exitoLectura && false;
                        }
                        if (exitoLectura)
                        {
                            this.addText("Tabla temporal " + tabla + "_TMP creada y cargada\n");
                            this.addText("Truncando la tabla " + tabla + "\n");
                            try
                            {
                                c.Truncate_NMT_Table(tabla, local);
                                this.addText("Tabla " + tabla + " truncada\n");
                                this.addText("Cargando los datos desde la tabla temporal " + tabla + "_TMP\n");
                                try
                                {
                                    c.Merge_NMT_Table(tabla + "_TMP", tabla, local);
                                    this.addText("Carga de datos desde la tabla temporal " + tabla + "_TMP exitosa\n");
                                    //--------- BZG
                                    c.SetLoadedNMT_CURRENT_FILES(kpi);
                                    //---------
                                    try
                                    {
                                        this.addText("Insertando a bitacora\n");
                                        DateTime stopTime = DateTime.Now;
                                        TimeSpan duration = stopTime - startTime;
                                        double totalSeconds = (double)stopTime.Ticks / TimeSpan.TicksPerSecond;
                                        string dateFormat = stopTime.ToString("yyyyMMddHHmmssffff");
                                        long fecha_sin_int = Convert.ToInt64(dateFormat);
                                        int duracion = Convert.ToInt32(duration.TotalSeconds);
                                        c.InsertVitacora(usuario, WindowsIdentity.GetCurrent().Name, DateTime.Now, versionCliente, duracion, kpi, territorio, fecha_sin_int, true);
                                    }
                                    catch (Exception ex5)
                                    {
                                        this.addText("Error en la inserción a bitacora\n" + ex5.Message);
                                    }
                                    this.addText("Eliminando tabla temporal " + tabla + "_TMP \n");
                                    try
                                    {
                                        c.Drop_NMT_Table(tabla + "_TMP", local);
                                    }
                                    catch (Exception ex6)
                                    {
                                        this.addText("Error eliminando la tabla temporal " + tabla + "_TMP\n" + ex6.Message);
                                    }
                                }
                                catch (Exception ex7)
                                {
                                    this.addText("Error al intentar cargar los datos desde la tabla temporal " + tabla + "_TMP\n" + ex7.Message);
                                }
                            }
                            catch (Exception ex8)
                            {
                                this.addText("Error al intentar truncar la tabla\n" + ex8.Message);
                            }
                        }
                        else
                        {
                            try
                            {
                                c.Drop_NMT_Table(tabla + "_TMP", local);
                            }
                            catch (Exception ex9)
                            {
                                this.addText("Error eliminando la tabla temporal " + tabla + "_TMP\n" + ex9.Message);
                            }
                        }
                    }
                    catch (Exception ex10)
                    {
                        this.addText("Ocurrió un error tratando de crear la tabla temporal\n" + ex10.Message);
                    }

                }
                catch(Exception ex11)
                {
                    this.addText("Ocurrió un error en la extracción del .zip\n" + ex11.Message);
                }
                actualProces++;
                Dispatcher.Invoke(updatePbDelegate,
                System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, Convert.ToDouble(actualProces) });
            }
        }