Ejemplo n.º 1
0
        protected Response GetAgentStatus(AgentParameters p)
        {
            if (p.agent == null)
            {
                Logger.LogError(HttpStatusCode.BadRequest, "Invalid value for parameter 'agent': {0}", p.agent);

                // Return disabled state so that the browsers properly indicate disabled logging.
                p.enabled = false;

                return(Response.AsJson(p));
            }

            IModel model = Models.GetAgents();

            SoftwareAgent agent    = null;
            Uri           agentUri = new Uri(p.agent);

            if (model.ContainsResource(agentUri))
            {
                agent = model.GetResource <SoftwareAgent>(agentUri);
            }

            // Capturing agent data is disabled by default.
            p.enabled = agent != null ? agent.IsCaptureEnabled : false;

            Logger.LogRequest(HttpStatusCode.OK, Request.Url + " " + p.agent, "GET", "");

            return(Response.AsJson(p));
        }
Ejemplo n.º 2
0
        private bool IsCaptureEnabled(ActivityParameters p)
        {
            IModel model = Models.GetAgents();

            SoftwareAgent agent    = null;
            Uri           agentUri = new Uri(p.agent);

            if (model.ContainsResource(agentUri))
            {
                agent = model.GetResource <SoftwareAgent>(agentUri);
            }

            return(agent.IsCaptureEnabled);
        }
Ejemplo n.º 3
0
        public static void InstallAgent(IModel model, string uri, string name, string executableName, string colour, bool captureEnabled = false)
        {
            Console.WriteLine("Installing agent {0}..", name);

            UriRef agentUri = new UriRef(uri);

            if (!model.ContainsResource(agentUri))
            {
                SoftwareAgent agent = model.CreateResource <SoftwareAgent>(agentUri);
                agent.Name             = name;
                agent.ExecutableName   = executableName;
                agent.IsCaptureEnabled = captureEnabled;
                agent.ColourCode       = colour;
                agent.Commit();
            }
            else
            {
                bool modified = false;

                SoftwareAgent agent = model.GetResource <SoftwareAgent>(agentUri);

                if (!agent.HasProperty(rdf.type, prov.SoftwareAgent))
                {
                    agent.AddProperty(rdf.type, prov.SoftwareAgent);

                    modified = true;
                }

                if (agent.Name != name)
                {
                    agent.Name = name;

                    modified = true;
                }

                if (string.IsNullOrEmpty(agent.ColourCode))
                {
                    agent.ColourCode = colour;

                    modified = true;
                }

                if (modified)
                {
                    agent.Commit();
                }
            }
        }
Ejemplo n.º 4
0
        protected Response SetAgentStatus(AgentParameters p)
        {
            try
            {
                if (p.agent == null)
                {
                    Logger.LogError(HttpStatusCode.BadRequest, "Invalid value for parameter 'agent': {0}", p.agent);

                    // Return disabled state so that the browsers properly indicate disabled logging.
                    return(Response.AsJson(new AgentParameters()
                    {
                        agent = p.agent, enabled = false
                    }));
                }

                IModel model = Models.GetAgents();

                SoftwareAgent agent    = null;
                Uri           agentUri = new Uri(p.agent);

                if (model.ContainsResource(agentUri))
                {
                    agent = model.GetResource <SoftwareAgent>(agentUri);
                }
                else
                {
                    agent = model.CreateResource <SoftwareAgent>(agentUri);
                }

                agent.IsCaptureEnabled = Convert.ToBoolean(p.enabled);
                agent.Commit();

                Logger.LogRequest(HttpStatusCode.OK, Request.Url + " " + p.agent, "POST", "");

                // We return the request so that the plugin can set the server's enabled status.
                return(Response.AsJson(p));
            }
            catch (Exception e)
            {
                return(Logger.LogError(HttpStatusCode.InternalServerError, Request.Url, e));
            }
        }