Beispiel #1
0
 /// <summary> slotToParameters is a convienant utility method that converts
 /// a list containing parameters and Slots to an array of Parameter[].
 /// The method is used by the parser to handle modify statements.
 /// </summary>
 /// <param name="">list
 /// </param>
 /// <returns>
 ///
 /// </returns>
 public static IParameter[] slotToParameters(IList list)
 {
     IParameter[] pms = new IParameter[list.Count];
     for (int idx = 0; idx < list.Count; idx++)
     {
         if (list[idx] is Slot)
         {
             pms[idx] = new SlotParam((Slot)list[idx]);
         }
         else
         {
             pms[idx] = (IParameter)list[idx];
         }
     }
     return(pms);
 }
Beispiel #2
0
        public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed)
        {
            bool exec = false;
            if (engine != null && params_Renamed != null && params_Renamed.Length >= 2 && params_Renamed[0].ObjectBinding)
            {
                BoundParam bp = (BoundParam) params_Renamed[0];
                Deffact fact = (Deffact) bp.Fact;
                try
                {
                    // first retract the fact
                    engine.retractFact(fact);
                    // now modify the fact
                    SlotParam[] sp = new SlotParam[params_Renamed.Length - 1];
                    for (int idx = 0; idx < sp.Length; idx++)
                    {
                        IParameter p = params_Renamed[idx + 1];
                        if (p is SlotParam)
                        {
                            sp[idx] = (SlotParam) p;
                        }
                    }
                    fact.updateSlots(engine, convertToSlots(sp, fact.Deftemplate));
                    if (fact.hasBinding())
                    {
                        fact.resolveValues(engine, triggerFacts);
                        fact = fact.cloneFact();
                    }
                    // now assert the fact using the same fact-id
                    engine.assertFact(fact);
                    exec = true;
                }
                catch (RetractException e)
                {
                    engine.writeMessage(e.Message);
                }
                catch (AssertException e)
                {
                    engine.writeMessage(e.Message);
                }
            }

            DefaultReturnVector rv = new DefaultReturnVector();
            DefaultReturnValue rval = new DefaultReturnValue(Constants.BOOLEAN_OBJECT, exec);
            rv.addReturnValue(rval);
            return rv;
        }