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
        /// <summary>
        /// Create an <see cref="Kernel" /> instance from a given settings file name.
        /// </summary>
        /// <param name="settings">The file name in the '.\config\' folder of the settings to use during the initialization (default: 'settings.xml').</param>
        /// <returns></returns>
        public static Kernel CreateFromSettings(string settings = @"config\settings.xml")
        {
            if (string.IsNullOrWhiteSpace(settings))
            {
                throw new ArgumentException(
                          @"Settings file name cannot be null or whitespace (default: 'settings.xml').",
                          nameof(settings));
            }

            Config   config   = Config.Instance;
            Registry registry = Registry.Instance;

            config.Initialize(settings);
            if (!config.IsInitialized)
            {
                throw new InvalidOperationException(
                          "Cannot create Kernel: couldn't correctly initialize the configuration");
            }

            registry.Initialize(config);
            if (!registry.IsInitialized)
            {
                throw new InvalidOperationException(
                          "Cannot create Kernel: couldn't correctly initialize the registry");
            }

            var agentProvider = AgentProvider.BuildFromConfig(config, registry);

            return(new Kernel(agentProvider.GetAgents(), config));
        }
Beispiel #3
0
 public ConsulClientV1(Polymath polymath)
 {
     ACL         = new ACLProvider(polymath);
     Agent       = new AgentProvider(polymath);
     Event       = new EventProvider(polymath);
     KeyValue    = new KeyValueProvider(polymath);
     Session     = new SessionProvider(polymath);
     Snapshot    = new SnapshotProvider(polymath);
     Status      = new StatusProvider(polymath);
     Transaction = new TransactionProvider(polymath);
 }
Beispiel #4
0
        public IActionResult GetDefaultAgentTransformer(AgentType agentType)
        {
            var transformerEntry      = AgentProvider.GetDefaultTransformerForAgentType(agentType);
            var availableTransformers = transformerEntry.OtherTransformers.Concat(new[] { transformerEntry.DefaultTransformer });
            var types = runtimeLoader.Transformers.Where(t => availableTransformers.Any(x => x.Type == t.TechnicalName));

            return(new OkObjectResult(new
            {
                DefaultTransformer = types.First(t => t.TechnicalName == transformerEntry.DefaultTransformer.Type),
                OtherTransformers = types.Where(t => t.TechnicalName != transformerEntry.DefaultTransformer.Type)
            }));
        }
Beispiel #5
0
        public IActionResult GetDefaultAgentSteps(AgentType agentType)
        {
            var steps = AgentProvider.GetDefaultStepConfigurationForAgentType(agentType);

            IEnumerable <ItemType> FilterStepsFor(IEnumerable <Step> xs)
            => xs.Select(x => runtimeLoader.Steps.First(s => s.TechnicalName == x.Type));

            return(new OkObjectResult(new
            {
                NormalPipeline = FilterStepsFor(steps.NormalPipeline),
                ErrorPipeline = FilterStepsFor(steps.ErrorPipeline ?? Enumerable.Empty <Step>())
            }));
        }
        public void ThrowsExceptionWhenBuildingAgents()
        {
            // Arrange
            var expected     = new Exception("ignored string");
            var stubRegistry = new Mock <IRegistry>();

            stubRegistry.SetupGet(r => r.IsInitialized)
            .Returns(true);

            // Act / Assert
            var actual = Assert.Throws <Exception>(
                () => AgentProvider.BuildFromConfig(new SaboteurAgentConfig(expected), stubRegistry.Object));

            Assert.Equal(expected, actual);
        }
Beispiel #7
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 #8
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 });
        }
        public Property Default_Transformers_Are_Serializable(AgentType type)
        {
            // Arrange
            TransformerConfigEntry expected = AgentProvider.GetDefaultTransformerForAgentType(type);
            string json = JsonConvert.SerializeObject(expected);

            // Act
            var actual = JsonConvert.DeserializeObject <TransformerConfigEntry>(json);

            // Assert
            bool sameDefault = expected.DefaultTransformer.Type == actual.DefaultTransformer.Type;
            bool sameOthers  = expected.OtherTransformers
                               .Zip(actual.OtherTransformers, (t1, t2) => t1.Type == t2.Type)
                               .All(x => x);

            return(sameDefault.ToProperty().And(sameOthers));
        }
        public void AssembleAgentBaseClasses_IfTypeIsSpecified()
        {
            // Arrange
            // Minder agents are being created and uses the registry
            Registry.Instance.Initialize(StubConfig.Default);
            var stubRegistry = new Mock <IRegistry>();

            stubRegistry.SetupGet(r => r.IsInitialized)
            .Returns(true);
            stubRegistry.SetupGet(r => r.CreateDatastoreContext)
            .Returns(() => (DatastoreContext)null);

            var sut = AgentProvider.BuildFromConfig(new SingleAgentConfig(), stubRegistry.Object);

            // Act
            IEnumerable <IAgent> agents = sut.GetAgents();

            // Assert
            Assert.NotEmpty(agents);
        }
Beispiel #11
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 });
                }
            }
        }
Beispiel #12
0
 public IActionResult GetDefaultAgentReceiver(AgentType agentType)
 {
     return(new OkObjectResult(AgentProvider.GetDefaultReceiverForAgentType(agentType)));
 }
Beispiel #13
0
 public AgentBusiness()
 {
     AgentProvider = new AgentProvider();
 }
 public void RegistryContainsDefaultTransformerForAllAgentTypes()
 {
     Assert.All(
         Enum.GetValues(typeof(AgentType)).Cast <AgentType>(),
         t => Assert.NotNull(AgentProvider.GetDefaultTransformerForAgentType(t)));
 }
 public void RegistryContainsDefaultConfigurationForAllAgentTypes()
 {
     Assert.All(
         Enum.GetValues(typeof(AgentType)).Cast <AgentType>(),
         t => Assert.NotNull(AgentProvider.GetDefaultStepConfigurationForAgentType(t)));
 }