<commit_before>using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace DD.CloudControl.Client
{
	using Models.Network;
	using Models.Server;

	/// <summary>
	/// 	Extension methods for <see cref="CloudControlClient"/>.
	/// </summary>
	public static class CloudControlClientExtensions
	{
		/// <summary>
		/// 	Retrieve a the first matching network domain by name and datacenter.
		/// </summary>
		/// <param name="client">
		/// 	The CloudControl API client.
		/// </param>
		/// <param name="name">
		/// 	The name of the network domain to retrieve.
		/// </param>
		/// <param name="datacenterId">
		/// 	The Id of the datacenter containing the network domain to retrieve.
		/// </param>
		/// <param name="cancellationToken">
		/// 	An optional cancellation token that can be used to cancel the request.
		/// </param>
		/// <returns>
		/// 	A <see cref="NetworkDomain"/> representing the network domain, or <c>null</c> if no network domain was found with the specified Id.
		/// </returns>
		public static async Task<NetworkDomain> GetNetworkDomainByName(this CloudControlClient client, string name, string datacenterId, CancellationToken cancellationToken = default(CancellationToken))
		{
			if (client == null)
				throw new ArgumentNullException(nameof(client));

			NetworkDomainQuery query = NetworkDomainQuery.ByNameAndDatacenter(name, datacenterId);
			NetworkDomains matchingNetworkDomains = await client.ListNetworkDomains(query, cancellationToken: cancellationToken);

			return matchingNetworkDomains.Items.FirstOrDefault();
		}

		/// <summary>
		/// 	Retrieve a list of servers in the specified network domain.
		/// </summary><commit_msg>Add convenience overload for listing network domains by datacenter.<commit_after>using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace DD.CloudControl.Client
{
	using Models.Network;
	using Models.Server;

	/// <summary>
	/// 	Extension methods for <see cref="CloudControlClient"/>.
	/// </summary>
	public static class CloudControlClientExtensions
	{
		/// <summary>
		/// 	List network domains in the specified datacenter.
		/// </summary>
		/// <param name="client">
		/// 	The CloudControl API client.
		/// </param>
		/// <param name="datacenterId">
		/// 	The Id of the datacenter containing the network domain to retrieve.
		/// </param>
		/// <param name="paging">
		/// 	An optional <see cref="Paging"/> configuration for the results.
		/// </param>
		/// <param name="cancellationToken">
		/// 	An optional cancellation token that can be used to cancel the request.
		/// </param>
		/// <returns>
		/// 	The network domains (as <see cref="NetworkDomains"/>).
		/// </returns>
		public static Task<NetworkDomains> ListNetworkDomains(this CloudControlClient client, string datacenterId, Paging paging, CancellationToken cancellationToken = default(CancellationToken))
		{
			if (client == null)
				throw new ArgumentNullException(nameof(client));
			
			NetworkDomainQuery query = NetworkDomainQuery.ByDatacenter(datacenterId);

			return client.ListNetworkDomains(query, paging, cancellationToken);
		}

		/// <summary>
		/// 	Retrieve the first network domain in the specified datacenter with the specified name.
		/// </summary>
		/// <param name="client">
		/// 	The CloudControl API client.
		/// </param>
		/// <param name="name">
		/// 	The name of the network domain to retrieve.
		/// </param>
		/// <param name="datacenterId">
		/// 	The Id of the datacenter containing the network domain to retrieve.
		/// </param>
		/// <param name="cancellationToken">
		/// 	An optional cancellation token that can be used to cancel the request.
		/// </param>
		/// <returns>
		/// 	A <see cref="NetworkDomain"/> representing the network domain, or <c>null</c> if no network domain was found with the specified Id.
		/// </returns>
		public static async Task<NetworkDomain> GetNetworkDomainByName(this CloudControlClient client, string name, string datacenterId, CancellationToken cancellationToken = default(CancellationToken))
		{
			if (client == null)
				throw new ArgumentNullException(nameof(client));

			NetworkDomainQuery query = NetworkDomainQuery.ByNameAndDatacenter(name, datacenterId);
			NetworkDomains matchingNetworkDomains = await client.ListNetworkDomains(query, cancellationToken: cancellationToken);

			return matchingNetworkDomains.Items.FirstOrDefault();
		}

		/// <summary>
		/// 	Retrieve a list of servers in the specified network domain.
		/// </summary>
{'fraction_non_alphanumeric': 0.12455908289241623, 'fraction_numerical': 0.0, 'mean_word_length': 3.5460921843687374, 'pattern_counts': {'":': 0, '<': 60, '<?xml version=': 0, '>': 60, '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': '2650228', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1266, 'n_words': 399}