Пример #1
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);
        }
Пример #2
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);
        }