Esempio n. 1
0
        protected Fixture()
        {
            testMethods = new Dictionary<Spec, FactInfo>();
            var specs = GetType()
                .GetMethods()
                .Where(mi => mi.HasAttribute<SpecAttribute>());

            foreach (var mi in specs)
            {
                var action = (Action)Delegate.CreateDelegate(typeof (Action), this, mi);
                var spec = new Spec(action) { Name = GetType().Name + "." + mi.Name};
                testMethods[spec] = new FactInfo { Name = spec.Name };
            }

            specs = GetType()
                .GetMethods()
                .Where(mi => mi.ReturnType == typeof(Spec));

            foreach (var mi in specs)
            {
                var action = (Func<Spec>)Delegate.CreateDelegate(typeof(Func<Spec>), this, mi);
                var spec = action();
                spec.Name = GetType().Name + "." + mi.Name;
                testMethods[spec] = new FactInfo { Name = spec.Name };
            }
        }
Esempio n. 2
0
        protected Fixture()
        {
            testMethods = new Dictionary <Spec, FactInfo>();
            var specs = GetType()
                        .GetMethods()
                        .Where(mi => mi.HasAttribute <SpecAttribute>());

            foreach (var mi in specs)
            {
                var action = (Action)Delegate.CreateDelegate(typeof(Action), this, mi);
                var spec   = new Spec(action)
                {
                    Name = GetType().Name + "." + mi.Name
                };
                testMethods[spec] = new FactInfo {
                    Name = spec.Name
                };
            }

            specs = GetType()
                    .GetMethods()
                    .Where(mi => mi.ReturnType == typeof(Spec));

            foreach (var mi in specs)
            {
                var action = (Func <Spec>)Delegate.CreateDelegate(typeof(Func <Spec>), this, mi);
                var spec   = action();
                spec.Name         = GetType().Name + "." + mi.Name;
                testMethods[spec] = new FactInfo {
                    Name = spec.Name
                };
            }
        }
Esempio n. 3
0
        //public bool ConInference(List<string> strNextRuleFileList, List<vMRClsDef.DataModel> oDataModelList)
        //{
        //    //must clear the result at first
        //    m_stInferResult.Init();

        //    bool bRet = true;

        //    /************************
        //    //Remarked by yy,200712220
        //    //if it is not by webservice,there is no need to define these functions again because of these functions is still existed.
        //    //UserDefinedFun();
        //    ***********************/

        //    m_oRuleEngine.Watch("all");

        //    for (int i = 0; i < strNextRuleFileList.Count; i++)
        //    {
        //        if (strNextRuleFileList[i] != string.Empty)
        //        {
        //            m_oRuleEngine.Load(strNextRuleFileList[i]); //load rule
        //        }
        //    }

        //    //load fact of data

        //    /****************************
        //    ////Remarked by yy,20080111
        //    ////if it is not by webservice,there is no need to load the fact existed before the interaction.
        //    //this.FactIndexMax = -1;
        //    //HTFactInfo.Clear();
        //    ////交互前引擎中已存在的事实
        //    //foreach (System.Collections.DictionaryEntry f in HTFactInfo)
        //    //{
        //    //    FactInfo fi =(FactInfo)f.Value;
        //    //    OperateFact(f.Key.ToString(), fi.FactValue);
        //    //}
        //    ****************************/

        //    //交互中新添的事实
        //    foreach (CDataModel oDataModel in oDataModelList)
        //    {
        //        OperateFact(oDataModel.DataName, oDataModel.DataValue);
        //    }

        //    //TODO: DribbleFile to be Dubug
        //    bool bDribbleOn = m_oRuleEngine.DribbleOn(ConfigurationManager.AppSettings["OUT_PATH"]);
        //    int nRunRet = m_oRuleEngine.Run(-1);
        //    m_oRuleEngine.DribbleOff();

        //    return bRet;

        //}

        private void OperateFact(string strName, string strValue)
        {
            if (HTFactInfo.Contains(strName) == false)
            {
                //该事实尚未存在
                string strFact = string.Format("({0} {1})", strName, strValue);
                bool   b       = m_oRuleEngine.LoadFactsFromString(strFact, -1);
                if (b == true)
                {
                    //同时需要更新最大事实索引地址,将事实信息添加到hashtable中。
                    FactIndexMax++;
                    HTFactInfo.Add(strName, new FactInfo(strValue, FactIndexMax, EnumFactChangeFlag.Add));
                }
            }
            else
            {   //已有该事实存在
                FactInfo fi = (FactInfo)HTFactInfo[strName];
                if (fi.FactValue != strValue)
                {   //事实的值有更新
                    //由于没有modify命令可用,所以先撤销事实,再添加事实,因此事实索引地址也被更新
                    string     strRetractFact = string.Format("(retract {0})", fi.FactIndex);
                    DataObject d = m_oRuleEngine.CreateDataObject();
                    m_oRuleEngine.Eval(strRetractFact, d);
                    string strFact = string.Format("({0} {1})", strName, strValue);
                    bool   b       = m_oRuleEngine.LoadFactsFromString(strFact, -1);
                    if (b == true)
                    {
                        //同时需要更新最大事实索引地址,更新hashtable信息。
                        FactIndexMax++;
                        HTFactInfo[strName] = new FactInfo(strValue, FactIndexMax, EnumFactChangeFlag.Modified);
                    }
                }
            }
        }
Esempio n. 4
0
 /// <summary>
 /// 获取clips推理过程中新生成的facts
 /// </summary>
 /// <param name="lstNewFact"></param>
 private void GetNewAddFact(ref List <vMRClsDef.DataModel> lstNewFact)
 {
     for (int i = 0; i < lstNewFact.Count; i++)
     {
         vMRClsDef.DataModel oDataModel = new vMRClsDef.DataModel();
         oDataModel = lstNewFact[i];
         if (HTFactInfo.Contains(oDataModel.strDataName) == true)
         {
             FactInfo fi = (FactInfo)HTFactInfo[oDataModel.strDataName];
             lstNewFact[i].strDataValue = fi.FactValue;
         }
     }
 }
Esempio n. 5
0
 //public bool ConInference(List<string> strNextRuleFileList, List<vMRClsDef.DataModel> oDataModelList)
 //{
 //    //must clear the result at first
 //    m_stInferResult.Init();
 //    bool bRet = true;
 //    /************************
 //    //Remarked by yy,200712220
 //    //if it is not by webservice,there is no need to define these functions again because of these functions is still existed.
 //    //UserDefinedFun();
 //    ***********************/
 //    m_oRuleEngine.Watch("all");
 //    for (int i = 0; i < strNextRuleFileList.Count; i++)
 //    {
 //        if (strNextRuleFileList[i] != string.Empty)
 //        {
 //            m_oRuleEngine.Load(strNextRuleFileList[i]); //load rule
 //        }
 //    }
 //    //load fact of data
 //    /****************************
 //    ////Remarked by yy,20080111
 //    ////if it is not by webservice,there is no need to load the fact existed before the interaction.
 //    //this.FactIndexMax = -1;
 //    //HTFactInfo.Clear();
 //    ////交互前引擎中已存在的事实
 //    //foreach (System.Collections.DictionaryEntry f in HTFactInfo)
 //    //{
 //    //    FactInfo fi =(FactInfo)f.Value;
 //    //    OperateFact(f.Key.ToString(), fi.FactValue);
 //    //}
 //    ****************************/
 //    //交互中新添的事实
 //    foreach (CDataModel oDataModel in oDataModelList)
 //    {
 //        OperateFact(oDataModel.DataName, oDataModel.DataValue);
 //    }
 //    //TODO: DribbleFile to be Dubug
 //    bool bDribbleOn = m_oRuleEngine.DribbleOn(ConfigurationManager.AppSettings["OUT_PATH"]);
 //    int nRunRet = m_oRuleEngine.Run(-1);
 //    m_oRuleEngine.DribbleOff();
 //    return bRet;
 //}
 private void OperateFact(string strName, string strValue)
 {
     if (HTFactInfo.Contains(strName) == false)
     {
         //该事实尚未存在
         string strFact = string.Format("({0} {1})", strName, strValue);
         bool b = m_oRuleEngine.LoadFactsFromString(strFact, -1);
         if (b == true)
         {
             //同时需要更新最大事实索引地址,将事实信息添加到hashtable中。
             FactIndexMax++;
             HTFactInfo.Add(strName, new FactInfo(strValue, FactIndexMax, EnumFactChangeFlag.Add));
         }
     }
     else
     {   //已有该事实存在
         FactInfo fi = (FactInfo)HTFactInfo[strName];
         if (fi.FactValue != strValue)
         {   //事实的值有更新
             //由于没有modify命令可用,所以先撤销事实,再添加事实,因此事实索引地址也被更新
             string strRetractFact = string.Format("(retract {0})", fi.FactIndex);
             DataObject d = m_oRuleEngine.CreateDataObject();
             m_oRuleEngine.Eval(strRetractFact, d);
             string strFact = string.Format("({0} {1})", strName, strValue);
             bool b = m_oRuleEngine.LoadFactsFromString(strFact, -1);
             if (b == true)
             {
                 //同时需要更新最大事实索引地址,更新hashtable信息。
                 FactIndexMax++;
                 HTFactInfo[strName] = new FactInfo(strValue, FactIndexMax, EnumFactChangeFlag.Modified);
             }
         }
     }
 }