public static List <AgentRegistration> CreateAgentRegistrationListByDirectory(string directoryPath) { List <AgentRegistration> importList = new List <AgentRegistration>(); foreach (string dllPath in Directory.GetFiles(directoryPath, "*.dll")) { try { if (RegistrationHelper.IsQuickMonAssembly(dllPath)) { foreach (string className in RegistrationHelper.LoadQuickMonClasses(dllPath)) { string name = className.Replace("QuickMon.", ""); AgentRegistration agentRegistration = new AgentRegistration(); agentRegistration.Name = name; agentRegistration.AssemblyPath = dllPath; agentRegistration.ClassName = className; agentRegistration.IsCollector = RegistrationHelper.IsCollectorClass(dllPath, className); agentRegistration.IsNotifier = !agentRegistration.IsCollector; importList.Add(agentRegistration); } } } catch { } } return(importList); }
private void LoadAgentAssemblies() { StringBuilder sbExceptions = new StringBuilder(); AgentLoadingErrors = ""; try { AgentRegistrations.Clear(); string agentAssemblyPathLocal = ""; #if DEBUG agentAssemblyPathLocal = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); #else agentAssemblyPathLocal = agentsAssemblyPath; #endif foreach (string assemblyPath in System.IO.Directory.GetFiles(agentAssemblyPathLocal, "*.dll")) { try { foreach (string className in LoadQuickMonClasses(assemblyPath)) { AgentRegistration ar = new AgentRegistration(); ar.Name = className.Replace("QuickMon.", ""); ar.AssemblyPath = assemblyPath; ar.ClassName = className; ar.IsCollector = IsCollectorClass(assemblyPath, className); ar.IsNotifier = !ar.IsCollector; AgentRegistrations.Add(ar); } } catch (System.Reflection.ReflectionTypeLoadException rex) { foreach (Exception lex in rex.LoaderExceptions) { sbExceptions.AppendLine(string.Format("Error in assembly '{0}' - {1}", assemblyPath, lex.Message)); } } catch (Exception innerEx) { throw new Exception(string.Format("Error loading {0}.\r\n{1}", assemblyPath, innerEx.Message)); } } } catch (Exception ex) { throw new Exception(string.Format("An error occured loading QuickMon agents from {0}.\r\n{1}", agentsAssemblyPath, ex.Message)); } if (sbExceptions.Length > 0) { AgentLoadingErrors = string.Format("There were errors loading some/all agent assemblies\r\n{0}", sbExceptions.ToString()); } }
public void ApplyCollectorConfig(CollectorEntry collectorEntry) { if (collectorEntry == null) { return; } AgentRegistration currentCollector = null; if (collectorEntry.IsFolder) { collectorEntry.Collector = null; } else { //first clear/release any existing references if (collectorEntry.Collector != null) { collectorEntry.Collector = null; } if (AgentRegistrations != null) { currentCollector = (from o in AgentRegistrations where o.IsCollector && o.Name == collectorEntry.CollectorRegistrationName select o).FirstOrDefault(); } if (currentCollector != null) { collectorEntry.Collector = CollectorEntry.CreateCollectorEntry(currentCollector.AssemblyPath, currentCollector.ClassName); XmlDocument configDoc = new XmlDocument(); configDoc.LoadXml(collectorEntry.Configuration); try { collectorEntry.Collector.ReadConfiguration(configDoc); } catch (Exception ex) { collectorEntry.LastMonitorState = MonitorStates.ConfigurationError; collectorEntry.Enabled = false; collectorEntry.LastMonitorDetails.PlainText = ex.Message; } } else { collectorEntry.LastMonitorState = MonitorStates.ConfigurationError; collectorEntry.Enabled = false; collectorEntry.LastMonitorDetails.PlainText = string.Format("Collector '{0}' cannot be loaded as the type '{1}' is not registered!", collectorEntry.Name, collectorEntry.CollectorRegistrationName); RaiseRaiseMonitorPackError(string.Format("Collector '{0}' cannot be loaded as the type '{1}' is not registered!", collectorEntry.Name, collectorEntry.CollectorRegistrationName)); } } }
public EditRegisteredMonitor() { InitializeComponent(); AgentRegistration = new AgentRegistration(); }
/// <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(); }