コード例 #1
0
        public void Correctly_executes_service_agents()
        {
            MockRepository mocks = new MockRepository();

            IApplicationSettings settings      = mocks.CreateMock <IApplicationSettings>();
            ITypeActivator       activator     = mocks.CreateMock <ITypeActivator>();
            IServiceAgentFactory factory       = mocks.CreateMock <IServiceAgentFactory>();
            IServiceAgent        serviceAgent1 = mocks.CreateMock <IServiceAgent>();
            IServiceAgent        serviceAgent2 = mocks.CreateMock <IServiceAgent>();

            IServiceAgent[] serviceAgents = new IServiceAgent[] { serviceAgent1, serviceAgent2 };

            IServiceAgentAggregator aggregator = new ServiceAgentAggregator(settings, activator);

            using (mocks.Record())
            {
                Expect.Call(settings.GetServiceAgentFactory()).Return("serviceAgentType");
                Expect.Call(activator.ActivateType <IServiceAgentFactory>("serviceAgentType")).Return(factory);
                Expect.Call(factory.GetServiceAgents()).Return(serviceAgents);

                Expect.Call(serviceAgent1.AgentName).Return("FirstAgent").Repeat.Any();
                serviceAgent1.Run();

                Expect.Call(serviceAgent2.AgentName).Return("SecondAgent").Repeat.Any();
                serviceAgent2.Run();
            }

            using (mocks.Playback())
            {
                aggregator.ExecuteServiceAgentCycle();
            }

            mocks.VerifyAll();
        }
コード例 #2
0
        public void Activates_type_from_descriptor()
        {
            ITypeActivator typeActivator = ObjectFactory.GetInstance <ITypeActivator>();

            IResourceFileLocator locator = typeActivator.ActivateType <IResourceFileLocator>(
                "Tarantino.Core.Commons.Services.Environment.Impl.ResourceFileLocator, Tarantino.Core");

            Assert.That(locator, Is.Not.Null);
        }
コード例 #3
0
        public void ExecuteServiceAgentCycle()
        {
            string factoryType           = _settings.GetServiceAgentFactory();
            IServiceAgentFactory factory = _activator.ActivateType <IServiceAgentFactory>(factoryType);

            foreach (IServiceAgent agent in factory.GetServiceAgents())
            {
                try
                {
                    Logger.Debug(this, string.Format("Executing agent: {0}", agent.AgentName));
                    agent.Run();
                    Logger.Debug(this, string.Format("Agent execution completed: {0}", agent.AgentName));
                }
                catch (Exception ex)
                {
                    Logger.Error(this, ex.Message, ex);
                }
            }
        }
コード例 #4
0
        public void Should_continue_with_next_agents_event_if_one_agent_fails()
        {
            ApplicationException exception = new ApplicationException("Test Exception");

            MockRepository mocks = new MockRepository();

            IApplicationSettings settings  = mocks.CreateMock <IApplicationSettings>();
            ITypeActivator       activator = mocks.CreateMock <ITypeActivator>();
            IServiceAgentFactory factory   = mocks.CreateMock <IServiceAgentFactory>();

            IServiceAgent serviceAgent1 = mocks.CreateMock <IServiceAgent>();
            IServiceAgent serviceAgent2 = mocks.CreateMock <IServiceAgent>();

            IServiceAgent[] serviceAgents = new IServiceAgent[] { serviceAgent1, serviceAgent2 };


            IServiceAgentAggregator aggregator = new ServiceAgentAggregator(settings, activator);

            using (mocks.Record())
            {
                Expect.Call(settings.GetServiceAgentFactory()).Return("serviceAgentType");
                Expect.Call(activator.ActivateType <IServiceAgentFactory>("serviceAgentType")).Return(factory);
                Expect.Call(factory.GetServiceAgents()).Return(serviceAgents);

                Expect.Call(serviceAgent1.AgentName).Return("FirstAgent").Repeat.Any();
                serviceAgent1.Run();
                LastCall.On(serviceAgent1).Throw(exception);

                Expect.Call(serviceAgent2.AgentName).Return("SecondAgent").Repeat.Any();
                serviceAgent2.Run();
            }

            using (mocks.Playback())
            {
                aggregator.ExecuteServiceAgentCycle();
            }

            mocks.VerifyAll();
        }
コード例 #5
0
        public async Task <IActionResult> Run(
            [HttpTrigger(
                 "post",
                 Route = Routes.ExportKontent
                 )] ExportKontentRequest exportKontentRequest
            )
        {
            try
            {
                var(kml, managementApiKey, mode) = exportKontentRequest;

                kontentStore.Configure(managementApiKey);
                kmlParser.Options.Mode = mode;

                var parsedKml = kmlParser.ParseKml(kml);

                var globalGuid            = Guid.NewGuid();
                var activatedTypes        = new Dictionary <string, ContentType>();
                var activatedTypeSnippets = new Dictionary <string, ContentType>();

                foreach (var typeDescription in parsedKml.TypeDescriptions)
                {
                    var contentType = typeActivator.ActivateType(typeDescription, globalGuid);

                    if (contentType.External_id is null)
                    {
                        throw new ArgumentNullException(nameof(contentType.External_id));
                    }

                    activatedTypes.Add(contentType.External_id, contentType);
                }

                foreach (var typeDescription in parsedKml.SnippetTypeDescriptions)
                {
                    var contentType = typeActivator.ActivateTypeSnippet(typeDescription, globalGuid);

                    if (contentType.External_id is null)
                    {
                        throw new ArgumentNullException(nameof(contentType.External_id));
                    }

                    activatedTypeSnippets.Add(contentType.External_id, contentType);
                }

                foreach (var activatedTypeSnippet in activatedTypeSnippets)
                {
                    await kontentStore.AddContentTypeSnippet(activatedTypeSnippet.Value);
                }

                foreach (var activatedType in activatedTypes)
                {
                    await kontentStore.AddContentType(activatedType.Value);
                }

                return(LogOk());
            }
            catch (Exception ex)
            {
                return(LogException(ex));
            }
        }