Ejemplo n.º 1
0
        public int ImportCategory(XmlNodeList nodes)
        {
            ReviewManager reviewManager = new ReviewManager();

            int count = 0;

            foreach (XmlNode x in nodes)
            {
                ReviewModel newItem = new ReviewModel();
                try
                {
                    XmlNodeList temp;
                    if (x["id"] != null)
                    {
                        newItem.CommonSenseMediaID = x["id"].InnerText;
                    }
                    if (x["link"] != null)
                    {
                        newItem.ExternalLink = x["link"].GetAttribute("href");
                    }
                    if (x["category"] != null)
                    {
                        newItem.Type = x["category"].GetAttribute("term");
                    }
                    if (x["published"] != null)
                    {
                        newItem.Published = Sitecore.DateUtil.ToIsoDate(DateTime.Parse(x["published"].InnerText));
                    }
                    if (x["title"] != null)
                    {
                        newItem.Title = x["title"].InnerText;
                    }
                    if (x["summary"] != null)
                    {
                        newItem.Summary = x["summary"].InnerText;
                    }
                    if (x["csm:product"] != null)
                    {
                        if (x["csm:product"]["csm:references"] != null)
                        {
                            temp = x["csm:product"]["csm:references"].ChildNodes;
                            foreach (XmlNode t in temp)
                            {
                                if (t.Attributes["type"].InnerText == "itunes")
                                {
                                    newItem.AppleAppStoreID = t.InnerText;
                                }
                                else if (t.Attributes["type"].InnerText == "googleplay")
                                {
                                    newItem.GooglePlayStoreID = t.InnerText;
                                }
                            }
                        }

                        if (x["csm:product"]["csm:images"] != null)
                        {
                            temp = x["csm:product"]["csm:images"].ChildNodes;
                            List <ReviewImageModel> images = new List <ReviewImageModel>();
                            foreach (XmlNode t in temp)
                            {
                                if (t.Attributes["type"].InnerText == "screenshot")
                                {
                                    ReviewImageModel image = new ReviewImageModel();
                                    image.URL     = t.InnerText;
                                    image.Name    = newItem.Title + "-screenshot-" + (images.Count + 1).ToString();
                                    image.AltText = "Screenshot";
                                    images.Add(image);
                                }
                                else if (t.Attributes["type"].InnerText == "product")
                                {
                                    ReviewImageModel image = new ReviewImageModel();
                                    image.URL         = t.InnerText;
                                    image.Name        = newItem.Title + "-screenshot-" + (images.Count + 1).ToString();
                                    image.AltText     = "Screenshot";
                                    newItem.Thumbnail = image;
                                }
                            }

                            newItem.Screenshots = images;
                        }

                        if (x["csm:product"]["csm:platforms"] != null)
                        {
                            temp = x["csm:product"]["csm:platforms"].ChildNodes;
                            foreach (XmlNode t in temp)
                            {
                                newItem.Platforms += t.InnerText + ",";
                            }
                        }

                        if (x["csm:product"]["csm:prices"] != null && x["csm:product"]["csm:prices"]["csm:price"] != null)
                        {
                            newItem.Price = x["csm:product"]["csm:prices"]["csm:price"].InnerText;
                        }
                        if (x["csm:product"]["csm:genre"] != null)
                        {
                            newItem.Genres = x["csm:product"]["csm:genre"].InnerText;
                        }
                    }

                    if (x["csm:review"] != null)
                    {
                        newItem.QualityRank = x["csm:review"].GetAttribute("star_rating");
                        if (x["csm:review"]["csm:slider"] != null)
                        {
                            newItem.TargetGrade = ResolveGrade(x["csm:review"]["csm:slider"].GetAttribute("target_age"));
                            newItem.OffGrade    = ResolveGrade(x["csm:review"]["csm:slider"].GetAttribute("off_age"));
                            newItem.OnGrade     = ResolveGrade(x["csm:review"]["csm:slider"].GetAttribute("on_age"));
                        }
                        if (x["csm:review"]["csm:parents_need_to_know"] != null)
                        {
                            newItem.ParentsNeedToKnow = x["csm:review"]["csm:parents_need_to_know"].InnerText;
                        }
                        if (x["csm:review"]["csm:description"] != null)
                        {
                            newItem.Description = x["csm:review"]["csm:description"].InnerText;
                        }
                        if (x["csm:review"]["csm:any_good"] != null)
                        {
                            newItem.AnyGood = x["csm:review"]["csm:any_good"].InnerText;
                        }
                        if (x["csm:review"]["csm:learning_rating"] != null)
                        {
                            newItem.LearningRank = x["csm:review"]["csm:learning_rating"].GetAttribute("value");
                            if (x["csm:review"]["csm:learning_rating"]["csm:what_kids_can_learn"] != null)
                            {
                                newItem.WhatKidsCanLearn = x["csm:review"]["csm:learning_rating"]["csm:what_kids_can_learn"].InnerText;
                            }
                            if (x["csm:review"]["csm:learning_rating"]["csm:how_parents_help"] != null)
                            {
                                newItem.HowParentsCanHelp = x["csm:review"]["csm:learning_rating"]["csm:how_parents_help"].InnerText;
                            }

                            if (x["csm:review"]["csm:learning_rating"]["csm:subjects"] != null)
                            {
                                temp = x["csm:review"]["csm:learning_rating"]["csm:subjects"].ChildNodes;
                                foreach (XmlNode t in temp)
                                {
                                    newItem.Subjects += t.Attributes["name"].InnerText + ",";
                                }
                            }

                            if (x["csm:review"]["csm:learning_rating"]["csm:skills"] != null)
                            {
                                temp = x["csm:review"]["csm:learning_rating"]["csm:skills"].ChildNodes;
                                foreach (XmlNode t in temp)
                                {
                                    newItem.Skills += t.Attributes["name"].InnerText + ",";
                                }
                            }
                        }

                        if (x["csm:review"]["csm:special_needs"] != null)
                        {
                            temp = x["csm:review"]["csm:special_needs"].ChildNodes;
                            foreach (XmlNode t in temp)
                            {
                                newItem.Issues += t.Attributes["name"].InnerText + ",";
                            }

                            newItem.Category = x["csm:review"]["csm:special_needs"].GetAttribute("assistive");
                        }
                    }
                }
                catch (Exception e)
                {
                    Log += e.Message + "<br><br><b>";
                }

                try
                {
                    reviewManager.Add(newItem);
                    count++;
                }
                catch
                {
                }
            }

            return(count);
        }
 /// <summary>
 /// Adds a single instace of ReviewImage to Sitecore. Inserts into the container defined in Settings.ImagePath
 /// </summary>
 /// <param name="image">Image to add to Sitecore</param>
 /// <returns>Returns GUID of the image that was added to Sitecore</returns>
 public static Item addMedia(ReviewImageModel image)
 {
     return(addMedia(image.URL, removePunctuation(image.Name), image.AltText));
 }