Ejemplo n.º 1
0
 /// <summary>Remove Tag</summary>
 /// <param name="gamer">GamerCard</param>
 public void Remove(GamerCard gamer)
 {
     DeleteFile(gamer.Picture.Filename);
     DeleteFile(gamer.Avatar.Filename);
     foreach (Game game in gamer.Games)
     {
         DeleteFile(game.Image.Filename);
     }
     GamerCards.Remove(gamer);
     Save();
 }
Ejemplo n.º 2
0
 /// <summary>FromXML</summary>
 /// <param name="xml">XML Data</param>
 private void FromXml(XElement xml)
 {
     gamerCards.Clear();
     if (xml.Name.LocalName == XML_ROOT)
     {
         foreach (XElement node in xml.Descendants(XML_CARD))
         {
             GamerCard item = new GamerCard();
             item.Tag     = node.Element(XML_TAG).Value;
             item.Link    = node.Element(XML_LINK).Value;
             item.Avatar  = PictureFromFile(node.Element(XML_AVATAR).Value);
             item.Picture = PictureFromFile(node.Element(XML_PICTURE).Value);
             // New Fields
             item.Location = node.Element(XML_LOCATION).Value;
             item.Motto    = node.Element(XML_MOTTO).Value;
             item.Name     = node.Element(XML_NAME).Value;
             item.Bio      = node.Element(XML_BIO).Value;
             foreach (XElement subnode in node.Elements(XML_REP))
             {
                 StarControl star = new StarControl();
                 star.Display = (GameCardr.StarControl.DisplayValue) int.Parse(subnode.Element(XML_STAR).Value);
                 item.Stars.Add(star);
             }
             item.Score   = int.Parse(node.Element(XML_SCORE).Value);
             item.Account = (GamerCard.AccountType) int.Parse(node.Element(XML_ACCOUNT).Value);
             item.Updated = DateTime.Parse(node.Element(XML_UPDATED).Value);
             foreach (XElement subnode in node.Elements(XML_GAME))
             {
                 Game game = new Game();
                 game.Link  = subnode.Attribute(XML_LINK).Value;
                 game.Title = subnode.Attribute(XML_TITLE).Value;
                 game.Image = PictureFromFile(subnode.Attribute(XML_IMAGE).Value);
                 // New Fields
                 game.ID                    = subnode.Attribute(XML_ID).Value;
                 game.Cover                 = PictureFromFile(subnode.Attribute(XML_COVER).Value);
                 game.LastPlayed            = subnode.Attribute(XML_LAST_PLAYED).Value;
                 game.EarnedGamerscore      = subnode.Attribute(XML_EARNED_GAMERSCORE).Value;
                 game.AvailableGamerscore   = subnode.Attribute(XML_AVAILABLE_GAMERSCORE).Value;
                 game.EarnedAchievements    = subnode.Attribute(XML_EARNED_ACHIEVEMENTS).Value;
                 game.AvailableAchievements = subnode.Attribute(XML_AVAILABLE_ACHIEVEMENTS).Value;
                 game.PercentageComplete    = subnode.Attribute(XML_PERCENTAGE_COMPLETE).Value;
                 item.Games.Add(game);
             }
             gamerCards.Add(item);
         }
     }
 }
Ejemplo n.º 3
0
 /// <summary>Refresh</summary>
 /// <param name="gamer">GamerCard</param>
 public void Refresh(GamerCard gamer)
 {
     Add(gamer.Tag);
 }
Ejemplo n.º 4
0
        /// <summary>Parse</summary>
        /// <param name="source">Source HTML</param>
        /// <param name="tag">Gamer Tag</param>
        private void Parse(string source, string tag)
        {
            try
            {
                GamerCard gamer = new GamerCard();
                xml = XElement.Parse(Sanitise(GetBody(source))); // Parse HTML

                // Card
                XElement xmlCard = (from element in xml.Descendants()
                                    where element.Name == HTML_DIV
                                    select element).First();

                // Link
                gamer.Link = (from element in xmlCard.Descendants()
                              where (string)element.Attribute(ATTR_ID) == VALUE_GAMERTAG
                              select element).Single().Attribute(ATTR_HREF).Value;

                // Gamer Tag
                gamer.Tag = (from element in xmlCard.Descendants()
                             where (string)element.Attribute(ATTR_ID) == VALUE_GAMERTAG
                             select element).Single().Value;

                // Avatar
                gamer.Avatar = PictureFromUri(new Uri(String.Format(URL_AVATAR, gamer.Tag)));

                // Account
                gamer.Account = xmlCard.FirstAttribute.Value.Contains(VALUE_GOLD)
                     ? GamerCard.AccountType.Gold : GamerCard.AccountType.Free;

                // Gamer Picture
                gamer.Picture = PictureFromUri(new Uri((from element in xmlCard.Descendants()
                                                        where (string)element.Attribute(ATTR_ID) == VALUE_GAMERPIC
                                                        select element).Single().Attribute(ATTR_SRC).Value));

                // Gamer Score
                try { gamer.Score = int.Parse(GetGamerItem(xmlCard, VALUE_GAMERSCORE)); }
                catch { gamer.Score = ZERO; }

                // Location
                gamer.Location = GetGamerItem(xmlCard, VALUE_LOCATION);

                // Motto
                gamer.Motto = GetGamerItem(xmlCard, VALUE_MOTTO);

                // Name
                gamer.Name = GetGamerItem(xmlCard, VALUE_NAME);

                // Bio
                gamer.Bio = GetGamerItem(xmlCard, VALUE_BIO);

                // Reputation Container
                XElement xmlRep = (from element in xmlCard.Descendants()
                                   where (string)element.Attribute(ATTR_CLASS) == VALUE_REPUTATION
                                   select element).Single();

                // Repututation
                IEnumerable <XElement> reputation = (from element in xmlRep.Descendants(HTML_DIV)
                                                     where element.Attribute(ATTR_CLASS).Value.StartsWith(VALUE_STAR)
                                                     select element);

                // Stars
                List <StarControl> stars = new List <StarControl>();
                foreach (XElement element in reputation)
                {
                    StarControl star = new StarControl();
                    switch (element.Attribute(ATTR_CLASS).Value)
                    {
                    case VALUE_STAR_FULL:
                        star.Display = StarControl.DisplayValue.Full;
                        stars.Add(star);
                        break;

                    case VALUE_STAR_HALF:
                        star.Display = StarControl.DisplayValue.Half;
                        stars.Add(star);
                        break;

                    case VALUE_STAR_QUARTER:
                        star.Display = StarControl.DisplayValue.Quarter;
                        stars.Add(star);
                        break;

                    case VALUE_STAR_THREE_QUARTER:
                        star.Display = StarControl.DisplayValue.ThreeQuarter;
                        stars.Add(star);
                        break;

                    default:
                        break;
                    }
                    ;
                }
                gamer.Stars = stars;

                // Played Section
                XElement xmlPlayed = (from element in xmlCard.Descendants()
                                      where (string)element.Attribute(ATTR_ID) == VALUE_PLAYED_GAMES
                                      select element).Single();

                // Played Games
                List <Game> games = new List <Game>();
                foreach (XElement element in xmlPlayed.Descendants(HTML_ITEM))
                {
                    try
                    {
                        Game game = new Game();
                        game.Link                  = element.Element(HTML_ANCHOR).Attribute(ATTR_HREF).Value;
                        game.Image                 = PictureFromUri(new Uri(element.Element(HTML_ANCHOR).Element(HTML_IMG).Attribute(ATTR_SRC).Value));
                        game.ID                    = GetID(game.Link);
                        game.Cover                 = PictureFromUri(GetCover(game.ID, false));
                        game.Title                 = GetGameItem(element, VALUE_TITLE);
                        game.LastPlayed            = GetGameItem(element, VALUE_LAST_PLAYED);
                        game.EarnedGamerscore      = GetGameItem(element, VALUE_EARNED_GAMERSCORE);
                        game.AvailableGamerscore   = GetGameItem(element, VALUE_AVAILABLE_GAMERSCORE);
                        game.EarnedAchievements    = GetGameItem(element, VALUE_EARNED_ACHIEVEMENTS);
                        game.AvailableAchievements = GetGameItem(element, VALUE_AVAILABLE_ACHIEVEMENTS);
                        game.PercentageComplete    = GetGameItem(element, VALUE_PERCENTAGE_COMPLETE);
                        games.Add(game);
                    }
                    catch
                    {
                        // Do Nothing
                    }
                }
                gamer.Games = games;
                // Date Updated
                gamer.Updated = DateTime.Now;
                if (Exists(tag))
                {
                    int       position;
                    GamerCard previous = new GamerCard();
                    previous = Get(tag);
                    position = GamerCards.IndexOf(previous);
                    Remove(previous);
                    GamerCards.Insert(position, gamer);
                }
                else
                {
                    GamerCards.Add(gamer);
                }
                Save();
                Completed(this, EventArgs.Empty);
                gamer = null;
            }
            catch
            {
                message = String.Format(ERR_PARSE, tag);
                Failed(this, EventArgs.Empty);
            }
        }