Esempio n. 1
0
        /* Returns a List of the MTGSets from the DB */
        public List <MTGSet> GetSetList()
        {
            List <MTGSet> retSet     = new List <MTGSet>();
            string        getSetList = "SELECT * FROM mtgSets";

            try
            {
                SQLiteCommand    cmd = new SQLiteCommand(getSetList, MTGDB);
                SQLiteDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    DateTime rd = (DateTime)rdr["releaseDate"];
                    DateTime lu = (DateTime)rdr["lastUpdate"];

                    MTGSet set = new MTGSet(rdr["setName"].ToString(), rd);
                    set.CardListLastUpdate = lu;
                    set.URL     = rdr["urlList"].ToString();
                    set.FoilURL = rdr["foilURLList"].ToString();
                    retSet.Add(set);
                }
            }
            catch (Exception err)
            {
                log.Warn("GetSetList():", err);
            }
            return(retSet);
        }
Esempio n. 2
0
        /* URL fetching/parsing for cards for a given set */
        public List <MTGCard> GetCardListForSet(MTGSet SetIn)
        {
            if (SetIn == null)
            {
                log.Error("GetCardListForSet supplied null MTGSet");
                return(null);
            }
            List <MTGCard> curCards = new List <MTGCard>();

            if (SetIn.CardListLastUpdate.CompareTo(DateTime.Today) < 0)
            {
                // Need to Update List
                URLFetcher Fetcher = new URLFetcher(startURL + SetIn.URL);
                string     ret     = Fetcher.Fetch();

                curCards = _MTGPriceParser.ParseCardURLs(ret, SetIn.ToString());
                curCards = curCards.OrderBy(card => card.ToString()).ToList();

                SetIn.CardListLastUpdate = DateTime.Today;

                _SQLWrapper.UpdateCardList(curCards, SetIn.ToString());
                _SQLWrapper.UpdateSetLastUpdate(SetIn.ToString(), SetIn.CardListLastUpdate);
            }
            else
            {
                // List is already up to date, parse from SQL
                curCards = _SQLWrapper.GetCardList(SetIn.ToString());
            }

            curCards = curCards.OrderByDescending(card => card.Price).ToList();

            return(curCards);
        }
Esempio n. 3
0
        /* From a list of set name strings get the matching MTGSets. */
        private List <MTGSet> ConvertStringsToSets(List <string> StringsIn)
        {
            log.Error("ConvertStringsToSets");
            if (StringsIn == null)
            {
                return(null);
            }

            List <MTGSet> ret = new List <MTGSet>();

            foreach (string setName in StringsIn)
            {
                try
                {
                    MTGSet z = Sets.Single(p => p.SetName.Equals(setName, StringComparison.OrdinalIgnoreCase));
                    ret.Add(z);
                }
                catch (System.InvalidOperationException)
                {
                    log.Error("ConvertStringsToSets() failed for set name '" + setName + "'");
                }
            }

            return(ret);
        }
Esempio n. 4
0
        /* Parse all price points for the given set and store properly. Ignore any cards that are up to date or under the given price.*/
        public void ParseAllPricePoints(MTGSet SetIn, UInt64 PriceIn)
        {
            if (SetIn == null)
            {
                log.Error("ParseAllPricePoints() SetIn was null.");
                return;
            }
            if (SetIn.Cards == null || SetIn.Cards.Count == 0)
            {
                log.Error("ParseAllPricePoints() SetIn had no cards.");
                return;
            }

            foreach (MTGCard card in SetIn.Cards)
            {
                if ((card.LastPricePointUpdate.CompareTo(DateTime.Today) > 0) ||
                    (card.Price < PriceIn))
                {
                    continue;
                }

                List <PricePoint> parsePP = new List <PricePoint>();
                URLFetcher        Fetcher = new URLFetcher(startURL + card.URL);
                string            ret     = Fetcher.Fetch();

                parsePP = _MTGPriceParser.ParsePricePoints(ret, card);

                card.LastPricePointUpdate = DateTime.Today;

                _SQLWrapper.UpdatePricePoints(parsePP, card);
                _SQLWrapper.UpdateCardLastUpdate(card, card.LastPricePointUpdate);
            }
        }
Esempio n. 5
0
 /*
  * Updates the elements of the mtgSetsGraphListBox based on checked state of mtgSetsCheckedListBox
  */
 private void updateMTGSetsGraphListBox()
 {
     mtgSetsGraphListBox.BeginUpdate();
     mtgSetsGraphListBox.Items.Clear();
     if (mtgSetsCheckedListBox.CheckedItems.Count > 0)
     {
         foreach (object checkedIndex in mtgSetsCheckedListBox.CheckedItems)
         {
             MTGSet curSet = (MTGSet)checkedIndex;
             mtgSetsGraphListBox.Items.Add(curSet);
         }
     }
     mtgSetsGraphListBox.EndUpdate();
 }
Esempio n. 6
0
        /* Pass current set and TextBoxParseCardPrice info to DataManager.ParseAllPricePoints() */
        private void parseAllPricePointsButton_Click(object sender, EventArgs e)
        {
            MTGSet curSet = (MTGSet)mtgSetsGraphListBox.SelectedItem;

            if (curSet == null)
            {
                UpdateStatusLabel("Status: Must select a set before parsing cards for a set.");
                return;
            }
            double GivenPrice = double.Parse(textBoxParseCardPrice.Text);

            UpdateStatusLabel("Status: Fetching info for current set");
            DM.ParseAllPricePoints(curSet, (ulong)(GivenPrice * 100));
            UpdateStatusLabel("Status: Complete");
        }
Esempio n. 7
0
        /* When a different set is selected, grab URL for specific cards if required and populate mtgCardsGraphListBox */
        private void mtgSetsGraphListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (mtgSetsGraphListBox.SelectedItem == null)
            {
                return;
            }
            MTGSet curSet = (MTGSet)mtgSetsGraphListBox.SelectedItem;

            UpdateStatusLabel("Status: Fetching info for " + curSet.ToString());
            List <MTGCard> Cards = DM.GetCardListForSet(curSet);

            curSet.Cards = Cards;
            UpdateStatusLabel("Status: Complete");

            if (Cards != null)
            {
                updateMTGCardsGraphListBox(Cards);
            }
            else
            {
                UpdateStatusLabel("Status: Error retrieving card list for set " + curSet.ToString());
            }
        }
Esempio n. 8
0
        /* Information stored in the second '<tbody>' */
        public List <MTGSet> ParseSets(string HTMLIn)
        {
            List <MTGSet> retSets = new List <MTGSet>();

            HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(HTMLIn.ToString());

            if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0)
            {
                foreach (HtmlAgilityPack.HtmlParseError err in htmlDoc.ParseErrors)
                {
                    log.Error("HTMLAgilityPack Error: " + err.ToString());
                }
                return(null);
            }

            if (htmlDoc.DocumentNode != null)
            {
                HtmlAgilityPack.HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("(//tbody)[2]");

                if (bodyNode != null)
                {
                    foreach (HtmlAgilityPack.HtmlNode childNode in bodyNode.ChildNodes)
                    {
                        if (childNode == null)
                        {
                            continue;
                        }
                        //FirstNode is URL & Name
                        HtmlAgilityPack.HtmlNode lineNode = childNode.FirstChild;
                        string setName = lineNode.InnerText.TrimEnd(' ');
                        string setURL  = lineNode.FirstChild.GetAttributeValue("href", null).TrimEnd(' ');

                        if (setName.Contains("Foil"))
                        { /* Foil Set, just add URL */
                            string setNameWithoutFoil = setName.Replace(" (Foil)", "");
                            bool   isFound            = false;
                            foreach (MTGSet set in retSets)
                            {
                                if (set.ToString().CompareTo(setNameWithoutFoil) == 0)
                                {
                                    set.FoilURL = setURL;
                                    isFound     = true;
                                }
                            }

                            if (!isFound)
                            {
                                log.Warn("Unable to find Non-Foil set for '" + setNameWithoutFoil + "'");
                            }
                        }
                        else
                        { /* New Set */
                            //SecondNode is Set Release Date
                            lineNode = lineNode.NextSibling;
                            string   date    = lineNode.FirstChild.WriteTo();
                            string[] dates   = date.Split('/');
                            DateTime setDate = new DateTime(Convert.ToInt16(dates[2]),
                                                            Convert.ToInt16(dates[0]),
                                                            Convert.ToInt16(dates[1]));

                            MTGSet tempSet = new MTGSet(setName, setDate);
                            tempSet.URL = setURL;
                            retSets.Add(tempSet);
                        }
                    }
                }
                else
                {
                    log.Error("Body Node Null");
                }
            }
            else
            {
                log.Error("HTMLDoc Node Null");
            }

            return(retSets);
        }