Beispiel #1
0
        public static CompareFile Compare(string currentFile, string originalFile)
        {
            var itm = new CompareFile()
            {
                FileOriginal = originalFile, FileCurrent = currentFile
            };

            if (!File.Exists(originalFile) || !File.Exists(currentFile))
            {
                itm.Status = CompareFileStatus.Missing;
                return(itm);
            }

            var originalLines = File.ReadAllLines(originalFile);
            var currentLines  = File.ReadAllLines(currentFile);

            if (originalLines.Length != currentLines.Length)
            {
                itm.Status = CompareFileStatus.LineCount;
                return(itm);
            }

            for (var i = 1; i < currentLines.Length; i++)
            {
                if (originalLines[i] != currentLines[i])
                {
                    itm.Status = CompareFileStatus.LineDiff;
                    itm.Diff   = new CompareFileDiff()
                    {
                        LineNumber = i + 1, LineContentCurrent = currentLines[i], LineContentOriginal = originalLines[i]
                    };
                    return(itm);
                }
            }

            return(itm);
        }
Beispiel #2
0
        static IEnumerable <CompareFile> IterateFolderComparison(string currentDir, string originalDir)
        {
            if (!Directory.Exists(originalDir))
            {
                throw new Exception("currentDir is missing");
            }

            if (!Directory.Exists(currentDir))
            {
                throw new Exception("originalDir is missing");
            }

            foreach (var currFile in Directory.GetFiles(currentDir, "*.js", SearchOption.AllDirectories))
            {
                var origFile = originalDir + currFile.Substring(currentDir.Length);

                if (updateSourceFromLocalHistory)
                {
                    getSVNFile(currFile, origFile);
                }

                yield return(CompareFile.Compare(currFile, origFile));
            }
        }