コード例 #1
0
        /// <summary>
        /// 加载案件;
        /// </summary>
        /// <param name="cFile"></param>
        public void LoadCase(ICase cs)
        {
            if (cs == null)
            {
                throw new ArgumentNullException(nameof(cs));
            }

            //关闭尚未关闭的案件;
            if (CurrentCase != null)
            {
                CloseCurrentCase();
            }

            //若当前案件仍不为空,则关闭案件未完成,需中断加载案件;
            if (CurrentCase != null)
            {
                return;
            }

            //发布案件加载中事件;
            CommonEventHelper.GetEvent <CaseLoadingEvent>().Publish(cs);
            CurrentCase = cs;

            //从文档中加载证据项;
            var msg = ServiceProvider.Current.GetInstance <IDialogService>()?.CreateDoubleLoadingDialog();

            if (msg == null)
            {
                LoggerService.Current?.WriteCallerLine($"{nameof(IDialogService)} can't be null.");
                return;
            }

            msg.Title = LanguageService.Current?.FindResourceString(LoadingCase);

            msg.DoWork += delegate {
                //构建进度回调器;
                var reporter = ProgessReporterFactory.CreateNew();
                reporter.ProgressReported += (sender, e) => {
                    msg.ReportProgress(e.totalPer, e.detailPer, e.desc, e.detail);
                };

                //证据项元素;
                var evidenceElems = cs.XDoc.Root.Elements(Contracts.Casing.Constants.CaseEvidenceRootElemName);

                foreach (var elem in evidenceElems)
                {
                    try {
                        var csEvidence = LoadCaseEvidenceFromXElem(elem);

                        //加载证据项;
                        CurrentCase.LoadCaseEvidence(csEvidence, reporter);
                    }
                    catch (Exception ex) {
                        Logger.WriteCallerLine(ex.Message);
                        ThreadInvoker.UIInvoke(() => {
                            MsgBoxService.ShowError(ex.Message);
                        });
                    }
                }

                //发布加载案件完成的事件;
                CommonEventHelper.GetEvent <CaseLoadedEvent>().Publish();
                CommonEventHelper.PublishEventToHandlers <ICaseLoadedEventHandler>();
            };


            msg.ShowDialog();
        }