Exemple #1
0
        public DiffResultSpanCollection DiffReport()
        {
            DiffResultSpanCollection returnResultSpanCollection = new DiffResultSpanCollection();
            int dcount = _dest.Count();
            int scount = _source.Count();

            //Deal with the special case of empty files
            if (dcount == 0)
            {
                if (scount > 0)
                {
                    returnResultSpanCollection.Add(DiffResultSpan.CreateDeleteSource(0, scount));
                }
                return(returnResultSpanCollection);
            }
            else
            {
                if (scount == 0)
                {
                    returnResultSpanCollection.Add(DiffResultSpan.CreateAddDestination(0, dcount));
                    return(returnResultSpanCollection);
                }
            }


            _matchList.Sort();
            int            curDest        = 0;
            int            curSource      = 0;
            DiffResultSpan lastResultSpan = null;

            //Process each match record
            foreach (DiffResultSpan resultSpan in _matchList)
            {
                if ((!AddChanges(returnResultSpanCollection, curDest, resultSpan.DestIndex, curSource, resultSpan.SourceIndex)) &&
                    (lastResultSpan != null))
                {
                    lastResultSpan.AddLength(resultSpan.Length);
                }
                else
                {
                    returnResultSpanCollection.Add(resultSpan);
                }
                curDest        = resultSpan.DestIndex + resultSpan.Length;
                curSource      = resultSpan.SourceIndex + resultSpan.Length;
                lastResultSpan = resultSpan;
            }

            //Process any tail end data
            AddChanges(returnResultSpanCollection, curDest, dcount, curSource, scount);

            return(returnResultSpanCollection);
        }
Exemple #2
0
        public DiffResultSpanCollection DiffReport()
        {
            DiffResultSpanCollection returnResultSpanCollection = new DiffResultSpanCollection();
            int dcount = _dest.Count();
            int scount = _source.Count();

            //Deal with the special case of empty files
            if (dcount == 0)
            {
                if (scount > 0)
                {
                    returnResultSpanCollection.Add(DiffResultSpan.CreateDeleteSource(0,scount));
                }
                return returnResultSpanCollection;
            }
            else
            {
                if (scount == 0)
                {
                    returnResultSpanCollection.Add(DiffResultSpan.CreateAddDestination(0,dcount));
                    return returnResultSpanCollection;
                }
            }

            _matchList.Sort();
            int curDest = 0;
            int curSource = 0;
            DiffResultSpan lastResultSpan = null;

            //Process each match record
            foreach (DiffResultSpan resultSpan in _matchList)
            {
                if ((!AddChanges(returnResultSpanCollection,curDest,resultSpan.DestIndex,curSource,resultSpan.SourceIndex))&&
                    (lastResultSpan != null))
                {
                    lastResultSpan.AddLength(resultSpan.Length);
                }
                else
                {
                    returnResultSpanCollection.Add(resultSpan);
                }
                curDest = resultSpan.DestIndex + resultSpan.Length;
                curSource = resultSpan.SourceIndex + resultSpan.Length;
                lastResultSpan = resultSpan;
            }

            //Process any tail end data
            AddChanges(returnResultSpanCollection,curDest,dcount,curSource,scount);

            return returnResultSpanCollection;
        }
Exemple #3
0
        private bool AddChanges(
            DiffResultSpanCollection report,
            int curDest,
            int nextDest,
            int curSource,
            int nextSource)
        {
            bool returnResultSpanCollection = false;
            int  diffDest   = nextDest - curDest;
            int  diffSource = nextSource - curSource;
            int  minDiff    = 0;

            if (diffDest > 0)
            {
                if (diffSource > 0)
                {
                    minDiff = Math.Min(diffDest, diffSource);
                    report.Add(DiffResultSpan.CreateReplace(curDest, curSource, minDiff));
                    if (diffDest > diffSource)
                    {
                        curDest += minDiff;
                        report.Add(DiffResultSpan.CreateAddDestination(curDest, diffDest - diffSource));
                    }
                    else
                    {
                        if (diffSource > diffDest)
                        {
                            curSource += minDiff;
                            report.Add(DiffResultSpan.CreateDeleteSource(curSource, diffSource - diffDest));
                        }
                    }
                }
                else
                {
                    report.Add(DiffResultSpan.CreateAddDestination(curDest, diffDest));
                }
                returnResultSpanCollection = true;
            }
            else
            {
                if (diffSource > 0)
                {
                    report.Add(DiffResultSpan.CreateDeleteSource(curSource, diffSource));
                    returnResultSpanCollection = true;
                }
            }
            return(returnResultSpanCollection);
        }
 //UPDATE
 internal DifferenceCollectionEnumerator(DiffResultSpanCollection collection)
 {
     _index = -1;
     _collection = collection;
 }
Exemple #5
0
 public DiffResultSpanSerializer(DiffResultSpanCollection diffResultSpanCollection)
 {
     _diffResultSpanCollection = diffResultSpanCollection;
 }
 public DiffResultSpanSerializer(DiffResultSpanCollection diffResultSpanCollection)
 {
     _diffResultSpanCollection = diffResultSpanCollection;
 }
Exemple #7
0
        public Results(TextMemory source, TextMemory destination, DiffResultSpanCollection diffResults, double seconds)
        {
            InitializeComponent();
            this.Text = string.Format("Results: {0} secs.",seconds.ToString("#0.00"));

            ListViewItem lviS;
            ListViewItem lviD;
            int cnt = 1;
            int i;

            foreach (DiffResultSpan drs in diffResults)
            {
                switch (drs.Status)
                {
                    case DiffResultSpanStatus.DeleteSource:
                        for (i = 0; i < drs.Length; i++)
                        {
                            lviS = new ListViewItem(cnt.ToString("00000"));
                            lviD = new ListViewItem(cnt.ToString("00000"));
                            lviS.BackColor = Color.Red;
                            lviS.SubItems.Add(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line);
                            lviD.BackColor = Color.LightGray;
                            lviD.SubItems.Add("");

                            lvSource.Items.Add(lviS);
                            lvDestination.Items.Add(lviD);
                            cnt++;
                        }

                        break;
                    case DiffResultSpanStatus.NoChange:
                        for (i = 0; i < drs.Length; i++)
                        {
                            lviS = new ListViewItem(cnt.ToString("00000"));
                            lviD = new ListViewItem(cnt.ToString("00000"));
                            lviS.BackColor = Color.White;
                            lviS.SubItems.Add(((TextLine)source.GetByIndex(drs.SourceIndex+i)).Line);
                            lviD.BackColor = Color.White;
                            lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex+i)).Line);

                            lvSource.Items.Add(lviS);
                            lvDestination.Items.Add(lviD);
                            cnt++;
                        }

                        break;
                    case DiffResultSpanStatus.AddDestination:
                        for (i = 0; i < drs.Length; i++)
                        {
                            lviS = new ListViewItem(cnt.ToString("00000"));
                            lviD = new ListViewItem(cnt.ToString("00000"));
                            lviS.BackColor = Color.LightGray;
                            lviS.SubItems.Add("");
                            lviD.BackColor = Color.LightGreen;
                            lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex+i)).Line);

                            lvSource.Items.Add(lviS);
                            lvDestination.Items.Add(lviD);
                            cnt++;
                        }

                        break;
                    case DiffResultSpanStatus.Replace:
                        for (i = 0; i < drs.Length; i++)
                        {
                            lviS = new ListViewItem(cnt.ToString("00000"));
                            lviD = new ListViewItem(cnt.ToString("00000"));
                            lviS.BackColor = Color.Red;
                            lviS.SubItems.Add(((TextLine)source.GetByIndex(drs.SourceIndex+i)).Line);
                            lviD.BackColor = Color.LightGreen;
                            lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex+i)).Line);

                            lvSource.Items.Add(lviS);
                            lvDestination.Items.Add(lviD);
                            cnt++;
                        }

                        break;
                }

            }
        }
Exemple #8
0
 //UPDATE
 internal DifferenceCollectionEnumerator(DiffResultSpanCollection collection)
 {
     _index      = -1;
     _collection = collection;
 }
Exemple #9
0
 private bool AddChanges(
     DiffResultSpanCollection report,
     int curDest,
     int nextDest,
     int curSource,
     int nextSource)
 {
     bool returnResultSpanCollection = false;
     int diffDest = nextDest - curDest;
     int diffSource = nextSource - curSource;
     int minDiff = 0;
     if (diffDest > 0)
     {
         if (diffSource > 0)
         {
             minDiff = Math.Min(diffDest,diffSource);
             report.Add(DiffResultSpan.CreateReplace(curDest,curSource,minDiff));
             if (diffDest > diffSource)
             {
                 curDest+=minDiff;
                 report.Add(DiffResultSpan.CreateAddDestination(curDest,diffDest - diffSource));
             }
             else
             {
                 if (diffSource > diffDest)
                 {
                     curSource+= minDiff;
                     report.Add(DiffResultSpan.CreateDeleteSource(curSource,diffSource - diffDest));
                 }
             }
         }
         else
         {
             report.Add(DiffResultSpan.CreateAddDestination(curDest,diffDest));
         }
         returnResultSpanCollection = true;
     }
     else
     {
         if (diffSource > 0)
         {
             report.Add(DiffResultSpan.CreateDeleteSource(curSource,diffSource));
             returnResultSpanCollection = true;
         }
     }
     return returnResultSpanCollection;
 }