コード例 #1
0
        /// <summary>
        /// 基础上传方法
        /// </summary>
        /// <param name="uuid"></param>
        /// <param name="experimentId"></param>
        /// <param name="courseId"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="score"></param>
        /// <param name="ReportSummary"></param>
        /// <param name="reportModels"></param>
        /// <param name="responseAction"></param>
        /// <param name="status"></param>
        private static void UploadReport(string uuid, int experimentId, int courseId, long startTime, long endTime, double score, string ReportSummary, ExperimentReportModelBuilder[] reportModels, Step[] steps, Action <string> responseAction = null, int status = 1)
        {
            int timeUsed = (int)((endTime - startTime) * 0.001f);

            appId  = ticket == string.Empty ? string.Empty : appId;
            secret = ticket == string.Empty ? string.Empty : secret;

            ExperimentReport.Create(uuid, experimentId, courseId, startTime, endTime, timeUsed, score, ReportSummary, reportModels, report =>
            {
                UploadReport(report, responseAction);
            }, status, steps, appId, secret);
        }
コード例 #2
0
        /// <summary>
        /// 最基本的上传
        /// </summary>
        /// <param name="experimentReport">实验报告</param>
        /// <param name="responseAction">响应事件</param>
        public static void UploadReport(ExperimentReport experimentReport, Action <string> responseAction = null)
        {
            string json = JsonConvert.SerializeObject(experimentReport);

            Debug.Log(json);

            Instance.StartCoroutine(StartUploadReport(json, p =>
            {
                try
                {
                    JObject back = JObject.Parse(p);
                    responseAction?.Invoke(urlOpenReport + experimentReport.courseId + "/0?reportId=" + back["reportId"].ToString());
                }
                catch
                {
                    responseAction("-1");
                }
            }));

            IEnumerator StartUploadReport(string reportJson, Action <string> responseActionReport)
            {
                UnityWebRequest webRequest = new UnityWebRequest(urlReport, "POST");
                WWWForm         form       = new WWWForm();

                form.AddField("jsonStr", reportJson);
                form.AddField("ticket", ticket);

                using (UnityWebRequest www = UnityWebRequest.Post(urlReport, form))
                {
                    yield return(www.SendWebRequest());

                    if (www.isNetworkError || www.isHttpError)
                    {
                        Debug.Log(www.error);
                        responseActionReport("-1");
                    }
                    else
                    {
                        Debug.Log("实验报告上传完毕!");
                        responseActionReport?.Invoke(www.downloadHandler.text);
                    }
                }
            }
        }