<commit_before>using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using GoCardless.Errors;
using GoCardless.Exceptions;
using GoCardless.Internals;
using GoCardless.Resources;
using GoCardless.Services;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using JsonSerializerSettings = GoCardless.Internals.JsonSerializerSettings;

namespace GoCardless
{

    /// <summary>
    ///Entry point into the client.
    /// </summary>
    public partial class GoCardlessClient
    {
        /// <summary>
        /// This is the singleton HttpClient used if none is passed in via the .Create factory methods.
        /// See https://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.110).aspx#Anchor_5
        /// </summary>
        public static HttpClient DefaultHttpClient { get; set; } = new HttpClient();

        public static ushort DefaultNumberOfRetriesOnTimeout { get; set; } = 2;
        public static TimeSpan DefaultWaitBetweenRetries { get; set; } = TimeSpan.FromSeconds(0.5d);

        private readonly HttpClient _httpClient;
        private readonly string _accessToken;
        private readonly Uri _baseUrl;

        private GoCardlessClient(string accessToken, string baseUrl, HttpClient httpClient)
        {
            this._httpClient = httpClient ?? DefaultHttpClient;
            _accessToken = accessToken;
            _baseUrl = new Uri(baseUrl, UriKind.Absolute);
        }


        /// <summary>
        ///Available environments for this client.
        /// </summary>
        public enum Environment
        {
            /// <summary>
            ///Live environment (base URL https://api.gocardless.com).
            /// </summary>
            LIVE,

            /// <summary>
            ///Sandbox environment (base URL https://api-sandbox.gocardless.com).
            /// </summary>
            SANDBOX

        }

        /// <summary>
        ///Creates an instance of the client in the live environment.
        ///
        ///@param accessToken the access token
        /// </summary>
        public static GoCardlessClient Create(String accessToken)
        {
            return Create(accessToken, Environment.LIVE);
        }

        /// <summary>
        ///Creates an instance of the client in a specified environment.
        ///
        ///@param accessToken the access token
        ///@param environment the environment
        /// </summary>
        public static GoCardlessClient Create(String accessToken, Environment environment, HttpClient httpClient = null)
        {
            return Create(accessToken, GetBaseUrl(environment), httpClient);
        }

        /// <summary>
        ///Creates an instance of the client running against a custom URL.
        ///
        ///@param accessToken the access token
        ///@param baseUrl the base URL of the API
        /// </summary>
        public static GoCardlessClient Create(string accessToken, string baseUrl, HttpClient client = null)
        {
            return new GoCardlessClient(accessToken, baseUrl, client);
        }

        private static String GetBaseUrl(Environment env)
        {
            switch (env)
            {
                case Environment.LIVE:
                    return "https://api.gocardless.com";
                case Environment.SANDBOX:
                    return "https://api-sandbox.gocardless.com";
            }
            throw new ArgumentException("Unknown environment:" + env);
        }

        internal async Task<T> ExecuteAsync<T>(string method, string path, List<KeyValuePair<string, object>> urlParams,
            object requestParams, Func<string, Task<T>> fetchById, string payloadKey,
            RequestSettings requestSettings)
            where T : ApiResponse
        {
            var numberOfRetries = requestSettings?.NumberOfRetriesOnTimeout ?? DefaultNumberOfRetriesOnTimeout;
            var waitBetweenRetries = requestSettings?.WaitBetweenRetries ?? DefaultWaitBetweenRetries;
            Func<Task<T>> execute = async () =>
            {
                try
                {
                    return await ExecuteAsyncInner<T>(method, path, urlParams, requestParams, payloadKey,
                            requestSettings)
                        .ConfigureAwait(false);
                }
                catch (InvalidStateException ex)
                    when (ex.Errors.FirstOrDefault()?.Reason == "idempotent_creation_conflict" &&
                          ex.Errors.First().Links?.ContainsKey("conflicting_resource_id") == true)
                {
                    var conflictingResourceId = ex.Errors.First().Links.FirstOrDefault().Key;
                    return await fetchById(conflictingResourceId)
                        .ConfigureAwait(false);
                }
            };
            for (var i = 0; i < numberOfRetries; i++)
            {
                try<commit_msg>Crankshaft[BU00000451XEMW] .NET client @ 2017-07-06 16:44:31 UTC<commit_after>using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using GoCardless.Errors;
using GoCardless.Exceptions;
using GoCardless.Internals;
using GoCardless.Resources;
using GoCardless.Services;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using JsonSerializerSettings = GoCardless.Internals.JsonSerializerSettings;

namespace GoCardless
{

    /// <summary>
    ///Entry point into the client.
    /// </summary>
    public partial class GoCardlessClient
    {
        /// <summary>
        /// This is the singleton HttpClient used if none is passed in via the .Create factory methods.
        /// See https://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.110).aspx#Anchor_5
        /// </summary>
        public static HttpClient DefaultHttpClient { get; set; } = new HttpClient();

        public static ushort DefaultNumberOfRetriesOnTimeout { get; set; } = 2;
        public static TimeSpan DefaultWaitBetweenRetries { get; set; } = TimeSpan.FromSeconds(0.5d);

        private readonly HttpClient _httpClient;
        private readonly string _accessToken;
        private readonly Uri _baseUrl;

        private GoCardlessClient(string accessToken, string baseUrl, HttpClient httpClient)
        {
            this._httpClient = httpClient ?? DefaultHttpClient;
            _accessToken = accessToken;
            _baseUrl = new Uri(baseUrl, UriKind.Absolute);
        }


        /// <summary>
        ///Available environments for this client.
        /// </summary>
        public enum Environment
        {
            /// <summary>
            ///Live environment (base URL https://api.gocardless.com).
            /// </summary>
            LIVE,

            /// <summary>
            ///Sandbox environment (base URL https://api-sandbox.gocardless.com).
            /// </summary>
            SANDBOX

        }

        /// <summary>
        ///Creates an instance of the client in the live environment.
        ///
        ///@param accessToken the access token
        /// </summary>
        public static GoCardlessClient Create(String accessToken)
        {
            return Create(accessToken, Environment.LIVE);
        }

        /// <summary>
        ///Creates an instance of the client in a specified environment.
        ///
        ///@param accessToken the access token
        ///@param environment the environment
        /// </summary>
        public static GoCardlessClient Create(String accessToken, Environment environment, HttpClient httpClient = null)
        {
            return Create(accessToken, GetBaseUrl(environment), httpClient);
        }

        /// <summary>
        ///Creates an instance of the client running against a custom URL.
        ///
        ///@param accessToken the access token
        ///@param baseUrl the base URL of the API
        /// </summary>
        public static GoCardlessClient Create(string accessToken, string baseUrl, HttpClient client = null)
        {
            return new GoCardlessClient(accessToken, baseUrl, client);
        }

        private static String GetBaseUrl(Environment env)
        {
            switch (env)
            {
                case Environment.LIVE:
                    return "https://api.gocardless.com";
                case Environment.SANDBOX:
                    return "https://api-sandbox.gocardless.com";
            }
            throw new ArgumentException("Unknown environment:" + env);
        }

        internal async Task<T> ExecuteAsync<T>(string method, string path, List<KeyValuePair<string, object>> urlParams,
            object requestParams, Func<string, Task<T>> fetchById, string payloadKey,
            RequestSettings requestSettings)
            where T : ApiResponse
        {
            var numberOfRetries = requestSettings?.NumberOfRetriesOnTimeout ?? DefaultNumberOfRetriesOnTimeout;
            var waitBetweenRetries = requestSettings?.WaitBetweenRetries ?? DefaultWaitBetweenRetries;
            Func<Task<T>> execute = async () =>
            {
                try
                {
                    return await ExecuteAsyncInner<T>(method, path, urlParams, requestParams, payloadKey,
                            requestSettings)
                        .ConfigureAwait(false);
                }
                catch (InvalidStateException ex)
                    when (ex.Errors.FirstOrDefault()?.Reason == "idempotent_creation_conflict" &&
                          ex.Errors.First().Links?.ContainsKey("conflicting_resource_id") == true)
                {
                    var conflictingResourceId = ex.Errors.First().Links.FirstOrDefault().Value;
                    return await fetchById(conflictingResourceId)
                        .ConfigureAwait(false);
                }
            };
            for (var i = 0; i < numberOfRetries; i++)
            {
                try
{'fraction_non_alphanumeric': 0.09345429714174226, 'fraction_numerical': 0.0037069554189835137, 'mean_word_length': 1.9375358166189112, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, 'https://': 10, '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': '7124453', 'n_tokens_mistral': 2599, 'n_tokens_neox': 2480, 'n_words': 674}