public void TestGetAgentsFromDatabase()
        {
            List <AgentDataModel> agents = databaseConnection.GetAgentsFromDatabase();

            if (agents.Count > 0)
            {
                AgentDataModel testAgent = agents[0];
                Assert.AreEqual(1, testAgent.AgentNr);
                Assert.AreEqual("sinv-56075.edu.hsr.ch", testAgent.Name);
                Assert.AreEqual("152.96.56.75", testAgent.IPAddress);
                TypeDataModel testAgentType = testAgent.Type;
                Assert.AreEqual(1, testAgentType.TypeNr);
                Assert.AreEqual(40001, testAgent.Port);
                Assert.AreEqual(1, testAgent.Status);
                Assert.AreEqual("{\n  \"Results\": [\n    {\n      \"OID\": \"1.3.6.1.2.1.1.1.0\",\n      \"Type\": \"OctetString\",\n      \"Value\": \"Hardware: Intel64 Family 6 Model 62 Stepping 4 AT/AT COMPATIBLE - Software: Windows Version 6.3 (Build 9600 Multiprocessor Free)\"\n    }\n  ]\n}".Replace("\n", Environment.NewLine), testAgent.SysDescription);
                Assert.AreEqual("{\n  \"Results\": [\n    {\n      \"OID\": \"1.3.6.1.2.1.1.5.0\",\n      \"Type\": \"OctetString\",\n      \"Value\": \"sinv-56075\"\n    }\n  ]\n}".Replace("\n", Environment.NewLine), testAgent.SysName);
            }

            Assert.AreEqual(1, agents.Count);
        }
        public void TestSetup()
        {
            databaseConnection = new DatabaseConnectionMonitor(Properties.Settings.Default.TestDatabase);

            List <AgentDataModel> agents = databaseConnection.GetAgentsFromDatabase();

            if (agents.Count == 0)
            {
                databaseConnection.AddAgentToDatabase(agent, false, false);
            }
        }
예제 #3
0
        public List <Agent> GetAgents()
        {
            List <Agent> agentList = new List <Agent>();

            try
            {
                List <AgentDataModel> resultList = _databaseConnection.GetAgentsFromDatabase();
                List <Type>           typeList   = GetTypes();

                foreach (AgentDataModel agentData in resultList)
                {
                    Type type = null;
                    foreach (Type temp in typeList)
                    {
                        if (temp.TypeNr == agentData.Type.TypeNr)
                        {
                            type = temp;
                        }
                    }
                    agentList.Add(new Agent(agentData.AgentNr, agentData.Name, agentData.IPAddress, type, agentData.Port, agentData.Status, agentData.SysDescription, agentData.SysName, agentData.SysUptime));
                }
            }
            catch (SqlException e)
            {
                ExceptionCore.HandleException(ExceptionCategory.Fatal, e);
            }
            catch (InvalidCastException e)
            {
                ExceptionCore.HandleException(ExceptionCategory.High, e);
            }
            catch (Exception e)
            {
                ExceptionCore.HandleException(ExceptionCategory.Normal, e);
            }
            return(agentList);
        }