private static void GroupedRowLevelCompare() { Console.WriteLine("Started Grouped Raw Row comparison."); XmlSerializer xml = new XmlSerializer(typeof(DBEntry[])); var xmls = Directory.EnumerateFiles(Output, "*.xml").ToList(); //int indexCur = xmls.FindIndex(x => x.ToLower().EndsWith("characterloadoutitem.xml")); //if (indexCur > -1) // xmls.RemoveRange(0, indexCur + 1); foreach (var f in xmls) { List <DBEntry> entries; using (var fs = File.OpenRead(f)) entries = ((DBEntry[])xml.Deserialize(fs)).ToList(); // ignore 1 entry if (entries.Count == 1) { continue; } // sort build numbers entries.ForEach(x => x.Builds.Sort((a, b) => a.CompareTo(b))); entries.Sort((a, b) => a.Builds.Min().CompareTo(b.Builds.Min())); // group by field types and compare var groups = entries.GroupBy(x => x.Fields.Select(y => y.Type).ShallowHash()).Where(x => x.Count() > 1); foreach (var group in groups) { for (int i = group.Count() - 1; i > 0; i--) { if (group.ElementAt(i - 1).Builds.Count > 0 && group.ElementAt(i).Builds.Count > 0) { DBComparer.RowLevelMatch(group.ElementAt(i - 1), group.ElementAt(i)); } } } // remove all invalid entries entries.RemoveAll(x => x.Builds.Count == 0); // save using (Stream file = File.Create(f)) { entries.ForEach(x => x.Builds.Sort((a, b) => a.CompareTo(b))); entries.Sort((a, b) => a.Builds.Min().CompareTo(b.Builds.Min())); xml.Serialize(file, entries.ToArray()); } Console.WriteLine($"Compared {Path.GetFileName(f)}"); } Console.WriteLine("Finished Raw Row comparison."); }
private static void RowLevelCompare() { Console.WriteLine("Started Raw Row comparison."); XmlSerializer xml = new XmlSerializer(typeof(DBEntry[])); var xmls = Directory.EnumerateFiles(Output, "*.xml").ToList(); //int indexCur = xmls.FindIndex(x => x.ToLower().EndsWith("characterloadoutitem.xml")); //if (indexCur > -1) // xmls.RemoveRange(0, indexCur + 1); foreach (var f in xmls) { List <DBEntry> entries; using (var fs = File.OpenRead(f)) entries = ((DBEntry[])xml.Deserialize(fs)).ToList(); // sort build numbers + fix formatting foreach (var entry in entries) { entry.Builds.Sort((a, b) => a.CompareTo(b)); entry.Name = entry.Name.ToUpper(); entry.Fields.ForEach(x => x.Name = x.Name.ToUpper()); } entries.Sort((a, b) => a.Builds.Min().CompareTo(b.Builds.Min())); // ID column never moves until WDB5 if (entries.Any(x => x.Fields.Count > 0 && x.Fields[0].Name == "ID")) { foreach (var entry in entries) { if (entry.Fields.Count > 0 && entry.Fields[0].Type == "INT") { entry.Fields[0].Name = "ID"; } } } // row checksum compare - work backwards as matching entries are grouped down for (int i = entries.Count - 1; i > 0; i--) { if (entries[i - 1].Builds.Count > 0 && entries[i].Builds.Count > 0) { DBComparer.RowLevelMatch(entries[i - 1], entries[i]); } } // remove all invalid entries entries.RemoveAll(x => x.Builds.Count == 0); // save using (Stream file = File.Create(f)) { entries.ForEach(x => x.Builds.Sort((a, b) => a.CompareTo(b))); entries.Sort((a, b) => a.Builds.Min().CompareTo(b.Builds.Min())); xml.Serialize(file, entries.ToArray()); } Console.WriteLine($"Compared {Path.GetFileName(f)}"); } Console.WriteLine("Finished Raw Row comparison."); }