Ejemplo n.º 1
0
        private IEnumerator SubmitTextFile()
        {
            for (int i = 0; i < 2; i++)
            {
                try
                {
                    var form = textFileUploadMethods[i].Invoke(_bugReport);
                    var url  = SlackApiUrl + UploadEndPoint;

                    _webRequest = UnityWebRequest.Post(url, form);
                    _webRequest.SendWebRequest();
                }
                catch (Exception e)
                {
                    ErrorMessage = e.Message;
                }
                if (_webRequest == null)
                {
                    SetCompletionState(false);
                    yield break;
                }

                while (!_webRequest.isDone)
                {
                    yield return(null);
                }

                if (!string.IsNullOrEmpty(_webRequest.error))
                {
                    ErrorMessage = _webRequest.error;
                    SetCompletionState(false);

                    yield break;
                }

                if (_webRequest.isHttpError || _webRequest.isNetworkError)
                {
                    ErrorMessage = "Completion State Unknown";
                    SetCompletionState(false);
                    yield break;
                }

                if (_webRequest.responseCode == 0)
                {
                    ErrorMessage = "Completion State Unknown";
                    SetCompletionState(false);
                    yield break;
                }

                if (_webRequest.responseCode != 200)
                {
                    ErrorMessage = SRDebugApiUtil.ParseErrorResponse(_webRequest.downloadHandler.text, _webRequest.responseCode.ToString());
                    SetCompletionState(false);

                    yield break;
                }
            }

            SetCompletionState(true);
        }
        private IEnumerator SubmitTextFile()
        {
            for (int i = 0; i < 2; i++)
            {
                try
                {
                    var form = textFileUploadMethods[i].Invoke(_bugReport);
                    var url  = SlackApiUrl + UploadEndPoint;

                    _www = new WWW(url, form);
                }
                catch (Exception e)
                {
                    ErrorMessage = e.Message;
                }
                if (_www == null)
                {
                    SetCompletionState(false);
                    yield break;
                }

                yield return(_www);

                if (!string.IsNullOrEmpty(_www.error))
                {
                    ErrorMessage = _www.error;
                    SetCompletionState(false);

                    yield break;
                }

                if (!_www.responseHeaders.ContainsKey("STATUS"))
                {
                    ErrorMessage = "Completion State Unknown";
                    SetCompletionState(false);
                    yield break;
                }

                var status = _www.responseHeaders["STATUS"];

                if (!status.Contains("200"))
                {
                    ErrorMessage = SRDebugApiUtil.ParseErrorResponse(_www.text, status);
                    SetCompletionState(false);

                    yield break;
                }
            }

            SetCompletionState(true);
        }
        private IEnumerator SubmitPlane()
        {
            foreach (var type in Enum.GetValues(typeof(ReportType)))
            {
                try
                {
                    if ((int)ReportType.ScreenShot == (int)type && _bugReport.ScreenshotData != null)
                    {
                        var form = BuildScrrenShotUploadRequest(_bugReport);
                        var url  = SlackApiUrl + UploadEndPoint;

                        _www = new WWW(url, form);
                    }
                    else
                    {
                        string json = BuildJsonRequest((int)type, _bugReport);

                        var jsonBytes = Encoding.UTF8.GetBytes(json);
                        var headers   = new Dictionary <string, string>();
                        headers["Content-type"] = "application/json";
                        headers["Accept"]       = "application/json";
                        headers["Method"]       = "POST";
                        headers["data"]         = json;

                        _www = new WWW(SlackAPISetting.WebHookUrl, jsonBytes, headers);
                    }
                }
                catch (Exception e)
                {
                    ErrorMessage = e.Message;
                }

                if (_www == null)
                {
                    SetCompletionState(false);
                    yield break;
                }

                yield return(_www);

                if (!string.IsNullOrEmpty(_www.error))
                {
                    ErrorMessage = _www.error;
                    SetCompletionState(false);

                    yield break;
                }

                if (!_www.responseHeaders.ContainsKey("STATUS"))
                {
                    ErrorMessage = "Completion State Unknown";
                    SetCompletionState(false);
                    yield break;
                }

                var status = _www.responseHeaders["STATUS"];

                if (!status.Contains("200"))
                {
                    ErrorMessage = SRDebugApiUtil.ParseErrorResponse(_www.text, status);
                    SetCompletionState(false);

                    yield break;
                }
            }

            SetCompletionState(true);
        }
Ejemplo n.º 4
0
        public IEnumerator Submit()
        {
            //Debug.Log("[BugReportApi] Submit()");

            if (_isBusy)
            {
                throw new InvalidOperationException("BugReportApi is already sending a bug report");
            }

            // Reset state
            _isBusy       = true;
            ErrorMessage  = "";
            IsComplete    = false;
            WasSuccessful = false;
            _www          = null;

            try
            {
                var json = BuildJsonRequest(_bugReport);

                var jsonBytes = Encoding.UTF8.GetBytes(json);

                var headers = new Dictionary <string, string>();
                headers["Content-Type"] = "application/json";
                headers["Accept"]       = "application/json";
                headers["Method"]       = "POST";
                headers["X-ApiKey"]     = _apiKey;

                _www = new WWW(SRDebugApi.BugReportEndPoint, jsonBytes, headers);
            }
            catch (Exception e)
            {
                ErrorMessage = e.Message;
            }

            if (_www == null)
            {
                SetCompletionState(false);
                yield break;
            }

            yield return(_www);

            if (!string.IsNullOrEmpty(_www.error))
            {
                ErrorMessage = _www.error;
                SetCompletionState(false);

                yield break;
            }

            if (!_www.responseHeaders.ContainsKey("X-STATUS"))
            {
                ErrorMessage = "Completion State Unknown";
                SetCompletionState(false);
                yield break;
            }

            var status = _www.responseHeaders["X-STATUS"];

            if (!status.Contains("200"))
            {
                ErrorMessage = SRDebugApiUtil.ParseErrorResponse(_www.text, status);
                SetCompletionState(false);

                yield break;
            }

            SetCompletionState(true);
        }
Ejemplo n.º 5
0
        public IEnumerator Submit()
        {
            //Debug.Log("[BugReportApi] Submit()");

            if (_isBusy)
            {
                throw new InvalidOperationException("BugReportApi is already sending a bug report");
            }

            // Reset state
            _isBusy       = true;
            ErrorMessage  = "";
            IsComplete    = false;
            WasSuccessful = false;
            _webRequest   = null;

            string json;

            byte[] jsonBytes;

            try
            {
                json      = BuildJsonRequest(_bugReport);
                jsonBytes = Encoding.UTF8.GetBytes(json);
            }
            catch (Exception e)
            {
                ErrorMessage = "Error building bug report.";
                Debug.LogError(e);
                SetCompletionState(false);
                yield break;
            }

            try
            {
                const string jsonContentType = "application/json";

                _webRequest = new UnityWebRequest(SRDebugApi.BugReportEndPoint, UnityWebRequest.kHttpVerbPOST,
                                                  new DownloadHandlerBuffer(), new UploadHandlerRaw(jsonBytes)
                {
                    contentType = jsonContentType
                });

                _webRequest.SetRequestHeader("Accept", jsonContentType);
                _webRequest.SetRequestHeader("X-ApiKey", _apiKey);
            }
            catch (Exception e)
            {
                ErrorMessage = "Error building bug report request.";
                Debug.LogError(e);

                if (_webRequest != null)
                {
                    _webRequest.Dispose();
                }

                SetCompletionState(false);
            }

            if (_webRequest == null)
            {
                SetCompletionState(false);
                yield break;
            }

#if !UNITY_2017_2_OR_NEWER
            yield return(_webRequest.Send());
#else
            yield return(_webRequest.SendWebRequest());
#endif

            if (_webRequest.isNetworkError)
            {
                ErrorMessage = "Request Error: " + _webRequest.error;
                SetCompletionState(false);
                _webRequest.Dispose();
                yield break;
            }

            long responseCode = _webRequest.responseCode;
            var  responseJson = _webRequest.downloadHandler.text;

            _webRequest.Dispose();

            if (responseCode != 200)
            {
                ErrorMessage = "Server: " + SRDebugApiUtil.ParseErrorResponse(responseJson, "Unknown response from server");
                SetCompletionState(false);
                yield break;
            }

            SetCompletionState(true);
        }
Ejemplo n.º 6
0
        private IEnumerator SubmitPlane()
        {
            foreach (var type in Enum.GetValues(typeof(ReportType)))
            {
                try
                {
                    if ((int)ReportType.ScreenShot == (int)type && _bugReport.ScreenshotData != null)
                    {
                        var form = BuildScrrenShotUploadRequest(_bugReport);
                        var url  = SlackApiUrl + UploadEndPoint;
                        _webRequest = UnityWebRequest.Post(url, form);
                    }
                    else
                    {
                        _webRequest = new UnityWebRequest(SlackAPISetting.WebHookUrl, "POST");
                        _webRequest.SetRequestHeader("Content-type", "application/json");

                        string json     = BuildJsonRequest((int)type, _bugReport);
                        var    jsonData = Encoding.UTF8.GetBytes(json);
                        _webRequest.uploadHandler = new UploadHandlerRaw(jsonData);
                    }

                    _webRequest.SendWebRequest();
                }
                catch (Exception e)
                {
                    ErrorMessage = e.Message;
                }

                if (_webRequest == null)
                {
                    SetCompletionState(false);
                    yield break;
                }

                while (!_webRequest.isDone)
                {
                    yield return(null);
                }

                if (_webRequest.isHttpError || _webRequest.isNetworkError)
                {
                    ErrorMessage = _webRequest.error;
                    SetCompletionState(false);

                    yield break;
                }

                if (_webRequest.responseCode == 0)
                {
                    ErrorMessage = "Completion State Unknown";
                    SetCompletionState(false);
                    yield break;
                }

                if (_webRequest.responseCode != 200)
                {
                    ErrorMessage = SRDebugApiUtil.ParseErrorResponse(_webRequest.downloadHandler.text, _webRequest.responseCode.ToString());
                    SetCompletionState(false);

                    yield break;
                }
            }

            SetCompletionState(true);
        }