protected override void Free(bool disposing) { // Messenger.Unregister(this); //释放所有ExamItem资源 // if (ExamItems != null) { var allItems = ExamItems.ToArray(); foreach (var examItem in allItems) { try { examItem.Dispose(); } catch (Exception exp) { Logger.ErrorFormat("释放考试项目 {0}-{1} 资源发生异常,原因:{2}", examItem.Name, examItem.ItemCode, exp, exp); } } lock (ExamItems) { ExamItems.Clear(); } //try //{ // ProviderFactory.BeforeLoadSimulationLight(); //} //catch (Exception ex) //{ // Logger.ErrorFormat("异步提前加载灯光出错:{0}", ex.Message); //} } }
protected virtual void OnExamItemStateChanged(ExamItemStateChangedMessage message) { if (message.ExamItem == null) { return; } var examItems = ExamItems.ToArray(); var itemState = Context.ExamItemStates.FirstOrDefault(x => x.ItemCode == message.ExamItem.ItemCode); if (itemState != null) { if (message.NewState == ExamItemState.Progressing) { itemState.Result = ExamItemResult.None; } itemState.State = message.NewState; } //KeiWEI if (message.NewState == ExamItemState.Finished) { if (itemState != null) { var rules = Context.Rules.Where(x => x.ExamItemCode == itemState.ItemCode).ToArray(); if (rules.Length == 0) { itemState.Result = ExamItemResult.Perfect; } else if (rules.Any(x => x.Required)) { itemState.Result = ExamItemResult.Failed; } else { itemState.Result = ExamItemResult.Passed; } } if (examItems.Contains(message.ExamItem)) { try { lock (ExamItems) { ExamItems.Remove(message.ExamItem); } message.ExamItem.Dispose(); } catch (Exception exp) { Logger.ErrorFormat("释放考试项目下{0}发生异常,原因:{1}", message.ExamItem.ItemCode, exp, exp); } } else { Logger.WarnFormat("ExamMananger中不存在考试项目{0}", message.ExamItem); } } }