public static List <CollectorEntry> GetCollectorEntriesFromString(string xmlString, bool preloadCollectorInstances = false, List <ConfigVariable> monitorPackVars = null) { List <CollectorEntry> collectors = new List <CollectorEntry>(); XmlDocument collectorEntryXml = new XmlDocument(); collectorEntryXml.LoadXml(xmlString); XmlElement root = collectorEntryXml.DocumentElement; foreach (XmlElement xmlCollectorEntry in root.SelectNodes("collectorEntry")) { CollectorEntry newCollectorEntry = CollectorEntry.FromConfig(xmlCollectorEntry); if (preloadCollectorInstances && !newCollectorEntry.IsFolder) { RegisteredAgent currentRA = RegisteredAgentCache.GetRegisteredAgentByClassName("." + newCollectorEntry.CollectorRegistrationName); if (currentRA != null) { newCollectorEntry.CreateAndConfigureEntry(currentRA, monitorPackVars); } } collectors.Add(newCollectorEntry); } return(collectors); }
/// <summary> /// Loading QuickMon monitor pack file /// </summary> /// <param name="configurationFile">Serialzed monitor pack file</param> public void Load(string configurationFile) { XmlDocument configurationXml = new XmlDocument(); configurationXml.LoadXml(System.IO.File.ReadAllText(configurationFile, Encoding.UTF8)); XmlElement root = configurationXml.DocumentElement; Name = root.Attributes.GetNamedItem("name").Value; Enabled = bool.Parse(root.Attributes.GetNamedItem("enabled").Value); AgentsAssemblyPath = root.ReadXmlElementAttr("agentRegistrationPath"); string defaultViewerNotifierName = root.ReadXmlElementAttr("defaultViewerNotifier"); RunCorrectiveScripts = bool.Parse(root.ReadXmlElementAttr("runCorrectiveScripts", "false")); foreach (XmlElement xmlCollectorEntry in root.SelectNodes("collectorEntries/collectorEntry")) { CollectorEntry newCollectorEntry = CollectorEntry.FromConfig(xmlCollectorEntry); ApplyCollectorConfig(newCollectorEntry); Collectors.Add(newCollectorEntry); } foreach (XmlElement xmlNotifierEntry in root.SelectNodes("notifierEntries/notifierEntry")) { NotifierEntry newNotifierEntry = NotifierEntry.FromConfig(xmlNotifierEntry); AgentRegistration currentNotifier = null; if (AgentRegistrations != null) { currentNotifier = (from o in AgentRegistrations where o.IsNotifier && o.Name == newNotifierEntry.NotifierRegistrationName select o).FirstOrDefault(); } if (currentNotifier != null) { newNotifierEntry.Notifier = NotifierEntry.CreateNotifierEntry(currentNotifier.AssemblyPath, currentNotifier.ClassName); XmlDocument configDoc = new XmlDocument(); configDoc.LoadXml(newNotifierEntry.Configuration); try { newNotifierEntry.Notifier.ReadConfiguration(configDoc); } catch // (Exception ex) { newNotifierEntry.Enabled = false; } } else { newNotifierEntry.Enabled = false; } Notifiers.Add(newNotifierEntry); if (newNotifierEntry.Name.ToUpper() == defaultViewerNotifierName.ToUpper()) { DefaultViewerNotifier = newNotifierEntry; } } MonitorPackPath = configurationFile; RaiseMonitorPackPathChanged(MonitorPackPath); if (Properties.Settings.Default.recentMonitorPacks == null) { Properties.Settings.Default.recentMonitorPacks = new System.Collections.Specialized.StringCollection(); } if (!Properties.Settings.Default.recentMonitorPacks.Contains(configurationFile)) { Properties.Settings.Default.recentMonitorPacks.Add(configurationFile); Properties.Settings.Default.Save(); } InitializeGlobalPerformanceCounters(); }