private void AddNewAgent(string name, string agent) { if (string.IsNullOrWhiteSpace(name)) { throw new CommandLineException(Local.AgentsCommandNameRequired); } if (string.Equals(name, Local.ReservedPackageNameAll)) { throw new CommandLineException(Local.AgentsCommandAllNameIsReserved); } if (string.IsNullOrWhiteSpace(agent)) { throw new CommandLineException(Local.AgentsCommandAgentRequired); } if (!Utility.IsValidAgent(agent)) { throw new CommandLineException(Local.AgentsCommandInvalidAgent); } var list = AgentProvider.LoadPackageAgents().ToList(); if (list.Any(pr => string.Equals(name, pr.Name, StringComparison.OrdinalIgnoreCase))) { throw new CommandLineException(Local.AgentsCommandUniqueName); } if (list.Any(pr => string.Equals(agent, pr.Agent, StringComparison.OrdinalIgnoreCase))) { throw new CommandLineException(Local.AgentsCommandUniqueAgent); } var item = new PackageAgent(agent, name); list.Add(item); AgentProvider.SavePackageAgents(list); Console.WriteLine(Local.AgentsCommandAgentAddedSuccessfully, new object[] { name }); }
private void EnableOrDisableAgent(string name, bool enabled) { if (string.IsNullOrWhiteSpace(name)) { throw new CommandLineException(Local.AgentsCommandNameRequired); } var agents = AgentProvider.LoadPackageAgents().ToList(); var agent = agents.Where(ps => string.Equals(name, ps.Name, StringComparison.OrdinalIgnoreCase)).ToList(); if (!agent.Any()) { throw new CommandLineException(Local.AgentsCommandNoMatchingAgentsFound, new object[] { name }); } agent.ForEach(pa => pa.IsEnabled = enabled); AgentProvider.SavePackageAgents(agents); Console.WriteLine(enabled ? Local.AgentsCommandAgentEnabledSuccessfully : Local.AgentsCommandAgentDisabledSuccessfully, new object[] { name }); }
private void RemoveAgent(string name) { if (string.IsNullOrWhiteSpace(name)) { throw new CommandLineException(Local.AgentsCommandNameRequired); } var agents = AgentProvider.LoadPackageAgents().ToList(); var list = agents.Where(pa => string.Equals(name, pa.Name, StringComparison.OrdinalIgnoreCase)).ToList(); if (!list.Any()) { throw new CommandLineException(Local.AgentsCommandNoMatchingAgentsFound, new object[] { name }); } list.ForEach(pa => agents.Remove(pa)); AgentProvider.SavePackageAgents(agents); Console.WriteLine(Local.AgentsCommandAgentRemovedSuccessfully, new object[] { name }); }