public HttpStatusCodeResult UpdateAgentInMonitor(int inputAgentNr, string inputAgentName, string inputIpAddress, string inputPortNr, string typeName, bool cpuCheck, bool discCheck)
        {
            HttpStatusCodeResult output = new HttpStatusCodeResult(System.Net.HttpStatusCode.OK);

            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 updatedAgent = new Agent(inputAgentNr, inputAgentName, inputIpAddress, type, portNr, 1, "", "", "");
                    controller.UpdateAgentInDatabase(updatedAgent, cpuCheck, discCheck);
                    output = new HttpStatusCodeResult(System.Net.HttpStatusCode.OK);
                }
            }
            catch (Exception exc)
            {
                BusinessLayer.ExceptionHandling.ExceptionCore.HandleException(BusinessLayer.ExceptionHandling.ExceptionCategory.Normal, exc);
            }

            return(output);
        }
        public HttpStatusCodeResult DeleteAgent(int id)
        {
            HttpStatusCodeResult output = new HttpStatusCodeResult(System.Net.HttpStatusCode.Conflict);

            try
            {
                if (id > 0)
                {
                    SNMPController controller = new SNMPController(Properties.Settings.Default.ProdDatabaseConnectionString);
                    controller.DeleteAgent(id);
                    output = new HttpStatusCodeResult(System.Net.HttpStatusCode.OK);
                }
                else
                {
                    output = new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest);
                }
            }
            catch (Exception exc)
            {
                BusinessLayer.ExceptionHandling.ExceptionCore.HandleException(BusinessLayer.ExceptionHandling.ExceptionCategory.Normal, exc);
                output = new HttpStatusCodeResult(System.Net.HttpStatusCode.InternalServerError);
            }

            return(output);
        }
        public CustomJsonResult HistoryDataForOID(string id, string oid, int count)
        {
            int agentId;
            HistoryMonitorDataModel history = null;

            try
            {
                SNMPController controller = new SNMPController(Properties.Settings.Default.ProdDatabaseConnectionString);

                if (int.TryParse(id, out agentId))
                {
                    List <MonitorData> businessLayerHistory = controller.GetHistoryOfOIDForAgent(agentId, oid, count);
                    businessLayerHistory.Sort((item1, item2) => item1.Timestamp.CompareTo(item2.Timestamp));
                    history = new HistoryMonitorDataModel(businessLayerHistory);
                }
                else
                {
                    BusinessLayer.ExceptionHandling.ExceptionCore.HandleException(BusinessLayer.ExceptionHandling.ExceptionCategory.Normal, new FormatException("HistoryDataForOID: id not Integer"));
                }
            }
            catch (Exception exc)
            {
                BusinessLayer.ExceptionHandling.ExceptionCore.HandleException(BusinessLayer.ExceptionHandling.ExceptionCategory.Normal, exc);
            }
            return(new CustomJsonResult {
                Data = history, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        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 CustomJsonResult GetAgents()
        {
            List <Agent> agents = null;

            try
            {
                SNMPController controller = new SNMPController(Properties.Settings.Default.ProdDatabaseConnectionString);
                agents = controller.GetAgents();
            }
            catch (Exception exc)
            {
                BusinessLayer.ExceptionHandling.ExceptionCore.HandleException(BusinessLayer.ExceptionHandling.ExceptionCategory.Normal, exc);
            }

            return(new CustomJsonResult {
                Data = agents, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        public CustomJsonResult GetMonitorSummaryForAgent(int id)
        {
            KeyValuePair <Agent, List <MonitoringType> > monitorSummary = new KeyValuePair <Agent, List <MonitoringType> >(null, null);

            try
            {
                SNMPController controller = new SNMPController(Properties.Settings.Default.ProdDatabaseConnectionString);
                monitorSummary = controller.GetMonitorSummaryForAgent(id);
            }
            catch (Exception exc)
            {
                BusinessLayer.ExceptionHandling.ExceptionCore.HandleException(BusinessLayer.ExceptionHandling.ExceptionCategory.Normal, exc);
            }

            return(new CustomJsonResult {
                Data = monitorSummary, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        public void TestSNMPController()
        {
            bool successfull = false;

            try
            {
                string         connectionString = Properties.Settings.Default.TestDatabase;
                SNMPController controller       = new SNMPController(connectionString);
                controller.GetSNMPDataFromAgents();
                successfull = true;
            }
            catch (Exception exc)
            {
                successfull = false;
            }

            Assert.IsTrue(successfull);
        }