public static CollectorEntry CreateNewCollector(CollectorEntry parentCollectorEntry = null) { CollectorEntry newCollectorEntry = null; SelectNewAgentType selectNewAgentType = new SelectNewAgentType(); selectNewAgentType.InitialRegistrationName = ""; if (selectNewAgentType.ShowCollectorSelection() == System.Windows.Forms.DialogResult.OK) { LastLaunchAddEntryOption = selectNewAgentType.SelectedPreset == null; LastShowRawEditOnStartOption = selectNewAgentType.ImportConfigAfterSelect; newCollectorEntry = new CollectorEntry(); if (parentCollectorEntry != null) { newCollectorEntry.ParentCollectorId = parentCollectorEntry.UniqueId; } RegisteredAgent ar = null; if (selectNewAgentType.SelectedPreset != null) { ar = RegisteredAgentCache.GetRegisteredAgentByClassName(selectNewAgentType.SelectedPreset.AgentClassName); } else if (selectNewAgentType.SelectedAgent != null) { ar = selectNewAgentType.SelectedAgent; } else { return(null); } if (ar == null) //in case agent is not loaded or available { return(null); } else if (ar.ClassName != "QuickMon.Collectors.Folder") { string initialConfig = ""; if (selectNewAgentType.SelectedPreset != null) { initialConfig = MacroVariables.FormatVariables(selectNewAgentType.SelectedPreset.Config); newCollectorEntry.Name = selectNewAgentType.SelectedPreset.Description; } newCollectorEntry.CreateAndConfigureEntry(ar.ClassName, initialConfig, true, false); } else { newCollectorEntry.IsFolder = true; newCollectorEntry.CollectorRegistrationDisplayName = ar.DisplayName; newCollectorEntry.CollectorRegistrationName = ar.Name; } } return(newCollectorEntry); }
public static INotifier CreateNotifierFromClassName(string agentClassName) { INotifier currentAgent = null; RegisteredAgent currentRA = RegisteredAgentCache.GetRegisteredAgentByClassName("." + agentClassName, false); if (currentRA != null) { if (System.IO.File.Exists(currentRA.AssemblyPath)) { Assembly notifierEntryAssembly = Assembly.LoadFile(currentRA.AssemblyPath); currentAgent = (INotifier)notifierEntryAssembly.CreateInstance(currentRA.ClassName); currentAgent.AgentClassName = currentRA.ClassName.Replace("QuickMon.Notifiers.", ""); currentAgent.AgentClassDisplayName = currentRA.DisplayName; } } return(currentAgent); }
public static NotifierEntry CreateNewNotifier() { NotifierEntry newNotifierEntry = null; SelectNewAgentType selectNewAgentType = new SelectNewAgentType(); selectNewAgentType.InitialRegistrationName = ""; if (selectNewAgentType.ShowNotifierSelection() == System.Windows.Forms.DialogResult.OK) { LastLaunchAddEntryOption = selectNewAgentType.SelectedPreset == null; LastShowRawEditOnStartOption = selectNewAgentType.ImportConfigAfterSelect; newNotifierEntry = new NotifierEntry(); RegisteredAgent ar = null; if (selectNewAgentType.SelectedPreset != null) { ar = RegisteredAgentCache.GetRegisteredAgentByClassName(selectNewAgentType.SelectedPreset.AgentClassName, false); } else if (selectNewAgentType.SelectedAgent != null) { ar = selectNewAgentType.SelectedAgent; } else { return(null); } if (ar == null) //in case agent is not loaded or available { return(null); } else { string initialConfig = ""; if (selectNewAgentType.SelectedPreset != null) { initialConfig = MacroVariables.FormatVariables(selectNewAgentType.SelectedPreset.Config); newNotifierEntry.Name = selectNewAgentType.SelectedPreset.Description; } newNotifierEntry.CreateAndConfigureEntry(ar.ClassName, initialConfig, true, false); } } return(newNotifierEntry); }
public void CreateAndConfigureEntry(string agentClassName, string overrideWithConfig = "", bool setAsInitialConfig = false, bool useConfigVars = true) { RegisteredAgent ra = null; if (agentClassName == "Folder") { return; } ra = RegisteredAgentCache.GetRegisteredAgentByClassName(agentClassName); if (ra == null) //in case agent is not loaded or available { throw new Exception("Collector '" + Name + "' with type of '" + agentClassName + "' cannot be loaded! No Assembly of this Agent type found!"); } else { string appliedConfig = ""; if (overrideWithConfig != null && overrideWithConfig.Trim().Length > 0) { appliedConfig = FormatUtils.N(overrideWithConfig); } else { appliedConfig = FormatUtils.N(InitialConfiguration); } //Create Collector instance Collector = CreateAndConfigureEntry(ra, appliedConfig, (useConfigVars ? ConfigVariables : null)); if (setAsInitialConfig) { if (overrideWithConfig != null && overrideWithConfig.Length > 0) { InitialConfiguration = overrideWithConfig; } else if (Collector != null) { InitialConfiguration = Collector.GetDefaultOrEmptyConfigString(); } } CollectorRegistrationDisplayName = ra.DisplayName; CollectorRegistrationName = ra.Name; } }
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); }