/// <summary> /// 上传作业 /// </summary> /// <param name="poxy"></param> /// <param name="swp"></param> private void uploadWorks(TeaClientServicePoxyFactory poxy, StudentWorkUpload swp) { try { if (swp.Number > this.repeatNumber) { swp.Progress.UploadFailure("已重复上传[" + (swp.Number - 1) + "]次达到最大限定次数!"); return; } string err = null; swp.Number += 1; if ((swp.Status = poxy.UploadStudentWorks(swp, out err) ? 1 : -1) == 1) { WorkStoreHelper.WorkReviewQueueEntity entity = new WorkStoreHelper.WorkReviewQueueEntity(swp.Student.StudentID, swp.Student.Work.WorkID, EnumWorkStatus.Upload, null, swp.Store.FileSavePath()); entity.Changed += this.OnChanged; WorkStoreHelper.UpdateWorkStatusToQueueStore(entity); this.OnChanged("开始保存[" + swp.Student.StudentName + "," + swp.Title + "]作业状态..."); } else if (!string.IsNullOrEmpty(err)) { this.OnChanged("[" + swp.Title + "]" + err); } if (swp.Status == -1 && swp.Number <= this.repeatNumber) { this.uploadFailureQueue.Enqueue(swp); } } catch (Exception exp) { swp.Progress.UploadFailure(exp.Message); this.OnChanged("上传[" + swp.Student.StudentName + "," + swp.Title + "]时发生异常:" + exp.Message); Yaesoft.SFIT.Client.Utils.UtilTools.OnExceptionRecord(exp, this.GetType()); } }
/// <summary> /// 创建静态实例。 /// </summary> /// <param name="service"></param> /// <param name="Changed"></param> /// <returns></returns> public static TeaClientServicePoxyFactory Instance(ICoreService service, RaiseChangedHandler changed) { lock (typeof(TeaClientServicePoxyFactory)) { Credentials cert = service["credentials"] as Credentials; if (cert == null) { throw new Exception("容器中密钥丢失!请关闭系统后重新登录!"); } TeaClientServicePoxyFactory factory = PoxyCache[cert] as TeaClientServicePoxyFactory; if (factory == null) { factory = new TeaClientServicePoxyFactory(cert); PoxyCache[cert] = factory; } factory.Changed = changed; return factory; } }
private void repeatUploadFailureWorks(TeaClientServicePoxyFactory poxy) { if (this.uploadFailureQueue == null || this.uploadFailureQueue.Count == 0) return; while (this.uploadFailureQueue.Count > 0) { StudentWorkUpload swp = this.uploadFailureQueue.Dequeue() as StudentWorkUpload; if (swp != null) { string msg = "开始[" + swp.Title + "]第[" + swp.Number + "]次上传作业!"; swp.Progress.UpdateProgressToolTipMessage(msg); this.OnChanged(msg); this.uploadWorks(poxy, swp); Thread.Sleep(100); } } }