/// <summary> /// 启动侦听。 /// </summary> /// <param name="students"></param> public void StartListen(StudentsEx students) { if (students == null) { throw new ArgumentNullException("students", "学生未准备就绪"); } students.SetOfflineStatus(); #region 初始化学生作品存储。 if (this.userInfo != null && this.sci != null) { lock (this) { this.classId = this.sci.ClassInfo.ClassID; LocalStudentWorkStore store = LocalStudentWorkStore.DeSerializer(this.userInfo.UserID, this.sci.CatalogInfo.CatalogID, this.sci.ClassInfo.ClassID); #region 初始化。 if (store == null) { store = new LocalStudentWorkStore(); store.TeacherID = this.userInfo.UserID; store.GradeID = this.sci.GradeID; store.CatalogID = this.sci.CatalogInfo.CatalogID; store.ClassID = this.sci.ClassInfo.ClassID; store.Evaluate = this.sci.Evaluate; } #endregion #region 更新。 store.TeacherName = this.userInfo.UserName; store.GradeName = this.sci.GradeName; store.CatalogName = this.sci.CatalogInfo.CatalogName; store.ClassName = this.sci.ClassInfo.ClassName; store.Evaluate = this.sci.Evaluate; #endregion #region 更新学生信息。 if (students != null && students.Count > 0) { if (store.Students == null) store.Students = new LocalStudents(); string sId = null; for (int i = 0; i < students.Count; i++) { sId = students[i].StudentID; if (!string.IsNullOrEmpty(sId)) { LocalStudent ls = store.Students[sId]; if (ls == null) { ls = new LocalStudent(students[i]); store.Students.Add(ls); } //恢复关联。 Tools.RecoveryWorkAssociation(ref store, ls.StudentID); if (ls.HasWork()) { students[i].Status |= StudentControl.EnumStudentState.Upload; if ((ls.Work.Status & EnumWorkStatus.Review) == EnumWorkStatus.Review) { students[i].Status |= StudentControl.EnumStudentState.Review; } } } } } #endregion //序列化数据。 if (!WorkStoreHelper.Serializer(ref store)) { throw new Exception("生成索引文件失败(索引文件被占用),请稍后重试!"); } //设置当前班级学生。 Program.STUDENTS = students; } } #endregion this.RaiseChanged("开启端口监听..."); this.udpSocket.Start(); this.RaiseChanged("打开文件上传端口侦听..."); this.workUpTcpService.StartListen(); }