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; }
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); }
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; }
/// <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(""", "\""); string uncleanext = ext.Value.Replace("\"", """); 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(""", "\"")); resultList.Add(newId, ext); UpdateListText(String.Format("Added extension {0} to database.", ext)); newId++; } return(resultList); }
/// <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("\"", """); } } 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(""", "\"").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++; } }