private void ApplyConfigToControls() { cmdConfigure.Enabled = editingNotifierEntry == null; cboAttendedOptionOverride.SelectedIndex = 0; if (editingNotifierEntry != null) { txtName.Text = editingNotifierEntry.Name; chkEnabled.Checked = editingNotifierEntry.Enabled; RegisteredAgent ar = RegisteredAgentCache.GetRegisteredAgentByClassName(editingNotifierEntry.NotifierRegistrationName, false); if (ar != null) { llblNotifierType.Text = ar.DisplayName; } cboAlertLevel.SelectedIndex = (int)editingNotifierEntry.AlertLevel; cboDetailLevel.SelectedIndex = (int)editingNotifierEntry.DetailLevel; if (editingNotifierEntry.Notifier != null && editingNotifierEntry.Notifier.AgentConfig != null) { INotifierConfig config = (INotifierConfig)editingNotifierEntry.Notifier.AgentConfig; lblConfigSummary.Text = config.ConfigSummary; if (editingNotifierEntry.Notifier.AttendedRunOption != AttendedOption.AttendedAndUnAttended) { editingNotifierEntry.AttendedOptionOverride = editingNotifierEntry.Notifier.AttendedRunOption; cboAttendedOptionOverride.Enabled = false; } else { cboAttendedOptionOverride.Enabled = true; } } cboAttendedOptionOverride.SelectedIndex = (int)editingNotifierEntry.AttendedOptionOverride; SetAlertForCollectors(); linkLabelServiceWindows.Text = editingNotifierEntry.ServiceWindows.ToString(); CheckOkEnable(); } }
private void configureEditButton1_ImportConfigurationClicked(object sender, EventArgs e) { ImportCollectorConfig importCollectorConfig = new ImportCollectorConfig(); importCollectorConfig.IsCollector = true; importCollectorConfig.MonitorPackPath = monitorPack.MonitorPackPath; importCollectorConfig.AgentType = ((RegisteredAgent)cboCollector.SelectedItem).Name; if (importCollectorConfig.ShowDialog() == System.Windows.Forms.DialogResult.OK) { editingCollectorEntry.InitialConfiguration = importCollectorConfig.SelectedConfig; RegisteredAgent ar = (RegisteredAgent)cboCollector.SelectedItem; editingCollectorEntry.Collector = CollectorEntry.CreateCollectorEntry(ar); editingCollectorEntry.Collector.SetConfigurationFromXmlString(importCollectorConfig.SelectedConfig); editingCollectorEntry.CollectorRegistrationName = ar.Name; } }
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 cmdConfig_Click(object sender, EventArgs e) { if (cboCollector.SelectedItem != null) { try { RegisteredAgent ar = (RegisteredAgent)cboCollector.SelectedItem; ICollector tmpcollector; if (editingCollectorEntry == null) { editingCollectorEntry = new CollectorEntry(); } tmpcollector = CollectorEntry.CreateCollectorEntry(ar); if (tmpcollector != null) { if (editingCollectorEntry.Collector != null && (ar.Name == editingCollectorEntry.CollectorRegistrationName)) { tmpcollector.SetConfigurationFromXmlString(editingCollectorEntry.Collector.AgentConfig.ToConfig()); } else { tmpcollector.SetConfigurationFromXmlString(tmpcollector.GetDefaultOrEmptyConfigString()); } if (txtName.Text.Length == 0) { txtName.Text = "No Name"; } if (tmpcollector.ShowEditConfiguration("Edit '" + txtName.Text + "' Config")) { editingCollectorEntry.Collector = tmpcollector; editingCollectorEntry.InitialConfiguration = tmpcollector.AgentConfig.ToConfig(); editingCollectorEntry.CollectorRegistrationName = ar.Name; } } CheckOkEnable(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void cmdSaveConfig_Click(object sender, EventArgs e) { XmlDocument testXml = new XmlDocument(); try { testXml.LoadXml(txtConfig.Text); editingCollectorEntry.InitialConfiguration = txtConfig.Text; RegisteredAgent ar = (RegisteredAgent)cboCollector.SelectedItem; ICollector tmpcollector = CollectorEntry.CreateCollectorEntry(ar); editingCollectorEntry.Collector = tmpcollector; editingCollectorEntry.Collector.SetConfigurationFromXmlString(txtConfig.Text); editingCollectorEntry.CollectorRegistrationName = ar.Name; HideManualConfig(); } catch (Exception ex) { MessageBox.Show(string.Format("Error parsing xml\r\n{0}", ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void LoadPresetAgents() { lvwAgentType.Items.Clear(); ListViewItem lvi; ListViewGroup generalGroup = (from ListViewGroup gr in lvwAgentType.Groups where gr.Header.ToLower() == "general" select gr).FirstOrDefault(); foreach (AgentPresetConfig preset in (from p in AgentPresetConfig.GetAllPresets() orderby p.Description select p)) { try { RegisteredAgent ar = (from a in RegisteredAgentCache.Agents where ((selectingCollectors && a.IsCollector) || (!selectingCollectors && a.IsNotifier)) && a.ClassName.EndsWith(preset.AgentClassName) orderby a.Name select a).FirstOrDefault(); if (ar != null) { ListViewGroup agentGroup = (from ListViewGroup gr in lvwAgentType.Groups where gr.Header.ToLower() == ar.CategoryName.ToLower() select gr).FirstOrDefault(); if (agentGroup == null) { agentGroup = generalGroup; } lvi = new ListViewItem(preset.Description); string details = preset.Config; lvi.ImageIndex = 0; lvi.Group = agentGroup; lvi.SubItems.Add(details); lvi.Tag = preset; lvwAgentType.Items.Add(lvi); } } catch { } } }
private void cmdManualConfig_Click(object sender, EventArgs e) { try { if ((editingCollectorEntry.Collector == null || editingCollectorEntry.Collector.AgentConfig == null) && cboCollector.SelectedItem != null) // || SelectedEntry.Collector.AgentConfig.to .Configuration == null || SelectedEntry.Configuration.Length == 0) && cboCollector.SelectedItem != null) { RegisteredAgent ar = (RegisteredAgent)cboCollector.SelectedItem; ICollector col = CollectorEntry.CreateCollectorEntry(ar); txtConfig.Text = XmlFormattingUtils.NormalizeXML(col.GetDefaultOrEmptyConfigString()); } else { txtConfig.Text = XmlFormattingUtils.NormalizeXML(editingCollectorEntry.Collector.AgentConfig.ToConfig()); } } catch (Exception ex) { MessageBox.Show(string.Format("Error getting new/existing configuration\r\n{0}", ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } ShowManualConfig(); }
private void lvwAgentType_SelectedIndexChanged(object sender, EventArgs e) { cmdOK.Enabled = lvwAgentType.SelectedItems.Count == 1; bool presets = false; try { if (lvwAgentType.SelectedItems.Count > 0 && lvwAgentType.SelectedItems[0].Tag is RegisteredAgent) { RegisteredAgent ra = (RegisteredAgent)lvwAgentType.SelectedItems[0].Tag; List <AgentPresetConfig> existingPresets = AgentPresetConfig.GetPresetsForClass(ra.Name); presets = (existingPresets != null && existingPresets.Count > 0); } } catch { } optSelectPreset.Enabled = presets; if (optSelectPreset.Checked && !presets) { optShowConfigEditor.Checked = true; } }
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(); }
private void CheckOkEnable() { bool isEnable = !manualEditPanel.Visible; if (txtName.Text.Length == 0 || cboParentCollector.SelectedIndex < 0 || (!chkFolder.Checked && (cboCollector.SelectedIndex < 0 || editingCollectorEntry.InitialConfiguration == null || editingCollectorEntry.InitialConfiguration.Length == 0))) { isEnable = false; } cmdOK.Enabled = isEnable; configureEditButtonCollector.Enabled = cboCollector.SelectedIndex > -1 && !txtConfig.Visible && !chkFolder.Checked; cboCollector.Enabled = !chkFolder.Checked && allowCollectorChange && !manualEditPanel.Visible; chkCollectOnParentWarning.Enabled = !chkFolder.Checked; numericUpDownRepeatAlertInXMin.Enabled = !chkFolder.Checked; AlertOnceInXMinNumericUpDown.Enabled = !chkFolder.Checked; delayAlertSecNumericUpDown.Enabled = !chkFolder.Checked; lblAgentDescription.Text = ""; if (cboCollector.SelectedIndex > -1) { try { RegisteredAgent ar = (RegisteredAgent)cboCollector.SelectedItem; lblAgentDescription.Text = "Description: " + ar.ClassName; System.Reflection.Assembly a = System.Reflection.Assembly.LoadFrom(ar.AssemblyPath); lblAgentDescription.Text += ", Version: " + a.GetName().Version.ToString(); lblAgentDescription.Text += ", Assembly: " + System.IO.Path.GetFileName(a.Location); //System.Reflection.AssemblyDescriptionAttribute ad = (System.Reflection.AssemblyDescriptionAttribute)System.Reflection.AssemblyDescriptionAttribute.GetCustomAttribute( // a, typeof(System.Reflection.AssemblyDescriptionAttribute)); //lblAgentDescription.Text = "Description: " + ad.Description; } catch { } } }
private void LoadTemplates() { lvwAgentType.Items.Clear(); ListViewItem lvi; ListViewGroup generalGroup = (from ListViewGroup gr in lvwAgentType.Groups where gr.Header.ToLower() == "general" select gr).FirstOrDefault(); List <QuickMonTemplate> allTemplates; if (selectingCollectors) { allTemplates = (from p in QuickMonTemplate.GetCollectorAgentTemplates() orderby p.Name select p).ToList(); } else { allTemplates = (from p in QuickMonTemplate.GetNotifierAgentTemplates() orderby p.Name select p).ToList(); } if (allTemplates == null || allTemplates.Count == 0) { if (!firstChoice) { /**************************/ MessageBox.Show("No templates found for the selected agent type!", "Templates", MessageBoxButtons.OK, MessageBoxIcon.Information); } /**************************/ optShowConfigEditor.Checked = true; } else { foreach (QuickMonTemplate template in allTemplates) { try { RegisteredAgent ar = (from a in RegisteredAgentCache.Agents where ((selectingCollectors && a.IsCollector) || (!selectingCollectors && a.IsNotifier)) && a.ClassName.EndsWith(template.ForClass) orderby a.Name select a).FirstOrDefault(); if (ar != null) { ListViewGroup agentGroup = (from ListViewGroup gr in lvwAgentType.Groups where gr.Header.ToLower() == ar.CategoryName.ToLower() select gr).FirstOrDefault(); if (agentGroup == null) { agentGroup = generalGroup; } lvi = new ListViewItem(template.Name); string details = template.Description.Trim().Length == 0 ? template.Config : template.Description; lvi.ImageIndex = 0; lvi.Group = agentGroup; lvi.SubItems.Add(details); lvi.Tag = template; lvwAgentType.Items.Add(lvi); } } catch { } } if (lvwAgentType.Items.Count == 0) { if (!firstChoice) { /**************************/ MessageBox.Show("No templates found for the selected agent type!", "Templates", MessageBoxButtons.OK, MessageBoxIcon.Information); } /**************************/ optShowConfigEditor.Checked = true; } } }
private void cmdOK_Click(object sender, EventArgs e) { if (SelectedEntry == null) { SelectedEntry = new CollectorEntry(); } SelectedEntry.Name = txtName.Text; SelectedEntry.Enabled = chkEnabled.Checked; SelectedEntry.ExpandOnStart = chkExpandOnStart.Checked; SelectedEntry.IsFolder = currentEditingEntry.IsFolder; if (cboParentCollector.SelectedIndex > 0) { CollectorEntryDisplay ced = (CollectorEntryDisplay)cboParentCollector.SelectedItem; SelectedEntry.ParentCollectorId = ced.CE.UniqueId; } else { SelectedEntry.ParentCollectorId = ""; } SelectedEntry.CollectOnParentWarning = chkCollectOnParentWarning.Checked && !SelectedEntry.IsFolder; //Collector type SelectedEntry.CollectorRegistrationName = currentEditingEntry.CollectorRegistrationName; SelectedEntry.CollectorRegistrationDisplayName = currentEditingEntry.CollectorRegistrationDisplayName; //Remote agents SelectedEntry.EnableRemoteExecute = chkRemoteAgentEnabled.Checked; SelectedEntry.ForceRemoteExcuteOnChildCollectors = chkForceRemoteExcuteOnChildCollectors.Checked; SelectedEntry.RemoteAgentHostAddress = txtRemoteAgentServer.Text; SelectedEntry.RemoteAgentHostPort = (int)remoteportNumericUpDown.Value; SelectedEntry.BlockParentOverrideRemoteAgentHostSettings = chkBlockParentRHOverride.Checked && !chkRemoteAgentEnabled.Checked; SelectedEntry.RunLocalOnRemoteHostConnectionFailure = chkRunLocalOnRemoteHostConnectionFailure.Checked; if (chkRemoteAgentEnabled.Checked && SelectedEntry.RemoteAgentHostAddress.Length > 0) { if (KnownRemoteHosts == null) { KnownRemoteHosts = new List <string>(); } if ((from string rh in KnownRemoteHosts where rh.ToLower() == SelectedEntry.RemoteAgentHostAddress.ToLower() + ":" + SelectedEntry.RemoteAgentHostPort.ToString() select rh).Count() == 0 ) { KnownRemoteHosts.Add(SelectedEntry.RemoteAgentHostAddress + ":" + SelectedEntry.RemoteAgentHostPort.ToString()); } } //Polling overrides if (onlyAllowUpdateOncePerXSecNumericUpDown.Value >= pollSlideFrequencyAfterFirstRepeatSecNumericUpDown.Value) { pollSlideFrequencyAfterFirstRepeatSecNumericUpDown.Value = onlyAllowUpdateOncePerXSecNumericUpDown.Value + 1; } if (pollSlideFrequencyAfterFirstRepeatSecNumericUpDown.Value >= pollSlideFrequencyAfterSecondRepeatSecNumericUpDown.Value) { pollSlideFrequencyAfterSecondRepeatSecNumericUpDown.Value = pollSlideFrequencyAfterFirstRepeatSecNumericUpDown.Value + 1; } if (pollSlideFrequencyAfterSecondRepeatSecNumericUpDown.Value >= pollSlideFrequencyAfterThirdRepeatSecNumericUpDown.Value) { pollSlideFrequencyAfterThirdRepeatSecNumericUpDown.Value = pollSlideFrequencyAfterSecondRepeatSecNumericUpDown.Value + 1; } SelectedEntry.EnabledPollingOverride = chkEnablePollingOverride.Checked; SelectedEntry.OnlyAllowUpdateOncePerXSec = (int)onlyAllowUpdateOncePerXSecNumericUpDown.Value; SelectedEntry.EnablePollFrequencySliding = chkEnablePollingFrequencySliding.Checked; SelectedEntry.PollSlideFrequencyAfterFirstRepeatSec = (int)pollSlideFrequencyAfterFirstRepeatSecNumericUpDown.Value; SelectedEntry.PollSlideFrequencyAfterSecondRepeatSec = (int)pollSlideFrequencyAfterSecondRepeatSecNumericUpDown.Value; SelectedEntry.PollSlideFrequencyAfterThirdRepeatSec = (int)pollSlideFrequencyAfterThirdRepeatSecNumericUpDown.Value; //Alert suppresion SelectedEntry.AlertsPaused = chkAlertsPaused.Checked; SelectedEntry.RepeatAlertInXMin = (int)numericUpDownRepeatAlertInXMin.Value; SelectedEntry.RepeatAlertInXPolls = (int)numericUpDownRepeatAlertInXPolls.Value; SelectedEntry.AlertOnceInXMin = (int)AlertOnceInXMinNumericUpDown.Value; SelectedEntry.AlertOnceInXPolls = (int)AlertOnceInXPollsNumericUpDown.Value; SelectedEntry.DelayErrWarnAlertForXSec = (int)delayAlertSecNumericUpDown.Value; SelectedEntry.DelayErrWarnAlertForXPolls = (int)delayAlertPollsNumericUpDown.Value; //Corrective scripts SelectedEntry.CorrectiveScriptDisabled = chkCorrectiveScriptDisabled.Checked; SelectedEntry.CorrectiveScriptOnWarningPath = txtCorrectiveScriptOnWarning.Text; SelectedEntry.CorrectiveScriptOnErrorPath = txtCorrectiveScriptOnError.Text; SelectedEntry.RestorationScriptPath = txtRestorationScript.Text; SelectedEntry.CorrectiveScriptsOnlyOnStateChange = chkOnlyRunCorrectiveScriptsOnStateChange.Checked; //Service windows SelectedEntry.ServiceWindows.CreateFromConfig(currentEditingEntry.ServiceWindows.ToConfig()); SelectedEntry.ConfigVariables = new List <ConfigVariable>(); SelectedEntry.ConfigVariables.AddRange((from ConfigVariable cv in currentEditingEntry.ConfigVariables select cv.Clone()).ToArray()); if (SelectedEntry.IsFolder) { SelectedEntry.Collector = null; } else { SelectedEntry.InitialConfiguration = currentEditingEntry.InitialConfiguration; RegisteredAgent currentRA = null; currentRA = RegisteredAgentCache.GetRegisteredAgentByClassName("." + SelectedEntry.CollectorRegistrationName); if (currentRA != null) { try { SelectedEntry.CreateAndConfigureEntry(currentRA, monitorPack.ConfigVariables); } catch (Exception ex) { SelectedEntry.LastMonitorState.State = CollectorState.ConfigurationError; SelectedEntry.Enabled = false; SelectedEntry.LastMonitorState.RawDetails = ex.Message; } } else { SelectedEntry.LastMonitorState.State = CollectorState.ConfigurationError; SelectedEntry.Enabled = false; SelectedEntry.LastMonitorState.RawDetails = string.Format("Collector '{0}' cannot be loaded as the type '{1}' is not registered!", SelectedEntry.Name, SelectedEntry.CollectorRegistrationName); } } DialogResult = System.Windows.Forms.DialogResult.OK; Close(); }
public DialogResult ShowCollectorSelection(string currentCollectorRegistrationName) { this.Text = "Select Collector type"; SetDetailColumnSizing(); lvwAgentType.Items.Clear(); lvwAgentType.Groups.Clear(); ListViewGroup generalGroup = new ListViewGroup("General"); lvwAgentType.Groups.Add(generalGroup); foreach (string categoryName in (from a in RegisteredAgentCache.Agents where a.IsCollector && a.CategoryName != "Test" && a.CategoryName != "General" group a by a.CategoryName into g select g.Key)) { lvwAgentType.Groups.Add(new ListViewGroup(categoryName)); } ListViewGroup folderGroup = new ListViewGroup("Folder"); lvwAgentType.Groups.Add(folderGroup); ListViewGroup testGroup = new ListViewGroup("Test"); lvwAgentType.Groups.Add(testGroup); RegisteredAgent folder = new RegisteredAgent() { ClassName = "QuickMon.Collectors.Folder", Name = "Folder", IsCollector = true, DisplayName = "Folder" }; ListViewItem lvi = new ListViewItem("Folder"); lvi.Group = folderGroup; lvi.ImageIndex = 1; lvi.SubItems.Add("Container for child objects"); lvi.Tag = folder; lvwAgentType.Items.Add(lvi); if (currentCollectorRegistrationName == "Folder") { lvi.Selected = true; } foreach (RegisteredAgent ar in (from a in RegisteredAgentCache.Agents where a.IsCollector orderby a.Name select a)) { ListViewGroup agentGroup = (from ListViewGroup gr in lvwAgentType.Groups where gr.Header.ToLower() == ar.CategoryName.ToLower() select gr).FirstOrDefault(); if (agentGroup == null) { agentGroup = generalGroup; } lvi = new ListViewItem(ar.DisplayName); string details = ar.ClassName; System.Reflection.Assembly a = System.Reflection.Assembly.LoadFrom(ar.AssemblyPath); details += ", Version: " + a.GetName().Version.ToString(); details += ", Assembly: " + System.IO.Path.GetFileName(a.Location); if (agentGroup == testGroup) { lvi.ImageIndex = 2; } else { lvi.ImageIndex = 0; } lvi.Group = agentGroup; lvi.SubItems.Add(details); lvi.Tag = ar; lvwAgentType.Items.Add(lvi); if (ar.Name == currentCollectorRegistrationName) { lvi.Selected = true; } } return(this.ShowDialog()); }
public void RemoveRegisteredAgent(RegisteredAgent registeredAgent) { var agents = _context.RegisteredAgents.Remove(registeredAgent); }
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); } } } } }
private void LoadRawAgents() { lvwAgentType.Items.Clear(); ListViewItem lvi; if (selectingCollectors) { RegisteredAgent folder = new RegisteredAgent() { ClassName = "QuickMon.Collectors.Folder", Name = "Folder", IsCollector = true, DisplayName = "Folder" }; lvi = new ListViewItem("Folder"); lvi.Group = (from ListViewGroup gr in lvwAgentType.Groups where gr.Header.ToLower() == "folder" select gr).FirstOrDefault(); lvi.ImageIndex = 1; lvi.SubItems.Add("Container for child objects"); lvi.Tag = folder; lvwAgentType.Items.Add(lvi); if (InitialRegistrationName == "Folder") { lvi.Selected = true; } } ListViewGroup generalGroup = (from ListViewGroup gr in lvwAgentType.Groups where gr.Header.ToLower() == "general" select gr).FirstOrDefault(); ListViewGroup testGroup = (from ListViewGroup gr in lvwAgentType.Groups where gr.Header.ToLower() == "test" select gr).FirstOrDefault(); foreach (RegisteredAgent ar in (from a in RegisteredAgentCache.Agents where (selectingCollectors && a.IsCollector) || (!selectingCollectors && a.IsNotifier) orderby a.Name select a)) { try { ListViewGroup agentGroup = (from ListViewGroup gr in lvwAgentType.Groups where gr.Header.ToLower() == ar.CategoryName.ToLower() select gr).FirstOrDefault(); if (agentGroup == null) { agentGroup = generalGroup; } lvi = new ListViewItem(ar.DisplayName); string details = ar.ClassName; System.Reflection.Assembly a = System.Reflection.Assembly.LoadFrom(ar.AssemblyPath); details += ", Version: " + a.GetName().Version.ToString(); details += ", Assembly: " + System.IO.Path.GetFileName(a.Location); if (agentGroup == testGroup) { lvi.ImageIndex = 2; } else { lvi.ImageIndex = 0; } lvi.Group = agentGroup; lvi.SubItems.Add(details); lvi.Tag = ar; lvwAgentType.Items.Add(lvi); if (ar.Name == InitialRegistrationName) { lvi.Selected = true; } } catch { } } }