public HttpStatusCodeResult AddAgentToMonitor(string inputAgentName, string inputIpAddress, string inputPortNr, string typeName, bool cpuCheck, bool discCheck)
        {
            HttpStatusCodeResult output = new HttpStatusCodeResult(System.Net.HttpStatusCode.InternalServerError);

            try
            {
                SNMPController controller = new SNMPController(Properties.Settings.Default.ProdDatabaseConnectionString);
                int            portNr;
                if (int.TryParse(inputPortNr, out portNr))
                {
                    List <SNMPMonitor.BusinessLayer.Type> types = controller.GetTypes();
                    SNMPMonitor.BusinessLayer.Type        type  = null;
                    foreach (SNMPMonitor.BusinessLayer.Type temp in types)
                    {
                        if (temp.Name == typeName)
                        {
                            type = temp;
                        }
                    }
                    Agent newAgent = new Agent(inputAgentName, inputIpAddress, type, portNr);
                    controller.AddAgentToDatabase(newAgent, cpuCheck, discCheck);
                    output = new HttpStatusCodeResult(System.Net.HttpStatusCode.OK);
                }
            }
            catch (Exception exc)
            {
                BusinessLayer.ExceptionHandling.ExceptionCore.HandleException(BusinessLayer.ExceptionHandling.ExceptionCategory.Normal, exc);
            }

            return(output);
        }
        public void TestSetup()
        {
            controller = new SNMPController(Properties.Settings.Default.TestDatabase);

            List <Agent> agents = controller.GetAgents();

            if (agents.Count == 0)
            {
                controller.AddAgentToDatabase(agent, false, false);
            }
        }
        public void TestAddAndDeleteAgent()
        {
            List <Agent> agentsBeforeAdd = controller.GetAgents();
            Agent        newAgent        = new Agent("Test-Server", "10.10.10.10", new Type(1, "Server"), 161);

            controller.AddAgentToDatabase(newAgent, false, false);

            List <Agent> agentsAfterAdd = controller.GetAgents();

            Assert.AreEqual(agentsBeforeAdd.Count + 1, agentsAfterAdd.Count);

            // Check old Agents
            int i;

            for (i = 0; i < agentsBeforeAdd.Count; i++)
            {
                Assert.AreEqual(agentsBeforeAdd[i].AgentNr, agentsAfterAdd[i].AgentNr);
                Assert.AreEqual(agentsBeforeAdd[i].Name, agentsAfterAdd[i].Name);
                Assert.AreEqual(agentsBeforeAdd[i].IPAddress, agentsAfterAdd[i].IPAddress);
                Assert.AreEqual(agentsBeforeAdd[i].Type.TypeNr, agentsAfterAdd[i].Type.TypeNr);
                Assert.AreEqual(agentsBeforeAdd[i].Port, agentsAfterAdd[i].Port);
                Assert.AreEqual(agentsBeforeAdd[i].Status, agentsAfterAdd[i].Status);
                Assert.AreEqual(agentsBeforeAdd[i].SysDesc, agentsAfterAdd[i].SysDesc);
                Assert.AreEqual(agentsBeforeAdd[i].SysName, agentsAfterAdd[i].SysName);
                Assert.AreEqual(agentsBeforeAdd[i].SysUptime, agentsAfterAdd[i].SysUptime);
            }

            // Check new Agent
            Assert.AreEqual(newAgent.Name, agentsAfterAdd[i].Name);
            Assert.AreEqual(newAgent.IPAddress, agentsAfterAdd[i].IPAddress);
            Assert.AreEqual(newAgent.Type.TypeNr, agentsAfterAdd[i].Type.TypeNr);
            Assert.AreEqual(newAgent.Port, agentsAfterAdd[i].Port);
            Assert.AreEqual(newAgent.Status, agentsAfterAdd[i].Status);

            // Delete new Agent
            controller.DeleteAgent(agentsAfterAdd[i].AgentNr);

            List <Agent> agentsAfterDelete = controller.GetAgents();

            Assert.AreEqual(agentsAfterDelete.Count, agentsBeforeAdd.Count);
        }