Пример #1
0
        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.");
        }
Пример #2
0
        public string Diff(string name, string build1, string build2)
        {
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(build1) || string.IsNullOrEmpty(build2))
            {
                return("Invalid arguments! Require name, build1, build2");
            }

            Logger.WriteLine("Serving diff for " + name + " between " + build1 + " and " + build2);

            var dbc1 = dbcManager.GetOrLoad(name, build1).BackingCollection;
            var dbc2 = dbcManager.GetOrLoad(name, build2).BackingCollection;

            var comparer            = new DBComparer(dbc1, dbc2);
            WoWToolsDiffResult diff = (WoWToolsDiffResult)comparer.Diff(DiffType.WoWTools);

            return(diff.ToJSONString());
        }
Пример #3
0
        public async Task <string> Diff(string name, string build1, string build2, bool useHotfixesFor1 = false, bool useHotfixesFor2 = false)
        {
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(build1) || string.IsNullOrEmpty(build2))
            {
                return("Invalid arguments! Require name, build1, build2");
            }

            Logger.WriteLine("Serving diff for " + name + " between " + build1 + " and " + build2);

            var dbc1 = (IDictionary)await dbcManager.GetOrLoad(name, build1, useHotfixesFor1);

            var dbc2 = (IDictionary)await dbcManager.GetOrLoad(name, build2, useHotfixesFor2);

            var comparer            = new DBComparer(dbc1, dbc2);
            WoWToolsDiffResult diff = (WoWToolsDiffResult)comparer.Diff(DiffType.WoWTools);

            return(diff.ToJSONString());
        }
Пример #4
0
        private void ProgressForm_Load(Object sender, EventArgs e)
        {
            thread = new Thread(() =>
            {
                try
                {
                    Parallel.Invoke(_db1.LoadObjects, _db2.LoadObjects);

                    OnPogressUpdate("Databases are compared...");
                    Result = DBComparer.CompareDatabases(_db1, _db2);
                    this.Invoke(new Action(() => { this.Close(); }));
                }
                catch (Exception ex)
                {
                    Program.LogException(ex);
                }
            });
            thread.IsBackground = true;
            thread.Start();
        }
Пример #5
0
        void ExistDictFileProcessing(Stream stream, Dictionary dict, UserChangeHistory change)
        {
            var tmpFolder = FileHelper.GetTemporaryDirectory();
            var tmpFile   = Path.Combine(tmpFolder, Path.GetFileName(dict.FileName));

            FileHelper.LoadFileFromStream(stream, tmpFile);
            ZipHelper.UnZip(tmpFile);
            var newFile = Directory.GetFiles(tmpFolder, "*.mdb").Single();

            if (AccessHelper.CheckIdentifyInfo(newFile) == dict.Dictionary_id)
            {
                var unZipFoler = ZipHelper.UnZipToTempDir(dict.PathToDict);
                var oldDict    = Directory.GetFiles(unZipFoler, "*.mdb").Single();
                var changes    = DBComparer.CompareDataBase(newFile, oldDict);
                if (changes.Any())
                {
                    using (var db = new DictServiceEntities())
                    {
                        db.DictionaryChangeHistories.AddRange(changes.Select(x => new DictionaryChangeHistory()
                        {
                            UserHistory_id = change.UserHistory_id,
                            Change_id      = (int)x.ChangeType,
                            Dictionary_id  = dict.Dictionary_id,
                            TableName      = x.TableName,
                            PrimaryKey     = x.PrimaryKey,
                            ColumnName     = x.ColumnName,
                            OldValue       = x.OldValue,
                            NewValue       = x.NewValue
                        }));
                        db.SaveChanges();
                    }
                    CreateDictionaryVersion(dict);
                    File.Move(tmpFile, dict.PathToDict);
                }
            }
            else
            {
                throw new Exception("Попытка загрузить неизвестный словарь");
            }
        }
Пример #6
0
        private static void Compare()
        {
            var xmls = Directory.EnumerateFiles(Output, "*.xml");

            foreach (var f in xmls)
            {
                DBComparer.Compare(f);
            }

            // create _log.csv
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("FILENAME,COMPLETION %");

            foreach (var r in DBComparer.Completion)
            {
                sb.AppendLine($"{r.Key},{r.Value.ToString("#000.00")}%");
            }

            sb.AppendLine("");
            sb.AppendLine($"TOTAL,{ DBComparer.Completion.Average(x => x.Value).ToString("000.00")}%");

            File.WriteAllText(Path.Combine(Output, "_Log.csv"), sb.ToString());
        }
Пример #7
0
        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.");
        }