Esempio n. 1
0
        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;
                }
            }
        }