<commit_before>﻿using UnityEngine;
using System.Net;
using System.IO;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using ICSharpCode.SharpZipLib.GZip;

namespace Unity3DRavenCS {


	public class RavenOptionType
	{
		public int timeout = 5000;
        public bool compression = true;
	}


	public class Unity3DRavenCS {
		private DSN m_dsn;
		private bool m_valid;
		private RavenOptionType m_option;

		public Unity3DRavenCS(string dsnUri, RavenOptionType option = null)
		{
			m_dsn = new DSN(dsnUri);
			if (!m_dsn.isValid) {
				m_valid = false;
				Debug.Log ("Unity3DRavenCS is disabled because the DSN is invalid.");
			} else {
				m_valid = true;

				m_option = option == null ? new RavenOptionType() : option;
			}
		}

		public string CaptureMessage(string message, LogType logType=LogType.Error, Dictionary<string, string> tags=null)
		{
			string resultId = "";

			if (m_valid) 
			{
				MessagePacket packet = new MessagePacket(message, logType, tags);

                Send(packet.ToJson());
			}

			return resultId;
		}

		public string CaptureException(Exception exception, Dictionary<string, string> tags = null)
		{
			string resultId = "";

            if (m_valid)
            {
                ExceptionPacket paket = new ExceptionPacket(exception, tags);

                Send(paket.ToJson());
            }

			return resultId;
		}

        public string CaptureException(string message, string stackTrace, Dictionary<string, string> tags = null)
        {
            string resultId = "";

            if (m_valid)
            {
                ExceptionPacket paket = new ExceptionPacket(message, stackTrace, tags);

                Send(paket.ToJson());
            }

            return resultId;
        }

        private string Send(string payload)
        {
            string resultId = "";

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_dsn.sentryUri);
            request.Method = "POST";
            request.Timeout = m_option.timeout;
            request.ReadWriteTimeout = m_option.timeout;
            request.Accept = "application/json";
            request.ContentType = "application/json; charset=utf-8";
            request.Headers.Add("X-Sentry-Auth", m_dsn.XSentryAuthHeader());
            request.UserAgent = m_dsn.UserAgent();

            if (m_option.compression)
            {
                request.Headers.Add("Content-Encoding", "gzip");
            }

            using (Stream requestStream = request.GetRequestStream())
            {
                if (m_option.compression)
                {
                    byte[] payloadBuffer = System.Text.Encoding.UTF8.GetBytes(payload);
                    using (GZipOutputStream gzipStream = new GZipOutputStream(requestStream))
                    {
                        gzipStream.Write(payloadBuffer, 0, payloadBuffer.Length);<commit_msg>fix issue: the result id is empty<commit_after>﻿using UnityEngine;
using System.Net;
using System.IO;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using ICSharpCode.SharpZipLib.GZip;

namespace Unity3DRavenCS {


	public class RavenOptionType
	{
		public int timeout = 5000;
        public bool compression = true;
	}


	public class Unity3DRavenCS {
		private DSN m_dsn;
		private bool m_valid;
		private RavenOptionType m_option;

		public Unity3DRavenCS(string dsnUri, RavenOptionType option = null)
		{
			m_dsn = new DSN(dsnUri);
			if (!m_dsn.isValid) {
				m_valid = false;
				Debug.Log ("Unity3DRavenCS is disabled because the DSN is invalid.");
			} else {
				m_valid = true;

				m_option = option == null ? new RavenOptionType() : option;
			}
		}

		public string CaptureMessage(string message, LogType logType=LogType.Error, Dictionary<string, string> tags=null)
		{
			string resultId = "";

			if (m_valid) 
			{
				MessagePacket packet = new MessagePacket(message, logType, tags);

                Send(packet.ToJson());
			}

			return resultId;
		}

		public string CaptureException(Exception exception, Dictionary<string, string> tags = null)
		{
			string resultId = "";

            if (m_valid)
            {
                ExceptionPacket paket = new ExceptionPacket(exception, tags);

                Send(paket.ToJson());
            }

			return resultId;
		}

        public string CaptureException(string message, string stackTrace, Dictionary<string, string> tags = null)
        {
            string resultId = "";

            if (m_valid)
            {
                ExceptionPacket paket = new ExceptionPacket(message, stackTrace, tags);

                resultId = Send(paket.ToJson());
            }

            return resultId;
        }

        private string Send(string payload)
        {
            string resultId = "";

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_dsn.sentryUri);
            request.Method = "POST";
            request.Timeout = m_option.timeout;
            request.ReadWriteTimeout = m_option.timeout;
            request.Accept = "application/json";
            request.ContentType = "application/json; charset=utf-8";
            request.Headers.Add("X-Sentry-Auth", m_dsn.XSentryAuthHeader());
            request.UserAgent = m_dsn.UserAgent();

            if (m_option.compression)
            {
                request.Headers.Add("Content-Encoding", "gzip");
            }

            using (Stream requestStream = request.GetRequestStream())
            {
                if (m_option.compression)
                {
                    byte[] payloadBuffer = System.Text.Encoding.UTF8.GetBytes(payload);
                    using (GZipOutputStream gzipStream = new GZipOutputStream(requestStream))
                    {
                        gzipStream.Write(payloadBuffer, 0, payloadBuffer.Length);
{'fraction_non_alphanumeric': 0.09313473720253382, 'fraction_numerical': 0.003766478342749529, 'mean_word_length': 2.1732753938077134, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5521464', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1578, 'n_words': 366}