Exemple #1
0
        public static void Run()
        {
            Entities    db  = new Entities();
            XmlDocument doc = new XmlDocument();

            doc.Load(Program.BaseURL + "categories");
            string     xmlcontents = doc.InnerXml;
            XmlElement xelRoot     = doc.DocumentElement;

            XmlNodeList Categories = xelRoot.SelectNodes("/Categories/Category");

            foreach (XmlNode xndNode in Categories)
            {
                Categories c = new Categories();
                c.Name = xndNode["Name"].InnerText;
                var original = db.Categories.Find(xndNode["Name"].InnerText);
                if (original != null)
                {
                    db.Entry(original).CurrentValues.SetValues(c);
                    db.SaveChanges();
                }
                else
                {
                    db.Categories.Add(c);
                    XmlNodeList SubCategories = xndNode.SelectNodes("Subcategory");
                    foreach (XmlNode SubNode in SubCategories)
                    {
                        SubCategories sc = new SubCategories();
                        sc.Name        = SubNode["Name"].InnerText;
                        sc.Parent_Name = xndNode["Name"].InnerText;
                        db.SubCategories.Add(sc);

                        XmlNodeList SubSubCategories = SubNode.SelectNodes("Subsubcategory");
                        foreach (XmlNode SubSubNode in SubSubCategories)
                        {
                            SubSubCategories ssc = new SubSubCategories();
                            ssc.Name        = SubSubNode["Name"].InnerText;
                            ssc.Parent_Name = sc.Name;
                            var originalSubSub = db.SubSubCategories.Find(SubSubNode["Name"].InnerText);
                            if (originalSubSub != null)
                            {
                                db.Entry(originalSubSub).CurrentValues.SetValues(c);
                                db.SaveChanges();
                            }
                            else
                            {
                                db.SubSubCategories.Add(ssc);
                            }
                        }
                    }
                    db.SaveChanges();
                }
            }
        }
Exemple #2
0
        public void RunCategory()
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(p.BaseURL + "categories");
            string     xmlcontents = doc.InnerXml;
            XmlElement xelRoot     = doc.DocumentElement;

            XmlNodeList Categories = xelRoot.SelectNodes("/Categories/Category");

            foreach (XmlNode xndNode in Categories)
            {
                Category c = new Category();
                c.Name = xndNode["Name"].InnerText;
                AllCat.Add(c);
                Console.WriteLine("Category: " + c.Name);

                XmlNodeList SubCategories = xndNode.SelectNodes("Subcategory");
                foreach (XmlNode SubNode in SubCategories)
                {
                    SubCategory sc = new SubCategory();
                    sc.Name = SubNode["Name"].InnerText;
                    AllSubCat.Add(sc);
                    Console.WriteLine("SubCategory: " + SubNode["Name"].InnerText);

                    XmlNodeList SubSubCategories = SubNode.SelectNodes("Subcategory");
                    foreach (XmlNode SubSubNode in SubCategories)
                    {
                        SubSubCategory ssc = new SubSubCategory();
                        ssc.Name = SubSubNode["Name"].InnerText;
                        AllSubSubCat.Add(ssc);
                        Console.WriteLine("SubSubCategory: " + SubSubNode["Name"].InnerText);
                    }
                }
            }
        }
Exemple #3
0
        public WolframAlphaQueryResult LoadResponse(XmlDocument Response)
        {
            System.Threading.Thread.Sleep(1);

            XmlNode MainNode = Response.SelectNodes("/queryresult")[0];

            WA_QueryResult              = new WolframAlphaQueryResult();
            WA_QueryResult.Success      = Convert.ToBoolean(MainNode.Attributes["success"].Value);
            WA_QueryResult.ErrorOccured = Convert.ToBoolean(MainNode.Attributes["error"].Value);
            WA_QueryResult.NumberOfPods = Convert.ToInt32(MainNode.Attributes["numpods"].Value);
            WA_QueryResult.Timing       = Convert.ToDouble(MainNode.Attributes["timing"].Value.Replace(".", ","));
            WA_QueryResult.TimedOut     = MainNode.Attributes["timedout"].Value;
            WA_QueryResult.DataTypes    = MainNode.Attributes["datatypes"].Value;
            WA_QueryResult.Pods         = new List <WolframAlphaPod>();

            foreach (XmlNode Node in MainNode.SelectNodes("pod"))
            {
                System.Threading.Thread.Sleep(1);

                WolframAlphaPod Pod = new WolframAlphaPod();

                Pod.Title           = Node.Attributes["title"].Value;
                Pod.Scanner         = Node.Attributes["scanner"].Value;
                Pod.Position        = Convert.ToInt32(Node.Attributes["position"].Value);
                Pod.ErrorOccured    = Convert.ToBoolean(Node.Attributes["error"].Value);
                Pod.NumberOfSubPods = Convert.ToInt32(Node.Attributes["numsubpods"].Value);
                Pod.SubPods         = new List <WolframAlphaSubPod>();

                foreach (XmlNode SubNode in Node.SelectNodes("subpod"))
                {
                    System.Threading.Thread.Sleep(1);

                    WolframAlphaSubPod SubPod = new WolframAlphaSubPod();
                    SubPod.Title = SubNode.Attributes["title"].Value;

                    foreach (XmlNode ContentNode in SubNode.SelectNodes("plaintext"))
                    {
                        System.Threading.Thread.Sleep(1);
                        SubPod.PodText = ContentNode.InnerText;
                    }

                    foreach (XmlNode ContentNode in SubNode.SelectNodes("img"))
                    {
                        System.Threading.Thread.Sleep(1);

                        WolframAlphaImage Image = new WolframAlphaImage();
                        Image.Location  = new Uri(ContentNode.Attributes["src"].Value);
                        Image.HoverText = ContentNode.Attributes["alt"].Value;
                        Image.Title     = ContentNode.Attributes["title"].Value;
                        Image.Width     = Convert.ToInt32(ContentNode.Attributes["width"].Value);
                        Image.Height    = Convert.ToInt32(ContentNode.Attributes["height"].Value);
                        SubPod.PodImage = Image;
                    }

                    Pod.SubPods.Add(SubPod);
                }

                WA_QueryResult.Pods.Add(Pod);
            }

            return(WA_QueryResult);
        }