private IEnumerator Send(string json, List <string> attachments, BacktraceReport report, Action <BacktraceResult> callback)
        {
            using (var request = new UnityWebRequest(_serverurl, "POST"))
            {
                AppendBodyToFile(json);
                byte[] bodyRaw = Encoding.UTF8.GetBytes(json);
                request.uploadHandler   = (UploadHandler) new UploadHandlerRaw(bodyRaw);
                request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
                request.SetRequestHeader("Content-Type", "application/json");
                yield return(request.SendWebRequest());

                BacktraceResult result;
                if (request.responseCode == 200)
                {
                    result = new BacktraceResult();
                    OnServerResponse?.Invoke(result);
                    var response = BacktraceResult.FromJson(request.downloadHandler.text);
                    if (attachments != null && attachments.Count > 0)
                    {
                        var stack = new Stack <string>(attachments);
                        yield return(SendAttachment(response.Object, stack));
                    }
                }
                else
                {
                    PrintLog(request);
                    var exception = new Exception(request.error);
                    result = BacktraceResult.OnError(report, exception);
                    OnServerError?.Invoke(exception);
                }
                callback?.Invoke(result);
                yield return(result);
            }
        }
Exemple #2
0
        /// <summary>
        /// Send minidump to Backtrace
        /// </summary>
        /// <param name="minidumpPath">Path to minidump</param>
        /// <param name="attachments">List of attachments</param>
        /// <param name="callback">Callback</param>
        /// <returns>Server response</returns>
        public IEnumerator SendMinidump(string minidumpPath, IEnumerable <string> attachments, Action <BacktraceResult> callback = null)
        {
            if (attachments == null)
            {
                attachments = new List <string>();
            }

            var stopWatch = EnablePerformanceStatistics
               ? System.Diagnostics.Stopwatch.StartNew()
               : new System.Diagnostics.Stopwatch();

            List <IMultipartFormSection> formData = new List <IMultipartFormSection>
            {
                new MultipartFormFileSection("upload_file", File.ReadAllBytes(minidumpPath))
            };

            foreach (var file in attachments)
            {
                if (File.Exists(file) && new FileInfo(file).Length < 10000000)
                {
                    formData.Add(new MultipartFormFileSection(
                                     string.Format("attachment__{0}", Path.GetFileName(file)),
                                     File.ReadAllBytes(file)));
                }
            }

            yield return(new WaitForEndOfFrame());

            var boundaryId      = string.Format("----------{0:N}", Guid.NewGuid());
            var boundaryIdBytes = Encoding.ASCII.GetBytes(boundaryId);

            using (var request = UnityWebRequest.Post(_minidumpUrl, formData, boundaryIdBytes))
            {
                request.SetRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundaryId);
                request.timeout = 15000;
                yield return(request.SendWebRequest());

                var result = request.isNetworkError || request.isHttpError
                    ? new BacktraceResult()
                {
                    Message = request.error,
                    Status  = Types.BacktraceResultStatus.ServerError
                }
                    : BacktraceResult.FromJson(request.downloadHandler.text);

                if (callback != null)
                {
                    callback.Invoke(result);
                }
                if (EnablePerformanceStatistics)
                {
                    stopWatch.Stop();
                    Debug.Log(string.Format("Backtrace - minidump send time: {0}μs", stopWatch.GetMicroseconds()));
                }

                yield return(result);
            }
        }
        private IEnumerator Send(string json, List <string> attachments, BacktraceReport report, int deduplication, Action <BacktraceResult> callback)
        {
            var requestUrl = _serverurl.ToString();

            if (deduplication > 0)
            {
                var startingChar = string.IsNullOrEmpty(_serverurl.Query) ? "?" : "&";
                requestUrl += string.Format("{0}_mod_duplicate={1}", startingChar, deduplication);
            }
            using (var request = new UnityWebRequest(requestUrl, "POST"))
            {
#if UNITY_2018_4_OR_NEWER
                if (_ignoreSslValidation)
                {
                    request.certificateHandler = new BacktraceSelfSSLCertificateHandler();
                }
#endif

                byte[] bodyRaw = Encoding.UTF8.GetBytes(json);
                request.uploadHandler   = (UploadHandler) new UploadHandlerRaw(bodyRaw);
                request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
                request.SetRequestHeader("Content-Type", "application/json");
                yield return(request.SendWebRequest());

                BacktraceResult result;
                if (request.responseCode == 200)
                {
                    result = new BacktraceResult();
                    if (OnServerResponse != null)
                    {
                        OnServerResponse.Invoke(result);
                    }
                    var response = BacktraceResult.FromJson(request.downloadHandler.text);
                    if (attachments != null && attachments.Count > 0)
                    {
                        var stack = new Stack <string>(attachments);
                        yield return(SendAttachment(response.RxId, stack));
                    }
                }
                else
                {
                    PrintLog(request);
                    var exception = new Exception(request.error);
                    result = BacktraceResult.OnError(report, exception);
                    if (OnServerError != null)
                    {
                        OnServerError.Invoke(exception);
                    }
                }

                if (callback != null)
                {
                    callback.Invoke(result);
                }
                yield return(result);
            }
        }
Exemple #4
0
        /// <summary>
        /// Send minidump to Backtrace
        /// </summary>
        /// <param name="minidumpPath">Path to minidump</param>
        /// <param name="attachments">List of attachments</param>
        /// <param name="callback">Callback</param>
        /// <returns>Server response</returns>
        public IEnumerator SendMinidump(string minidumpPath, IEnumerable <string> attachments, IDictionary <string, string> queryAttributes, Action <BacktraceResult> callback = null)
        {
            if (attachments == null)
            {
                attachments = new HashSet <string>();
            }

            var stopWatch = EnablePerformanceStatistics
               ? System.Diagnostics.Stopwatch.StartNew()
               : new System.Diagnostics.Stopwatch();

            var minidumpBytes = File.ReadAllBytes(minidumpPath);

            if (minidumpBytes == null || minidumpBytes.Length == 0)
            {
                yield break;
            }

            var requestUrl = queryAttributes != null
                ? GetParametrizedQuery(_minidumpUrl, queryAttributes)
                : _minidumpUrl;

            using (var request = _httpClient.Post(requestUrl, minidumpBytes, attachments))
            {
                yield return(request.SendWebRequest());

                var result = request.ReceivedNetworkError()
                    ? new BacktraceResult()
                {
                    Message = request.error,
                    Status  = Types.BacktraceResultStatus.ServerError
                }
                    : BacktraceResult.FromJson(request.downloadHandler.text);

                if (callback != null)
                {
                    callback.Invoke(result);
                }
                if (EnablePerformanceStatistics)
                {
                    stopWatch.Stop();
                    Debug.Log(string.Format("Backtrace - minidump send time: {0}μs", stopWatch.GetMicroseconds()));
                }

                yield return(result);
            }
        }
        /// <summary>
        /// Sending diagnostic report to Backtrace
        /// </summary>
        /// <param name="json">diagnostic data JSON</param>
        /// <param name="attachments">List of report attachments</param>
        /// <param name="queryAttributes">Query string attributes</param>
        /// <param name="callback">coroutine callback</param>
        /// <returns>Server response</returns>
        public IEnumerator Send(string json, List <string> attachments, Dictionary <string, string> queryAttributes, Action <BacktraceResult> callback)
        {
            var stopWatch = EnablePerformanceStatistics
              ? System.Diagnostics.Stopwatch.StartNew()
              : new System.Diagnostics.Stopwatch();

            var requestUrl = queryAttributes != null
                ? GetParametrizedQuery(_serverUrl.ToString(), queryAttributes)
                : ServerUrl;


            List <IMultipartFormSection> formData = new List <IMultipartFormSection>
            {
                new MultipartFormFileSection("upload_file", Encoding.UTF8.GetBytes(json), "upload_file.json", "application/json")
            };

            foreach (var file in attachments)
            {
                if (File.Exists(file) && new FileInfo(file).Length < 10000000)
                {
                    formData.Add(new MultipartFormFileSection(
                                     string.Format("attachment__{0}", Path.GetFileName(file)),
                                     File.ReadAllBytes(file)));
                }
            }


            var boundaryIdBytes = UnityWebRequest.GenerateBoundary();

            using (var request = UnityWebRequest.Post(requestUrl, formData, boundaryIdBytes))
            {
#if UNITY_2018_4_OR_NEWER
                if (_ignoreSslValidation)
                {
                    request.certificateHandler = new BacktraceSelfSSLCertificateHandler();
                }
#endif
                request.SetRequestHeader("Content-Type", "multipart/form-data; boundary=" + Encoding.UTF8.GetString(boundaryIdBytes));
                request.timeout = 15000;
                yield return(request.SendWebRequest());

                BacktraceResult result;
                if (request.responseCode == 429)
                {
                    result = new BacktraceResult()
                    {
                        Message = "Server report limit reached",
                        Status  = Types.BacktraceResultStatus.LimitReached
                    };
                    if (OnServerResponse != null)
                    {
                        OnServerResponse.Invoke(result);
                    }
                }
                else if (request.responseCode == 200 && (!request.isNetworkError || !request.isHttpError))
                {
                    result = BacktraceResult.FromJson(request.downloadHandler.text);
                    _shouldDisplayFailureMessage = true;

                    if (OnServerResponse != null)
                    {
                        OnServerResponse.Invoke(result);
                    }
                }
                else
                {
                    PrintLog(request);
                    var exception = new Exception(request.error);
                    result = BacktraceResult.OnNetworkError(exception);
                    if (OnServerError != null)
                    {
                        OnServerError.Invoke(exception);
                    }
                }

                if (callback != null)
                {
                    callback.Invoke(result);
                }

                if (EnablePerformanceStatistics)
                {
                    stopWatch.Stop();
                    Debug.Log(string.Format("Backtrace - JSON send time: {0}μs", stopWatch.GetMicroseconds()));
                }
                yield return(result);
            }
        }
        /// <summary>
        /// Send minidump to Backtrace
        /// </summary>
        /// <param name="minidumpPath">Path to minidump</param>
        /// <param name="attachments">List of attachments</param>
        /// <param name="callback">Callback</param>
        /// <returns>Server response</returns>
        public IEnumerator SendMinidump(string minidumpPath, IEnumerable <string> attachments, Action <BacktraceResult> callback = null)
        {
            if (attachments == null)
            {
                attachments = new List <string>();
            }

            var stopWatch = EnablePerformanceStatistics
               ? System.Diagnostics.Stopwatch.StartNew()
               : new System.Diagnostics.Stopwatch();

            var minidumpBytes = File.ReadAllBytes(minidumpPath);

            if (minidumpBytes == null || minidumpBytes.Length == 0)
            {
                yield break;
            }
            List <IMultipartFormSection> formData = new List <IMultipartFormSection>
            {
                new MultipartFormFileSection("upload_file", minidumpBytes)
            };

            foreach (var file in attachments)
            {
                if (File.Exists(file) && new FileInfo(file).Length < 10000000)
                {
                    formData.Add(new MultipartFormFileSection(
                                     string.Format("attachment__{0}", Path.GetFileName(file)),
                                     File.ReadAllBytes(file)));
                }
            }

            yield return(new WaitForEndOfFrame());

            var boundaryIdBytes = UnityWebRequest.GenerateBoundary();

            using (var request = UnityWebRequest.Post(_minidumpUrl, formData, boundaryIdBytes))
            {
#if UNITY_2018_4_OR_NEWER
                if (_ignoreSslValidation)
                {
                    request.certificateHandler = new BacktraceSelfSSLCertificateHandler();
                }
#endif
                request.SetRequestHeader("Content-Type", string.Format("multipart/form-data; boundary={0}", Encoding.UTF8.GetString(boundaryIdBytes)));
                request.timeout = 15000;
                yield return(request.SendWebRequest());

                var result = request.isNetworkError || request.isHttpError
                    ? new BacktraceResult()
                {
                    Message = request.error,
                    Status  = Types.BacktraceResultStatus.ServerError
                }
                    : BacktraceResult.FromJson(request.downloadHandler.text);

                if (callback != null)
                {
                    callback.Invoke(result);
                }
                if (EnablePerformanceStatistics)
                {
                    stopWatch.Stop();
                    Debug.Log(string.Format("Backtrace - minidump send time: {0}μs", stopWatch.GetMicroseconds()));
                }

                yield return(result);
            }
        }
Exemple #7
0
        /// <summary>
        /// Sending diagnostic report to Backtrace
        /// </summary>
        /// <param name="json">diagnostic data JSON</param>
        /// <param name="attachments">List of report attachments</param>
        /// <param name="queryAttributes">Query string attributes</param>
        /// <param name="callback">coroutine callback</param>
        /// <returns>Server response</returns>
        public IEnumerator Send(string json, List <string> attachments, Dictionary <string, string> queryAttributes, Action <BacktraceResult> callback)
        {
            var stopWatch = EnablePerformanceStatistics
              ? System.Diagnostics.Stopwatch.StartNew()
              : new System.Diagnostics.Stopwatch();

            var requestUrl = queryAttributes != null
                ? GetParametrizedQuery(_serverUrl.ToString(), queryAttributes)
                : ServerUrl;


            using (var request = new UnityWebRequest(requestUrl, "POST"))
            {
#if UNITY_2018_4_OR_NEWER
                if (_ignoreSslValidation)
                {
                    request.certificateHandler = new BacktraceSelfSSLCertificateHandler();
                }
#endif
                request.timeout = 15000;
                byte[] bodyRaw = Encoding.UTF8.GetBytes(json);
                request.uploadHandler   = (UploadHandler) new UploadHandlerRaw(bodyRaw);
                request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
                request.SetRequestHeader("Content-Type", "application/json");
                yield return(request.SendWebRequest());

                BacktraceResult result;
                if (request.responseCode == 200)
                {
                    result = BacktraceResult.FromJson(request.downloadHandler.text);

                    if (OnServerResponse != null)
                    {
                        OnServerResponse.Invoke(result);
                    }
                    if (attachments != null && attachments.Count > 0)
                    {
                        var stack = new Stack <string>(attachments);
                        yield return(SendAttachment(result.RxId, stack));
                    }
                }
                else
                {
                    PrintLog(request);
                    var exception = new Exception(request.error);
                    result = BacktraceResult.OnError(exception);
                    if (OnServerError != null)
                    {
                        OnServerError.Invoke(exception);
                    }
                }

                if (callback != null)
                {
                    callback.Invoke(result);
                }

                if (EnablePerformanceStatistics)
                {
                    stopWatch.Stop();
                    Debug.Log(string.Format("Backtrace - JSON send time: {0}μs", stopWatch.GetMicroseconds()));
                }
                yield return(result);
            }
        }
Exemple #8
0
        /// <summary>
        /// Sending diagnostic report to Backtrace
        /// </summary>
        /// <param name="json">diagnostic data JSON</param>
        /// <param name="attachments">List of report attachments</param>
        /// <param name="queryAttributes">Query string attributes</param>
        /// <param name="callback">coroutine callback</param>
        /// <returns>Server response</returns>
        public IEnumerator Send(string json, IEnumerable <string> attachments, Dictionary <string, string> queryAttributes, Action <BacktraceResult> callback)
        {
            var stopWatch = EnablePerformanceStatistics
              ? System.Diagnostics.Stopwatch.StartNew()
              : new System.Diagnostics.Stopwatch();

            var requestUrl = queryAttributes != null
                ? GetParametrizedQuery(_serverUrl.ToString(), queryAttributes)
                : ServerUrl;

            using (var request = _httpClient.Post(requestUrl, json, attachments))
            {
                yield return(request.SendWebRequest());

                BacktraceResult result;
                if (request.responseCode == 429)
                {
                    result = new BacktraceResult()
                    {
                        Message = "Server report limit reached",
                        Status  = Types.BacktraceResultStatus.LimitReached
                    };
                    if (OnServerResponse != null)
                    {
                        OnServerResponse.Invoke(result);
                    }
                }
                else if (request.responseCode == 200 && request.ReceivedNetworkError() != true)
                {
                    result = BacktraceResult.FromJson(request.downloadHandler.text);
                    _shouldDisplayFailureMessage = true;

                    if (OnServerResponse != null)
                    {
                        OnServerResponse.Invoke(result);
                    }
                }
                else
                {
                    PrintLog(request);
                    var exception = new Exception(request.error);
                    result = BacktraceResult.OnNetworkError(exception);
                    if (OnServerError != null)
                    {
                        OnServerError.Invoke(exception);
                    }
                }

                if (callback != null)
                {
                    callback.Invoke(result);
                }

                if (EnablePerformanceStatistics)
                {
                    stopWatch.Stop();
                    Debug.Assert(EnablePerformanceStatistics, string.Format("Backtrace - JSON send time: {0}μs", stopWatch.GetMicroseconds()));
                }
                yield return(result);
            }
        }