public static void ParseData(UInt32 typeId, Int32 subTypeIdFlags, UInt32 entry) { List <String> content; List <int> ids = Defines.ExtractFlags(typeId, subTypeIdFlags); try { content = (usePreCached ? ReadFile(Defines.GenerateWowheadFileName(typeId, entry)) : ReadPage(Defines.GenerateWowheadUrl(typeId, entry))); } catch (Exception e) { dataDone += Defines.GetValidFlags(typeId, subTypeIdFlags); Console.WriteLine("{0}% - Error while parsing Entry {1} ({2})", Math.Round(dataDone / (float)commandList.Count * 100, 2), entry, e.Message); return; } foreach (uint subTypeId in ids) { Ripp(Defines.GetParserType(typeId, subTypeId), entry, typeId, subTypeId, content); } return; }
public static void ParseData(UInt32 type, UInt32 entry) { UInt32 totalCount = 0; UInt32 count = 0; List <string> content; try { content = ReadPage(Defines.GenerateWowheadUrl(type, entry)); } catch (Exception e) { Console.WriteLine("Id {0} Doesn't exist ({1})", entry, e.Message); datad++; return; } foreach (string line in content) { Regex dataRegex = Defines.GetDataRegex(type); Regex totalCountRegex = Defines.GetTotalCountRegex(type); Match m = dataRegex.Match(line); Match m2 = totalCountRegex.Match(line); if (m2.Success) { string str = m2.Groups[0].Captures[0].Value; string[] numbers = Regex.Split(str, @"\D+"); totalCount = uint.Parse(numbers[2]); } if (!m.Success) { continue; } var json = new JavaScriptSerializer() { MaxJsonLength = int.MaxValue }; string data = m.Groups[1].Captures[0].Value; data = data.Replace("[,", "[0,"); // otherwise deserializer complains object[] m_object = (object[])json.DeserializeObject(data); AddToStream(string.Format("-- Parsing {0} loot for entry {1}", Defines.id_name[0], entry)); AddToStream(string.Format("DELETE FROM `{0}` WHERE entry = {1};", Defines.db_name[type], entry)); AddToStream(""); foreach (dict objectInto in m_object) { try { count++; int id = (int)objectInto["id"]; int maxcount = 1; int mincount = 1; float pct = 0.0f; string name = ""; int lootmode = 0; if (type == 0) { lootmode = 1; } if (objectInto.ContainsKey("name")) { name = (string)objectInto["name"]; } int m_count = (int)objectInto["count"]; int ArraySize = ((Array)objectInto["stack"]).GetLength(0); int[] stack = new int[ArraySize]; Array.Copy((Array)objectInto["stack"], stack, ArraySize); pct = (float)m_count / totalCount * 100.0f; maxcount = stack[1]; mincount = stack[0]; pct = (float)Math.Round(pct, 3); string strpct = pct.ToString(); strpct = strpct.Replace(",", "."); // needs to be changed otherwise SQL errors string str = string.Format("INSERT INTO `{0}` VALUES ( '{1}', '{2}', '{3}', '{4}', '{5}', '{6}' , '{7}'); -- {8}", Defines.db_name[type], entry, id, strpct, 1, lootmode, mincount, maxcount, name); AddToStream(str); } catch (Exception e) { Console.WriteLine(e.Message); } } if (count != 0) { AddToStream(string.Format("-- Parsed {0} loot for entry {1}", Defines.id_name[0], entry)); AddToStream(""); } Console.WriteLine("Parsed {0} loot for entry {1}", Defines.id_name[0], entry); datad++; return; } datad++; return; }