<commit_before>using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using Mindscape.Raygun4Net.Messages;

using System.Threading;
using System.Reflection;
using Android.Content;
using Android.Views;
using Android.Runtime;
using Android.App;
using Android.Net;
using Java.IO;
using Android.OS;
using System.Text;
using System.Threading.Tasks;
using Android.Bluetooth;
using Android.Provider;
using Android.Content.PM;

namespace Mindscape.Raygun4Net
{
  public class RaygunClient : RaygunClientBase
  {
    private const string RaygunSharedPrefsFile = "io.raygun.pref";
    private const string RaygunUserIdentifierDefaultsKey = "io.raygun.identifier";

    private static RaygunClient _client;
    private readonly string _apiKey;
    private readonly List<Type> _wrapperExceptions = new List<Type>();

    private string _user;
    private RaygunIdentifierMessage _userInfo;
    private string _sessionId;
    private PulseEventBatch _activeBatch;
    private static readonly object _batchLock = new object();

    /// <summary>
    /// Gets the <see cref="RaygunClient"/> created by the Attach method.
    /// </summary>
    public static RaygunClient Current
    {
      get { return _client; }
    }

    internal static Context Context
    {
      get { return Application.Context; }
    }

    private string DeviceId
    {
      get
      {
        try
        {
          return Settings.Secure.GetString(Context.ContentResolver, Settings.Secure.AndroidId);
        }
        catch (Exception ex)
        {
          System.Diagnostics.Debug.WriteLine("Failed to get device id: {0}", ex.Message);
        }
        return null;
      }
    }

    public override string User
    {
      get { return _user; }
      set { SetUserInfo(value); }
    }

    public override RaygunIdentifierMessage UserInfo
    {
      get { return _userInfo; }
      set { SetUserInfo(value); }
    }

    private void SetUserInfo(string identifier)
    {
      if (string.IsNullOrEmpty(identifier) || string.IsNullOrWhiteSpace(identifier))
      {
        SetUserInfo(GetAnonymousUserInfo());
      }
      else
      {
        SetUserInfo(new RaygunIdentifierMessage(identifier));
      }
    }

    private void SetUserInfo(RaygunIdentifierMessage userInfo)
    {
      if (string.IsNullOrWhiteSpace(userInfo?.Identifier) || string.IsNullOrEmpty(userInfo.Identifier))
      {
        userInfo = GetAnonymousUserInfo();
      }

      // Has the user changed ?
      if (_userInfo != null 
       && _userInfo.Identifier != userInfo.Identifier  // Different user
       && _userInfo.IsAnonymous == false) // Previous user was not anonymous.
      {
        if (!string.IsNullOrEmpty(_sessionId))
        {
          SendPulseSessionEventNow(RaygunPulseSessionEventType.SessionEnd); // End current user's session
          _userInfo = userInfo;
          _user = userInfo.Identifier;
          SendPulseSessionEventNow(RaygunPulseSessionEventType.SessionStart); // Start new session for new user.
        }<commit_msg>Code formating and removing comments that are not needed.<commit_after>using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using Mindscape.Raygun4Net.Messages;

using System.Threading;
using System.Reflection;
using Android.Content;
using Android.Views;
using Android.Runtime;
using Android.App;
using Android.Net;
using Java.IO;
using Android.OS;
using System.Text;
using System.Threading.Tasks;
using Android.Bluetooth;
using Android.Provider;
using Android.Content.PM;

namespace Mindscape.Raygun4Net
{
  public class RaygunClient : RaygunClientBase
  {
    private const string RaygunSharedPrefsFile = "io.raygun.pref";
    private const string RaygunUserIdentifierDefaultsKey = "io.raygun.identifier";

    private static RaygunClient _client;
    private readonly string _apiKey;
    private readonly List<Type> _wrapperExceptions = new List<Type>();

    private string _sessionId;
    private string _user;
    private RaygunIdentifierMessage _userInfo;
    private PulseEventBatch _activeBatch;
    private static readonly object _batchLock = new object();

    /// <summary>
    /// Gets the <see cref="RaygunClient"/> created by the Attach method.
    /// </summary>
    public static RaygunClient Current
    {
      get { return _client; }
    }

    internal static Context Context
    {
      get { return Application.Context; }
    }

    private string DeviceId
    {
      get
      {
        try
        {
          return Settings.Secure.GetString(Context.ContentResolver, Settings.Secure.AndroidId);
        }
        catch (Exception ex)
        {
          System.Diagnostics.Debug.WriteLine("Failed to get device id: {0}", ex.Message);
        }
        return null;
      }
    }

    public override string User
    {
      get { return _user; }
      set { SetUserInfo(value); }
    }

    public override RaygunIdentifierMessage UserInfo
    {
      get { return _userInfo; }
      set { SetUserInfo(value); }
    }

    private void SetUserInfo(string identifier)
    {
      if (string.IsNullOrEmpty(identifier) || string.IsNullOrWhiteSpace(identifier))
      {
        SetUserInfo(GetAnonymousUserInfo());
      }
      else
      {
        SetUserInfo(new RaygunIdentifierMessage(identifier));
      }
    }

    private void SetUserInfo(RaygunIdentifierMessage userInfo)
    {
      if (string.IsNullOrWhiteSpace(userInfo?.Identifier) || string.IsNullOrEmpty(userInfo.Identifier))
      {
        userInfo = GetAnonymousUserInfo();
      }

      // Has the user changed ?
      if (_userInfo != null 
       && _userInfo.Identifier != userInfo.Identifier
       && _userInfo.IsAnonymous == false)
      {
        if (!string.IsNullOrEmpty(_sessionId))
        {
          SendPulseSessionEventNow(RaygunPulseSessionEventType.SessionEnd);
          _userInfo = userInfo;
          _user = userInfo.Identifier;
          SendPulseSessionEventNow(RaygunPulseSessionEventType.SessionStart);
        }
{'fraction_non_alphanumeric': 0.08604576216564615, 'fraction_numerical': 0.0009668063164679343, 'mean_word_length': 2.884230287859825, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '2363215', 'n_tokens_mistral': 1697, 'n_tokens_neox': 1683, 'n_words': 415}