Beispiel #1
0
        private SideBySideDiffModel BuildLineDiff(string oldText, string newText)
        {
            var model      = new SideBySideDiffModel();
            var diffResult = differ.CreateLineDiffs(oldText, newText, true);

            BuildDiffPieces(diffResult, model.OldText.Lines, model.NewText.Lines, BuildWordDiffPieces);
            return(model);
        }
Beispiel #2
0
        public DiffPaneModel BuildDiffModel(string oldText, string newText)
        {
            if (oldText == null)
            {
                throw new ArgumentNullException(nameof(oldText));
            }
            if (newText == null)
            {
                throw new ArgumentNullException(nameof(newText));
            }

            var model      = new DiffPaneModel();
            var diffResult = differ.CreateLineDiffs(oldText, newText, ignoreWhitespace: true);

            BuildDiffPieces(diffResult, model.Lines);
            return(model);
        }
Beispiel #3
0
        // Handle fileSystemWatcher update
        private static void fsw_Changed(object sender, FileSystemEventArgs e)
        {
            // Make sure file/directory still exists - otherwise, remove it from the list of tracked files
            if (!File.Exists(e.FullPath))
            {
                string dumpPath = getDumpPath(e.FullPath);

                if (trackedLocations.ContainsKey(e.FullPath))
                {
                    trackedLocations.Remove(e.FullPath);
                }
                else if (trackedLocations.ContainsKey(dumpPath))
                {
                    trackedLocations.Remove(dumpPath);
                }

                // Skip this file since it no longer exists
                return;
            }

            // --- Get changes ---
            // Get old/new filepaths
            string oldText = File.ReadAllText(getDumpPath(e.FullPath));
            string newText = File.ReadAllText(e.FullPath);

            // Get diff
            object     model     = new SideBySideDiffModel();
            DiffResult lineDiffs = differ.CreateLineDiffs(oldText, newText, true, true);

            // If nothing actually changed, move along
            if (lineDiffs.DiffBlocks.Count == 0)
            {
                return;
            }

            // Calculate LOC change
            int locChanged = 0;

            for (int i = 0; i < lineDiffs.DiffBlocks.Count; i++)
            {
                locChanged += lineDiffs.PiecesOld[i].ToCharArray().Count(x => @"\n".Contains(x));
            }

            // Calculate code quality metrics (on the entire file)
            int avgCodeQualityChange = 0;

            avgCodeQualityChange += getCodeQuality(newText) - getCodeQuality(oldText);
            avgCodeQualityChange /= lineDiffs.DiffBlocks.Count;

            // --- Log changes ---
            File.AppendAllLines(changeLogDump, new string[] {
                "---",
                "File changed: " + e.FullPath,
                "Timestamp: " + DateTime.Now.ToString(),
                "Code quality change: " + avgCodeQualityChange.ToString(),
                "Lines changed: " + locChanged
            });

            // --- Store changes ---
            File.Copy(e.FullPath, getDumpPath(e.FullPath), true);
        }