<commit_before>﻿using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

using Tgstation.Server.Host.Components.StaticFiles;
using Tgstation.Server.Host.Components.Watchdog;

namespace Tgstation.Server.Host.Components.Events
{
	/// <inheritdoc />
	sealed class EventConsumer : IEventConsumer
	{
		/// <summary>
		/// The <see cref="IConfiguration"/> for the <see cref="EventConsumer"/>.
		/// </summary>
		readonly IConfiguration configuration;

		/// <summary>
		/// The <see cref="IWatchdog"/> for the <see cref="EventConsumer"/>.
		/// </summary>
		IWatchdog watchdog;

		/// <summary>
		/// Initializes a new instance of the <see cref="EventConsumer"/> class.
		/// </summary>
		/// <param name="configuration">The value of <see cref="configuration"/>.</param>
		public EventConsumer(IConfiguration configuration)
		{
			this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
		}

		/// <inheritdoc />
		public async Task HandleEvent(EventType eventType, IEnumerable<string> parameters, CancellationToken cancellationToken)
		{
			if (parameters == null)
				throw new ArgumentNullException(nameof(parameters));

			if (watchdog == null)
				throw new InvalidOperationException("EventConsumer used without watchdog set!");

			await configuration.HandleEvent(eventType, parameters, cancellationToken).ConfigureAwait(false);
			await watchdog.HandleEvent(eventType, parameters, cancellationToken).ConfigureAwait(false);
		}

		/// <summary>
		/// Set the <paramref name="watchdog"/> for the <see cref="EventConsumer"/>.
		/// </summary>
		/// <param name="watchdog">The value of <see cref="watchdog"/>.</param>
		public void SetWatchdog(IWatchdog watchdog)
		{
#pragma warning disable IDE0016 // Use 'throw' expression
			if (watchdog == null)
				throw new ArgumentNullException(nameof(watchdog));
#pragma warning restore IDE0016 // Use 'throw' expression
			if (this.watchdog != null)
				throw new InvalidOperationException("watchdog already set!");
			this.watchdog = watchdog;
		}
	}
}<commit_msg>Event scripts and DMAPI events run in parallel<commit_after>﻿using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

using Tgstation.Server.Host.Components.StaticFiles;
using Tgstation.Server.Host.Components.Watchdog;

namespace Tgstation.Server.Host.Components.Events
{
	/// <inheritdoc />
	sealed class EventConsumer : IEventConsumer
	{
		/// <summary>
		/// The <see cref="IConfiguration"/> for the <see cref="EventConsumer"/>.
		/// </summary>
		readonly IConfiguration configuration;

		/// <summary>
		/// The <see cref="IWatchdog"/> for the <see cref="EventConsumer"/>.
		/// </summary>
		IWatchdog watchdog;

		/// <summary>
		/// Initializes a new instance of the <see cref="EventConsumer"/> class.
		/// </summary>
		/// <param name="configuration">The value of <see cref="configuration"/>.</param>
		public EventConsumer(IConfiguration configuration)
		{
			this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
		}

		/// <inheritdoc />
		public async Task HandleEvent(EventType eventType, IEnumerable<string> parameters, CancellationToken cancellationToken)
		{
			if (parameters == null)
				throw new ArgumentNullException(nameof(parameters));

			if (watchdog == null)
				throw new InvalidOperationException("EventConsumer used without watchdog set!");

			var scriptTask = configuration.HandleEvent(eventType, parameters, cancellationToken);
			await watchdog.HandleEvent(eventType, parameters, cancellationToken).ConfigureAwait(false);
			await scriptTask.ConfigureAwait(false);
		}

		/// <summary>
		/// Set the <paramref name="watchdog"/> for the <see cref="EventConsumer"/>.
		/// </summary>
		/// <param name="watchdog">The value of <see cref="watchdog"/>.</param>
		public void SetWatchdog(IWatchdog watchdog)
		{
#pragma warning disable IDE0016 // Use 'throw' expression
			if (watchdog == null)
				throw new ArgumentNullException(nameof(watchdog));
#pragma warning restore IDE0016 // Use 'throw' expression
			if (this.watchdog != null)
				throw new InvalidOperationException("watchdog already set!");
			this.watchdog = watchdog;
		}
	}
}
{'fraction_non_alphanumeric': 0.13191990577149587, 'fraction_numerical': 0.003769140164899882, 'mean_word_length': 4.327478042659975, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, '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': '13463', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1158, 'n_words': 312}