private void LoadPresets() { List <AgentPresetConfig> allPresets = AgentPresetConfig.GetAllPresets(); lvwPresets.Groups.Clear(); foreach (string agentType in (from p in allPresets group p by p.AgentClassName into g select g.Key).OrderBy(p1 => p1)) { lvwPresets.Groups.Add(new ListViewGroup(agentType)); } lvwPresets.Items.Clear(); foreach (AgentPresetConfig preset in (from p in allPresets orderby p.Description select p)) { ListViewItem lvi = new ListViewItem(preset.Description); lvi.ImageIndex = 0; lvi.Group = (from ListViewGroup gr in lvwPresets.Groups where gr.Header == preset.AgentClassName select gr).FirstOrDefault(); lvi.Tag = preset; lvwPresets.Items.Add(lvi); } lvwPresets.SetGroupState(QuickMon.Controls.ListViewGroupState.Collapsible); SetTitleSaved(); }
private void llblExportConfigAsTemplate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (editingNotifierEntry != null && editingNotifierEntry.Notifier != null && txtName.Text.Trim().Length > 0) { if (MessageBox.Show("Are you sure you want to export the current config as a template?\r\nThe notifier entry name will be used as name for the template.", "Export", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { try { AgentPresetConfig newPreset = new AgentPresetConfig(); newPreset.AgentClassName = editingNotifierEntry.NotifierRegistrationName; newPreset.Description = txtName.Text; newPreset.Config = editingNotifierEntry.InitialConfiguration; List <AgentPresetConfig> allExistingPresets = AgentPresetConfig.GetAllPresets(); if ((from p in allExistingPresets where p.AgentClassName == newPreset.AgentClassName && p.Description == newPreset.Description select p).Count() > 0) { if (MessageBox.Show("A template with the name '" + newPreset.Description + "' already exist!\r\nDo you want to replace it?", "Export", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No) { return; } else { AgentPresetConfig existingEntry = (from p in allExistingPresets where p.AgentClassName == newPreset.AgentClassName && p.Description == newPreset.Description select p).FirstOrDefault(); existingEntry.Config = newPreset.Config; } } else { allExistingPresets.Add(newPreset); } AgentPresetConfig.SaveAllPresetsToFile(allExistingPresets); } catch (Exception ex) { MessageBox.Show(ex.Message, "Export", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
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 { } } }