Пример #1
0
        /// <summary>
        /// 执行检查
        /// </summary>
        /// <returns></returns>
        public bool Check()
        {
            //初始化
            Init();

            if (m_NormalRuleList == null && m_TopoRuleList == null)
            {
                SendMessage(enumMessageType.RuleError, "没有可检查的规则,检查结束");
                return(false);
            }

            // 验证
            Verify();

            ReOpenTopo();

            // 预处理
            Pretreat();


            if (m_NormalRuleList.Count == 0 && m_TopoRuleList.Count == 0)
            {
                SendMessage(enumMessageType.RuleError, "没有可检查的规则,检查结束");
                return(false);
            }


            bool        isSucceed = true;
            ErrorHelper errHelper = ErrorHelper.Instance;

            errHelper.ResultConnection = this.m_ResultConnection;
            CheckHelper checkHelper = new CheckHelper(this.m_ResultConnection);

            // 自动检查
            for (int i = 0; i < m_NormalRuleList.Count; i++)
            {
                SendCheckingEvent(m_NormalRuleList[i]);
                SendMessage(enumMessageType.RuleError, string.Format("规则“{0}”开始检查", m_NormalRuleList[i].InstanceName));

                List <Error> errList  = new List <Error>();
                int          errCount = 0;
                try
                {
                    bool ruleSucceed = m_NormalRuleList[i].Check(ref errList);
                    if (ruleSucceed)
                    {
                        this.m_SucceedCount++;
                        if (errList != null)
                        {
                            errCount = errList.Count;
                        }

                        this.m_ErrorCount += 0;
                        SendMessage(enumMessageType.RuleError, string.Format("规则“{0}”检查成功,错误数:{1}\r\n", m_NormalRuleList[i].InstanceName, errCount));


                        checkHelper.UpdateRuleState(m_DictRuleAndInfo[m_NormalRuleList[i]].arrayRuleParas[0].strInstID, errCount, enumRuleState.ExecuteSucceed);
                    }
                    else
                    {
                        // 添加时默认了为失败,不用更新
                        //checkHelper.UpdateRuleState(m_DictRuleAndInfo[m_NormalRuleList[i]].arrayRuleParas[0].strInstID, 0, enumRuleState.ExecuteFailed);

                        SendMessage(enumMessageType.RuleError, string.Format("规则“{0}”检查失败\r\n", m_NormalRuleList[i].InstanceName));
                        isSucceed = false;
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    // 添加时默认了为失败,不用更新
                    //checkHelper.UpdateRuleState(m_DictRuleAndInfo[m_NormalRuleList[i]].arrayRuleParas[0].strInstID, 0, enumRuleState.ExecuteFailed);

                    SendMessage(enumMessageType.Exception, string.Format("规则“{0}”检查失败,信息:{1}\r\n", m_NormalRuleList[i].InstanceName, ex.Message));
                    continue;
                }
                finally
                {
                    // 无论如何,检查完成了
                    SendRuleCheckedEvent(m_NormalRuleList[i], errCount);
                }

                errHelper.AddErrorList(errList);
            }

            // Topo检查
            // 由本类在Init方法中创建拓扑
            // 在Topo规则的预处理中进行拓扑规则添加
            // 在这里统一进行拓扑验证
            // 规则的Hy.Check方法只负责错误结果的读取
            if (m_TopoRuleList.Count > 0)
            {
                if (this.TopoRuleCheckBegin != null)
                {
                    this.TopoRuleCheckBegin.Invoke(this);
                }

                if (this.m_Topology != null)
                {
                    this.m_Topology.ValidateTopology((this.m_Topology.FeatureDataset as IGeoDataset).Extent);
                }

                for (int i = 0; i < m_TopoRuleList.Count; i++)
                {
                    SendCheckingEvent(m_TopoRuleList[i]);
                    SendMessage(enumMessageType.RuleError, string.Format("规则“{0}”开始获取(拓扑)结果", m_TopoRuleList[i].InstanceName));

                    List <Error> errList  = new List <Error>();
                    int          errCount = 0;
                    try
                    {
                        bool ruleSucceed = m_TopoRuleList[i].Check(ref errList);
                        if (ruleSucceed)
                        {
                            this.m_SucceedCount++;
                            if (errList != null)
                            {
                                errCount = errList.Count;
                            }

                            this.m_ErrorCount += errCount;
                            SendMessage(enumMessageType.RuleError, string.Format("规则“{0}”获取(拓扑)结果成功,错误数:{1}\r\n", m_TopoRuleList[i].InstanceName, errCount));

                            checkHelper.UpdateRuleState(m_DictRuleAndInfo[m_TopoRuleList[i]].arrayRuleParas[0].strInstID, errCount, enumRuleState.ExecuteSucceed, m_TopoRuleList[i].InstanceName);
                        }
                        else
                        {
                            // 添加时默认了为失败,不用更新
                            //checkHelper.UpdateRuleState(m_DictRuleAndInfo[m_TopoRuleList[i]].arrayRuleParas[0].strInstID, 0, enumRuleState.ExecuteFailed,m_TopoRuleList[i].InstanceName);

                            SendMessage(enumMessageType.RuleError, string.Format("规则“{0}”获取(拓扑)结果失败\r\n", m_TopoRuleList[i].InstanceName));
                            isSucceed = false;
                            continue;
                        }
                    }
                    catch (Exception ex)
                    {
                        // 添加时默认了为失败,不用更新
                        //checkHelper.UpdateRuleState(m_DictRuleAndInfo[m_TopoRuleList[i]].arrayRuleParas[0].strInstID, 0, enumRuleState.ExecuteFailed,m_TopoRuleList[i].InstanceName);

                        SendMessage(enumMessageType.Exception, string.Format("规则“{0}”获取(拓扑)结果失败,信息:{1}\r\n", m_TopoRuleList[i].InstanceName, ex.Message));
                        continue;
                    }
                    finally
                    {
                        // 无论如何,检查完成了
                        SendRuleCheckedEvent(m_TopoRuleList[i], errCount);
                    }

                    errHelper.AddErrorList(errList);
                }
            }

            errHelper.Flush();
            this.Release();

            if (this.CheckComplete != null)
            {
                this.CheckComplete.Invoke(this);
            }

            return(isSucceed);
        }