public static void ClassCleanup()
        {
            using (var ctx = new DataFlowDbContext())
            {
                AgentAgentChrome aac = ctx.AgentAgentChromes.Find(_agentAgentChromeId);
                ctx.AgentAgentChromes.Remove(aac);

                AgentChrome chrome = ctx.AgentChromes.Find(_agentChromeId);
                ctx.AgentChromes.Remove(chrome);

                Agent agent = ctx.Agents.Find(_agentId);
                // Remove the directory with the agent temp file sample.csv
                System.IO.Directory.Delete(PathUtility.EnsureTrailingSlash(ConfigurationManager.AppSettings["ShareName"]) + agent.Queue.ToString(), true);
                ctx.Agents.Remove(agent);

                ctx.SaveChanges();
            }
        }
예제 #2
0
        public List <AgentResponse> Agents([FromBody] AgentMessage message)
        {
            List <AgentResponse> response = new List <AgentResponse>();

            try
            {
                using (var ctx = new DataFlowDbContext())
                {
                    AgentChrome agentChrome = ctx.AgentChromes.Where(ac => ac.AgentUuid == message.uuid && ac.AccessToken == message.token).FirstOrDefault();
                    if (agentChrome != null)
                    {
                        List <AgentAgentChrome> agentAgentChromes = ctx.AgentAgentChromes.Where(aacc => aacc.AgentChromeId == agentChrome.Id && aacc.Agent.Enabled == true).Include(aacc => aacc.Agent.AgentSchedules).ToList();

                        foreach (var agentAgentChrome in agentAgentChromes)
                        {
                            AgentResponse responseAgent = new AgentResponse();
                            responseAgent.agent_id   = agentAgentChrome.Agent.Id;
                            responseAgent.name       = agentAgentChrome.Agent.Name;
                            responseAgent.action     = agentAgentChrome.Agent.AgentAction;
                            responseAgent.parameters = agentAgentChrome.Agent.Custom;
                            responseAgent.url        = agentAgentChrome.Agent.Url;
                            responseAgent.loginUrl   = agentAgentChrome.Agent.LoginUrl;
                            responseAgent.schedule   = new List <AgentScheduleResponse>();

                            foreach (var sch in agentAgentChrome.Agent.AgentSchedules)
                            {
                                AgentScheduleResponse schedule = new AgentScheduleResponse(sch.Day, sch.Hour, sch.Minute);
                                responseAgent.schedule.Add(schedule);
                            }

                            response.Add(responseAgent);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                _logger.Error(ex, "Unexpected error in Agents");
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }

            return(response);
        }
예제 #3
0
        // This method validates the uuid and token is related to the agent, if so, return the agent object
        public Agent GetAgent(Guid uuid, Guid token, int agent_id)
        {
            Agent returnAgent = null;

            using (var ctx = new DataFlowDbContext())
            {
                AgentChrome chrome = ctx.AgentChromes.Where(ac => ac.AgentUuid == uuid && ac.AccessToken == token).FirstOrDefault();
                if (chrome != null)
                {
                    var aac = ctx.AgentAgentChromes.Where(aacc => aacc.AgentChromeId == chrome.Id && aacc.AgentId == agent_id).Include(aacc => aacc.Agent.AgentSchedules).FirstOrDefault();
                    if (aac != null && aac.Agent != null)
                    {
                        returnAgent = aac.Agent;
                    }
                }
            }

            return(returnAgent);
        }
예제 #4
0
        public HttpResponseMessage Register([FromBody] AgentMessage message)
        {
            try
            {
                using (var ctx = new DataFlowDbContext())
                {
                    AgentChrome chrome = ctx.AgentChromes.FirstOrDefault(ac => ac.AgentUuid == message.uuid);

                    if (chrome != null)
                    {
                        _logger.Error(String.Format("Duplicate Chrome Agent registration requested for uuid = {0}", message.uuid));
                        return(new HttpResponseMessage()
                        {
                            StatusCode = HttpStatusCode.BadRequest
                        });
                    }
                    else
                    {
                        chrome             = new AgentChrome();
                        chrome.AgentUuid   = message.uuid;
                        chrome.AccessToken = Guid.NewGuid();
                        chrome.Created     = DateTime.Now;
                        ctx.AgentChromes.Add(chrome);
                        ctx.SaveChanges();
                        message.token = chrome.AccessToken;
                        _logger.Info(String.Format("Registered new Chrome Agent with uuid = {0}", message.uuid));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Unexpected error in Register");

                return(new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.InternalServerError
                });
            }

            return(Request.CreateResponse((HttpStatusCode)200, message));
        }
        public void RegisterAgent()
        {
            ChromeExtensionController cec = new ChromeExtensionController();

            cec.Request = new HttpRequestMessage();
            cec.Request.SetConfiguration(new HttpConfiguration());

            AgentMessage message = new AgentMessage();

            message.uuid = Guid.NewGuid();

            HttpResponseMessage response = cec.Register(message);
            var content = response.Content;

            Assert.IsNotNull(content);
            Assert.IsInstanceOfType(content, typeof(ObjectContent <AgentMessage>));
            AgentMessage responseMessage = (AgentMessage)((ObjectContent <AgentMessage>)content).Value;

            Assert.IsNotNull(responseMessage.token);
            Assert.AreNotEqual(Guid.Parse("00000000-0000-0000-0000-000000000000"), responseMessage.token);
            _agentGuid  = responseMessage.uuid;
            _agentToken = responseMessage.token;

            // If we've gotten this far, we've registered a new AgentChrome, let's associate it with the agent
            using (var ctx = new DataFlowDbContext())
            {
                AgentChrome      ac  = ctx.AgentChromes.Where(chr => chr.AgentUuid == _agentGuid && chr.AccessToken == _agentToken).FirstOrDefault();
                AgentAgentChrome aac = new AgentAgentChrome();
                aac.AgentChromeId = ac.Id;
                aac.AgentId       = _agentId;
                ctx.AgentAgentChromes.Add(aac);
                ctx.SaveChanges();
                _agentChromeId      = ac.Id;
                _agentAgentChromeId = aac.Id;
            }
        }