Exemplo n.º 1
0
 public static void LoadAgentsOverride(string agentsPath)
 {
     cacheLoaded = false;
     AgentsPath  = agentsPath;
     agents      = new List <RegisteredAgent>();
     agents      = RegistrationHelper.GetAllRegisteredAgentsByDirectory(agentsPath);
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public static List <AgentPresetConfig> ReadPresetsFromFile(string filePath)
        {
            List <AgentPresetConfig> presets = new List <AgentPresetConfig>();

            try
            {
                if (System.IO.File.Exists(filePath))
                {
                    XmlDocument presetDoc = new XmlDocument();
                    presetDoc.Load(filePath);
                    XmlElement root = presetDoc.DocumentElement;
                    if (root.Name == "qmpresets")
                    {
                        foreach (XmlElement presetNode in root.SelectNodes("preset"))
                        {
                            try
                            {
                                AgentPresetConfig apc = new AgentPresetConfig();
                                apc.AgentClassName = presetNode.ReadXmlElementAttr("class", "");
                                apc.Description    = presetNode.ReadXmlElementAttr("description", "");
                                apc.Config         = presetNode.InnerXml; //all of it e.g. <config>...</config>
                                //to nmake sure only 'available' agents get loaded
                                if ((from r in RegistrationHelper.GetAllAvailableAgents()
                                     where r.ClassName.EndsWith(apc.AgentClassName)
                                     select r).Count() > 0)
                                {
                                    presets.Add(apc);
                                }
                            }
                            catch (Exception nodeEx)
                            {
                                System.Diagnostics.Trace.WriteLine("Error reading preset: " + nodeEx.ToString());
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
            }
            return(presets);
        }
Exemplo n.º 4
0
        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);
        }