private void CreateAgents() { try { using (IAgentManager agentManager = _serviceFactory.CreateProxy <IAgentManager>()) { AgentUtilities.IAgentHelper agentHelper = new AgentHelper( agentManager: agentManager, sqlDatabaseServerName: TestConstants.InstanceDetails.SQL_SERVER_NAME, sqlDatabaseName: TestConstants.InstanceDetails.SQL_DATABASE_NAME, sqlUsername: TestConstants.InstanceDetails.SQL_USERNAME, sqlPassword: TestConstants.InstanceDetails.SQL_PASSWORD); // Check if Agent exists in the instance int agentArtifactTypeId = agentHelper.GetAgentArtifactTypeIdByNameAsync(Helpers.Constants.Names.AGENT_INSTANCE_METRICS_CALCULATOR).Result; int agentServerArtifactId = agentHelper.GetAgentServerByResourceServerTypeAsync("Agent").Result; List <Agent> agentList = agentHelper.GetAgentByNameAsync(Helpers.Constants.Names.AGENT_INSTANCE_METRICS_CALCULATOR).Result; if (agentList.Count == 0) { //Create Agent Console.WriteLine("Creating Agent."); int newAgentArtifactId = agentHelper.CreateAgentAsync( agentName: Helpers.Constants.Names.AGENT_INSTANCE_METRICS_CALCULATOR, agentTypeId: agentArtifactTypeId, agentServer: agentServerArtifactId, enableAgent: TestConstants.ENABLE_AGENT, agentInterval: TestConstants.AGENT_INTERVAL, agentLoggingLevel: TestConstants.AGENT_LOGGING_LEVEL).Result; Console.WriteLine($"Agent Created. {nameof(newAgentArtifactId)} = {newAgentArtifactId}"); } else { Console.WriteLine("Agent exists in the Instance. Skipped creation."); } } } catch (Exception ex) { throw new Exception("An error encountered while creating Agents.", ex); } }