/// <inheritdoc cref="IUserReportingPlatform"/> public void Post(string endpoint, string contentType, byte[] content, Action <float, float> progressCallback, Action <bool, byte[]> callback) { UnityWebRequest webRequest = new UnityWebRequest(endpoint, "POST"); webRequest.uploadHandler = new UploadHandlerRaw(content); webRequest.downloadHandler = new DownloadHandlerBuffer(); webRequest.SetRequestHeader("Content-Type", contentType); webRequest.SendWebRequest(); AsyncUnityUserReportingPlatform.PostOperation postOperation = new AsyncUnityUserReportingPlatform.PostOperation(); postOperation.WebRequest = webRequest; postOperation.Callback = callback; postOperation.ProgressCallback = progressCallback; this.postOperations.Add(postOperation); }
/// <inheritdoc cref="IUserReportingPlatform"/> public void Update(UserReportingClient client) { // Log Messages lock (this.logMessages) { foreach (AsyncUnityUserReportingPlatform.LogMessage logMessage in this.logMessages) { UserReportEventLevel eventLevel = UserReportEventLevel.Info; if (logMessage.LogType == LogType.Warning) { eventLevel = UserReportEventLevel.Warning; } else if (logMessage.LogType == LogType.Error) { eventLevel = UserReportEventLevel.Error; } else if (logMessage.LogType == LogType.Exception) { eventLevel = UserReportEventLevel.Error; } else if (logMessage.LogType == LogType.Assert) { eventLevel = UserReportEventLevel.Error; } if (client.IsConnectedToLogger) { client.LogEvent(eventLevel, logMessage.LogString, logMessage.StackTrace); } } this.logMessages.Clear(); } // Metrics if (client.Configuration.MetricsGatheringMode == MetricsGatheringMode.Automatic) { // Sample Automatic Metrics this.SampleAutomaticMetrics(client); // Profiler Samplers foreach (AsyncUnityUserReportingPlatform.ProfilerSampler profilerSampler in this.profilerSamplers) { client.SampleMetric(profilerSampler.Name, profilerSampler.GetValue()); } } // Post Operations int postOperationIndex = 0; while (postOperationIndex < this.postOperations.Count) { AsyncUnityUserReportingPlatform.PostOperation postOperation = this.postOperations[postOperationIndex]; if (postOperation.WebRequest.isDone) { bool isError = postOperation.WebRequest.error != null && postOperation.WebRequest.responseCode != 200; if (isError) { string errorMessage = string.Format("UnityUserReportingPlatform.Post: {0} {1}", postOperation.WebRequest.responseCode, postOperation.WebRequest.error); UnityEngine.Debug.Log(errorMessage); client.LogEvent(UserReportEventLevel.Error, errorMessage); } postOperation.ProgressCallback(1, 1); postOperation.Callback(!isError, postOperation.WebRequest.downloadHandler.data); this.postOperations.Remove(postOperation); } else { postOperation.ProgressCallback(postOperation.WebRequest.uploadProgress, postOperation.WebRequest.downloadProgress); postOperationIndex++; } } }