Beispiel #1
0
        private static Diff.Item[] FileToIncrementalData(string sourceFile, string targetFile)
        {
            var array1 = File.ReadAllBytes(sourceFile).Select(temp => (int)temp).ToArray();
            var array2 = File.ReadAllBytes(targetFile).Select(temp => (int)temp).ToArray();

            return(Diff.DiffInt(array1, array2));
        }
Beispiel #2
0
        private static void ProcessDiff(RevisionData previousRevision, RevisionData thisRevision, List <LineInfo> lineInfo, int[] prevData, int[] thisData)
        {
            Diff.Item[] script = Diff.DiffInt(prevData, thisData);

            foreach (Diff.Item edit in script)
            {
                // Console.WriteLine("-{0}+{1} @{2}/{3}", edit.deletedA, edit.insertedB, edit.StartA, edit.StartB);
                if (edit.deletedA > 0)
                {
                    lineInfo.RemoveRange(edit.StartB, edit.deletedA);
                }
                for (int i = 0; i < edit.insertedB; ++i)
                {
                    lineInfo.Insert(edit.StartB + i, new LineInfo(thisRevision.Lines[edit.StartB + i], thisRevision));
                }
            }
        }
Beispiel #3
0
        public virtual void SynchronizeLists <T>(ICollection <T> me, ICollection <T> other) where T : class, IValueListEntry
        {
            if (me == null)
            {
                throw new ArgumentNullException("me");
            }
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            var meList    = me.OrderBy(i => i.Index ?? -1).ToList();
            var otherList = other.OrderBy(i => i.Index ?? -1).ToList();

            var diff = Diff.DiffInt(
                meList.Select(i => i == null ? -1 : i.ID).ToArray(),
                otherList.Select(i => i == null ? -1 : i.ID).ToArray());

            foreach (var item in diff)
            {
                int deleted = 0;
                while (deleted < item.deletedA)
                {
                    me.Remove(meList[item.StartA]);
                    meList.RemoveAt(item.StartA);
                    deleted += 1;
                }
                int added = 0;
                while (added < item.insertedB)
                {
                    var otherItem = otherList[item.StartB + added];
                    meList.Insert(item.StartA + added, otherItem);
                    me.Add(otherItem);
                    if (otherItem.ID < Helper.INVALIDID)
                    {
                        Context.Internals().AttachAsNew(otherItem);
                    }
                    else
                    {
                        Context.Attach(otherItem);
                    }
                    added += 1;
                }
            }
        }
Beispiel #4
0
        private static void TestIntDiff(int[] a, int[] b)
        {
            var f = Diff.DiffInt(a, b);

            void WriteLine(int nr, string typ, int num)
            {
                Console.WriteLine($"{typ}({nr}) - {num}");
            }

            int n = 0;

            for (int fdx = 0; fdx < f.Length; fdx++)
            {
                Diff.Item aItem = f[fdx];

                // write unchanged lines
                while ((n < aItem.StartB) && (n < b.Length))
                {
                    //WriteLine(n, "", bLines[n]);
                    n++;
                } // while

                // write deleted lines
                for (int m = 0; m < aItem.deletedA; m++)
                {
                    WriteLine(n, "delete", a[aItem.StartA + m]);
                } // for

                // write inserted lines
                while (n < aItem.StartB + aItem.insertedB)
                {
                    WriteLine(n, "add", b[n]);
                    n++;
                } // while
            }     // while

            // write rest of unchanged lines
            while (n < b.Length)
            {
                WriteLine(n, null, b[n]);
                n++;
            } // while
        }