void SerializeData() { for (Int32 i = 0; i < _content.Count; i++) { String line = GetFixedLine(i); Match match = Defines.GetDataRegex(_typeId, _subTypeId).Match(line); if (match.Success) { JavaScriptSerializer json = new JavaScriptSerializer() { MaxJsonLength = int.MaxValue }; if (line.Contains("_totalCount")) { TotalCount = UInt32.Parse(Defines.GetStringBetweenTwoOthers(line, "_totalCount: ", ",")); } else { TotalCount = 0; } Objects = (Object[])json.DeserializeObject(match.Groups[1].Captures[0].Value); } } if (Objects == null) { Objects = new Object[0]; } }
public static void ParseOutdatedQuests(uint entry, uint typeId, uint subTypeId, List <string> content) { StringBuilder strBuilder = new StringBuilder(); foreach (string line in content) { Match match = Defines.GetDataRegex(typeId, subTypeId).Match(line); if (match.Success) { strBuilder.AppendLine(string.Format("UPDATE `{0}` SET minLvl = -1, maxLvl = -1 WHERE entry = {1};", Defines.GetDBName(typeId, subTypeId), entry)); } } WriteSQL(typeId, entry, strBuilder.ToString()); Console.WriteLine("{0}% - Parsed {1} data for entry {2}", Math.Round(++dataDone / (float)commandList.Count * 100, 2), Defines.GetStreamName(typeId, subTypeId), entry); }
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; }