//-----------------------------------------------------------------------------------------
        //!@brief Genera el fichero JSON con los datos de configuración para el proxy
        //!@param[MySqlConnection] objConexionBD Comando para ejecutar sentencias en la BD de MySql
        //!@param[string] strIdSistema Identificador del sistema
        //!@param[string] strNombreFichero Nombre del fichero JSON con ruta
        //-----------------------------------------------------------------------------------------
        public bool GeneraFicheroProxy(MySqlConnection objConexionBD, string strIdSistema, string strNombreFichero)
        {
            bool bCorrecto = false;

            if (!string.IsNullOrEmpty(strNombreFichero) && !string.IsNullOrEmpty(strIdSistema))
            {
                try
                {
                    if (objConexionBD != null && objConexionBD.State == ConnectionState.Open)
                    {
                        string strDirFich = Path.GetDirectoryName(strNombreFichero);

                        //Comprobamos si el directorio existe
                        if (strDirFich.Length > 0 && !File.Exists(strDirFich))
                        {
                            Log(false, "GeneraFicheroProxy", "No se ha podido generar el fichero. El directorio " + strDirFich + "no existe");
                        }
                        else
                        {
                            using (MySqlCommand cmdBD = objConexionBD.CreateCommand())
                            {
                                StringBuilder        strOutputJSON = new StringBuilder();
                                JavaScriptSerializer objSerializa  = new JavaScriptSerializer();
                                CDatosParaProxy      objDatos      = new CDatosParaProxy();

                                objDatos.ObtenerDatosCnfParaProxy(cmdBD, strIdSistema);

                                strOutputJSON.Append(objSerializa.Serialize(objDatos));
                                File.WriteAllText(strNombreFichero, strOutputJSON.ToString());
                                bCorrecto = true;
                            }
                        }
                    }
                    else
                    {
                        Log(false, "GeneraFicheroProxy", "Conexión no establecida con la BD");
                    }
                }
                catch (Exception ex)
                {
                    Log(true, "GeneraFicheroProxy", string.Format("Error al generar el fichero proxy: sistema={0}, fichero={1}.Error:", strIdSistema, strNombreFichero) + ex.ToString());
                }
            }
            else
            {
                Log(false, "GeneraFicheroProxy", "El nombre del fichero,identificador del sistema no se ha informado");
            }

            return(bCorrecto);
        }
Ejemplo n.º 2
0
        //-----------------------------------------------------------------------------------------
        //!@brief Obtiene la dirección IP del servidor proxy interno configurado en la BD
        //!@param[DbCommand] cmdBD Comando para ejecutar sentencias en la BD de MySql
        //!@param[string] strIdSistema Identificador del sistema
        //----------------------------------------------------------------------------------------
        private bool ObtenerDireccionIPProxy(DbCommand cmdBD, string strSistema)
        {
            bool   bCorrecto = false;
            string strDirFtp = string.Empty;

            //Se obtiene la dirección IP del proxy interno, si no está configurado no se genera el fichero
            CDatosParaProxy objDatos = new CDatosParaProxy();

            //Se obtiene la dirección IP interna del proxy
            if (objDatos.ObtenerDirIpProxy(cmdBD, strSistema, ref strDirFtp))
            {
                strDirFtpProxy = strDirFtp;
                bCorrecto      = true;
            }

            return(bCorrecto);
        }
Ejemplo n.º 3
0
        //WMG 11/12/2018
        //-----------------------------------------------------------------------------------------
        //!@brief Genera el fichero JSON con los datos de configuración para el proxy. Al llamar a esta función
        //        la conexión con la BD debe estar previamente establecida
        //!@param[MySqlCommand] pcmdBD Comando para ejecutar sentencias en la BD de MySql
        //!@param[string] strIdSistema Identificador del sistema
        //!@param[string] strNombreFichero Nombre del fichero JSON con ruta
        //----------------------------------------------------------------------------------------
        private bool GeneraFicheroProxy(MySqlCommand pcmdBD, string strIdSistema, string strNombreFichero)
        {
            bool         bCorrecto = false;
            MySqlCommand cmdBD     = null;

            if (!string.IsNullOrEmpty(strNombreFichero) && !string.IsNullOrEmpty(strIdSistema))
            {
                try
                {
                    if (pcmdBD != null)
                    {
                        string strDirFich = Path.GetDirectoryName(strNombreFichero);

                        //Comprobamos si el directorio existe
                        if (strDirFich.Length > 0 && !Directory.Exists(strDirFich))
                        {
                            CTraza.EscribeLog(false, "GeneraFicheroProxy", "No se ha podido generar el fichero. El directorio " + strDirFich + " no existe");
                        }
                        else
                        {
                            using (cmdBD = pcmdBD)
                            {
                                if (cmdBD.Connection.State == ConnectionState.Open)
                                {
                                    //Se obtiene la dirección IP del proxy interno, si no está configurado no se genera el fichero
                                    CDatosParaProxy objDatos = new CDatosParaProxy();

                                    StringBuilder        strOutputJSON = new StringBuilder();
                                    JavaScriptSerializer objSerializa  = new JavaScriptSerializer();
                                    //VMG 11/12/2018
                                    objDatos.ObtenerDatosCnfParaProxy(cmdBD, strIdSistema);

                                    strOutputJSON.Append(objSerializa.Serialize(objDatos));

                                    try
                                    {
                                        File.WriteAllText(strNombreFichero, strOutputJSON.ToString());
                                        bCorrecto = true;
                                    }
                                    catch (IOException exFich)
                                    {
                                        CTraza.EscribeLog(true, "GeneraFicheroProxy", string.Format("Error al guardar en disco el fichero json: sistema={0}, fichero={1}.Error:", strIdSistema, strNombreFichero) + exFich.Message.ToString());
                                    }
                                }
                                else
                                {
                                    CTraza.EscribeLog(false, "GeneraFicheroProxy", "La conexión con la BD no está abierta. BD: " + cmdBD.Connection.ConnectionString);
                                }
                            }
                        }
                    }
                    else
                    {
                        CTraza.EscribeLog(false, "GeneraFicheroProxy", "Conexión a BD no definida ");
                    }
                }
                catch (Exception ex)
                {
                    CTraza.EscribeLog(true, "GeneraFicheroProxy", string.Format("Error al generar el fichero json para el proxy: sistema={0}, fichero={1}.Error:", strIdSistema, strNombreFichero) + ex.ToString());

                    if (cmdBD != null && cmdBD.Connection.State == ConnectionState.Open)
                    {
                        cmdBD.Connection.Close();
                    }
                }
            }
            else
            {
                CTraza.EscribeLog(false, "GeneraFicheroProxy", "El nombre del fichero,identificador del sistema no se ha informado");
            }

            return(bCorrecto);
        }