/// <summary>
        /// Obtiene un String con el contenido del archivo xml de configuracion.
        /// Si este metodo es accedido desde el servicio web extrae la informacion de estado del archivo:
        /// Encrypt
        /// TTL
        /// ForceUpdate
        /// CurrentVersion
        /// BaseConfigFile
        /// Cacheable
        /// </summary>
        /// <param name="provider">Proveedor de configuración.</param>
        /// <Author>Marcelo Oviedo</Author>
        static ConfigurationFile SetConfigurationFile(ConfigProviderElement provider)
        {
            ConfigurationFile wConfigurationFile = new ConfigurationFile();


            string wFullFileName;

            if (System.IO.File.Exists(provider.BaseConfigFile))
            {
                wFullFileName = provider.BaseConfigFile;
            }
            else
            {
                //Application.StartupPath
                wFullFileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), provider.BaseConfigFile);
            }

            if (!System.IO.File.Exists(wFullFileName))
            {
                TechnicalException te = new TechnicalException(string.Concat("El archivo de artchivo de configuración ", provider.BaseConfigFile, " no existe. ", Environment.NewLine, "Revisar en el archivo .config de la aplicacion la configuración del proveedor [", provider.Name, "]"));
                te.ErrorId = "8011";
                Fwk.Exceptions.ExceptionHelper.SetTechnicalException(te, typeof(LocalFileConfigurationManager));
                throw te;
            }

            wConfigurationFile = ConfigurationFile.GetFromXml <ConfigurationFile>(Fwk.HelperFunctions.FileFunctions.OpenTextFile(wFullFileName));



            wConfigurationFile.FileName = wFullFileName;

            if (wConfigurationFile != null)
            {
                wConfigurationFile.TTL            = wConfigurationFile.TTL;
                wConfigurationFile.Encrypted      = wConfigurationFile.Encrypted;
                wConfigurationFile.ForceUpdate    = wConfigurationFile.ForceUpdate;
                wConfigurationFile.CurrentVersion = wConfigurationFile.CurrentVersion;
                wConfigurationFile.ProviderName   = provider.Name;
            }

            return(wConfigurationFile);
        }
Exemple #2
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            SqlConnection     wConn       = null;
            string            wXmlText    = string.Empty;
            ConfigurationFile wConfigFile = null;

            System.IO.FileInfo wFInfo = null;

            try
            {
                progressBar1.Value = 0;

                wConn = CreateConnection();
                if (wConn == null || !XmlValidationRequired())
                {
                    return;
                }

                progressBar1.Increment(2);

                //Obtengo los datos del xml
                wFInfo      = new System.IO.FileInfo(txtXml.Text);
                wXmlText    = Fwk.HelperFunctions.FileFunctions.OpenTextFile(txtXml.Text);
                wConfigFile = new ConfigurationFile();
                wConfigFile = ConfigurationFile.GetFromXml <ConfigurationFile>(wXmlText);
                if (wConfigFile.Groups == null)
                {
                    MessageBox.Show("No hay datos para migrar", "Exportar", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                progressBar1.Increment(48);


                progressBar1.Increment(40);
                ConfigProviderElement tempProvider = new ConfigProviderElement();
                tempProvider.BaseConfigFile               = txtConfigFileName.Text;
                tempProvider.ConfigProviderType           = ConfigProviderType.sqldatabase;
                tempProvider.SourceInfo                   = wConn.ConnectionString;
                tempProvider.SourceInfoIsConnectionString = true;


                Fwk.Configuration.ConfigurationManager_CRUD.Import(wConfigFile, tempProvider);


                progressBar1.Increment(10);

                MessageBox.Show("Exportación terminada exitosamente", "Exportar", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (wConn != null && wConn.State == ConnectionState.Open)
                {
                    wConn.Close();
                }
            }
        }