void SendSuccess(string ss, int objectiveID, int ActivityID, SendReportLate reportLate) { ReportAnalytics ra = new ReportAnalytics(); ra.ObjectiveID = objectiveID; ra.ActivityID = ActivityID; ra.sms = "send success"; ra.dateTime = reportLate.dateTime; // Debug.Log(ss + "" + objectiveID + "//acti" + ActivityID); numSuccess++; // Debug.Log("failed " + numfailed + "/ success" + numSuccess + " / total" + totalsend); if (reportLate.dateTime == DateTime.Today.ToString()) { controlpage.SaveDataTodayReport(reportLate.RepID, reportLate.dcthisDay); } if (numSuccess + numfailed == totalsend) { PopupWaiting.SetActive(false); string mes = ""; if (numSuccess > 0) { mes = "Send succeed " + numSuccess.ToString() + " report. "; } if (numfailed > 0) { mes = "Failed to send" + numfailed.ToString() + " report. that report will be sent in the next time. "; } // controlpage.ShowMesage(mes); Debug.Log(resultsSend.ToString() + "ss"); controlpage.ShowMesage(resultsSend.ToString()); PopupWaiting.SetActive(false); SaveListLate(); controlpage.SaveAfterReport(); } }
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)); } }