Esempio n. 1
0
        public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed)
        {
            DefaultReturnVector ret = new DefaultReturnVector();

            if (params_Renamed != null && params_Renamed.Length == 1)
            {
                String         rlz   = params_Renamed[0].StringValue;
                Defrule        r     = (Defrule)engine.CurrentFocus.findRule(params_Renamed[0].StringValue);
                IList <object> facts = GenerateFacts.generateFacts(r, engine);
                if (facts.Count > 0)
                {
                    try
                    {
                        engine.Watch = WatchType.WATCH_ALL;
                        IEnumerator itr = facts.GetEnumerator();
                        while (itr.MoveNext())
                        {
                            Object data = itr.Current;
                            if (data is Deffact)
                            {
                                engine.assertFact((Deffact)data);
                            }
                            else
                            {
                                engine.assertObject(data, null, false, true);
                            }
                        }
                        engine.fire();
                        engine.UnWatch = WatchType.WATCH_ALL;
                    }
                    catch (AssertException e)
                    {
                        System.Diagnostics.Trace.WriteLine(e.Message);
                    }
                }
            }
            DefaultReturnValue rv = new DefaultReturnValue(Constants.BOOLEAN_OBJECT, true);

            ret.addReturnValue(rv);
            return(ret);
        }
        public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed)
        {
            DefaultReturnVector ret = new DefaultReturnVector();
            bool           echo     = false;
            IList <Object> facts    = null;
            String         output   = null;

            if (params_Renamed != null && params_Renamed.Length >= 1)
            {
                Defrule r = (Defrule)engine.CurrentFocus.findRule(params_Renamed[0].StringValue);
                if (params_Renamed.Length == 2)
                {
                    if (params_Renamed[1].BooleanValue)
                    {
                        echo = true;
                    }
                }
                // if there's 3 parameters, it means we should save the fact
                // to a file
                if (params_Renamed.Length == 3)
                {
                    output = params_Renamed[2].StringValue;
                }
                facts = GenerateFacts.generateFacts(r, engine);
                if (facts.Count > 0)
                {
                    if (echo)
                    {
                        IEnumerator itr = facts.GetEnumerator();
                        while (itr.MoveNext())
                        {
                            Object data = itr.Current;
                            if (data is Deffact)
                            {
                                Deffact f = (Deffact)data;
                                engine.writeMessage(f.toFactString());
                            }
                            else
                            {
                                engine.writeMessage(data.ToString());
                            }
                        }
                    }
                    if (output != null)
                    {
                        // we need to save facts to a file
                        IOUtilities.saveFacts(facts, output);
                    }

                    object[] ary = new object[facts.Count];
                    facts.CopyTo(ary, 0);
                    DefaultReturnValue rv = new DefaultReturnValue(Constants.OBJECT_TYPE, ary);
                    ret.addReturnValue(rv);
                }
                else
                {
                    DefaultReturnValue rv = new DefaultReturnValue(Constants.BOOLEAN_OBJECT, false);
                    ret.addReturnValue(rv);
                }
            }
            return(ret);
        }