public void Merge_Success()
        {
            XsdReader reader = new XsdReader();
            ConfigurationFile.Xsd = new Element();

            if (reader.ProcessSchema(FileLocation.XsdFile))
            {
                NewRelic.AgentConfiguration.MainForm.XsdPath = FileLocation.XsdFile;
            }

            XmlWalker xm = new XmlWalker();
            xm.ProcessXml(FileLocation.ConfigFile);
            NewRelic.AgentConfiguration.MainForm.ConfigPath = FileLocation.ConfigFile; ;
            ConfigMerge cm = new ConfigMerge();

            //How to test this?  It just does it  with the defaults
            //I could refactor to make it take the config and xsd so I could replace them with elements.
            Assert.IsTrue(true);
        }
        public void Build_Sucessful()
        {
            XsdReader reader = new XsdReader();
            ConfigurationFile.Xsd = new Element();

            if (reader.ProcessSchema(FileLocation.XsdFile))
            {
                NewRelic.AgentConfiguration.MainForm.XsdPath = FileLocation.XsdFile;
            }

            XmlWalker xm = new XmlWalker();
            xm.ProcessXml(FileLocation.ConfigFile);
            NewRelic.AgentConfiguration.MainForm.ConfigPath = FileLocation.ConfigFile;;
            ConfigMerge cm = new ConfigMerge();

            FlowLayoutPanel panel = new FlowLayoutPanel();
            ToolTip mainFormToolTip = new ToolTip();

            UIBuilder ui = new UIBuilder(panel, mainFormToolTip);
            ui.Build(true);

            Assert.IsTrue(panel.Controls.Count > 0, panel.Controls.Count.ToString());
        }
        /// <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 reader = new XsdReader();
            ConfigurationFile.Xsd = new Element();

            if (reader.ProcessSchema(FileLocation.XsdFile))
            {
                XsdPath = FileLocation.XsdFile;
            }
            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
                    {
                        //reader = new XsdReader();
                        reader.ProcessSchema(openFile.FileName);
                        XsdPath = openFile.FileName;
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                        MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                    }
                }
                else
                {
                    try
                    {
                        if (DialogResult.Yes == MessageBox.Show("Do you want to use the built in newrelic.xsd file?", "Use built in newrelic.xsd?", MessageBoxButtons.YesNo))
                        {
                            using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("NewRelic.AgentConfiguration.Resources.newrelic.xsd"))
                            {
                                using (var file = new FileStream(Application.StartupPath + "\\newrelic.xsd", FileMode.Create, FileAccess.Write))
                                {
                                    resource.CopyTo(file);
                                }
                            }

                            reader.ProcessSchema(Application.StartupPath + "\\newrelic.xsd");
                            XsdPath = Application.StartupPath + "\\newrelic.xsd";
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                        MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                    }
                }
            }

            if (ConfigurationFile.Xsd != null)
            {
                var openFile = new OpenFileDialog();
                openFile.Title = "Select the newrelic.config file";
                openFile.InitialDirectory = Path.GetDirectoryName(FileLocation.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 xm = new XmlWalker();
                        xm.ProcessXml(openFile.FileName);
                        ConfigPath = openFile.FileName;
                        var cm = new ConfigMerge();
                        LoadUI();
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                        MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                    }
                }
                else
                {
                    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 xm = new XmlWalker();
                            xm.ProcessXml(Application.StartupPath + "\\newrelic.config");
                            ConfigPath = Application.StartupPath + "\\newrelic.config";
                            var cm = new ConfigMerge();
                            LoadUI();
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                        MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                    }
                }
            }
            LoadingLabel.Visible = false;
        }