<commit_before>using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using PlayFab.Json;

namespace PlayFab.Internal
{
    /// <summary>
    /// This is a wrapper for Http So we can better separate the functionaity of Http Requests delegated to WWW or HttpWebRequest
    /// </summary>
    public class PlayFabHttp : SingletonMonoBehaviour<PlayFabHttp>
    {
        private static IPlayFabHttp _internalHttp; //This is the default;
        public delegate void ApiProcessingEvent<in TEventArgs>(TEventArgs e);
        public delegate void ApiProcessErrorEvent(object request, PlayFabError error);
        public static event ApiProcessingEvent<ApiProcessingEventArgs> ApiProcessingEventHandler;
        public static event ApiProcessErrorEvent ApiProcessingErrorEventHandler;

        private IPlayFabTailLogger _logger; //Removed PaperTrail ( UdpPaperTrailLogger )
        private static PlayFabDataGatherer _gatherer = new PlayFabDataGatherer();

        private readonly object _logMessageLock = new object();
        private readonly Queue<string> _logMessageQueue = new Queue<string>();
        private bool _systemInfoLogged = false;

#if PLAYFAB_REQUEST_TIMING
        public struct RequestTiming
        {
            public DateTime StartTimeUtc;
            public string ApiEndpoint;
            public int WorkerRequestMs;
            public int MainThreadRequestMs;
        }

        public delegate void ApiRequestTimingEvent(RequestTiming time);
        public static event ApiRequestTimingEvent ApiRequestTimingEventHandler;
#endif

        /// <summary>
        /// Return the number of api calls that are waiting for results from the server
        /// </summary>
        /// <returns></returns>
        public static int GetPendingMessages()
        {
            return _internalHttp == null ? 0 : _internalHttp.GetPendingMessages();
        }

        /// <summary>
        /// Optional redirect to allow mocking of _internalHttp calls, or use a custom _internalHttp utility
        /// </summary>
        public static void SetHttp<THttpObject>(THttpObject httpObj) where THttpObject : IPlayFabHttp
        {
            _internalHttp = httpObj;
        }

        /// <summary>
        /// Optional redirect to allow mocking of AuthKey
        /// </summary>
        /// <param name="AuthKey"></param>
        public static void SetAuthKey(string AuthKey)
        {
            _internalHttp.AuthKey = AuthKey;
        }

        /// <summary>
        /// This initializes the GameObject and ensures it is in the scene.
        /// </summary>
        public static void InitializeHttp()
        {
            if (_internalHttp != null)
                return;

            CreateInstance(); // Invoke the SingletonMonoBehaviour
            Application.runInBackground = true; // Http requests respond even if you lose focus
#if !UNITY_WSA && !UNITY_WP8
            if (PlayFabSettings.RequestType == WebRequestType.HttpWebRequest)
                _internalHttp = new PlayFabWebRequest();
#endif
            if (_internalHttp == null)
                _internalHttp = new PlayFabWWW();

#if ENABLE_PLAYFABADMIN_API || ENABLE_PLAYFABSERVER_API
            _internalHttp.DevKey = PlayFabSettings.DeveloperSecretKey;
#endif
            _internalHttp.Awake();
        }

        /// <summary>
        /// Internal method for Make API Calls
        /// </summary>
        /// <typeparam name="TRequestType"></typeparam>
        /// <typeparam name="TResultType"></typeparam>
        /// <param name="api"></param>
        /// <param name="apiEndpoint"></param>
        /// <param name="request"></param>
        /// <param name="authType"></param>
        /// <param name="resultCallback"></param>
        /// <param name="errorCallback"></param>
        /// <param name="customData"></param>
        protected internal static void MakeApiCall<TRequestType, TResultType>(string api, string apiEndpoint,
            TRequestType request, string authType, Action<TResultType> resultCallback,
            Action<PlayFabError> errorCallback, object customData = null)
        {
            InitializeHttp();
            SendEvent(request, null, ApiProcessingEventType.Pre);
            _internalHttp.MakeApiCall(api, apiEndpoint, request, authType, resultCallback, errorCallback, customData);
        }

        /// <summary>
        /// Monobehaviour Awake Method, gathers system data
        /// </summary>
        public override void Awake()
        {
#if ENABLE_PLAYFABADMIN_API || ENABLE_PLAYFABSERVER_API
            _devKey = PlayFabSettings.DeveloperSecretKey ?? _devKey;
#endif
            _gatherer.GatherData();
            base.Awake();
        }

        /// <summary>
        /// Monobehaviour OnEnable Method, registers logger
        /// </summary>
        public void OnEnable()
        {
            StartCoroutine(RegisterLogger());
        }

        /// <summary>
        /// Monobehaviour OnDisable method, performs cleanup of Logger and bindings to Log Messages
        /// </summary>
        public void OnDisable()
        {
            if (!string.IsNullOrEmpty(PlayFabSettings.LoggerHost))
            {
                _logger = null;
#if UNITY_5
                UnityEngine.Application.logMessageReceivedThreaded -= HandleLogOutput;
#else
                UniytEngine.Application.RegisterLogCallback(null);
#endif
            }
        }

        /// <summary><commit_msg>fix for null ref on Dev Key<commit_after>using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using PlayFab.Json;

namespace PlayFab.Internal
{
    /// <summary>
    /// This is a wrapper for Http So we can better separate the functionaity of Http Requests delegated to WWW or HttpWebRequest
    /// </summary>
    public class PlayFabHttp : SingletonMonoBehaviour<PlayFabHttp>
    {
        private static IPlayFabHttp _internalHttp; //This is the default;
        public delegate void ApiProcessingEvent<in TEventArgs>(TEventArgs e);
        public delegate void ApiProcessErrorEvent(object request, PlayFabError error);
        public static event ApiProcessingEvent<ApiProcessingEventArgs> ApiProcessingEventHandler;
        public static event ApiProcessErrorEvent ApiProcessingErrorEventHandler;

        private IPlayFabTailLogger _logger; //Removed PaperTrail ( UdpPaperTrailLogger )
        private static PlayFabDataGatherer _gatherer = new PlayFabDataGatherer();

        private readonly object _logMessageLock = new object();
        private readonly Queue<string> _logMessageQueue = new Queue<string>();
        private bool _systemInfoLogged = false;

#if PLAYFAB_REQUEST_TIMING
        public struct RequestTiming
        {
            public DateTime StartTimeUtc;
            public string ApiEndpoint;
            public int WorkerRequestMs;
            public int MainThreadRequestMs;
        }

        public delegate void ApiRequestTimingEvent(RequestTiming time);
        public static event ApiRequestTimingEvent ApiRequestTimingEventHandler;
#endif

        /// <summary>
        /// Return the number of api calls that are waiting for results from the server
        /// </summary>
        /// <returns></returns>
        public static int GetPendingMessages()
        {
            return _internalHttp == null ? 0 : _internalHttp.GetPendingMessages();
        }

        /// <summary>
        /// Optional redirect to allow mocking of _internalHttp calls, or use a custom _internalHttp utility
        /// </summary>
        public static void SetHttp<THttpObject>(THttpObject httpObj) where THttpObject : IPlayFabHttp
        {
            _internalHttp = httpObj;
        }

        /// <summary>
        /// Optional redirect to allow mocking of AuthKey
        /// </summary>
        /// <param name="AuthKey"></param>
        public static void SetAuthKey(string AuthKey)
        {
            _internalHttp.AuthKey = AuthKey;
        }

        /// <summary>
        /// This initializes the GameObject and ensures it is in the scene.
        /// </summary>
        public static void InitializeHttp()
        {
            if (_internalHttp != null)
                return;

            CreateInstance(); // Invoke the SingletonMonoBehaviour
            Application.runInBackground = true; // Http requests respond even if you lose focus
#if !UNITY_WSA && !UNITY_WP8
            if (PlayFabSettings.RequestType == WebRequestType.HttpWebRequest)
                _internalHttp = new PlayFabWebRequest();
#endif
            if (_internalHttp == null)
                _internalHttp = new PlayFabWWW();

#if ENABLE_PLAYFABADMIN_API || ENABLE_PLAYFABSERVER_API
            _internalHttp.DevKey = PlayFabSettings.DeveloperSecretKey;
#endif
            _internalHttp.Awake();
        }

        /// <summary>
        /// Internal method for Make API Calls
        /// </summary>
        /// <typeparam name="TRequestType"></typeparam>
        /// <typeparam name="TResultType"></typeparam>
        /// <param name="api"></param>
        /// <param name="apiEndpoint"></param>
        /// <param name="request"></param>
        /// <param name="authType"></param>
        /// <param name="resultCallback"></param>
        /// <param name="errorCallback"></param>
        /// <param name="customData"></param>
        protected internal static void MakeApiCall<TRequestType, TResultType>(string api, string apiEndpoint,
            TRequestType request, string authType, Action<TResultType> resultCallback,
            Action<PlayFabError> errorCallback, object customData = null)
        {
            InitializeHttp();
            SendEvent(request, null, ApiProcessingEventType.Pre);
            _internalHttp.MakeApiCall(api, apiEndpoint, request, authType, resultCallback, errorCallback, customData);
        }

        /// <summary>
        /// Monobehaviour Awake Method, gathers system data
        /// </summary>
        public override void Awake()
        {
#if ENABLE_PLAYFABADMIN_API || ENABLE_PLAYFABSERVER_API
            _internalHttp.DevKey = PlayFabSettings.DeveloperSecretKey ?? _internalHttp.DevKey;
#endif
            _gatherer.GatherData();
            base.Awake();
        }

        /// <summary>
        /// Monobehaviour OnEnable Method, registers logger
        /// </summary>
        public void OnEnable()
        {
            StartCoroutine(RegisterLogger());
        }

        /// <summary>
        /// Monobehaviour OnDisable method, performs cleanup of Logger and bindings to Log Messages
        /// </summary>
        public void OnDisable()
        {
            if (!string.IsNullOrEmpty(PlayFabSettings.LoggerHost))
            {
                _logger = null;
#if UNITY_5
                UnityEngine.Application.logMessageReceivedThreaded -= HandleLogOutput;
#else
                UniytEngine.Application.RegisterLogCallback(null);
#endif
            }
        }

        /// <summary>
{'fraction_non_alphanumeric': 0.09193519024212635, 'fraction_numerical': 0.0005461496450027307, 'mean_word_length': 2.261205105372514, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2278528', 'n_tokens_mistral': 2790, 'n_tokens_neox': 2751, 'n_words': 753}