public static bool ObtainConcludeWithEventFromCLIPSDataModel(string strEvent, ref List <vMRClsDef.DataModel> lstNewFact)
        {
            string strFilePath         = AppDomain.CurrentDomain.BaseDirectory + ClipsConfig.ReadConfig("Filepath");
            string strConcludeFileName = ClipsConfig.ReadConfig("ConcludeFileName");

            OpenXmlDoc(strFilePath + strConcludeFileName);

            XmlNodeList nl_DataModel = null;
            XmlNodeList nl_Event     = FindMulInstance("EventModel");//查找出xml文件中所有的触发事件节点

            foreach (XmlNode n_Event in nl_Event)
            {
                //得到事件名字
                string strEventENName = n_Event.SelectSingleNode("x:ENName", m_xmlManager).InnerText;
                if (strEventENName == strEvent)
                {
                    //得到事件包含的数据模型
                    nl_DataModel = n_Event.SelectNodes("x:DataModel", m_xmlManager);//查找该事件包含的所有数据模型
                    //循环,依次取出datamodel中data的变量名和它的类型
                    foreach (XmlNode n_DataModel in nl_DataModel)
                    {
                        vMRClsDef.DataModel oDataModel = new vMRClsDef.DataModel();
                        oDataModel.strDataName   = n_DataModel.SelectSingleNode("x:Data/x:DataName", m_xmlManager).InnerText;//数据名字
                        oDataModel.strDataCNName = n_DataModel.SelectSingleNode("x:Data/x:DisplayName", m_xmlManager).InnerText;
                        oDataModel.strDataCode   = n_DataModel.SelectSingleNode("x:Code", m_xmlManager).InnerText;
                        oDataModel.m_emDataType  = vMRClsDef.EnumDataType.STRING;
                        oDataModel.strDataValue  = "NULL";
                        lstNewFact.Add(oDataModel);
                    }
                    break;
                }
            }
            return(true);
        }
        public static bool ObtainTriggeringEventListFromCLIPSDataModel()
        {
            string strFilePath                   = AppDomain.CurrentDomain.BaseDirectory + ClipsConfig.ReadConfig("Filepath");
            string strDataModelFileName          = ClipsConfig.ReadConfig("DataModelFileName");
            string strManualAddDataModelFileName = ClipsConfig.ReadConfig("ManualAddDataModelFileName");

            ObtainTriggeringEventList(strFilePath, strDataModelFileName);
            //ObtainTriggeringEventList(strFilePath, strManualAddDataModelFileName);

            return(true);
        }
        public static bool ObtainDataModelWithEventFromCLIPSDataModel(ref vMRClsDef.InputDataModel oInputDataModel)
        {
            string strFilePath                   = AppDomain.CurrentDomain.BaseDirectory + ClipsConfig.ReadConfig("Filepath");
            string strDataModelFileName          = ClipsConfig.ReadConfig("DataModelFileName");
            string strManualAddDataModelFileName = ClipsConfig.ReadConfig("ManualAddDataModelFileName");

            ObtainDataModel(strFilePath, strDataModelFileName, ref oInputDataModel);
            //ObtainDataModel(strFilePath, strManualAddDataModelFileName, ref oInputDataModel);

            return(true);
        }
Beispiel #4
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);
        }