コード例 #1
0
        private static Agent CreateAgentBaseFromSettings(IRegistry registry, AgentConfig config)
        {
            string agentLogTag = $"{config.Type} Agent {config.Name}";

            if (config.Settings == null)
            {
                throw new ArgumentNullException(nameof(config.Settings), $@"{agentLogTag} hasn't got valid Settings");
            }

            if (config.Settings.Receiver?.Type == null)
            {
                throw new ArgumentNullException(nameof(config.Settings.Receiver.Type), $@"{agentLogTag} hasn't got a Receiver.Type");
            }

            if (config.Settings.Transformer?.Type == null)
            {
                throw new ArgumentNullException(nameof(config.Settings.Transformer.Type), $@"{agentLogTag} hasn't got a Transformer.Type");
            }

            if (config.Settings.StepConfiguration?.NormalPipeline != null &&
                config.Settings.StepConfiguration.NormalPipeline.Count(s => s?.Type == null) > 0)
            {
                throw new ArgumentNullException(
                          nameof(config.Settings.StepConfiguration.NormalPipeline),
                          $@"{agentLogTag} has one ore more Steps in the NormalPipeline without a Type");
            }

            if (config.Settings.StepConfiguration?.ErrorPipeline != null &&
                config.Settings.StepConfiguration.ErrorPipeline?.Count(s => s?.Type == null) > 0)
            {
                throw new ArgumentNullException(
                          nameof(config.Settings.StepConfiguration.ErrorPipeline),
                          $@"{agentLogTag} has one or more Steps in the ErrorPipeline without a Type");
            }

            IReceiver receiver =
                new ReceiverBuilder()
                .SetSettings(config.Settings.Receiver)
                .Build();

            return(new Agent(
                       config: config,
                       receiver: receiver,
                       transformerConfig: config.Settings.Transformer,
                       exceptionHandler: ExceptionHandlerRegistry.GetHandler(config.Type),
                       stepConfiguration: config.Settings.StepConfiguration ?? GetDefaultStepConfigurationForAgentType(config.Type),
                       journalLogger: new JournalDatastoreLogger(registry.CreateDatastoreContext)));
        }
コード例 #2
0
        public static IServiceCollection AddExceptionProcessor(this IServiceCollection services, Action <IExceptionHandlerRegistry> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            var exceptionHandlerRegistry = new ExceptionHandlerRegistry();

            action(exceptionHandlerRegistry);

            foreach (var registeredHandler in exceptionHandlerRegistry.RegisteredHandlers)
            {
                services.AddScoped(registeredHandler);
            }

            services.AddSingleton <IExceptionHandlerRegistry>(exceptionHandlerRegistry);
            return(services);
        }