Example #1
0
        /// <summary>
        /// Clips推理接口调用
        /// </summary>
        /// <param name="strRuleLevel"></param>
        /// <param name="lstDataModelForIE"></param>
        /// <param name="lstNewFact"></param>
        /// <param name="oTriggeringEvent"></param>
        /// <returns></returns>
        public bool DoInference(string strRuleLevel, List <vMRClsDef.DataModel> lstDataModelForIE,
                                ref List <vMRClsDef.DataModel> lstNewFact, vMRClsDef.TriggeringEvent oTriggeringEvent)
        {
            bool   bRet            = true;
            string strRuleEntrance = ObtainRuleEntrance(strRuleLevel, oTriggeringEvent);

            UserDefinedFun();
            m_oRuleEngine.Watch("all");
            //////////////////////////////////////////////////////////////////////////
            string strfilepath = AppDomain.CurrentDomain.BaseDirectory + ClipsConfig.ReadConfig("Filepath");

            //////////////////////////////////////////////////////////////////////////
            m_oRuleEngine.Load(strfilepath + strRuleEntrance); //load rule
            m_oRuleEngine.Load(strfilepath + "function.clp");  //load deffunction
            DataObject d = m_oRuleEngine.CreateDataObject();

            OperateFact("filepath", "\"" + strfilepath.Replace("\\", "\\\\") + "\"");//load fact filepath

            //load fact of data
            foreach (vMRClsDef.DataModel oDataModel in lstDataModelForIE)
            {
                OperateFact(oDataModel.strDataName, oDataModel.strDataValue);
            }

            //bool bDribbleOn = m_oRuleEngine.DribbleOn("..\\Rule\\out.txt");
            string strIEProcessName =
                System.DateTime.Now.ToString("yyyyMMddHHmmss") + "_"
                + oTriggeringEvent.oEvent.strEventName;
            //////////////////////////////////////////////////////////////////////////
            string strLogPath = AppDomain.CurrentDomain.BaseDirectory + ClipsConfig.ReadConfig("LogPath");
            string strLogFlag = AppDomain.CurrentDomain.BaseDirectory + ClipsConfig.ReadConfig("LogFlag");
            //////////////////////////////////////////////////////////////////////////
            string strIELogDirectory = strLogPath + "IELog\\";

            //如果日志文件目录不存在,则创建该目录
            if (Directory.Exists(strIELogDirectory) == false)
            {
                Directory.CreateDirectory(strIELogDirectory);
            }
            strIELogDirectory = strIELogDirectory + strIEProcessName + ".txt";
            if (strLogFlag == "1")
            {
                bool bDribbleOn = m_oRuleEngine.DribbleOn(strIELogDirectory);
            }

            int nRunRet = m_oRuleEngine.Run(-1);

            m_oRuleEngine.DribbleOff();
            GetNewAddFact(ref lstNewFact);

            return(bRet);
        }