SetAgentAuthorizationAsync() public method

public SetAgentAuthorizationAsync ( int agentId, bool authorized ) : System.Threading.Tasks.Task
agentId int
authorized bool
return System.Threading.Tasks.Task
コード例 #1
0
        private static async Task <Agent> PrepareAgentAsync(Options options, TeamCityClient client)
        {
            Agent agent = null;

            while (agent == null)
            {
                Console.WriteLine("Ensuring the agent is connected and has been authorized. Fetching the list of agents...");
                var agents = await client.GetAgentsAsync();

                agent = agents.FirstOrDefault(x => string.Equals(
                                                  x.Name,
                                                  options.AgentName,
                                                  StringComparison.OrdinalIgnoreCase));

                if (agent == null)
                {
                    Console.WriteLine($"Agent '{options.AgentName}' does not appear in the list. Waiting {WaitDuration.TotalSeconds} seconds...");
                }
                else if (!agent.Connected)
                {
                    Console.WriteLine($"Agent '{agent.Name}' is not yet connected. Waiting {WaitDuration.TotalSeconds} seconds...");
                    agent = null;
                }
                else if (agent.Enabled != options.AgentEnabled)
                {
                    Console.WriteLine($"The agent '{agent.Name}' does not have the proper enabled status '{options.AgentEnabled}'. Changing...");
                    await client.SetAgentEnabledAsync(agent.Id, options.AgentEnabled);

                    Console.WriteLine($"Waiting {WaitDuration.TotalSeconds} seconds...");
                    agent = null;
                }
                else if (!agent.Authorized)
                {
                    Console.WriteLine($"The agent '{agent.Name}' is not yet authorized. Authorizing...");
                    await client.SetAgentAuthorizationAsync(agent.Id, true);

                    Console.WriteLine($"Waiting {WaitDuration.TotalSeconds} seconds...");
                    agent = null;
                }

                if (agent == null)
                {
                    await Task.Delay(WaitDuration);
                }
            }

            return(agent);
        }
コード例 #2
0
ファイル: Application.cs プロジェクト: NuGet/Entropy
        private static async Task<Agent> PrepareAgentAsync(Options options, TeamCityClient client)
        {
            Agent agent = null;

            while (agent == null)
            {
                Console.WriteLine("Ensuring the agent is connected and has been authorized. Fetching the list of agents...");
                var agents = await client.GetAgentsAsync();
                agent = agents.FirstOrDefault(x => string.Equals(
                    x.Name,
                    options.AgentName,
                    StringComparison.OrdinalIgnoreCase));

                if (agent == null)
                {
                    Console.WriteLine($"Agent '{options.AgentName}' does not appear in the list. Waiting {WaitDuration.TotalSeconds} seconds...");
                }
                else if (!agent.Connected)
                {
                    Console.WriteLine($"Agent '{agent.Name}' is not yet connected. Waiting {WaitDuration.TotalSeconds} seconds...");
                    agent = null;
                }
                else if (agent.Enabled != options.AgentEnabled)
                {
                    Console.WriteLine($"The agent '{agent.Name}' does not have the proper enabled status '{options.AgentEnabled}'. Changing...");
                    await client.SetAgentEnabledAsync(agent.Id, options.AgentEnabled);
                    Console.WriteLine($"Waiting {WaitDuration.TotalSeconds} seconds...");
                    agent = null;
                }
                else if (!agent.Authorized)
                {
                    Console.WriteLine($"The agent '{agent.Name}' is not yet authorized. Authorizing...");
                    await client.SetAgentAuthorizationAsync(agent.Id, true);
                    Console.WriteLine($"Waiting {WaitDuration.TotalSeconds} seconds...");
                    agent = null;
                }

                if (agent == null)
                {
                    await Task.Delay(WaitDuration);
                }
            }

            return agent;
        }