예제 #1
0
        private void bwUpdateLibrary_DoWork(object sender, DoWorkEventArgs e)
        {
            SortableBindingList <Archivist.MagicObjects.MagicCard> tempLib = new SortableBindingList <Archivist.MagicObjects.MagicCard>();

            if (File.Exists(libraryFile))
            {
                ArchivistDatabase adb = new ArchivistDatabase();

                using (StreamReader reader = new StreamReader(libraryFile))
                {
                    while (!reader.EndOfStream)
                    {
                        string[] split = reader.ReadLine().Split(';');
                        Archivist.MagicObjects.MagicCard card = adb.GetCard(Convert.ToInt32(split[0])) as Archivist.MagicObjects.MagicCard;
                        if (card != null)
                        {
                            card.Amount = Convert.ToInt32(split[1]);
                            tempLib.Add(card);
                        }
                    }
                }
            }

            e.Result = tempLib;
        }
예제 #2
0
        private MagicCard GetCardFromText(string text)
        {
            int    blank = text.IndexOf(" ");
            int    amount;
            string name;

            if (blank > 0)
            {
                amount = Convert.ToInt32(text.Substring(0, blank).Trim());
                name   = text.Substring(blank).Trim();
            }
            else
            {
                amount = 1;
                name   = text.Trim();
            }

            ArchivistDatabase adb  = new ArchivistDatabase();
            MagicCard         card = adb.GetCard(name) as MagicCard;

            if (card == null)
            {
                card = new MagicCard(true)
                {
                    Name   = name,
                    Amount = amount
                };
            }
            else
            {
                card.Amount = amount;
            }

            return(card);
        }
예제 #3
0
        private void bwUpdateCardList_DoWork(object sender, DoWorkEventArgs e)
        {
            object[]      args        = e.Argument as object[];
            string        whereclause = args[0] as string;
            List <object> data        = args[1] as List <object>;

            ArchivistDatabase adb = new ArchivistDatabase();
            SortableBindingList <Archivist.MagicObjects.Card> cards = new SortableBindingList <MagicObjects.Card>(adb.GetCards(whereclause, data.ToArray()));

            e.Result = cards;
        }
예제 #4
0
        /// <summary>
        /// Update extensions table
        /// </summary>
        /// <param name="setList"></param>
        /// <param name="id"></param>
        /// <param name="adb"></param>
        private Dictionary <int, string> UpdateExtensions(List <string> setList)
        {
            UpdateListText("Writing extensions to database...");

            ArchivistDatabase        adb          = new ArchivistDatabase();
            Dictionary <int, string> dbExtensions = adb.GetExtensions();
            Dictionary <int, string> resultList   = new Dictionary <int, string>();

            foreach (KeyValuePair <int, string> ext in dbExtensions)
            {
                //string cleanext = ext.Value.Replace("&quot;", "\"");
                string uncleanext = ext.Value.Replace("\"", "&quot;");
                if (setList.Contains(uncleanext))
                {
                    setList.Remove(uncleanext);
                    UpdateListText(String.Format("Extension {0} exists in database. Skipping.", uncleanext));
                }
                else
                {
                    resultList.Add(ext.Key, ext.Value);
                }
            }

            int newId = dbExtensions.Max(sel => sel.Key) + 1;

            foreach (string ext in setList)
            {
                adb.InsertExtension(newId, "", ext.Replace("&quot;", "\""));
                resultList.Add(newId, ext);
                UpdateListText(String.Format("Added extension {0} to database.", ext));

                newId++;
            }

            return(resultList);
        }
예제 #5
0
        /// <summary>
        /// Generate card data from files
        /// </summary>
        /// <param name="setList"></param>
        private void GenerateCards(ref Dictionary <int, string> setList)
        {
            ArchivistDatabase adb = new ArchivistDatabase();

            string currentCardName = string.Empty;
            string paraCardName = string.Empty, paraCost = string.Empty, paraPowTgh = string.Empty, paraRulesText = string.Empty, paraType = string.Empty;
            string paraCardExtCID = string.Empty, paraCardExtRar = string.Empty, paraMultiverseidString = string.Empty;
            int /*paraCardExtEID,*/ paraMultiverseid = 0;
            int id = 1;
            int extId = setList.Count + 1;

            foreach (KeyValuePair <int, string> ext in setList)
            {
                string extoutfile = String.Format("{0}\\{1}.dat", tempDirectory, System.Web.HttpUtility.UrlEncode(ext.Value));
                UpdateListText(String.Format("Analyzing extension file for {0}...", ext.Value));

                if (!System.IO.File.Exists(extoutfile))
                {
                    UpdateListText("File not found. Skipping.");
                    continue;
                }

                HtmlAgilityPack.HtmlWeb      web             = new HtmlAgilityPack.HtmlWeb();
                HtmlAgilityPack.HtmlDocument doc             = web.Load(extoutfile);
                HtmlAgilityPack.HtmlNode     textspoilerNode = doc.DocumentNode.SelectSingleNode("//div[@class=\"textspoiler\"]/table");

                foreach (HtmlAgilityPack.HtmlNode rows in textspoilerNode.SelectNodes("tr"))
                {
                    HtmlAgilityPack.HtmlNodeCollection cols = rows.SelectNodes("td");
                    if (cols.Count == 2)
                    {
                        string key   = cols[0].InnerText.Replace(":", "").Trim();
                        string value = cols[1].InnerText.TrimStart().TrimEnd();

                        if (key == "Name")
                        {
                            currentCardName = value;
                            paraCardName    = value;
                            string href = cols[1].SelectSingleNode("a").GetAttributeValue("href", "");                      //../Card/Details.aspx?multiverseid=201281
                            paraMultiverseidString = href.Substring(href.LastIndexOf("=") + 1);                             //201281
                            paraMultiverseid       = Convert.ToInt32(paraMultiverseidString);
                        }
                        if (key == "Cost")
                        {
                            paraCost = value;
                        }
                        if (key == "Type")
                        {
                            paraType = value.Replace("—", "-").Replace("  ", " ");
                        }
                        if (key == "Pow/Tgh")
                        {
                            paraPowTgh = value;
                        }
                        if (key == "Rules Text")
                        {
                            paraRulesText = value;
                        }
                        if (key == "Set/Rarity")
                        {
                            paraCardExtRar = value.Replace("\"", "&quot;");
                        }
                    }
                    else
                    {
                        if (currentCardName != "")
                        {
                            string[] setrlist = paraCardExtRar.Split(',');
                            string   cid      = string.Empty;
                            foreach (string setr in setrlist)
                            {
                                if (setr.Contains(ext.Value))
                                {
                                    string set    = ext.Value.Replace("&quot;", "\"").Trim();
                                    string rarity = setr.Replace(ext.Value, "").Trim(); // Might be Common/Uncomm/Rare/Mythic Rare

                                    Card card = MagicCardFactory.BuildCard(paraCardName, paraCost, paraPowTgh, paraRulesText, paraType, rarity, set, paraMultiverseid);
                                    cid = adb.InsertCard(card);
                                    break;
                                }
                            }

                            if (string.IsNullOrEmpty(cid))
                            {
                                UpdateListText("Error inserting card: " + currentCardName);
                            }
                        }

                        // New card
                        paraCardName           = null; paraCost = null; paraType = null;
                        paraPowTgh             = null; paraRulesText = null; paraCardExtRar = null;
                        paraMultiverseidString = null;
                        currentCardName        = "";
                    }
                }

                UpdateTotalStatus(setList.Count + id + 1, 2 * setList.Count + 2);
                id++;
            }
        }