private void UpdateSuccessSend(int i, RootObjectSendReport result) { LongTermObject lt = INitData.instance.initData.result.longTermObject.Find( m => m.ObjectiveID == listLate.listReport[i].fakeObjectId); if (lt != null) { lt.ObjectiveID = result.result.ObjectiveID; } List <EvaluationActivity> listEva = INitData.instance.initData.result.evaluationActivity .FindAll(m => m.EvaluationActivityID == listLate.listReport[i].FakeACtivitiesID); foreach (var lvs in listEva) { lvs.EvaluationActivityID = result.result.EvaluationActivityID; } UpdateListLate(result.result.ObjectiveID, listLate.listReport[i].fakeObjectId); if (listLate.listReport[i].dateTime == DateTime.Today.ToString()) { controlpage.SetLastReport(listLate.listReport[i].RepID, listLate.listReport[i].dualCallReportObject.step2.datefrom, listLate.listReport[i].dualCallReportObject.step2.dateto, listLate.listReport[i].dualCallReportObject.step2.longterm, listLate.listReport[i].dcthisDay.step2.howto); controlpage.SaveDataTodayReport(listLate.listReport[i].RepID, listLate.listReport[i].dcthisDay); } listLate.listReport[i].Status = 1; }
IEnumerator SendReportList(List <SendReportLate> listReportLate) { string resultSendreport = ""; string reportError = ""; for (int i = 0; i < listReportLate.Count; i++) { if (listReportLate[i].Status == 0) { WWWForm form = new WWWForm(); form.AddBinaryData("pdf1", listReportLate[i].img1, "ScreenShot1.png", "image/png"); form.AddBinaryData("pdf2", listReportLate[i].img2, "ScreenShot2.png", "image/png"); // convert here form.AddField("data", listReportLate[i].dcreport); WWW httpResponse = new WWW("http://vn1ln01.int.grs.net/api/user/save-report", form); yield return(httpResponse); if (!string.IsNullOrEmpty(httpResponse.error)) { reportError += httpResponse.error; } else { try { string t = httpResponse.text; RootObjectSendReport result = JsonMapper.ToObject <RootObjectSendReport>(t); if (result.error == 0) { listReportLate[i].Status = 1; } else { //Debug.Log("Failed to send report"); } } catch (Exception) { reportError += i + " Failed to send report. Please try again\n"; // Debug.Log(reportError + httpResponse.error + httpResponse.text); } } } yield return(new WaitForSeconds(5)); } }
IEnumerator SendReportOffline(List <SendReportLate> listReportLate, Action <string, int, int, SendReportLate> success, Action <string> faild) { resultsSend = new StringBuilder(); rpAftersend = new ReportAfterSend(); reportAnalytics = new ReportAnalytics(); isCatchException = false; numSuccess = 0; numfailed = 0; string resultSendreport = ""; string reportError = ""; totalsend = listLate.listReport.FindAll(a => a.Status == 0).Count; for (int i = 0; i < listLate.listReport.Count; i++) { if (listLate.listReport[i].Status == 0) { WWWForm form = new WWWForm(); form.AddBinaryData("pdf1", listLate.listReport[i].img1, "ScreenShot1.png", "image/png"); form.AddBinaryData("pdf2", listLate.listReport[i].img2, "ScreenShot2.png", "image/png"); string datarp = PublicClassDualCallToJson(listLate.listReport[i].dcthisDay, listLate.listReport[i].dateTime, listLate.listReport[i].dualCallReportObject.rep); form.AddField("data", datarp); WWW httpResponse = new WWW("http://vn1ln01.int.grs.net/api/user/save-report", form); // WWW httpResponse = new WWW("http://localhost/Makas/ItemsData.php", form); float timer = 0; bool failed = false; while (!httpResponse.isDone) { if (timer > 120) // sua thanh 120 { failed = true; if (failed) { resultsSend.AppendLine("Waiting too long, the data will be save in local and send in the next time"); faild("Waiting too long, the data will be save in local and send in the next time"); httpResponse.Dispose(); } break; } timer += Time.deltaTime; yield return(null); } yield return(httpResponse); if (!string.IsNullOrEmpty(httpResponse.error)) { reportError += httpResponse.error; resultsSend.AppendLine(httpResponse.error); faild("Waiting too long, the data will be save in local and send in the next time"); resultsSend.AppendLine(httpResponse.error); } else { try { RootObjectSendReport result = JsonMapper.ToObject <RootObjectSendReport>(httpResponse.text); Debug.Log(httpResponse.text); if (result.error == 0) { UpdateSuccessSend(i, result); resultsSend.AppendLine(result.msg); success("Success", result.result.ObjectiveID, result.result.EvaluationActivityID, listLate.listReport[i]); } else { resultsSend.AppendLine(result.msg); if (result.error_code == 1) { UpdateToomany(i, result.result_error[0].ObjectiveID, result.result_error[0].EvaluationActivityID); } if (result.error_code == 2) { UpdateTooBig(i, result.result_error[0].ObjectiveID, result.result_error[0].EvaluationActivityID); } if (result.error_code == 3) { listLate.listReport[i].Status = 1; } if (result.error_code == 4) { listLate.listReport[i].Status = 1; } if (result.error_code == 5) { listLate.listReport[i].Status = 1; } //const API_CODE_MANY_ACTIVITY = 1; //too mayny activity //const API_CODE_WRONG_LONG_TERM_OBJECT = 2; //longterm object id too big //const API_CODE_OBJECT_ARCHIVED = 3; //đã achieve rồi mà đi lại //const API_CODE_MORE_LONG_TERM_OBJECT = 4;// chưa xong object cũ mà đã tạo mới //const API_CODE_MISSING_LONG_TERM_OBJECT = 5; // không có long term object //const API_CODE_NO_ERROR = 6; if (!string.IsNullOrEmpty(result.msg)) { faild(result.msg); } else { faild("Failed to send report. Please try again"); } } } catch (Exception) { resultsSend.AppendLine(" Can't parse data from server " + httpResponse.error); faild("Failed to send report. Can't parse data from server"); reportError += "Failed to send report. Please try again \n" + "vitri late" + i.ToString(); // Debug.Log(reportError + httpResponse.error + httpResponse.text); isCatchException = true; break; } } } yield return(new WaitForSeconds(1)); } }