<commit_before>﻿using System;
using System.Threading;
using System.Threading.Tasks;
using RawRabbit.Common;
using RawRabbit.Configuration.Queue;
using RawRabbit.Logging;

namespace RawRabbit.Pipe.Middleware
{
	public class QueueDeclareOptions
	{
		public Func<IPipeContext, QueueDeclaration> QueueDeclarationFunc { get; set; }
	}

	public class QueueDeclareMiddleware : Middleware
	{
		protected readonly Func<IPipeContext, QueueDeclaration> QueueDeclareFunc;
		protected readonly ITopologyProvider Topology;
		private readonly ILog _logger = LogProvider.For<QueueDeclareMiddleware>();

		public QueueDeclareMiddleware(ITopologyProvider topology, QueueDeclareOptions options = null )
		{
			Topology = topology;
			QueueDeclareFunc = options?.QueueDeclarationFunc ?? (context => context.GetQueueDeclaration());
		}

		public override async Task InvokeAsync(IPipeContext context, CancellationToken token)
		{
			var queue = GetQueueDeclaration(context);

			if (queue != null)
			{
				_logger.Debug("Declaring queue '{queueName}'.", queue.Name);
				await DeclareQueueAsync(queue, context, token);
			}<commit_msg>(#123) Add default value for CancellationToken arg<commit_after>﻿using System;
using System.Threading;
using System.Threading.Tasks;
using RawRabbit.Common;
using RawRabbit.Configuration.Queue;
using RawRabbit.Logging;

namespace RawRabbit.Pipe.Middleware
{
	public class QueueDeclareOptions
	{
		public Func<IPipeContext, QueueDeclaration> QueueDeclarationFunc { get; set; }
	}

	public class QueueDeclareMiddleware : Middleware
	{
		protected readonly Func<IPipeContext, QueueDeclaration> QueueDeclareFunc;
		protected readonly ITopologyProvider Topology;
		private readonly ILog _logger = LogProvider.For<QueueDeclareMiddleware>();

		public QueueDeclareMiddleware(ITopologyProvider topology, QueueDeclareOptions options = null )
		{
			Topology = topology;
			QueueDeclareFunc = options?.QueueDeclarationFunc ?? (context => context.GetQueueDeclaration());
		}

		public override async Task InvokeAsync(IPipeContext context, CancellationToken token = default (CancellationToken))
		{
			var queue = GetQueueDeclaration(context);

			if (queue != null)
			{
				_logger.Debug("Declaring queue '{queueName}'.", queue.Name);
				await DeclareQueueAsync(queue, context, token);
			}
{'fraction_non_alphanumeric': 0.08627450980392157, 'fraction_numerical': 0.00130718954248366, 'mean_word_length': 5.792899408284024, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '5827844', 'n_tokens_mistral': 713, 'n_tokens_neox': 655, 'n_words': 158}