public void ObjectMapTest()
        {
            //String[] items = {"camera", "film"};
            //String[] discounts = {"nodiscount", "nodiscount"};

            //PurchaseOrder po = new PurchaseOrder(items, discounts);
            //PurchaseOrder po1 = new PurchaseOrder(items, discounts);
            CustomerTestClass cust = new CustomerTestClass();
            CustomerTestClass cust2 = new CustomerTestClass();
            LocationTestClass theLoc = new LocationTestClass("1", "root location");

            cust.IntVal = 4;
            cust.TheLocation.Description = "first location";
            cust2.TheLocation.Description = "second location";
            cust2.TheLocation.ID = "3";

            Stream mapStream = this.GetType().Assembly.GetManifestResourceStream("Expergent.Tester.ObjectMap.xml");
            StreamReader mapReader = new StreamReader(mapStream);

            ObjectMapTable theTable = new ObjectMapTable(mapReader);

            Agenda agenda = new Agenda();
            List<WME> facts = new List<WME>();
            facts.AddRange(agenda.CreateFactSetFromObjectInstance(new ObjectInstance("CustomerTestClass", cust), theTable));
            facts.AddRange(agenda.CreateFactSetFromObjectInstance(new ObjectInstance("CustomerTestClass", cust2), theTable));
            facts.AddRange(agenda.CreateFactSetFromObjectInstance(new ObjectInstance("LocationTestClass", theLoc), theTable));
            facts.AddRange(agenda.CreateFactSetFromObjectInstance(new ObjectInstance("MyClass", this), theTable));

            Assert.IsTrue(facts.Count == 31, "Wrong # of facts.");
        }
Esempio n. 2
0
        public List<WME> createFactSetFromObjectInstance(Object obj, ObjectMapTable objectmaptable)
        {
            List<WME> list = new List<WME>();
            if (obj is IEnumerable && !(obj is string))
            {
                if (obj is Hashtable)
                {
                    foreach (object eachObject in ((IDictionary) obj).Values)
                    {
                        list.AddRange(
                            createFactSetFromObjectInstance(eachObject, objectmaptable, obj));
                    }
                }
                else
                {
                    foreach (object eachObject in (IEnumerable) obj)
                    {
                        list.AddRange(
                            createFactSetFromObjectInstance(eachObject, objectmaptable, obj));
                    }
                }
            }

            list.AddRange(createFactSetFromObjectInstance(obj, objectmaptable, null));

            return list;
        }
Esempio n. 3
0
        public List <WME> createFactSetFromObjectInstance(Object obj, ObjectMapTable objectmaptable)
        {
            List <WME> list = new List <WME>();

            if (obj is IEnumerable && !(obj is string))
            {
                if (obj is Hashtable)
                {
                    foreach (object eachObject in ((IDictionary)obj).Values)
                    {
                        list.AddRange(
                            createFactSetFromObjectInstance(eachObject, objectmaptable, obj));
                    }
                }
                else
                {
                    foreach (object eachObject in (IEnumerable)obj)
                    {
                        list.AddRange(
                            createFactSetFromObjectInstance(eachObject, objectmaptable, obj));
                    }
                }
            }

            list.AddRange(createFactSetFromObjectInstance(obj, objectmaptable, null));

            return(list);
        }
Esempio n. 4
0
        /// <summary>
        /// use the objectmaptable to create the facts
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <param name="objectMapTable">The object map table.</param>
        /// <param name="parentObj">The parent obj.</param>
        /// <returns></returns>
        public List<WME> createFactSetFromObjectInstance(Object obj, ObjectMapTable objectMapTable, Object parentObj)
        {
            objectmaptable = objectMapTable;
            ArrayList mappedPredicateNames = null;
            WME cliteral = null;
            List<WME> cliteralList = new List<WME>();

            // TODO:  Fix it
            if (obj == null)
                return cliteralList;

            if (objectmaptable != null)
            {
                mappedPredicateNames = objectmaptable.getObjectMappingsByClassName(obj.GetType().FullName);

                if (mappedPredicateNames.Count > 0)
                {
                    //loop through the object mappings for each class and create the List<WME>
                    //

                    #region build cliterals from an object mapping

                    foreach (ObjectMapping eachMapping in mappedPredicateNames)
                    {
                        bool bParentMapped = false;

                        // Add the object reference
                        List<Term> termlist = new List<Term>();
                        termlist.Add(new ObjectTerm(obj));

                        // Add the parent object reference if contained in a list
                        if ((eachMapping.IsContained) && (!bParentMapped))
                        {
                            if (parentObj != null)
                                termlist.Add(new ObjectTerm(parentObj));
                            else
                                termlist.Add(new StringTerm(""));
                            bParentMapped = true;
                        }

                        //ALiteral aliteral = new ALiteral(eachMapping.getPredicateName());
                        //cliteral = new CLiteral(1, aliteral);
                        //cliteral.ArgList = (termlist);

                        foreach (string eachPred in eachMapping.getAttNames())
                        {
                            PropertyInfo theProp = obj.GetType().GetProperty(eachPred);
                            if (theProp == null)
                            {
                                termlist.Add(new StringTerm(""));
                            }
                            else
                            {
                                object objProp = theProp.GetValue(obj, BindingFlags.GetProperty, null, null, null);
                                if (objProp == null)
                                    objProp = String.Empty;

                                switch (theProp.PropertyType.Name)
                                {
                                    case "String[]":
                                        List<Term> termList1 = new List<Term>();
                                        foreach (string eachString in (String[]) objProp)
                                        {
                                            termList1.Add(new StringTerm(eachString));
                                        }
                                        //FuncTerm functerm = new FuncTerm("list", termList1);
                                        //termlist.Add(functerm);
                                        break;

                                    case "String":
                                        termlist.Add(new StringTerm(objProp.ToString()));
                                        break;
                                    case ("Int32"):
                                        termlist.Add(new IntegerTerm((int) objProp));
                                        break;
                                    case ("DateTime"):
                                        termlist.Add(new DateTimeTerm((DateTime) objProp));
                                        break;
                                    case ("Double"):
                                        termlist.Add(new DoubleTerm((double) objProp));
                                        break;
                                    case ("ArrayList"):
                                        List<Term> termList2_ = new List<Term>();
                                        foreach (string eachString in (IEnumerable) objProp)
                                        {
                                            termList2_.Add(new StringTerm(eachString));
                                        }
                                        //FuncTerm functerm2_ = new FuncTerm("list", termList2_);
                                        //termlist.Add(functerm2_);

                                        foreach (object eachObject in (IEnumerable) objProp)
                                        {
                                            if (!eachObject.GetType().IsPrimitive)
                                            {
                                                List<WME> clist =
                                                    createFactSetFromObjectInstance(eachObject, objectmaptable, objProp);
                                                cliteralList.AddRange(clist);
                                            }
                                        }

                                        break;
                                    case ("Boolean"):
                                        termlist.Add(new BooleanTerm((bool) objProp));
                                        break;
                                    default:
                                        bool bAddObjectTerm = true;
                                        if (objProp is IEnumerable)
                                        {
                                            if (objProp is Hashtable)
                                            {
                                                foreach (object eachObject in ((IDictionary) objProp).Values)
                                                {
                                                    if (eachObject.GetType().FullName == "System.String")
                                                    {
                                                        //ALiteral aliteral_ = new ALiteral(objProp.GetType().Name + "Values");
                                                        //CLiteral cliteral_ = new CLiteral(1, aliteral_);

                                                        //List<Term> termlist_ = new List<Term>();
                                                        //termlist_.Add(new StringTerm(eachObject.ToString()));
                                                        //termlist_.Add(new ObjectTerm(objProp));

                                                        //cliteral_.ArgList = (termlist_);
                                                        //cliteralList.Add(cliteral_);
                                                    }
                                                    else
                                                    {
                                                        List<WME> clist =
                                                            createFactSetFromObjectInstance(eachObject, objectmaptable, objProp);
                                                        cliteralList.AddRange(clist);
                                                    }
                                                }
                                            }
                                            else if (objProp.GetType().BaseType.ToString() == "System.Collections.ArrayList")
                                            {
                                                bAddObjectTerm = false;
                                                // Map as an embedded list t
                                                List<Term> termList1_ = new List<Term>();
                                                foreach (object eachObject in (IEnumerable) objProp)
                                                {
                                                    if (eachObject is string)
                                                    {
                                                        termList1_.Add(new StringTerm(eachObject as string));
                                                    }
                                                    else
                                                    {
                                                        List<WME> clist = createFactSetFromObjectInstance(eachObject, objectmaptable, objProp);
                                                        cliteralList.AddRange(clist);
                                                    }
                                                }
                                                if (termList1_.Count > 0)
                                                {
                                                    //FuncTerm functerm_ = new FuncTerm("list", termList1_);
                                                    //termlist.Add(functerm_);
                                                }

                                                //												foreach (object eachObject in (IEnumerable) objProp)
                                                //												{
                                                //													List<WME> clist = this.createFactSetFromObjectInstance(eachObject, objectmaptable, objProp);
                                                //													cliteralList.addCLiteralList(clist);
                                                //												}
                                            }
                                            else
                                            {
                                                foreach (object eachObject in (IEnumerable) objProp)
                                                {
                                                    List<WME> clist =
                                                        createFactSetFromObjectInstance(eachObject, objectmaptable, objProp);
                                                    cliteralList.AddRange(clist);
                                                }
                                            }
                                        }

                                        if (bAddObjectTerm)
                                            termlist.Add(new ObjectTerm(objProp));
                                        List<WME> newList = createFactSetFromObjectInstance(objProp, objectmaptable);
                                        cliteralList.AddRange(newList);
                                        break;
                                } //end switch
                            } // end if prop null
                        } //end foreach eachpred
                    } //end foreach mapping

                    #endregion

                    cliteralList.Add(cliteral);
                } //if (mappedPredicateNames.Count > 0)
            } //if (objectmaptable != null)
            else
            {
                #region build cliterals without an object mapping

                return createFactSetObjectInstanceWithObjectGrapher(obj);

                #endregion
            } //else
            if (CaptureDataValues)
                WriteDataValues(_LogFile + "." + obj.GetType().FullName, cliteralList.ToString());
            return cliteralList;
        }
Esempio n. 5
0
 /// <summary>
 /// Creates the fact set from an object instance.
 /// </summary>
 /// <param name="objectinstance">The object instance.</param>
 /// <param name="objectMapTable">The object map table.</param>
 /// <returns></returns>
 public List<WME> CreateFactSetFromObjectInstance(ObjectInstance objectinstance, ObjectMapTable objectMapTable)
 {
     ObjectInterface objectinterface = new ObjectInterface(AgendaName);
     Object obj = objectinstance.Object;
     return objectinterface.createFactSetFromObjectInstance(obj, objectMapTable);
 }
Esempio n. 6
0
        /// <summary>
        /// use the objectmaptable to create the facts
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <param name="objectMapTable">The object map table.</param>
        /// <param name="parentObj">The parent obj.</param>
        /// <returns></returns>
        public List <WME> createFactSetFromObjectInstance(Object obj, ObjectMapTable objectMapTable, Object parentObj)
        {
            objectmaptable = objectMapTable;
            ArrayList  mappedPredicateNames = null;
            WME        cliteral             = null;
            List <WME> cliteralList         = new List <WME>();

            // TODO:  Fix it
            if (obj == null)
            {
                return(cliteralList);
            }

            if (objectmaptable != null)
            {
                mappedPredicateNames = objectmaptable.getObjectMappingsByClassName(obj.GetType().FullName);

                if (mappedPredicateNames.Count > 0)
                {
                    //loop through the object mappings for each class and create the List<WME>
                    //

                    #region build cliterals from an object mapping

                    foreach (ObjectMapping eachMapping in mappedPredicateNames)
                    {
                        bool bParentMapped = false;

                        // Add the object reference
                        List <Term> termlist = new List <Term>();
                        termlist.Add(new ObjectTerm(obj));

                        // Add the parent object reference if contained in a list
                        if ((eachMapping.IsContained) && (!bParentMapped))
                        {
                            if (parentObj != null)
                            {
                                termlist.Add(new ObjectTerm(parentObj));
                            }
                            else
                            {
                                termlist.Add(new StringTerm(""));
                            }
                            bParentMapped = true;
                        }

                        //ALiteral aliteral = new ALiteral(eachMapping.getPredicateName());
                        //cliteral = new CLiteral(1, aliteral);
                        //cliteral.ArgList = (termlist);

                        foreach (string eachPred in eachMapping.getAttNames())
                        {
                            PropertyInfo theProp = obj.GetType().GetProperty(eachPred);
                            if (theProp == null)
                            {
                                termlist.Add(new StringTerm(""));
                            }
                            else
                            {
                                object objProp = theProp.GetValue(obj, BindingFlags.GetProperty, null, null, null);
                                if (objProp == null)
                                {
                                    objProp = String.Empty;
                                }

                                switch (theProp.PropertyType.Name)
                                {
                                case "String[]":
                                    List <Term> termList1 = new List <Term>();
                                    foreach (string eachString in (String[])objProp)
                                    {
                                        termList1.Add(new StringTerm(eachString));
                                    }
                                    //FuncTerm functerm = new FuncTerm("list", termList1);
                                    //termlist.Add(functerm);
                                    break;

                                case "String":
                                    termlist.Add(new StringTerm(objProp.ToString()));
                                    break;

                                case ("Int32"):
                                    termlist.Add(new IntegerTerm((int)objProp));
                                    break;

                                case ("DateTime"):
                                    termlist.Add(new DateTimeTerm((DateTime)objProp));
                                    break;

                                case ("Double"):
                                    termlist.Add(new DoubleTerm((double)objProp));
                                    break;

                                case ("ArrayList"):
                                    List <Term> termList2_ = new List <Term>();
                                    foreach (string eachString in (IEnumerable)objProp)
                                    {
                                        termList2_.Add(new StringTerm(eachString));
                                    }
                                    //FuncTerm functerm2_ = new FuncTerm("list", termList2_);
                                    //termlist.Add(functerm2_);

                                    foreach (object eachObject in (IEnumerable)objProp)
                                    {
                                        if (!eachObject.GetType().IsPrimitive)
                                        {
                                            List <WME> clist =
                                                createFactSetFromObjectInstance(eachObject, objectmaptable, objProp);
                                            cliteralList.AddRange(clist);
                                        }
                                    }

                                    break;

                                case ("Boolean"):
                                    termlist.Add(new BooleanTerm((bool)objProp));
                                    break;

                                default:
                                    bool bAddObjectTerm = true;
                                    if (objProp is IEnumerable)
                                    {
                                        if (objProp is Hashtable)
                                        {
                                            foreach (object eachObject in ((IDictionary)objProp).Values)
                                            {
                                                if (eachObject.GetType().FullName == "System.String")
                                                {
                                                    //ALiteral aliteral_ = new ALiteral(objProp.GetType().Name + "Values");
                                                    //CLiteral cliteral_ = new CLiteral(1, aliteral_);

                                                    //List<Term> termlist_ = new List<Term>();
                                                    //termlist_.Add(new StringTerm(eachObject.ToString()));
                                                    //termlist_.Add(new ObjectTerm(objProp));

                                                    //cliteral_.ArgList = (termlist_);
                                                    //cliteralList.Add(cliteral_);
                                                }
                                                else
                                                {
                                                    List <WME> clist =
                                                        createFactSetFromObjectInstance(eachObject, objectmaptable, objProp);
                                                    cliteralList.AddRange(clist);
                                                }
                                            }
                                        }
                                        else if (objProp.GetType().BaseType.ToString() == "System.Collections.ArrayList")
                                        {
                                            bAddObjectTerm = false;
                                            // Map as an embedded list t
                                            List <Term> termList1_ = new List <Term>();
                                            foreach (object eachObject in (IEnumerable)objProp)
                                            {
                                                if (eachObject is string)
                                                {
                                                    termList1_.Add(new StringTerm(eachObject as string));
                                                }
                                                else
                                                {
                                                    List <WME> clist = createFactSetFromObjectInstance(eachObject, objectmaptable, objProp);
                                                    cliteralList.AddRange(clist);
                                                }
                                            }
                                            if (termList1_.Count > 0)
                                            {
                                                //FuncTerm functerm_ = new FuncTerm("list", termList1_);
                                                //termlist.Add(functerm_);
                                            }

                                            //												foreach (object eachObject in (IEnumerable) objProp)
                                            //												{
                                            //													List<WME> clist = this.createFactSetFromObjectInstance(eachObject, objectmaptable, objProp);
                                            //													cliteralList.addCLiteralList(clist);
                                            //												}
                                        }
                                        else
                                        {
                                            foreach (object eachObject in (IEnumerable)objProp)
                                            {
                                                List <WME> clist =
                                                    createFactSetFromObjectInstance(eachObject, objectmaptable, objProp);
                                                cliteralList.AddRange(clist);
                                            }
                                        }
                                    }

                                    if (bAddObjectTerm)
                                    {
                                        termlist.Add(new ObjectTerm(objProp));
                                    }
                                    List <WME> newList = createFactSetFromObjectInstance(objProp, objectmaptable);
                                    cliteralList.AddRange(newList);
                                    break;
                                } //end switch
                            }     // end if prop null
                        }         //end foreach eachpred
                    }             //end foreach mapping

                    #endregion

                    cliteralList.Add(cliteral);
                } //if (mappedPredicateNames.Count > 0)
            }     //if (objectmaptable != null)
            else
            {
                #region build cliterals without an object mapping

                return(createFactSetObjectInstanceWithObjectGrapher(obj));

                #endregion
            } //else
            if (CaptureDataValues)
            {
                WriteDataValues(_LogFile + "." + obj.GetType().FullName, cliteralList.ToString());
            }
            return(cliteralList);
        }