public void MergeFiles()
 {
     DataFile.Instance.MergedFile = DataFile.Instance.SchemaFile.Clone();
     var merger = new MergeProcessor();
     merger.PrePopulateMergedFile(DataFile.Instance.SchemaFile, DataFile.Instance.MergedFile);
     merger.Merge(DataFile.Instance.ConfigFile);
     merger.SetMergedRootObject(DataFile.Instance.MergedFile);
 }
Exemplo n.º 2
0
        private void TryExportConfig()
        {
            try
            {
                if (DialogResult.Yes ==
                    MessageBox.Show("Do you want to use the built in newrelic.config file?", "Use built in newrelic.config?",
                        MessageBoxButtons.YesNo))
                {
                    using (
                        var resource =
                            Assembly.GetExecutingAssembly()
                                .GetManifestResourceStream("NewRelic.AgentConfiguration.Resources.newrelic.config"))
                    {
                        using (
                            var file = new FileStream(Application.StartupPath + "\\newrelic.config", FileMode.Create,
                                FileAccess.Write))
                        {
                            resource.CopyTo(file);
                        }
                    }

                    var configProcessor = new ConfigProcessor();
                    configProcessor.ProcessConfig(Application.StartupPath + "\\newrelic.config");
                    ConfigPath = Application.StartupPath + "\\newrelic.config";
                    var mergeProcessor = new MergeProcessor();
                    mergeProcessor.PrePopulateMergedFile(DataFile.Instance.SchemaFile, DataFile.Instance.MergedFile);
                    mergeProcessor.Merge(DataFile.Instance.ConfigFile);
                    mergeProcessor.SetMergedRootObject(DataFile.Instance.MergedFile);
                    LoadUI();
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Click event handler for the Open button.  This handles finding and opening the XSD file and the CONFIG file.
        /// Will always prompt for CONFIG and only prompts for XSD if it cannot locate it.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OpenFile_Click(object sender, EventArgs e)
        {
            LoadingLabel.Visible = true;
            var schemaProcessor = new SchemaProcessor();
            DataFile.Instance.SchemaFile = schemaProcessor.ProcessSchema(FilePaths.Instance.SchemaFile);

            if (DataFile.Instance.SchemaFile != null)
            {
                SchemaPath = FilePaths.Instance.SchemaFile;
            }
            else
            {
                var openFile = new OpenFileDialog();
                openFile.Title = "Select the newrelic.xsd file";
                openFile.InitialDirectory = "c:\\ProgramData\\New Relic\\.Net Agent";
                openFile.FileName = "newrelic.xsd";
                openFile.Filter = "xsd files (*.xsd)|*.xsd|All files (*.*)|*.*";
                openFile.FilterIndex = 0;
                openFile.Multiselect = false;
                openFile.RestoreDirectory = true;

                if (openFile.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        DataFile.Instance.SchemaFile = schemaProcessor.ProcessSchema(openFile.FileName);
                        SchemaPath = openFile.FileName;
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                        MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                    }
                }
                else
                {
                    TryExportSchema(schemaProcessor);
                }
            }

            if (DataFile.Instance.SchemaFile != null)
            {
                var openFile = new OpenFileDialog();
                openFile.Title = "Select the newrelic.config file";
                openFile.InitialDirectory = Path.GetDirectoryName(FilePaths.Instance.ConfigFile);
                openFile.FileName = "newrelic.config";
                openFile.Filter = "config files (*.config)|*.config|All files (*.*)|*.*";
                openFile.FilterIndex = 0;
                openFile.Multiselect = false;
                openFile.RestoreDirectory = true;

                if (openFile.ShowDialog() == DialogResult.OK)
                {

                    try
                    {
                        var configProcessor = new ConfigProcessor();
                        DataFile.Instance.ConfigFile = configProcessor.ProcessConfig(openFile.FileName);
                        ConfigPath = openFile.FileName;
                        DataFile.Instance.MergedFile = DataFile.Instance.SchemaFile.Clone();
                        var mergeProcessor = new MergeProcessor();
                        mergeProcessor.PrePopulateMergedFile(DataFile.Instance.SchemaFile, DataFile.Instance.MergedFile);
                        mergeProcessor.Merge(DataFile.Instance.ConfigFile);
                        mergeProcessor.SetMergedRootObject(DataFile.Instance.MergedFile);
                        LoadUI();
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                        MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                    }
                }
                else
                {
                    TryExportConfig();
                }
            }
            LoadingLabel.Visible = false;
        }