Example #1
0
        public ActionResult Index()
        {
            var agentManager = new AgentsManager();
            var agents       = agentManager.GetAgents();

            return(View(agents));
        }
Example #2
0
        public ActionResult Add(AddAgentViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Неправильные данные формы создания.");
                return(View());
            }
            var agentManager = new AgentsManager();
            var existedAgent = agentManager
                               .GetAgents()
                               .FirstOrDefault(a => a.IpAddress == model.IpAddress && a.Port == model.Port);

            if (existedAgent != null)
            {
                ModelState.AddModelError("", "Агент уже зарегистрирован.");
                return(View());
            }
            var agentAddress  = string.Format("http://{0}:{1}", model.IpAddress, model.Port);
            var agentResponse = PingAgent(agentAddress);

            if (agentResponse.Equals(AgentPingResponse))
            {
                //var agentSettings = GetAgentConfig(agentAddress);
                var agent = new AgentSettings
                {
                    Status       = AgentStatus.Working,
                    CreationDate = DateTime.UtcNow,
                    IpAddress    = model.IpAddress,
                    Port         = model.Port
                };
                agentManager.Add(agent);
                return(RedirectToAction("Index", "Agents"));
            }
            ModelState.AddModelError("", "Не удалось установить соединение с агентом.");
            return(View());
        }