private void bw_DoWork(object sender, DoWorkEventArgs e) { // parsing instance ParseTTDb parseTTDb = new ParseTTDb(GetAllProducers(), GetItemCount()); DataToSave[] dataToSave = new DataToSave[parseTTDb.Pages.Length]; // initiate dictionries with items in database Dictionary <string, dynamic>[] invenoryList = { GetAllInventory(parseTTDb.Types[0]), GetAllInventory(parseTTDb.Types[1]), GetAllInventory(parseTTDb.Types[2]) }; // perform parsing for (int i = 0; i < parseTTDb.Pages.Length; i++) { bw.ReportProgress(0, parseTTDb.Pages[i] + " parsing"); dataToSave[i] = parseTTDb.ParseItems(parseTTDb.Pages[i], parseTTDb.Types[i], invenoryList[i], bw, out itemCount); } // insert producers into database bw.ReportProgress(0, "Insert producers"); InsertProducers(parseTTDb.ProducersToInsert); // insert and update database for (int i = 0; i < dataToSave.Length; i++) { bw.ReportProgress(0, $"Insert {parseTTDb.Pages[i]}"); InsertItems(dataToSave[i].ItemsToInsert); bw.ReportProgress(0, $"Update {parseTTDb.Pages[i]}"); UpdateItems(dataToSave[i].ItemsToUpdate); } }
public void TestItemsCount() { ParseTTDb parse = new ParseTTDb(); HtmlNode root = PageData.GetPageRootNode(url); // tables with items urls var itemsTables = root.Descendants().Where(x => x.GetAttributeValue("class", "").Equals("specscompare no-side-border-xxs")).ToList(); // items count int itemsCount = parse.GetItemsCount(itemsTables); Assert.AreNotEqual(itemsCount, 0); }
public void TestInitializeProducers() { ParseTTDb parse = new ParseTTDb(); var root = PageData.GetPageRootNode(url); // divs with the names of producers var producersDivs = root.Descendants().Where(x => x.GetAttributeValue("class", "").Equals("dbcat max-xxs no-radius-xxs no-side-border-xxs")).ToList(); foreach (var producersDiv in producersDivs) { parse.InitializeProducer(producersDiv); } Assert.AreNotEqual(parse.ProducerList.Count, 0); }
public void TestParsePips() { string iurl = "http://www.tabletennisdb.com/pips/andro-blowfish-plus.html"; ParseTTDb parse = new ParseTTDb(); parse.currentItemType = typeof(Pips); parse.constructor = parse.currentItemType.GetConstructor(new Type[0]); parse.itemRatingsProperties = parse.currentItemType.GetProperties().Where(x => x.PropertyType == typeof(double)).ToArray(); //var tmp = parse.itemRatingsProperties. List <Pips> pipses = new List <Pips>(); parse.pipsFlag = true; pipses.Add(parse.ParseItem(iurl, 2)); Assert.AreNotEqual(pipses.Count, 0); }
public void TestParseRubber() { string iurl = "http://www.revspin.net/rubber/darker-vlon-s-blue-v.html"; ParseTTDb parse = new ParseTTDb { currentItemType = typeof(Rubber) }; parse.constructor = parse.currentItemType.GetConstructor(new Type[0]); parse.itemRatingsProperties = parse.currentItemType.GetProperties().Where(x => x.PropertyType == typeof(double)).ToArray(); //var tmp = parse.itemRatingsProperties. List <Rubber> rubbers = new List <Rubber>(); rubbers.Add(parse.ParseItem(iurl, 2)); Assert.AreNotEqual(rubbers.Count, 0); }