/// <summary> /// Create a new instance of the collector agent /// </summary> /// <param name="ra">Agent registration type</param> /// <returns>Instance of ICollector</returns> public static ICollector CreateCollectorEntry(RegisteredAgent ra) { if (ra != null) { return(CreateCollectorEntry(ra.AssemblyPath, ra.ClassName)); } else { return(null); } }
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); }
private static ICollector CreateAndConfigureEntry(RegisteredAgent ra, string appliedConfig, List <ConfigVariable> configVariables) { ICollector newEntry = CreateCollectorEntry(ra); if (newEntry != null) { if (appliedConfig == null || appliedConfig.Length == 0) { appliedConfig = newEntry.GetDefaultOrEmptyConfigString(); } if (configVariables != null && configVariables.Count > 0) { foreach (ConfigVariable vc in configVariables) { if (vc.Name.Length > 0) { appliedConfig = appliedConfig.Replace(vc.Name, vc.Value); } } } newEntry.AgentConfig.ReadConfiguration(appliedConfig); } return(newEntry); }
public void CreateAndConfigureEntry(RegisteredAgent ra, List <ConfigVariable> monitorPackVars) { List <ConfigVariable> allConfigVars = new List <ConfigVariable>(); if (monitorPackVars != null) { allConfigVars.AddRange(monitorPackVars.ToArray()); } if (ConfigVariables != null) { allConfigVars.AddRange(ConfigVariables.ToArray()); } if (InitialConfiguration != null && InitialConfiguration.Length > 0) { Collector = CreateAndConfigureEntry(ra, InitialConfiguration, allConfigVars); } else { Collector = CreateAndConfigureEntry(ra, "", allConfigVars); } ActiveConfiguration = Collector.AgentConfig.ToConfig(); CollectorRegistrationDisplayName = ra.DisplayName; }
public static List <RegisteredAgent> GetAllRegisteredAgentsByDirectory(string directoryPath) { List <RegisteredAgent> list = new List <RegisteredAgent>(); //Check in dll's in directory foreach (string dllPath in Directory.GetFiles(directoryPath, "*.dll")) { try { Assembly quickMonAssembly = Assembly.LoadFile(dllPath); if (IsQuickMonAssembly(quickMonAssembly)) { Type[] types = quickMonAssembly.GetTypes(); foreach (Type type in types) { try { if (!type.IsInterface && !type.IsAbstract) { foreach (Type interfaceType in type.GetInterfaces()) { try { if (interfaceType.FullName == "QuickMon.IAgent") { string className = type.FullName; if (list.FirstOrDefault(a => a.ClassName == className) == null) { string name = className;//.Replace("QuickMon.", ""); string displayName = name; //name = name.Replace("Collectors.", ""); //name = name.Replace("Notifiers.", ""); string categoryName = "General"; try { displayName = GetTypeDisplayName(type, name); } catch { } try { categoryName = GetCategoryName(type); } catch { } RegisteredAgent agentRegistration = new RegisteredAgent(); agentRegistration.Name = name; agentRegistration.DisplayName = displayName; agentRegistration.CategoryName = categoryName; agentRegistration.AssemblyPath = dllPath; agentRegistration.ClassName = className; agentRegistration.IsCollector = RegistrationHelper.IsCollectorClass(quickMonAssembly, className); agentRegistration.IsNotifier = RegistrationHelper.IsNotifierClass(quickMonAssembly, className); list.Add(agentRegistration); } } } catch (Exception interfaceEx) { System.Diagnostics.Trace.WriteLine(interfaceEx.ToString()); } } } } catch (Exception isInterfaceEx) { System.Diagnostics.Trace.WriteLine(isInterfaceEx.ToString()); } } } } catch (Exception isQuickMonAssemblyEx) { System.Diagnostics.Trace.WriteLine(isQuickMonAssemblyEx.ToString()); } } //also check current executing Assembly Assembly currentAssembly = Assembly.GetExecutingAssembly(); if (IsQuickMonAssembly(currentAssembly)) { Type[] types = currentAssembly.GetTypes(); foreach (Type type in types) { if (!type.IsInterface && !type.IsAbstract) { foreach (Type interfaceType in type.GetInterfaces()) { if (interfaceType.FullName == "QuickMon.IAgent") { string className = type.FullName; if (list.FirstOrDefault(a => a.ClassName == className) == null) { string name = className; //.Replace("QuickMon.", ""); //name = name.Replace("Collectors.", ""); //name = name.Replace("Notifiers.", ""); string displayName = name; string categoryName = "General"; try { displayName = GetTypeDisplayName(type, name); } catch { } try { categoryName = GetCategoryName(type); } catch { } RegisteredAgent agentRegistration = new RegisteredAgent(); agentRegistration.Name = name; agentRegistration.DisplayName = displayName; agentRegistration.CategoryName = categoryName; agentRegistration.AssemblyPath = Assembly.GetExecutingAssembly().Location; agentRegistration.ClassName = className; agentRegistration.IsCollector = RegistrationHelper.IsCollectorClass(currentAssembly, className); agentRegistration.IsNotifier = !agentRegistration.IsCollector; list.Add(agentRegistration); } } } } } } return(list); }