Esempio n. 1
0
        public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed)
        {
            bool saved             = false;
            bool sortid            = true;
            DefaultReturnVector rv = new DefaultReturnVector();

            if (params_Renamed != null && params_Renamed.Length >= 1)
            {
                if (params_Renamed[1] != null && params_Renamed[1].StringValue.Equals("template"))
                {
                    sortid = false;
                }
                try
                {
                    StreamWriter writer = new StreamWriter(params_Renamed[0].StringValue);
                    System.Collections.Generic.IList <Object> facts = engine.AllFacts;
                    Object[] sorted = null;
                    if (sortid)
                    {
                        sorted = FactUtils.sortFacts(facts);
                    }
                    else
                    {
                        sorted = FactUtils.sortFactsByTemplate(facts);
                    }
                    for (int idx = 0; idx < sorted.Length; idx++)
                    {
                        Deffact ft = (Deffact)sorted[idx];
                        writer.Write(ft.toPPString() + Constants.LINEBREAK);
                    }
                    writer.Close();
                    saved = true;
                }
                catch (IOException e)
                {
                    // we should log this
                }
            }
            DefaultReturnValue drv = new DefaultReturnValue(Constants.BOOLEAN_OBJECT, saved);

            rv.addReturnValue(drv);
            return(rv);
        }
 public virtual String toPPString(IParameter[] params_Renamed, int indents)
 {
     if (params_Renamed != null && params_Renamed.Length > 0)
     {
         StringBuilder buf = new StringBuilder();
         buf.Append("(assert-temporal ");
         for (int idx = 0; idx < params_Renamed.Length; idx++)
         {
             // the parameter should be a deffact
             Deffact fact = (Deffact)params_Renamed[idx].Value;
             buf.Append(fact.toPPString());
         }
         buf.Append(" )");
         return(buf.ToString());
     }
     else
     {
         return("(assert-temporal [deffact])");
     }
 }