private void llblRawEdit_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (SetEditingNotifierHost()) { RAWXmlEditor editor = new RAWXmlEditor(); string oldMarkUp = editingNotifierHost.ToXml(); editor.SelectedMarkup = oldMarkUp; if (editor.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { editingNotifierHost = NotifierHost.FromXml(editor.SelectedMarkup, null, false); if (editor.SelectedMarkup == null || editor.SelectedMarkup.Length == 0) { if (MessageBox.Show("Editing the raw config resulted in a configuration error!\r\nDo you want to accept this?", "Configuration error", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.No) { editingNotifierHost = NotifierHost.FromXml(oldMarkUp, null, false); } } } catch (Exception ex) { MessageBox.Show("An error occured while processing the config!\r\n" + ex.Message, "Edit config", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } LoadControlData(); } } }
private void LoadNotifierHostItems() { lvwAgentType.Items.Clear(); lvwAgentType.Groups.Clear(); ListViewGroup generalGroup = new ListViewGroup("General"); lvwAgentType.Groups.Add(generalGroup); ListViewItem lviDefaultNotifier = new ListViewItem("Default Notifier"); lviDefaultNotifier.SubItems.Add("Creates a default notifier with 'In Memory' agent"); lviDefaultNotifier.Group = generalGroup; lviDefaultNotifier.Tag = NotifierHost.FromXml("<notifierHost name=\"Default Notifier\" enabled=\"True\" alertLevel=\"Warning\" detailLevel=\"Detail\" attendedOptionOverride=\"OnlyAttended\"><notifierAgents><notifierAgent name=\"Memory agent\" type=\"QuickMon.Notifiers.InMemoryNotifier\" enabled=\"True\"><config><inMemory maxEntryCount=\"99999\" /></config></notifierAgent></notifierAgents></notifierHost>"); lvwAgentType.Items.Add(lviDefaultNotifier); ListViewGroup templatesGroup = new ListViewGroup("Templates"); lvwAgentType.Groups.Add(templatesGroup); foreach (QuickMonTemplate qt in QuickMonTemplate.GetAllTemplates().Where(t => t.TemplateType == TemplateType.NotifierHost)) { ListViewItem lviTemplateCollector = new ListViewItem(qt.Name); lviTemplateCollector.SubItems.Add(qt.Description); lviTemplateCollector.Group = templatesGroup; lviTemplateCollector.Tag = qt; lvwAgentType.Items.Add(lviTemplateCollector); } }
//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); } }
private void SetAlertForCollectors(NotifierHost editingNotifierHost, TreeNode parent = null) { if (parent == null) { parent = tvwCollectors.Nodes[0]; } foreach (TreeNode child in parent.Nodes) { if (child.Checked && child.Tag is CollectorHost) { CollectorHost ch = (CollectorHost)child.Tag; editingNotifierHost.AlertForCollectors.Add(ch.Name); } SetAlertForCollectors(editingNotifierHost, child); } }
private void cboClass_SelectedIndexChanged(object sender, EventArgs e) { //if (txtConfig.Text.Length == 0) if (cboType.SelectedIndex == 2 || cboType.SelectedIndex == 4) { RegisteredAgent ra = (from r in RegisteredAgentCache.Agents where r.ClassName.EndsWith(cboClass.Text) select r).FirstOrDefault(); if (ra != null) { IAgent a; if (ra.IsCollector) { a = CollectorHost.CreateCollectorFromClassName(ra.ClassName.Replace("QuickMon.Collectors.", "")); } else { a = NotifierHost.CreateNotifierFromClassName(ra.ClassName.Replace("QuickMon.Notifiers.", "")); } if (a != null) { string agentConfig = a.AgentConfig.GetDefaultOrEmptyXml(); if (cboType.SelectedIndex == 2) { txtConfig.Text = Properties.Resources.BlankTemplateCollectorAgent.Replace("{0}", agentConfig); } else if (cboType.SelectedIndex == 4) { txtConfig.Text = Properties.Resources.BlankTemplateNotifierAgent.Replace("{0}", agentConfig); } //txtConfig.Text = XmlFormattingUtils.NormalizeXML(txtConfig.Text); try { txtConfig.Text = txtConfig.Text.BeautifyXML(); // XmlFormattingUtils.NormalizeXML(txtConfig.Text); } catch (Exception ex) { MessageBox.Show(string.Format("Error formatting xml\r\n{0}", ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } } IsSaveEnabled(); }
private void EditNotifierHost_Load(object sender, EventArgs e) { try { if (SelectedConfig != null && SelectedConfig.Length > 0 && SelectedConfig.StartsWith("<notifierHost", StringComparison.CurrentCultureIgnoreCase)) { editingNotifierHost = NotifierHost.FromXml(SelectedConfig, null, false); } else { editingNotifierHost = new NotifierHost(); } } catch (Exception ex) { MessageBox.Show("Loading error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void cboClass_SelectedIndexChanged(object sender, EventArgs e) { //if (txtConfig.Text.Length == 0) if (cboType.SelectedIndex == 2 || cboType.SelectedIndex == 4) { RegisteredAgent ra = (from r in RegisteredAgentCache.Agents where r.ClassName.EndsWith(cboClass.Text) select r).FirstOrDefault(); if (ra != null) { IAgent a; if (ra.IsCollector) { a = CollectorHost.CreateCollectorFromClassName(ra.ClassName.Replace("QuickMon.Collectors.", "")); } else { a = NotifierHost.CreateNotifierFromClassName(ra.ClassName.Replace("QuickMon.Notifiers.", "")); } if (a != null) { string agentConfig = a.AgentConfig.GetDefaultOrEmptyXml(); if (cboType.SelectedIndex == 2) { txtConfig.Text = Properties.Resources.BlankTemplateCollectorAgent.Replace("{0}", agentConfig); } else if (cboType.SelectedIndex == 4) { txtConfig.Text = Properties.Resources.BlankTemplateNotifierAgent.Replace("{0}", agentConfig); } txtConfig.Text = XmlFormattingUtils.NormalizeXML(txtConfig.Text); } } } IsSaveEnabled(); }
public override bool EditAgent() { INotifier agent = NotifierHost.CreateNotifierFromClassName(AgentType); if (agent != null) { agent.Name = AgentName; agent.Enabled = AgentEnabled; EditNotifierAgentEntry editNotifierAgentEntry = new EditNotifierAgentEntry(); agent.InitialConfiguration = SelectedAgentConfig; agent.AgentConfig.FromXml(SelectedAgentConfig); editNotifierAgentEntry.SelectedEntry = agent; editNotifierAgentEntry.DetailEditor = DetailEditor; if (editNotifierAgentEntry.ShowDialog() == System.Windows.Forms.DialogResult.OK) { agent = editNotifierAgentEntry.SelectedEntry; AgentName = agent.Name; AgentEnabled = agent.Enabled; SelectedAgentConfig = agent.AgentConfig.ToXml(); return(true); } } return(false); }
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(); } }
private void cmdOK_Click(object sender, EventArgs e) { if (lvwAgentType.SelectedItems.Count == 1) { RegisteredAgent ra = null; string configToUse = ""; if (lvwAgentType.SelectedItems[0].Tag is RegisteredAgent) { ra = (RegisteredAgent)lvwAgentType.SelectedItems[0].Tag; TemplateUsed = false; } else if (lvwAgentType.SelectedItems[0].Tag is QuickMonTemplate) { QuickMonTemplate template = (QuickMonTemplate)lvwAgentType.SelectedItems[0].Tag; ra = RegisteredAgentCache.GetRegisteredAgentByClassName(template.ForClass, selectingCollectors); configToUse = template.Config; TemplateUsed = true; } 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.Replace("QuickMon.Collectors.", "").Replace("QuickMon.Notifiers.", ""); 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() == System.Windows.Forms.DialogResult.OK) { configToUse = editor.SelectedMarkup; } } try { if (selectingCollectors && configToUse.StartsWith("<collectorAgent")) { SelectedAgent = CollectorHost.GetCollectorAgentFromString(configToUse); } else if (!selectingCollectors && configToUse.StartsWith("<notifierAgent")) { SelectedAgent = NotifierHost.GetNotifierAgentFromString(configToUse); } else { SelectedAgent.AgentConfig.FromXml(configToUse); } DialogResult = System.Windows.Forms.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); } } } } }