Example #1
0
 private void LoadAgents()
 {
     try
     {
         lvwAgents.Items.Clear();
         lvwAgents.Items.Add("Loading...");
         Application.DoEvents();
         Cursor.Current = Cursors.WaitCursor;
         if (File.Exists(txtMonitorPack.Text))
         {
             CurrentMonitorPack = new MonitorPack();
             CurrentMonitorPack.Load(txtMonitorPack.Text);
             Cursor.Current = Cursors.WaitCursor;
             LoadAgentsForMonitorPack();
         }
         else if (CurrentMonitorPack != null)
         {
             LoadAgentsForMonitorPack();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     Cursor.Current = Cursors.Default;
 }
Example #2
0
        private void toolStripoad_Click(object sender, EventArgs e)
        {
            try
            {
                string startUpPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify), "Hen IT\\QuickMon");
                if (!System.IO.Directory.Exists(startUpPath))
                {
                    System.IO.Directory.CreateDirectory(startUpPath);
                }
                openFileDialogOpen.InitialDirectory = startUpPath;
                openFileDialogOpen.FileName         = filePathtoolStripStatusLabel.Text;

                if (openFileDialogOpen.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    monitorPack = new MonitorPack();
                    monitorPack.Load(openFileDialogOpen.FileName);
                    filePathtoolStripStatusLabel.Text = openFileDialogOpen.FileName;
                    RefreshMonitorPack();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Open", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #3
0
 public DialogResult ShowNotifierCollectors(MonitorPack monitorPack)
 {
     if (SelectedCollectors == null)
     {
         SelectedCollectors = new List <string>();
     }
     this.monitorPack = monitorPack;
     return(ShowDialog());
 }
Example #4
0
 public DialogResult ShowDialog(MonitorPack monitorPack)
 {
     this.monitorPack      = monitorPack;
     editingCollectorEntry = CollectorEntry.FromConfig(SelectedEntry.ToConfig());
     if (SelectedEntry.Collector != null)
     {
         monitorPack.ApplyCollectorConfig(editingCollectorEntry);
     }
     return(ShowDialog());
 }
Example #5
0
        private void recentToolStripButton_Click(object sender, EventArgs e)
        {
            RecentMonitorPacks recentMonitorPacks = new RecentMonitorPacks();

            if (recentMonitorPacks.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                monitorPack = new MonitorPack();
                monitorPack.Load(recentMonitorPacks.SelectedPack);
                filePathtoolStripStatusLabel.Text = recentMonitorPacks.SelectedPack;
                RefreshMonitorPack();
            }
        }
Example #6
0
        //private bool loading = false;

        public DialogResult ShowDialog(NotifierHost nh, MonitorPack hostingMonitorPack = null)
        {
            if (nh != null)
            {
                SelectedConfig     = nh.ToXml();
                HostingMonitorPack = hostingMonitorPack;
                return(ShowDialog());
            }
            else
            {
                return(System.Windows.Forms.DialogResult.Cancel);
            }
        }
Example #7
0
        private void toolStripButtonNew_Click(object sender, EventArgs e)
        {
            string oldAgentsAssemblyPath = "";

            if (monitorPack != null && monitorPack.AgentsAssemblyPath.Length > 0)
            {
                oldAgentsAssemblyPath = monitorPack.AgentsAssemblyPath;
            }
            monitorPack = new MonitorPack()
            {
                AgentsAssemblyPath = oldAgentsAssemblyPath
            };
            RefreshMonitorPack();
        }
Example #8
0
 private void exportToolStripButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (exportFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             System.IO.File.Copy(MonitorPack.GetQuickMonUserDataTemplatesFile(), exportFileDialog.FileName, true);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Export", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
Example #9
0
 private void LoadAgents()
 {
     try
     {
         lvwAgents.BeginUpdate();
         if (File.Exists(txtMonitorPack.Text))
         {
             MonitorPack monitorPack = new MonitorPack();
             monitorPack.Load(txtMonitorPack.Text);
             lvwAgents.Items.Clear();
             if (IsCollector)
             {
                 foreach (var item in (from c in monitorPack.Collectors
                                       where c.CollectorRegistrationName == AgentType
                                       orderby c.Name
                                       select c))
                 {
                     ListViewItem lvi = new ListViewItem(item.Name);
                     lvi.SubItems.Add(item.Configuration.Replace("\r\n", "->"));
                     lvi.Tag = item.Configuration;
                     lvwAgents.Items.Add(lvi);
                 }
             }
             else
             {
                 foreach (var item in (from c in monitorPack.Notifiers
                                       where c.NotifierRegistrationName == AgentType
                                       orderby c.Name
                                       select c))
                 {
                     ListViewItem lvi = new ListViewItem(item.Name);
                     lvi.SubItems.Add(item.Configuration.Replace("\r\n", "->"));
                     lvi.Tag = item.Configuration;
                     lvwAgents.Items.Add(lvi);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         lvwAgents.EndUpdate();
     }
 }
Example #10
0
        private void exportSelectedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                TreeNode currentNode = tvwMonPack.SelectedNode;
                if (currentNode.ImageIndex == collectorImgIndex || currentNode.ImageIndex == folderImgIndex)
                {
                    List <CollectorEntry> list = new List <CollectorEntry>();
                    list.Add(((CollectorEntry)currentNode.Tag).Clone());
                    list[0].ParentCollectorId = "";
                    list.AddRange(monitorPack.GetAllChildCollectors((CollectorEntry)currentNode.Tag));

                    MonitorPack exportPack = new MonitorPack();
                    exportPack.Collectors.AddRange(list);

                    string startUpPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify), "Hen IT\\QuickMon");
                    if (!System.IO.Directory.Exists(startUpPath))
                    {
                        System.IO.Directory.CreateDirectory(startUpPath);
                    }
                    saveFileDialogSave.InitialDirectory = startUpPath;
                    saveFileDialogSave.FileName         = list[0].Name + " - Exported";
                    if (saveFileDialogSave.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        exportPack.Name    = list[0].Name + " - Export";
                        exportPack.Enabled = true;
                        exportPack.DefaultViewerNotifier = null;
                        exportPack.Save(saveFileDialogSave.FileName);

                        if (MessageBox.Show("Do you want to load this exported monitor pack now?", "Export", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                        {
                            monitorPack = new MonitorPack();
                            monitorPack.Load(saveFileDialogSave.FileName);
                            filePathtoolStripStatusLabel.Text = saveFileDialogSave.FileName;
                            RefreshMonitorPack();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Export", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #11
0
 private void importToolStripButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (MessageBox.Show("Are you sure you want to import and reset all existing templates?", "Import", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
         {
             if (importFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
                 System.IO.File.Copy(importFileDialog.FileName, MonitorPack.GetQuickMonUserDataTemplatesFile(), true);
                 LoadTemplates();
                 CreateNewTemplate();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Export", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
Example #12
0
 private void linkLabelQueryTips_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     try
     {
         string outputPath = MonitorPack.GetQuickMonUserDataDirectory();// System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify);
         //outputPath = System.IO.Path.Combine(outputPath, "Hen IT\\QuickMon");
         if (!System.IO.Directory.Exists(outputPath))
         {
             System.IO.Directory.CreateDirectory(outputPath);
         }
         outputPath = System.IO.Path.Combine(outputPath, "SQLQueryTips.htm");
         if (System.IO.File.Exists(outputPath))
         {
             System.IO.File.Delete(outputPath);
         }
         System.IO.File.WriteAllText(outputPath, Properties.Resources.SQLQueryTips, Encoding.UTF8);
         System.Diagnostics.Process.Start(outputPath);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Query Tips", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #13
0
        public DialogResult ShowDialog(MonitorPack monitorPack)
        {
            if (SelectedEntry == null)
            {
                return(System.Windows.Forms.DialogResult.Cancel);
            }
            else
            {
                this.monitorPack     = monitorPack;
                editingNotifierEntry = NotifierEntry.FromConfig(SelectedEntry.ToConfig());

                try
                {
                    //Create Notifier instance but do not apply Config Variables!
                    editingNotifierEntry.CreateAndConfigureEntry(editingNotifierEntry.NotifierRegistrationName, "", false);
                    return(ShowDialog());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Loading", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(System.Windows.Forms.DialogResult.Cancel);
                }
            }
        }
Example #14
0
 public DialogResult ShowDialog(MonitorPack monitorPack)
 {
     this.monitorPack = monitorPack;
     return(ShowDialog());
 }
Example #15
0
 public DialogResult ShowMonitorPack(MonitorPack monitorPack)
 {
     this.monitorPack = monitorPack;
     filePathtoolStripStatusLabel.Text = monitorPack.MonitorPackPath;
     return(this.ShowDialog());
 }
        private void LoadRecentMonitorPackList()
        {
            int      widest = 400;
            Graphics g      = this.CreateGraphics();

            lvwMonitorPacks.Items.Clear();
            lvwMonitorPacks.Groups.Clear();
            List <MonitorPack.NameAndTypeSummary> recentMPs = new List <MonitorPack.NameAndTypeSummary>();
            List <ListViewGroup> groups  = new List <ListViewGroup>();
            ListViewGroup        naGroup = new ListViewGroup("<None>");

            groups.Add(naGroup);
            lvwMonitorPacks.Groups.Add(naGroup);

            foreach (string filePath in (from string s in Properties.Settings.Default.RecentQMConfigFiles
                                         orderby s
                                         select s))
            {
                MonitorPack.NameAndTypeSummary summaryInfo = MonitorPack.GetMonitorPackTypeName(filePath);
                recentMPs.Add(summaryInfo);
                //if (summaryInfo.Exists)
                //{
                //    if (summaryInfo.TypeName.Trim().Length > 0)
                //    {
                //        ListViewGroup currentGroup = (from ListViewGroup grp in groups
                //                                      where grp.Header.ToLower() == summaryInfo.TypeName.ToLower()
                //                                      select grp).FirstOrDefault();
                //        if (currentGroup == null)
                //        {
                //            currentGroup = new ListViewGroup(summaryInfo.TypeName);
                //            groups.Add(currentGroup);
                //            lvwMonitorPacks.Groups.Add(currentGroup);
                //        }
                //    }
                //}
            }
            foreach (MonitorPack.NameAndTypeSummary summaryInfo in (from MonitorPack.NameAndTypeSummary r in recentMPs
                                                                    orderby r.TypeName, r.Path
                                                                    select r))
            {
                ListViewItem lvi = new ListViewItem(summaryInfo.Path);
                if (!summaryInfo.Exists || summaryInfo.TypeName.Trim().Length == 0)
                {
                    lvi.Group = naGroup;
                }
                else
                {
                    ListViewGroup currentGroup = (from ListViewGroup grp in groups
                                                  where grp.Header.ToLower() == summaryInfo.TypeName.ToLower()
                                                  select grp).FirstOrDefault();
                    if (currentGroup == null)
                    {
                        currentGroup = new ListViewGroup(summaryInfo.TypeName);
                        groups.Add(currentGroup);
                        lvwMonitorPacks.Groups.Add(currentGroup);
                    }
                    lvi.Group = currentGroup;
                }
                lvwMonitorPacks.Items.Add(lvi);
                SizeF sz = g.MeasureString(summaryInfo.Path, lvwMonitorPacks.Font);
                if (sz.Width > widest)
                {
                    widest = (int)sz.Width;
                }
            }

            /*
             * foreach (string filePath in (from string s in Properties.Settings.Default.RecentQMConfigFiles
             *                           orderby s
             *                           select s))
             * {
             *
             *  MonitorPack.NameAndTypeSummary summaryInfo = MonitorPack.GetMonitorPackTypeName(filePath);
             *  recentMPs.Add(summaryInfo);
             *
             *  ListViewItem lvi = new ListViewItem(filePath);
             *  if (!summaryInfo.Exists)
             *  {
             *      lvi.Text = "!" + lvi.Text;
             *      lvi.Group = naGroup;
             *  }
             *  else
             *  {
             *      if (summaryInfo.TypeName.Trim().Length == 0)
             *      {
             *          lvi.Group = naGroup;
             *      }
             *      else
             *      {
             *          ListViewGroup currentGroup = (from ListViewGroup grp in groups
             *                                        where grp.Header.ToLower() == summaryInfo.TypeName.ToLower()
             *                                        select grp).FirstOrDefault();
             *          if (currentGroup == null)
             *          {
             *              currentGroup = new ListViewGroup(summaryInfo.TypeName);
             *              groups.Add(currentGroup);
             *              lvwMonitorPacks.Groups.Add(currentGroup);
             *          }
             *          lvi.Group = currentGroup;
             *      }
             *  }
             *
             *  lvwMonitorPacks.Items.Add(lvi);
             *  SizeF sz = g.MeasureString(filePath, lvwMonitorPacks.Font);
             *  if (sz.Width > widest)
             *      widest = (int)sz.Width;
             * }
             */


            if (widest + 50 < Screen.PrimaryScreen.WorkingArea.Width)
            {
                Width = widest + 50;
            }
        }
Example #17
0
        private void RefreshMonitorPack()
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                if (monitorPack == null)
                {
                    monitorPack = new MonitorPack();
                }
                txtName.Text                    = monitorPack.Name;
                chkEnabled.Checked              = monitorPack.Enabled;
                txtAgentsRegistrationFile.Text  = monitorPack.AgentsAssemblyPath;
                chkRunCorrectiveScripts.Checked = monitorPack.RunCorrectiveScripts;
                TreeNode root = tvwMonPack.Nodes[0];
                tvwMonPack.BeginUpdate();
                root.Expand();

                TreeNode collectorRootNode = (from TreeNode n in root.Nodes
                                              where n.Name == "Collectors"
                                              select n).First();
                collectorRootNode.Nodes.Clear();
                foreach (CollectorEntry ce in monitorPack.GetRootCollectors()) //(from c in monitorPack.Collectors
                //where c.ParentCollectorId.Length == 0
                //select c)
                {
                    LoadCollectorEntry(ce, collectorRootNode);
                }
                TreeNode notifierRootNode = (from TreeNode n in root.Nodes
                                             where n.Name == "Notifiers"
                                             select n).First();
                notifierRootNode.Nodes.Clear();
                cboDefaultViewerNotifier.Items.Clear();
                foreach (NotifierEntry ne in monitorPack.Notifiers)
                {
                    LoadNotifierEntry(ne, notifierRootNode);
                    if (ne.Notifier != null && ne.Notifier.HasViewer)
                    {
                        cboDefaultViewerNotifier.Items.Add(ne.Name);
                    }
                }
                if (monitorPack.DefaultViewerNotifier != null)
                {
                    cboDefaultViewerNotifier.SelectedItem = monitorPack.DefaultViewerNotifier.Name;
                }

                collectorRootNode.Expand();
                notifierRootNode.Expand();
                root.EnsureVisible();
                tvwMonPack.SelectedNode = root;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                tvwMonPack.EndUpdate();
                Cursor.Current = Cursors.Default;
            }
            EnableContextMenus();
            EnableOKButton();
        }
Example #18
0
        public DialogResult ShowDialog(MonitorPack monitorPack)
        {
            if (KnownRemoteHosts == null)
            {
                KnownRemoteHosts = new List <string>();
            }
            if (SelectedEntry == null)
            {
                return(System.Windows.Forms.DialogResult.Cancel);
            }
            else
            {
                this.monitorPack    = monitorPack;
                currentEditingEntry = CollectorEntry.FromConfig(SelectedEntry.ToConfig());
                try
                {
                    //Create Collector instance but do not apply Config Variables!
                    currentEditingEntry.CreateAndConfigureEntry(currentEditingEntry.CollectorRegistrationName, "", false, false);

                    ApplyConfigToControls();

                    txtName.Text             = currentEditingEntry.Name;
                    chkEnabled.Checked       = currentEditingEntry.Enabled;
                    chkExpandOnStart.Checked = currentEditingEntry.ExpandOnStart;
                    lblId.Text                    = currentEditingEntry.UniqueId;
                    llblCollectorType.Text        = currentEditingEntry.CollectorRegistrationDisplayName;
                    chkRemoteAgentEnabled.Checked = currentEditingEntry.EnableRemoteExecute;
                    chkForceRemoteExcuteOnChildCollectors.Checked = currentEditingEntry.ForceRemoteExcuteOnChildCollectors;
                    txtRemoteAgentServer.Text = currentEditingEntry.RemoteAgentHostAddress;
                    remoteportNumericUpDown.SaveValueSet(currentEditingEntry.RemoteAgentHostPort);
                    chkBlockParentRHOverride.Checked = currentEditingEntry.BlockParentOverrideRemoteAgentHostSettings;
                    chkRunLocalOnRemoteHostConnectionFailure.Checked = currentEditingEntry.RunLocalOnRemoteHostConnectionFailure;

                    try
                    {
                        chkEnablePollingOverride.Checked = currentEditingEntry.EnabledPollingOverride;
                        onlyAllowUpdateOncePerXSecNumericUpDown.SaveValueSet(currentEditingEntry.OnlyAllowUpdateOncePerXSec);
                        chkEnablePollingFrequencySliding.Checked = currentEditingEntry.EnablePollFrequencySliding;
                        pollSlideFrequencyAfterThirdRepeatSecNumericUpDown.SaveValueSet(currentEditingEntry.PollSlideFrequencyAfterThirdRepeatSec);
                        pollSlideFrequencyAfterSecondRepeatSecNumericUpDown.SaveValueSet(currentEditingEntry.PollSlideFrequencyAfterSecondRepeatSec);
                        pollSlideFrequencyAfterFirstRepeatSecNumericUpDown.SaveValueSet(currentEditingEntry.PollSlideFrequencyAfterFirstRepeatSec);
                    }
                    catch { }
                    PollingOverrideControlsEnable();

                    numericUpDownRepeatAlertInXMin.SaveValueSet(currentEditingEntry.RepeatAlertInXMin);
                    numericUpDownRepeatAlertInXPolls.SaveValueSet(currentEditingEntry.RepeatAlertInXPolls);
                    AlertOnceInXMinNumericUpDown.SaveValueSet(currentEditingEntry.AlertOnceInXMin);
                    AlertOnceInXPollsNumericUpDown.SaveValueSet(currentEditingEntry.AlertOnceInXPolls);
                    delayAlertSecNumericUpDown.SaveValueSet(currentEditingEntry.DelayErrWarnAlertForXSec);
                    delayAlertPollsNumericUpDown.SaveValueSet(currentEditingEntry.DelayErrWarnAlertForXPolls);

                    chkCollectOnParentWarning.Checked = currentEditingEntry.CollectOnParentWarning;

                    chkAlertsPaused.Checked             = currentEditingEntry.AlertsPaused;
                    chkCorrectiveScriptDisabled.Checked = currentEditingEntry.CorrectiveScriptDisabled;
                    txtCorrectiveScriptOnWarning.Text   = currentEditingEntry.CorrectiveScriptOnWarningPath;
                    txtCorrectiveScriptOnError.Text     = currentEditingEntry.CorrectiveScriptOnErrorPath;
                    txtRestorationScript.Text           = currentEditingEntry.RestorationScriptPath;
                    chkOnlyRunCorrectiveScriptsOnStateChange.Checked = currentEditingEntry.CorrectiveScriptsOnlyOnStateChange;
                    linkLabelServiceWindows.Text = currentEditingEntry.ServiceWindows.ToString();

                    LoadParentCollectorList();
                    CheckOkEnabled();
                    return(ShowDialog());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Loading", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(System.Windows.Forms.DialogResult.Cancel);
                }
            }
        }
Example #19
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (lvwAgentType.SelectedItems.Count == 1)
            {
                string configToUse = "";
                if (selectingMonitorPacks)
                {
                    #region Monitor pack
                    if (lvwAgentType.SelectedItems[0].Tag is string)
                    {
                        configToUse = lvwAgentType.SelectedItems[0].Tag.ToString();
                    }
                    else if (lvwAgentType.SelectedItems[0].Tag is QuickMonTemplate)
                    {
                        QuickMonTemplate selectedTemplate = (QuickMonTemplate)(lvwAgentType.SelectedItems[0].Tag);
                        configToUse = selectedTemplate.Config;
                    }
                    if (chkShowCustomConfig.Checked)
                    {
                        RAWXmlEditor editor = new RAWXmlEditor();
                        editor.SelectedMarkup = configToUse;
                        if (editor.ShowDialog() == DialogResult.OK)
                        {
                            configToUse = editor.SelectedMarkup;
                        }
                    }
                    configToUse = FormatTemplateVariables(configToUse);
                    if (configToUse.Length == 0)
                    {
                        return;
                    }

                    MonitorPack mp = new MonitorPack();
                    mp.LoadXml(configToUse);
                    SelectedMonitorPack = mp;
                    #endregion
                }
                else if (selectingCollectorHosts)
                {
                    #region Collector hosts
                    if (lvwAgentType.SelectedItems[0].Tag is CollectorHost)
                    {
                        CollectorHost newCH = (CollectorHost)lvwAgentType.SelectedItems[0].Tag;
                        newCH.UniqueId = "";
                        configToUse    = newCH.ToXml();
                    }
                    else if (lvwAgentType.SelectedItems[0].Tag is QuickMonTemplate)
                    {
                        QuickMonTemplate selectedTemplate = (QuickMonTemplate)(lvwAgentType.SelectedItems[0].Tag);
                        configToUse = selectedTemplate.Config;
                    }
                    if (chkShowCustomConfig.Checked)
                    {
                        RAWXmlEditor editor = new RAWXmlEditor();
                        editor.SelectedMarkup = configToUse;
                        if (editor.ShowDialog() == DialogResult.OK)
                        {
                            configToUse = editor.SelectedMarkup;
                        }
                    }

                    configToUse = FormatTemplateVariables(configToUse);
                    if (configToUse.Length == 0)
                    {
                        return;
                    }

                    CollectorHost cls = CollectorHost.FromXml(configToUse);
                    if (cls != null)
                    {
                        SelectedCollectorHost = cls;
                    }
                    else
                    {
                        MessageBox.Show("The configuration for this template is invalid! Please correct and try again.", "Template", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    #endregion
                }
                else if (selectingCollectorAgents || selectingNotifierAgents)
                {
                    #region Collector agents
                    RegisteredAgent ra = null;
                    if (lvwAgentType.SelectedItems[0].Tag is RegisteredAgent)
                    {
                        ra = (RegisteredAgent)lvwAgentType.SelectedItems[0].Tag;
                    }
                    else if (lvwAgentType.SelectedItems[0].Tag is QuickMonTemplate)
                    {
                        QuickMonTemplate template = (QuickMonTemplate)lvwAgentType.SelectedItems[0].Tag;
                        ra          = RegisteredAgentCache.GetRegisteredAgentByClassName(template.ForClass, selectingCollectorAgents);
                        configToUse = template.Config;
                    }
                    if (ra != null)
                    {
                        if (System.IO.File.Exists(ra.AssemblyPath))
                        {
                            Assembly collectorEntryAssembly = Assembly.LoadFile(ra.AssemblyPath);
                            SelectedAgent = (IAgent)collectorEntryAssembly.CreateInstance(ra.ClassName);
                            SelectedAgent.AgentClassName        = ra.ClassName;
                            SelectedAgent.AgentClassDisplayName = ra.DisplayName;
                            if (configToUse.Length == 0)
                            {
                                configToUse = SelectedAgent.AgentConfig.GetDefaultOrEmptyXml();
                            }
                            if (chkShowCustomConfig.Checked)
                            {
                                RAWXmlEditor editor = new RAWXmlEditor();
                                editor.SelectedMarkup = configToUse;
                                if (editor.ShowDialog() == DialogResult.OK)
                                {
                                    configToUse = editor.SelectedMarkup;
                                }
                            }
                            try
                            {
                                if ((selectingCollectorAgents && configToUse.StartsWith("<collectorAgent")) || (selectingNotifierAgents && configToUse.StartsWith("<notifierAgent")))
                                {
                                    System.Xml.XmlDocument collectorAgentDoc = new System.Xml.XmlDocument();
                                    collectorAgentDoc.LoadXml(configToUse);
                                    System.Xml.XmlNode configNode = collectorAgentDoc.DocumentElement.SelectSingleNode("config");
                                    if (configNode != null)
                                    {
                                        configToUse = configNode.OuterXml;
                                    }
                                }

                                configToUse = FormatTemplateVariables(configToUse);
                                if (configToUse.Length == 0)
                                {
                                    return;
                                }

                                SelectedAgent.AgentConfig.FromXml(configToUse);
                                DialogResult = DialogResult.OK;
                                Close();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("An error occured while processing the config!\r\n" + ex.Message, "Edit config", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                    }
                    #endregion
                }
                else if (selectingNotifierHosts)
                {
                    #region Notifier hosts
                    if (lvwAgentType.SelectedItems[0].Tag is NotifierHost)
                    {
                        configToUse = ((NotifierHost)lvwAgentType.SelectedItems[0].Tag).ToXml();
                    }
                    else if (lvwAgentType.SelectedItems[0].Tag is QuickMonTemplate)
                    {
                        QuickMonTemplate selectedTemplate = (QuickMonTemplate)(lvwAgentType.SelectedItems[0].Tag);
                        configToUse = selectedTemplate.Config;
                    }

                    if (chkShowCustomConfig.Checked)
                    {
                        RAWXmlEditor editor = new RAWXmlEditor();
                        editor.SelectedMarkup = configToUse;
                        if (editor.ShowDialog() == DialogResult.OK)
                        {
                            configToUse = editor.SelectedMarkup;
                        }
                    }

                    configToUse = FormatTemplateVariables(configToUse);
                    if (configToUse.Length == 0)
                    {
                        return;
                    }

                    NotifierHost cls = NotifierHost.FromXml(configToUse);
                    if (cls != null)
                    {
                        SelectedNotifierHost = cls;
                    }
                    else
                    {
                        MessageBox.Show("The configuration for this template is invalid! Please correct and try again.", "Template", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    #endregion
                }
                EditAfterCreation = chkEditAfterCreate.Checked;
                DialogResult      = DialogResult.OK;
                Close();
            }
        }