Пример #1
0
        private IEnumerator SendLogFile(int kind)
        {
            if (Application.isEditor && IgnoreEditorErrors)
            {
                DebugLogger.Log("Sending log... (not really, ignored by inspector property)");
                yield break;
            }

            _isLogBeingSent = true;

            DebugLogger.Log("Sending log...");

            DebugLogger.Log("Requesting PUT URL...");

            var putLinkRequest = new PutLinkRequest()
            {
                AppId       = "patcher-unity",
                Version     = PatcherInfo.GetVersion(),
                Priority    = kind.ToString(),
                Guid        = _guid.ToString(),
                Compression = "gz"
            };

            string json = JsonConvert.SerializeObject(putLinkRequest);

            UnityWebRequest putUrlRequest = new UnityWebRequest(PutUrlRequestUrl, "POST");

            byte[] bodyRaw = Encoding.UTF8.GetBytes(json);
            putUrlRequest.uploadHandler   = new UploadHandlerRaw(bodyRaw);
            putUrlRequest.downloadHandler = new DownloadHandlerBuffer();
            putUrlRequest.SetRequestHeader("Content-Type", "application/json");

            yield return(putUrlRequest.Send());

            if (putUrlRequest.isError)
            {
                DebugLogger.LogError("Error while requesting PUT URL: " + putUrlRequest.error);
                _isLogBeingSent = false;
                yield break;
            }


            var responseText = putUrlRequest.downloadHandler.text;

            DebugLogger.Log("Got response: " + responseText);

            var requestPutUrlJson = JsonConvert.DeserializeObject <PutLinkResponse>(responseText);
            var putUrl            = requestPutUrlJson.Url;


            UnityWebRequest putRequest = UnityWebRequest.Put(putUrl, GetCompressedLogFileData());

            yield return(putRequest.Send());

            if (putRequest.isError)
            {
                DebugLogger.LogError("Error while sending log file: " + putRequest.error);
                _isLogBeingSent = false;
                yield break;
            }

            DebugLogger.Log("Log file sent!");

            DebugLogger.Log(string.Format("Waiting {0} seconds before next log could be sent...", SendDelaySeconds));

            float startWaitTime = Time.unscaledTime;

            while (Time.unscaledTime - startWaitTime < SendDelaySeconds && !_hasApplicationQuit)
            {
                yield return(null);
            }

            DebugLogger.Log("Next log can be now send.");

            _isLogBeingSent = false;
        }
Пример #2
0
        public IEnumerator SendLogFileCoroutine(string logFilePath)
        {
            while (IsLogBeingSent)
            {
                yield return(null);
            }

            IsLogBeingSent = true;

            DebugLogger.Log("Sending log...");

            DebugLogger.Log("Requesting PUT URL...");

            var putLinkRequest = new PutLinkRequest()
            {
                AppId       = "patcher-unity",
                Version     = PatcherInfo.GetVersion(),
                Priority    = "201",
                Guid        = Guid.ToString(),
                Compression = "gz"
            };

            string json = JsonConvert.SerializeObject(putLinkRequest);

            UnityWebRequest putUrlRequest = new UnityWebRequest(PutUrlRequestUrl, "POST");

            byte[] bodyRaw = Encoding.UTF8.GetBytes(json);
            putUrlRequest.uploadHandler   = new UploadHandlerRaw(bodyRaw);
            putUrlRequest.downloadHandler = new DownloadHandlerBuffer();
            putUrlRequest.SetRequestHeader("Content-Type", "application/json");

            yield return(putUrlRequest.Send());

            if (putUrlRequest.isError)
            {
                DebugLogger.LogError("Error while requesting PUT URL: " + putUrlRequest.error);
                IsLogBeingSent = false;
                yield break;
            }


            var responseText = putUrlRequest.downloadHandler.text;

            DebugLogger.Log("Got response: " + responseText);

            var requestPutUrlJson = JsonConvert.DeserializeObject <PutLinkResponse>(responseText);
            var putUrl            = requestPutUrlJson.Url;


            UnityWebRequest putRequest = UnityWebRequest.Put(putUrl, GetCompressedLogFileData(logFilePath));

            yield return(putRequest.Send());

            if (putRequest.isError)
            {
                DebugLogger.LogError("Error while sending log file: " + putRequest.error);
                IsLogBeingSent = false;
                yield break;
            }

            DebugLogger.Log("Log file sent!");

            const float sendDelaySeconds = 5f;

            DebugLogger.Log(string.Format("Waiting {0} seconds before next log could be sent...", sendDelaySeconds));

            float startWaitTime = Time.unscaledTime;

            while (Time.unscaledTime - startWaitTime < sendDelaySeconds && !_shouldAbortSending)
            {
                yield return(null);
            }

            _shouldAbortSending = false;

            DebugLogger.Log("Next log can be now send.");

            IsLogBeingSent = false;
        }