Beispiel #1
0
        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 });
        }
Beispiel #2
0
        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 });
        }
Beispiel #3
0
        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 });
        }
Beispiel #4
0
        private void PrintRegisteredAgents()
        {
            var list = AgentProvider.LoadPackageAgents().ToList();

            if (!list.Any())
            {
                Console.WriteLine(Local.AgentsCommandNoAgents);
            }
            else
            {
                Console.PrintJustified(0, Local.AgentsCommandRegisteredAgents);
                Console.WriteLine();
                var str = new string(' ', 6);
                for (var i = 0; i < list.Count; i++)
                {
                    var agent = list[i];
                    var num2  = i + 1;
                    var str2  = new string(' ', (i >= 9 ? 1 : 2));
                    Console.WriteLine("  {0}.{1}{2} [{3}]", new object[] { num2, str2, agent.Name, agent.IsEnabled ? Local.AgentsCommandEnabled : Local.AgentsCommandDisabled });
                    Console.WriteLine("{0}{1}", new object[] { str, agent.Agent });
                }
            }
        }