Ejemplo n.º 1
0
        /// <summary>
        /// <see cref="IAgentRunnerService.RunningAgentsAsync(AgentRunner, CancellationToken)"/>
        /// </summary>
        public async Task <List <string> > RunningAgentsAsync(AgentRunner agentRunner, CancellationToken cancellationToken = default)
        {
            if ((await this.agentRunnerProvider.RunningCountAsync) == 0)
            {
                return(new List <string>());
            }

            var agentsRunning = new List <string>();

            var channels = await this.agentRunnerProvider.RunningChannelsAsync;

            var agents = await this.agentService.GetAllAsync(cancellationToken);

            foreach (var agent in agents)
            {
                cancellationToken.ThrowIfCancellationRequested();

                agentRunner.Agent = agent;
                var channel = AgentRunnerHelpers.GetChannel(agentRunner);

                if (channels.Any(c => c.Contains(channel)))
                {
                    agentsRunning.Add(agent.Name);
                }
            }

            return(agentsRunning);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> StopAgent([FromBody] AgentRunnerDto agentRunnerDto, CancellationToken cancellationToken)
        {
            var agent = await agentService.GetByCriteriaAsync(a => a.Name == agentRunnerDto.Agent, cancellationToken);

            if (agent == null)
            {
                return(BadRequest());
            }

            Target target = default;

            if (!string.IsNullOrWhiteSpace(agentRunnerDto.Target))
            {
                target = await this.targetService.GetByCriteriaAsync(t => t.Name == agentRunnerDto.Target, cancellationToken);

                if (target == null)
                {
                    return(BadRequest());
                }
            }

            RootDomain rootDomain = default;

            if (!string.IsNullOrWhiteSpace(agentRunnerDto.RootDomain))
            {
                rootDomain = await this.rootDomainService.GetByCriteriaAsync(t => t.Name == agentRunnerDto.RootDomain && t.Target == target, cancellationToken);

                if (rootDomain == null)
                {
                    return(NotFound());
                }
            }

            Subdomain subdomain = null;

            if (!string.IsNullOrWhiteSpace(agentRunnerDto.Subdomain))
            {
                subdomain = await this.subdomainService.GetByCriteriaAsync(s => s.RootDomain == rootDomain && s.Name == agentRunnerDto.Subdomain, cancellationToken);

                if (subdomain == null)
                {
                    return(NotFound());
                }
            }

            var agentRunner = new AgentRunner
            {
                Agent      = agent,
                Target     = target,
                RootDomain = rootDomain,
                Subdomain  = subdomain
            };

            var channel = AgentRunnerHelpers.GetChannel(agentRunner);

            await this.agentRunnerService.StopAgentAsync(agentRunner, channel, cancellationToken);

            return(NoContent());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// <see cref="IAgentRunnerService.StopAgentAsync(AgentRunner,  CancellationToken)"></see>
        /// </summary>
        public async Task StopAgentAsync(AgentRunner agentRunner, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var channel = AgentRunnerHelpers.GetChannel(agentRunner);

            await this.StopAgentAsync(channel, cancellationToken);

            await this.agentRunService.DoneOnScopeAsync(agentRunner, channel, true, false, cancellationToken);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// <see cref="IAgentRunnerService.RunAgentAsync(AgentRunner, CancellationToken)"></see>
        /// </summary>
        public async Task RunAgentAsync(AgentRunner agentRunner, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();

            Thread.Sleep(1000);

            var channel = AgentRunnerHelpers.GetChannel(agentRunner);

            await this.agentRunnerProvider.InitializesAsync(channel);

            var agentRunnerType = this.GetAgentRunnerType(agentRunner);

            if (agentRunnerType.Contains("Current"))
            {
                await this.RunAgentAsync(agentRunner, channel, agentRunnerType, last : true);
            }
            else
            {
                await this.RunAgenthInEachSubConceptAsync(agentRunner, channel, agentRunnerType, cancellationToken);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// <see cref="IAgentRunnerService.RunAgentAsync(AgentRunner, CancellationToken)"></see>
        /// </summary>
        public async Task RunAgentAsync(AgentRunner agentRunner, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var channel = AgentRunnerHelpers.GetChannel(agentRunner);

            await this.agentRunnerProvider.InitializesAsync(channel);

            _logger.Info($"Start channel {channel}");

            await this.agentRunService.StartOnScopeAsync(agentRunner, channel, cancellationToken);

            var agentRunnerType = this.GetAgentRunnerType(agentRunner);

            if (agentRunnerType.StartsWith("Current"))
            {
                await this.RunAgentAsync(agentRunner, channel, agentRunnerType, last : true, allowSkip : false);
            }
            else
            {
                await this.RunAgenthInEachSubConceptAsync(agentRunner, channel, agentRunnerType, cancellationToken);
            }
        }