<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging;
using Nimbus.Extensions;
using Nimbus.Infrastructure;
using Nimbus.Infrastructure.Commands;
using Nimbus.Infrastructure.Events;
using Nimbus.Infrastructure.RequestResponse;
using Nimbus.InfrastructureContracts;
using Nimbus.MessageContracts;
using Nimbus.PoisonMessages;

namespace Nimbus.Configuration
{
    public class BusBuilder
    {
        public BusBuilderConfiguration Configure()
        {
            return new BusBuilderConfiguration();
        }

        internal static Bus Build(BusBuilderConfiguration configuration)
        {
            var logger = configuration.Logger;

            logger.Debug("Constructing bus...");

            var replyQueueName = string.Format("InputQueue.{0}.{1}", configuration.ApplicationName, configuration.InstanceName);

            var namespaceManager = NamespaceManager.CreateFromConnectionString(configuration.ConnectionString);
            var versionInfo = namespaceManager.GetVersionInfo();

            var messagingFactory = MessagingFactory.CreateFromConnectionString(configuration.ConnectionString);

            var messagePumps = new List<IMessagePump>();

            var queueManager = new QueueManager(namespaceManager, messagingFactory, configuration.MaxDeliveryAttempts, logger);

            var clock = new SystemClock();
            var requestResponseCorrelator = new RequestResponseCorrelator(clock);

            var messageSenderFactory = new MessageSenderFactory(messagingFactory);
            var topicClientFactory = new TopicClientFactory(messagingFactory);
            var commandSender = new BusCommandSender(messageSenderFactory, clock, configuration.CommandTypes);
            var requestSender = new BusRequestSender(messageSenderFactory, replyQueueName, requestResponseCorrelator, clock, configuration.DefaultTimeout, configuration.RequestTypes);
            var multicastRequestSender = new BusMulticastRequestSender(topicClientFactory, replyQueueName, requestResponseCorrelator, clock, configuration.MulticastEventHandlerTypes);
            var eventSender = new BusEventSender(topicClientFactory, configuration.EventTypes);

            if (configuration.Debugging.RemoveAllExistingNamespaceElements)
            {
                RemoveAllExistingNamespaceElements(namespaceManager, logger);
            }

            logger.Debug("Creating queues and topics");

            var queueCreationTasks =
                new[]
                {
                    Task.Run(() => CreateMyInputQueue(queueManager, replyQueueName, logger)),
                    Task.Run(() => CreateCommandQueues(configuration, queueManager, logger)),
                    Task.Run(() => CreateRequestQueues(configuration, queueManager, logger)),
                    Task.Run(() => CreateMulticastRequestTopics(configuration, queueManager, logger)),
                    Task.Run(() => CreateEventTopics(configuration, queueManager, logger))
                };
            Task.WaitAll(queueCreationTasks);
            logger.Debug("Queues and topics are all created.");

            logger.Debug("Creating message pumps and subscriptions.");
            var messagePumpCreationTasks =
                new[]
                {
                    Task.Run(() => CreateResponseMessagePump(configuration, messagingFactory, replyQueueName, requestResponseCorrelator, messagePumps, logger)),<commit_msg>Passed correct collection to multicast request sender<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging;
using Nimbus.Extensions;
using Nimbus.Infrastructure;
using Nimbus.Infrastructure.Commands;
using Nimbus.Infrastructure.Events;
using Nimbus.Infrastructure.RequestResponse;
using Nimbus.InfrastructureContracts;
using Nimbus.MessageContracts;
using Nimbus.PoisonMessages;

namespace Nimbus.Configuration
{
    public class BusBuilder
    {
        public BusBuilderConfiguration Configure()
        {
            return new BusBuilderConfiguration();
        }

        internal static Bus Build(BusBuilderConfiguration configuration)
        {
            var logger = configuration.Logger;

            logger.Debug("Constructing bus...");

            var replyQueueName = string.Format("InputQueue.{0}.{1}", configuration.ApplicationName, configuration.InstanceName);

            var namespaceManager = NamespaceManager.CreateFromConnectionString(configuration.ConnectionString);
            var versionInfo = namespaceManager.GetVersionInfo();

            var messagingFactory = MessagingFactory.CreateFromConnectionString(configuration.ConnectionString);

            var messagePumps = new List<IMessagePump>();

            var queueManager = new QueueManager(namespaceManager, messagingFactory, configuration.MaxDeliveryAttempts, logger);

            var clock = new SystemClock();
            var requestResponseCorrelator = new RequestResponseCorrelator(clock);

            var messageSenderFactory = new MessageSenderFactory(messagingFactory);
            var topicClientFactory = new TopicClientFactory(messagingFactory);
            var commandSender = new BusCommandSender(messageSenderFactory, clock, configuration.CommandTypes);
            var requestSender = new BusRequestSender(messageSenderFactory, replyQueueName, requestResponseCorrelator, clock, configuration.DefaultTimeout, configuration.RequestTypes);
            var multicastRequestSender = new BusMulticastRequestSender(topicClientFactory, replyQueueName, requestResponseCorrelator, clock, configuration.RequestTypes);
            var eventSender = new BusEventSender(topicClientFactory, configuration.EventTypes);

            if (configuration.Debugging.RemoveAllExistingNamespaceElements)
            {
                RemoveAllExistingNamespaceElements(namespaceManager, logger);
            }

            logger.Debug("Creating queues and topics");

            var queueCreationTasks =
                new[]
                {
                    Task.Run(() => CreateMyInputQueue(queueManager, replyQueueName, logger)),
                    Task.Run(() => CreateCommandQueues(configuration, queueManager, logger)),
                    Task.Run(() => CreateRequestQueues(configuration, queueManager, logger)),
                    Task.Run(() => CreateMulticastRequestTopics(configuration, queueManager, logger)),
                    Task.Run(() => CreateEventTopics(configuration, queueManager, logger))
                };
            Task.WaitAll(queueCreationTasks);
            logger.Debug("Queues and topics are all created.");

            logger.Debug("Creating message pumps and subscriptions.");
            var messagePumpCreationTasks =
                new[]
                {
                    Task.Run(() => CreateResponseMessagePump(configuration, messagingFactory, replyQueueName, requestResponseCorrelator, messagePumps, logger)),
{'fraction_non_alphanumeric': 0.07791842475386779, 'fraction_numerical': 0.0005625879043600563, 'mean_word_length': 3.1755725190839694, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4137675', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1546, 'n_words': 347}