예제 #1
0
                public void Model_Count_Children_With_Attribute_Order_Equal_To_X_CODE()
                {
                    PreferenceDataStructureEntity entity = Create_Exahustive_ModelGDS();

                    Console.WriteLine(entity.Key);
                    Console.WriteLine("Count children with attribute order equals to 51 (CODE): ");

                    // time start
                    Stopwatch stopWatch = new ();

                    stopWatch.Start();

                    for (int i = 0; i < 1000; i++)
                    {
                        int count  = 0;
                        int length = entity.Children.Count;
                        for (int j = 0; j < length; ++j)
                        {
                            if ((int)entity.Children[j].Attributes["Order"] == 51)
                            {
                                count++;
                            }
                        }
                    }

                    stopWatch.Stop();
                    Console.WriteLine("RunTime Query: " + stopWatch.Elapsed.TotalMilliseconds);

                    // Console.WriteLine(count);
                }
예제 #2
0
                public void Count_Children_Of_CopyOF_Glass_With_Order_X_CODE()
                {
                    PreferenceDataStructureEntity entity = Create_Exahustive_ModelGDS();

                    // time start
                    Stopwatch stopWatch = new();

                    stopWatch.Start();

                    // search a glass that is copy of another glass
                    Atom search = entity.Search("KEY_GLASS_2");

                    // with its order number
                    int order = (int)search.Attributes["Order"];

                    for (int i = 0; i < 1000; i++)
                    {
                        // perform the search
                        Atom atom = entity.ChildrenSearchByAttribute("Order", order);

                        atom.CountChildrenOfCopy();
                    }

                    stopWatch.Stop();
                    Console.WriteLine("RunTime Query: " + stopWatch.Elapsed.TotalMilliseconds);
                }
                public void Store_Model_With_Name()
                {
                    PreferenceDataStructureEntity entity = null;

                    Gds = new PreferenceDataStructure();

                    // xml of example
                    String xml = Path.GetFullPath("./xml-descriptive/UseCase-ReadXML-Model3d.xml");

                    // class to read the descriptive xml
                    ReadDescriptiveXML descriptive = new(xml);

                    // get the information about the model
                    XmlNodeList xmlNodeList = descriptive.XmlDoc.DocumentElement.GetElementsByTagName("dsc:Model");

                    Xunit.Assert.NotNull(xmlNodeList);

                    // time start
                    Stopwatch stopWatch = new();

                    stopWatch.Start();

                    // for each model
                    foreach (XmlNode node in xmlNodeList)
                    {
                        // create the model only with its name
                        entity = Gds.Create(node.Attributes["name"].Value, "model");
                        Assert.Equal(node.Attributes["name"].Value, Gds.GetKeyEntity());
                    }

                    stopWatch.Stop();
                    Console.WriteLine("RunTime Query: " + stopWatch.Elapsed.TotalMilliseconds);
                    entity.Print();
                }
예제 #4
0
                public void Model_Order_Children_By_Attribute_Order_LINQ()
                {
                    PreferenceDataStructureEntity entity = Create_Exahustive_ModelGDS();

                    Console.WriteLine(entity.Key);
                    Console.WriteLine("Childs order by the field order: ");

                    // time start
                    Stopwatch stopWatch = new();

                    stopWatch.Start();

                    for (int i = 0; i < 1000; i++)
                    {
                        var result = from atom in entity.Children
                                     orderby atom.Attributes["Order"]
                                     select atom;
                        _ = result.ToList();
                    }

                    stopWatch.Stop();
                    Console.WriteLine("RunTime Query: " + stopWatch.Elapsed.TotalMilliseconds);

                    // Print(result);
                }
예제 #5
0
                public void Model_Count_Children_With_Attribute_Order_Equal_To_X_LINQ()
                {
                    PreferenceDataStructureEntity entity = Create_Exahustive_ModelGDS();

                    Console.WriteLine(entity.Key);
                    Console.WriteLine("Count children with attribute order equals to 51 (LINQ): ");

                    // time start
                    Stopwatch stopWatch = new();

                    stopWatch.Start();

                    for (int i = 0; i < 1000; i++)
                    {
                        var result = from atom in entity.Children
                                     where ((int)atom.Attributes["Order"]) == 51
                                     select atom;
                        _ = result.ToList();
                    }

                    stopWatch.Stop();
                    Console.WriteLine("RunTime Query: " + stopWatch.Elapsed.TotalMilliseconds);

                    // Console.WriteLine(result.Count());
                }
예제 #6
0
                public void Count_Ancestors_Glass_With_Order_X_LINQ()
                {
                    PreferenceDataStructureEntity entity = Create_Exahustive_ModelGDS();


                    // time start
                    Stopwatch stopWatch = new();

                    stopWatch.Start();

                    // search a glass with many Ancestors
                    Atom search = entity.Search("KEY_GLASS_19");

                    for (int i = 0; i < 1000; i++)
                    {
                        // search a glass with many Ancestors
                        var result = from atom in entity
                                     where (int)atom.Attributes["Order"] == (int)search.Attributes["Order"]
                                     select atom.Ancestors;
                        result.ToList();
                    }

                    // Print(result);

                    stopWatch.Stop();
                    Console.WriteLine("RunTime Query: " + stopWatch.Elapsed.TotalMilliseconds);
                }
        private void Create_Model_And_Attributes(XmlNodeList xmlNodeList, ref PreferenceDataStructureEntity entity, ref PreferenceDataStructure Gds)
        {
            // for each model
            foreach (XmlNode node in xmlNodeList)
            {
                // create the model with its name and the type of model
                entity = Gds.Create(node.Attributes[KEY_XML_NAME].Value, node.Attributes[KEY_XML_PREFSUITEITEM].Value);

                // for each attribute
                foreach (XmlAttribute atr in node.Attributes)
                {
                    // get the name of the attribute and its value
                    string key = atr.Name;

                    // if the attribute is the name and prefSuiteItem we skip them since they were previously stored
                    if (key.Equals(KEY_XML_NAME) || key.Equals(KEY_XML_PREFSUITEITEM))
                    {
                        continue;
                    }

                    // store the attribute
                    entity.AddAttribute(key, atr.Value);
                }
            }
        }
예제 #8
0
                public void Count_Children_Of_CopyOF_Glass_With_Order_X_LINQ()
                {
                    PreferenceDataStructureEntity entity = Create_Exahustive_ModelGDS();

                    // time start
                    Stopwatch stopWatch = new();

                    stopWatch.Start();

                    // search a glass that is copy of another glass
                    Atom search = entity.Search("KEY_GLASS_2");

                    // with its order number
                    int order = (int)search.Attributes["Order"];

                    for (int i = 0; i < 1000; i++)
                    {
                        // perform the search
                        var result = from atom in entity
                                     where (int)atom.Attributes["Order"] == order
                                     join atomOrder in entity on atom.CopyOf equals atomOrder.CopyOf
                                     join f in entity on atomOrder.CopyOf.Key equals f.Key
                                     select f.Children.Count;
                        result.ToList();
                    }

                    stopWatch.Stop();
                    Console.WriteLine("RunTime Query: " + stopWatch.Elapsed.TotalMilliseconds);
                }
예제 #9
0
                public void Model_Query_In_Dictionary_Definitions_Retrieve_All_Materials_LINQ()
                {
                    PreferenceDataStructureEntity entity = Create_Simple_ModelGDS();

                    Console.WriteLine("\nQuerys in the first dictionary: ");

                    // time start
                    Stopwatch stopWatch = new();

                    stopWatch.Start();

                    for (int i = 0; i < 1000; i++)
                    {
                        var result = from atom in entity.Definitions
                                     where atom.Key == TypeDefinitions.Materials
                                     select atom;
                        result.ToList();
                    }

                    stopWatch.Stop();
                    Console.WriteLine("RunTime Query: " + stopWatch.Elapsed.TotalMilliseconds);

                    /*foreach (var c in result)
                     * {
                     *  foreach (var item in c.Value)
                     *  {
                     *      Print(item.Value);
                     *  }
                     * }*/
                }
        private PreferenceDataStructure ReadData()
        {
            string xmlDescriptive = Path;

            // read the xml
            XmlDocument XmlDoc = new XmlDocument();

            XmlDoc.LoadXml(File.ReadAllText(xmlDescriptive));

            PreferenceDataStructureEntity entity = null;

            PreferenceDataStructure Data = new PreferenceDataStructure();

            // Get the information about the model
            XmlNodeList xmlNodeList = XmlDoc.DocumentElement.GetElementsByTagName(KEY_XML_MODEL);

            // Create the model with its attributes
            Create_Model_And_Attributes(xmlNodeList, ref entity, ref Data);

            // Create the definitions
            Create_Definitions(XmlDoc, TypeDefinitions.Materials, KEY_XML_MATERIAL, ref entity);

            Create_Atoms(XmlDoc, KEY_XML_PRICEDOCUMENTATION, KEY_XML_ITEM, ref entity, KEY_XML_ENDID_GROUP);

            return(Data);
        }
예제 #11
0
        /**
         * It creates the Entity
         *
         * @param key is the key name of the entity
         * @param type of the Entity. The type is related to the field prefSuiteItem of the descriptive model
         */
        public PreferenceDataStructureEntity Create(string key, string type)
        {
            // create the model
            Entity = new PreferenceDataStructureEntity(key);
            Entity.AddAttribute("type", type);

            return(Entity);
        }
예제 #12
0
                private PreferenceDataStructureEntity Create_Exahustive_ModelGDS()
                {
                    Atom atom;

                    Gds = new PreferenceDataStructure();
                    PreferenceDataStructureEntity entity = Gds.Create("M01", "model");

                    Random rnd   = new(3173);
                    int    total = 3;

                    // create the list of materials
                    for (int i = 0; i < total; ++i)
                    {
                        atom = entity.AddAtomDefinition("KEY_MATERIAL_" + i, TypeDefinitions.Materials);
                        atom.AddAttribute("Description", "Description of the material");
                        atom.AddAttribute("Order", rnd.Next(total));
                    }


                    total = 2000;

                    // create the list of glasses
                    for (int i = 0; i < total; ++i)
                    {
                        atom = entity.AddAtomDefinition("KEY_GLASS_" + i, TypeDefinitions.Glasses);
                        atom.AddAttribute("Description", "Description of the glass");
                        atom.AddAttribute("Order", rnd.Next(total));

                        bool assignMaterial = (rnd.Next(0, 2) == 1);

                        if (assignMaterial)
                        {
                            atom.AddAttribute("Material", "KEY_MATERIAL_" + rnd.Next(entity.Definitions[TypeDefinitions.Materials].Count));
                        }

                        entity.AddChildren(atom);
                    }

                    // logic relationships
                    entity.AddChildren("KEY_GLASS_0", "KEY_GLASS_5");
                    entity.AddChildren("KEY_GLASS_0", "KEY_GLASS_10");
                    entity.AddChildren("KEY_GLASS_0", "KEY_GLASS_12");

                    entity.AddChildren("KEY_GLASS_5", "KEY_GLASS_16");
                    entity.AddChildren("KEY_GLASS_16", "KEY_GLASS_17");
                    entity.AddChildren("KEY_GLASS_17", "KEY_GLASS_19");

                    entity.AddCopyOf("KEY_GLASS_2", "KEY_GLASS_0");

                    return(entity);
                }
예제 #13
0
                private PreferenceDataStructureEntity Create_Exahustive_ModelGDS()
                {
                    Atom atom;

                    Gds = new PreferenceDataStructure();
                    PreferenceDataStructureEntity entity = Gds.Create("M01", "model");


                    Random rnd   = new(3173);
                    int    total = 3;

                    // create the list of materials
                    for (int i = 0; i < total; ++i)
                    {
                        atom = entity.AddAtomDefinition("KEY_MATERIAL_" + i, TypeDefinitions.Materials);
                        atom.AddAttribute("Description", "Description of the material");
                        atom.AddAttribute("Order", rnd.Next(total));
                    }

                    atom = entity.AddAtomDefinition("KEY_PROFILE_0", TypeDefinitions.Profiles);
                    atom.AddAttribute("Description", "Description of the profile");
                    atom.AddAttribute("Order", rnd.Next(total));
                    atom.AddAttribute("Material", "KEY_MATERIAL_0");
                    atom.AddAttribute("Material_interior", "KEY_MATERIAL_1");
                    atom.AddAttribute("Material_exterior", "KEY_MATERIAL_2");
                    atom.AddAttribute("Longitud", 1000);
                    atom.AddAttribute("Others1", "Any other value");
                    atom.AddAttribute("Others2", "Any other value");
                    atom.AddAttribute("Others3", "Any other value");
                    atom.AddAttribute("Others4", "Any other value");
                    atom.AddAttribute("Others5", "Any other value");
                    entity.AddChildren(atom);


                    total = 10000;

                    // create the two more profiles
                    for (int i = 1; i < total; ++i)
                    {
                        atom = entity.CreateAtomAsCopyOf("KEY_PROFILE_" + i, "KEY_PROFILE_0");

                        atom.AddAttribute("Order", 51); //  rnd.Next(total));
                        atom.AddAttribute("Longitud", 200);

                        entity.AddChildren(atom);
                    }

                    return(entity);
                }
예제 #14
0
                private PreferenceDataStructureEntity Create_Simple_ModelGDS()
                {
                    Atom atom;

                    Gds = new PreferenceDataStructure();
                    PreferenceDataStructureEntity entity = Gds.Create("M01", "model");

                    Random rnd   = new(3173);
                    int    total = 3;

                    // create the list of materials
                    for (int i = 0; i < total; ++i)
                    {
                        atom = entity.AddAtomDefinition("KEY_MATERIAL_" + i, TypeDefinitions.Materials);
                        atom.AddAttribute("Description", "Description of the material");
                        atom.AddAttribute("Order", rnd.Next(total));
                    }



                    total = 4;

                    // create the list of glasses
                    for (int i = 0; i < total; ++i)
                    {
                        atom = entity.AddAtomDefinition("KEY_GLASS_" + i, TypeDefinitions.Glasses);
                        atom.AddAttribute("Description", "Description of the glass");
                        atom.AddAttribute("Order", rnd.Next(total));

                        bool assignMaterial = (rnd.Next(0, 2) == 1);

                        if (assignMaterial)
                        {
                            atom.AddAttribute("Material", "KEY_MATERIAL_" + rnd.Next(entity.Definitions[TypeDefinitions.Materials].Count));
                        }
                    }

                    // create the children of the model. Assume two glass
                    entity.AddChildren("KEY_GLASS_0", "KEY_GLASS_1");
                    entity.AddChildren("KEY_GLASS_0", "KEY_GLASS_3");

                    entity.AddChildren("KEY_GLASS_2");
                    entity.AddChildren("KEY_GLASS_0");

                    return(entity);
                }
예제 #15
0
                public void Model_Search_Children_That_No_Exists_CODE()
                {
                    PreferenceDataStructureEntity entity = Create_Simple_ModelGDS();

                    Console.WriteLine("\nConsultar sobre un hijo que no existe: ");

                    // time start
                    Stopwatch stopWatch = new();

                    stopWatch.Start();

                    for (int i = 0; i < 1000; i++)
                    {
                        var result = entity.Search("KEY_GLASS_2");
                    }

                    stopWatch.Stop();
                    Console.WriteLine("RunTime Query:" + stopWatch.Elapsed.TotalMilliseconds);

                    // Assert.IsNotNull(result);
                }
예제 #16
0
                public void Model_Order_Children_By_Attribute_Order_CODE()
                {
                    PreferenceDataStructureEntity entity = Create_Exahustive_ModelGDS();

                    Console.WriteLine(entity.Key);
                    Console.WriteLine("Childs order by the field order: ");

                    // time start
                    Stopwatch stopWatch = new();

                    stopWatch.Start();

                    for (int i = 0; i < 1000; i++)
                    {
                        entity.ChildrenOrder("Order");
                    }

                    stopWatch.Stop();
                    Console.WriteLine("RunTime Query: " + stopWatch.Elapsed.TotalMilliseconds);

                    // Print(Gds.Model.Children);
                }
예제 #17
0
                public void Count_Ancestors_Glass_With_Order_X_CODE()
                {
                    PreferenceDataStructureEntity entity = Create_Exahustive_ModelGDS();

                    // time start
                    Stopwatch stopWatch = new();

                    stopWatch.Start();

                    // search a glass with many Ancestors
                    Atom search = entity.Search("KEY_GLASS_19");

                    for (int i = 0; i < 1000; i++)
                    {
                        // we use the order of the glass to perform the query
                        Atom atom = entity.ChildrenSearchByAttribute("Order", search.Attributes["Order"]);

                        /*if (atom != null)
                         *  Console.WriteLine(atom.Ancestors);*/
                    }

                    stopWatch.Stop();
                    Console.WriteLine("RunTime Query: " + stopWatch.Elapsed.TotalMilliseconds);
                }
예제 #18
0
                public void Model_Query_In_Dictionary_Definitions_Retrieve_All_Materials_CODE()
                {
                    PreferenceDataStructureEntity entity = Create_Simple_ModelGDS();

                    Console.WriteLine("\nQuerys in the first dictionary: ");

                    // time start
                    Stopwatch stopWatch = new();

                    stopWatch.Start();

                    for (int i = 0; i < 1000; i++)
                    {
                        SortedList <string, Atom> result = entity.Definitions[TypeDefinitions.Materials];
                    }

                    stopWatch.Stop();
                    Console.WriteLine("RunTime Query: " + stopWatch.Elapsed.TotalMilliseconds);

                    /*foreach (var c in result)
                     * {
                     *  Print(c.Value);
                     * }*/
                }
        private void Create_Atoms(XmlDocument XmlDoc, string type, string tagName, ref PreferenceDataStructureEntity entity, string id = "id")
        {
            XmlNodeList xmlNodeList = XmlDoc.DocumentElement.GetElementsByTagName(tagName);

            // for each element in xmlNodeList
            foreach (XmlNode node in xmlNodeList)
            {
                // create the atom with all its attribute
                Atom atom = entity.AddAtom(node.Attributes[id].Value);
                atom.AddAttribute(KEY_XML_TYPE_ATOM, type);

                // create the attributes of the atom
                foreach (XmlAttribute atr in node.Attributes)
                {
                    // get the name of the attribute and its value
                    string key   = atr.Name;
                    string value = atr.Value;

                    // if the attribute is the ref we skip it since it is the name previously stored
                    if (key == id) // || value.Length == 0)
                    {
                        continue;
                    }

                    if (key.Equals("type"))
                    {
                        key = "Type";
                    }

                    // store the attribute
                    atom.AddAttribute(key, value);
                }

                entity.AddChildren(atom);
            }
        }
        private void Create_Definitions(XmlDocument XmlDoc, TypeDefinitions typeDefinition, string tagName, ref PreferenceDataStructureEntity entity)
        {
            XmlNodeList xmlNodeList = XmlDoc.DocumentElement.GetElementsByTagName(tagName);

            // for each element in xmlNodeList
            foreach (XmlNode node in xmlNodeList)
            {
                // create the atom with all its attribute
                Atom atom = entity.AddAtomDefinition(node.Attributes[KEY_XML_REF].Value, typeDefinition);

                // create the attributes of the atom
                foreach (XmlAttribute atr in node.Attributes)
                {
                    // get the name of the attribute and its value
                    string key   = atr.Name;
                    string value = atr.Value;

                    // if the attribute is the ref we skip it since it is the name previously stored
                    if (key == KEY_XML_REF) // || value.Length == 0)
                    {
                        continue;
                    }

                    if (key.Equals("type"))
                    {
                        key = "Type";
                    }

                    // store the attribute
                    atom.AddAttribute(key, value);
                }
            }
        }
예제 #21
0
        static void Main(string[] args)

        {
            Atom atom;

            PreferenceDataStructure Gds = new();

            // first we create the entity
            PreferenceDataStructureEntity entity = Gds.Create("M01", "model");

            // second we create the attributes
            entity.AddAttribute("system", "PRACTICABLE");

            // third we create the atoms
            Random rnd   = new(3173);
            int    total = 3;

            // create the list of materials
            for (int j = 0; j < total; ++j)
            {
                atom = entity.AddAtomDefinition("KEY_MATERIAL_" + j, TypeDefinitions.Materials);
                atom.AddAttribute("Description", "Description of the material");
                atom.AddAttribute("Order", rnd.Next(total));
            }



            total = 3;

            // create the list of glasses
            atom = entity.AddAtomDefinition("KEY_GLASS_0", TypeDefinitions.Glasses);
            atom.AddAttribute("Description", "Description of the profile");
            atom.AddAttribute("Order", rnd.Next(total));
            atom.AddAttribute("Material", "KEY_MATERIAL_2");
            atom.AddAttribute("Material_interior", "KEY_MATERIAL_1");
            atom.AddAttribute("Material_exterior", "KEY_MATERIAL_2");
            atom.AddAttribute("Longitud", 1000);
            atom.AddAttribute("Others1", "Any other value");
            atom.AddAttribute("Others2", "Any other value");
            atom.AddAttribute("Others3", "Any other value");
            atom.AddAttribute("Others4", "Any other value");
            atom.AddAttribute("Others5", "Any other value");
            entity.AddChildren(atom);



            total = 5;

            // create more profiles as copy of KEY_GLASS_0
            for (int j = 1; j < total; ++j)
            {
                // Create Atom as copy of
                atom = entity.CreateAtomAsCopyOf("KEY_GLASS_" + j, "KEY_GLASS_0");

                atom.AddAttribute("Order", rnd.Next(total));
                atom.AddAttribute("Longitud", 200);

                entity.AddChildren(atom);
            }

            // create the children of the model. Assume two glass
            entity.AddChildren("KEY_GLASS_1", "KEY_GLASS_2");
            entity.AddChildren("KEY_GLASS_1", "KEY_GLASS_4");

            entity.AddChildren("KEY_GLASS_3");
            entity.AddChildren("KEY_GLASS_1");


            // TESTS
            Console.WriteLine(Gds.Entity.Key);
            Console.WriteLine("Childs order by the field order: ");

            var result = from at in entity.Children
                         orderby at.Attributes["Order"]
                         select at;

            foreach (var item in result)
            {
                item.Print();
            }


            Console.WriteLine("Filter by the attribute Material: ");

            /*
             * PrefGDSModelFilter filter = new PrefGDSModelFilter();
             * filter.AddCriteria(new CriteriaByAttribute("Material", "KEY_MATERIAL_2"));
             * Atom[] elements = filter.Filter(Gds.Entity);
             * foreach (Atom e in elements)
             *  e.Print();
             *
             */

            /** example of dynamic generation of attributes */
            // Dictionary<String, Object> Attributes = new Dictionary<String, Object>();
            // Attributes.Add("Order", 20);
            // dynamic atom1 = new Atom("Key", Attributes);
            // Console.WriteLine(atom1.Order);

            dynamic myobject = new ExpandoObject();
            IDictionary <string, object> myUnderlyingObject = myobject;

            myUnderlyingObject.Add("IsDynamic", true); // Adding dynamically named property
            Console.WriteLine(myobject.IsDynamic);     // Accessing the property the usual way
        }