private void btnSyncCourseTask_Click(object sender, EventArgs e) { /*JsonResult jr = RemoteServiceProxy.UploadWork(@"C:\Users\乙郎\Pictures\7cbc9488-0a4b-4ab5-a6ed-70e319096680.png", "12", "14"); * AddLog("result=" + jr.message);*/ EnableButton(false); List <long> courseTaskIds = StoreModel.GetFinishCourseTaskIds(); pb.Maximum = courseTaskIds.Count; int syncCount = 0; int successCount = 0; int errorCount = 0; foreach (var id in courseTaskIds) { syncCount++; pb.Value = syncCount; CourseTask ct = StoreModel.GetById(id); JsonResultList list = RemoteServiceProxy.Report(ct, FrmActive.machineCode, FrmActive.activeCode); if (list.error) { AddLog("同步课程任务失败:" + id.ToString() + " 错误信息:" + list.message); errorCount++; continue; } List <WorkInfo4Upload> works = RemoteServiceProxy.PrepareWork(ct.Works, list.data); //然后传到服务器!--作品! bool error = false; foreach (var w in works) { JsonResult jr = RemoteServiceProxy.ReportWork(w); if (jr.error) { AddLog("同步作品失败:" + id.ToString() + " 作品=" + w.StudentNo); error = true; continue; } } if (!error) { StoreModel.FinishReportCourseTask(id); StoreModel.RemoveFiles(ct.Works); successCount++; } else { errorCount++; } } //全部更新完成了 //界面刷新一下 this.UpdateLeftCourseCount(); pb.Value = 0; EnableButton(true); AddLog("同步数量:" + syncCount.ToString() + " 成功数量:" + successCount.ToString() + " 错误数量:" + errorCount.ToString()); }
public static void Main() { // setup trace TextWriterTraceListener traceLog = new TextWriterTraceListener("log.txt"); Debug.Listeners.Add(traceLog); Trace.WriteLine("start at : " + DateTime.Now.ToLongDateString()); //// create a fake course task //long id = 1; ////CourseTask ct = StoreModel.GetById(id); //CourseTask ct = new CourseTask(); //ct.Master = new CardInfo() //{ // No = "400001", // Name = "舒凡", // Rfid = "T:5" //}; //ct.BeginTime = DateTime.Now; //ct.EndTime = DateTime.Now; //ct.CourseId = 1; //ct.CourseNo = "123"; //ct.Assistant1 = new CardInfo() //{ // No = "500001", // Name = "舒凡", // Rfid = "T:5" //}; //ct.Id = 18; //ct.Status = CourseTask.STATUS_START; //ct.AddStudent(new CardInfo() //{ // No = "17", // Name = "苏鹂", // Rfid = "S:23" //}); //ct.AddWork(new WorkInfo() //{ // FilePath = "work1.png", // StudentNo = "17", //}); //JsonResultList list = RemoteServiceProxy.Report(ct, "730427b2ec993b13b3f6697faab1cf", // "abc"); //if (list.error) //{ // Trace.TraceWarning("report course failed! Exit!!!"); // return; //} //List<WorkInfo4Upload> works = RemoteServiceProxy.PrepareWork(ct.Works, list.data); ////然后传到服务器!--作品! //bool error = false; //foreach (var w in works) //{ WorkInfo4Upload w = new WorkInfo4Upload() { FilePath = "student-button.png", ResultStudentId = 17, CourseTaskResultId = 16, }; JsonResult jr = RemoteServiceProxy.ReportWork(w); if (jr.error) { //Trace.TraceWarning("同步作品失败:" + id.ToString() + " 作品=" + w.StudentNo); //error = true; //continue; } //} //if (error) //{ // Trace.TraceError("There are errors when handle the work uploading."); //} }