public bool EnqueueInFile() { #if UNITY_STANDALONE || UNITY_EDITOR string firstFile = ToastFileManager.GetFirstFile(ToastLoggerCommonLogic.AppKey); if (!string.IsNullOrEmpty(firstFile)) { ToastLoggerBulkLog bulkLog = new ToastLoggerBulkLog(); string fileName = firstFile.Substring(firstFile.LastIndexOf("\\", StringComparison.OrdinalIgnoreCase) + 1); if (firstFile.LastIndexOf("\\", StringComparison.OrdinalIgnoreCase) == -1) { fileName = firstFile.Substring(firstFile.LastIndexOf("/", StringComparison.OrdinalIgnoreCase) + 1); } string[] subString = fileName.Split('_'); bulkLog.CreateTime = long.Parse(subString[0]); bulkLog.TransactionId = subString[1]; string strLogContents = ToastFileManager.FileLoad(ToastLoggerCommonLogic.AppKey, bulkLog.CreateTime, bulkLog.TransactionId); ToastFileManager.FileDelete(ToastLoggerCommonLogic.AppKey, bulkLog.CreateTime, bulkLog.TransactionId); bulkLog.LogContents = strLogContents; _queueBulkLog.Enqueue(bulkLog); return(true); } #endif return(false); }
public ToastLoggerBulkLog Dequeue() { ToastLoggerBulkLog bulkLog = _queueBulkLog.Dequeue(); if (string.IsNullOrEmpty(bulkLog.LogContents)) { bulkLog.LogContents = bulkLog.GetString(); } return(bulkLog); }
// Update is called once per frame void FixedUpdate() { if (!_isStartSender) { return; } ToastLoggerSendQueue.Instance.Enqueue(); if (ToastLoggerSendQueue.Instance.Count > 0 && _couroutineCount < MAX_COROUTINE_SIZE) { ToastLoggerBulkLog bulkLog = ToastLoggerSendQueue.Instance.Dequeue(); StartCoroutine(SendReport(bulkLog, bulkLog.LogContents, bulkLog.CreateTime, bulkLog.TransactionId)); } }
public bool Enqueue() { if (_bulkLog.Count == 0) { return(false); } ToastLoggerBulkLog bulkLog = new ToastLoggerBulkLog(_bulkLog); _bulkLog.RemoveAll(); bulkLog.CreateTime = ToastUtil.GetEpochMilliSeconds(); bulkLog.TransactionId = Guid.NewGuid().ToString().Replace("-", ""); _queueBulkLog.Enqueue(bulkLog); return(true); }
public ToastLoggerBulkLog(ToastLoggerBulkLog bulkLog) { _logDatas = new List <ToastLoggerLogObject>(bulkLog.Gets()); }
IEnumerator SendReport(ToastLoggerBulkLog bulkLog, string logContents, long createTime, string transactionId) { _couroutineCount++; string url = ToastLoggerCommonLogic.CollectorUrl; string errorString = ""; string jsonString = ""; float timeout = 5.0f; bool isTimeout = false; #if UNITY_2017_2_OR_NEWER var downloadHandler = new DownloadHandlerBuffer(); var uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(logContents)); using (var request = new UnityWebRequest(url, UnityWebRequest.kHttpVerbPOST, downloadHandler, uploadHandler)) { request.SetRequestHeader("Content-Type", "application/json"); request.timeout = System.Convert.ToInt32(timeout); yield return(request.SendWebRequest()); errorString = request.error; if (request.isNetworkError || request.isHttpError) { isTimeout = true; } else { jsonString = request.downloadHandler.text; } } #else float timer = 0f; Dictionary <string, string> header = new Dictionary <string, string>(); header.Add("Content-Type", "application/json"); using (WWW www = new WWW(url, System.Text.Encoding.UTF8.GetBytes(logContents), header)) { do { if (timer > timeout) { isTimeout = true; break; } timer += Time.deltaTime; yield return(null); }while (!www.isDone); if (isTimeout) { www.Dispose(); } else { errorString = www.error; jsonString = www.text; } } #endif // UNITY_2017_2_OR_NEWER #if UNITY_STANDALONE || UNITY_EDITOR if (isTimeout == false && string.IsNullOrEmpty(errorString)) // success { if (ToastFileManager.FileCheck(ToastLoggerCommonLogic.AppKey, createTime, transactionId)) { ToastFileManager.FileDelete(ToastLoggerCommonLogic.AppKey, createTime, transactionId); } ToastLoggerSendQueue.Instance.EnqueueInFile(); if (ToastLoggerCommonLogic.IsLoggerListener) { foreach (ToastLoggerLogObject logData in bulkLog.Gets()) { CrashLoggerListenerReceiver.Instance.OnLogSuccess(logData); } } } else { if (ToastFileManager.GetProjectFileCount(ToastLoggerCommonLogic.AppKey) < MAX_FILE_SIZE) { ToastFileManager.FileSave(ToastLoggerCommonLogic.AppKey, createTime, transactionId, logContents); if (ToastLoggerCommonLogic.IsLoggerListener) { foreach (ToastLoggerLogObject logData in bulkLog.Gets()) { CrashLoggerListenerReceiver.Instance.OnLogSave(logData); } } } } #elif UNITY_WEBGL if (isTimeout == false && string.IsNullOrEmpty(errorString)) // success { } else { if (ToastLoggerCommonLogic.IsLoggerListener) { foreach (ToastLoggerLogObject logData in bulkLog.Gets()) { CrashLoggerListenerReceiver.Instance.OnLogError(logData, errorString); } } } #endif _couroutineCount--; yield return(null); }