Click here to Skip to main content
15,884,099 members
Articles / Programming Languages / C#

DeltaScope

Rate me:
Please Sign up or sign in to vote.
4.96/5 (10 votes)
1 Sep 2009CPOL2 min read 37.5K   408   17  
A reusable delta engine with GDI+ front-end controls.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using ErkerTech.DeltaScope.Engine;

namespace ErkerTech.DeltaScope.App.Models
{
    public class DeltaScopeEngine
    {
        public TimeSpan ElapsedTime { get; private set; }
        public long PeakMemoryUsage { get; private set; }
        public IList<DeltaBlock> Compare(string tsLeftFile, string tsRightFile)
        {
            GC.Collect();
            var process = Process.GetCurrentProcess();
            process.Refresh();
            var peakWorkingSet64 = process.PeakWorkingSet64;

            var sw = new Stopwatch();
            sw.Start();

            IList<DeltaBlock> results;
            using (var deltaEngine = new DeltaEngine())
            {
                results = deltaEngine.GetDifferences(tsLeftFile, tsRightFile, fileName =>
                                                         {
                                                             var deltaStrings = new List<DeltaString>();
                                                             using (var sr = new StreamReader(fileName))
                                                             {
                                                                 while (!sr.EndOfStream)
                                                                     deltaStrings.Add(new DeltaString(sr.ReadLine()));
                                                             }
                                                             return deltaStrings;
                                                         });
            }

            sw.Stop();
            ElapsedTime = sw.Elapsed;
            process.Refresh();
            PeakMemoryUsage = process.PeakWorkingSet64 - peakWorkingSet64;

            return results;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions