Exemple #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            Func f  = ef.FuncList[0];
            Func f1 = ef1.FuncList[0];


            diff_match_patch dfp      = new diff_match_patch();
            List <Diff>      dfresult = new List <Diff>();

            dfresult = dfp.diff_lineMode(f.BusinFlow.ToString(), f1.BusinFlow.ToString());
            //dfresult = dfp.diff_main("good well \r\ntest", "test well \r\ntest");
            foreach (Diff d in dfresult)
            {
                if (d.operation != Operation.EQUAL)
                {
                    rtbLog.AppendText(d.operation.ToString() + " " + d.text);
                }
            }


            //IDiffer df = new Differ();
            //DiffPlex.Model.DiffResult dfresult = df.CreateLineDiffs(f.BusinFlow.ToString(), f1.BusinFlow.ToString(), false);
            //DiffPlex.Model.d dfresult = df.CreateLineDiffs(f.BusinFlow.ToString(), f1.BusinFlow.ToString(), false);

            // 分析对比结果,怎么分析?
            // 以eques 为分界
            // 到下一个 equas 为止
            // 如何界定多少行
            //

            return;
        }
        private BuildDiffViewModel BuildViewModel(BuildEvent first, BuildEvent second, ExceptionEvent firstBuildException = null)
        {
            BuildDiffViewModel vm   = new BuildDiffViewModel();
            diff_match_patch   diff = new diff_match_patch();

            //loop through each document in the first, original build
            foreach (BuildDocument doc in first.Documents)
            {
                CodeDocument firstDoc  = doc.Document;
                CodeDocument secondDoc = second.Documents.Where(d => d.Document.FileName == doc.Document.FileName).Select(d => d.Document).FirstOrDefault();
                if (secondDoc == null)
                {
                    continue;
                }

                //compute the diff
                List <Diff>   diffs         = diff.diff_lineMode(firstDoc.Content, secondDoc.Content);
                StringBuilder firstBuilder  = new StringBuilder();
                StringBuilder secondBuilder = new StringBuilder();

                //loop through each piece in the return list of diffs.  Three possibilities:
                // EQUAL: the documents share the same code, so re-include in both
                // DELETE: The code existed in the original but not in the modified.  Add back to the original (first).
                // INSERT: The code exists in the modified, but not the original.  Add back to the modified (second).
                foreach (Diff d in diffs)
                {
                    switch (d.operation)
                    {
                    case Operation.DELETE:

                        //encase the deleted code in a special token so that we can find it more easily later
                        firstBuilder.Append(string.Format("{0}{1}", BuildDiffViewModel.DIFF_ESCAPE, d.text));
                        break;

                    case Operation.EQUAL:
                    default:
                        firstBuilder.Append(d.text);
                        secondBuilder.Append(d.text);
                        break;

                    case Operation.INSERT:

                        //encase the inserted code in a special token so that we can find it more easily later
                        secondBuilder.Append(string.Format("{0}{1}", BuildDiffViewModel.DIFF_ESCAPE, d.text));
                        break;
                    }
                }
                firstDoc.Content  = firstBuilder.ToString();
                secondDoc.Content = secondBuilder.ToString();
            }

            //figure out what lines had build errors on them.
            foreach (BuildEventErrorListItem item in first.CriticalErrorItems)
            {
                string        fileName = Path.GetFileName(item.ErrorListItem.File);
                DocumentError error    = new DocumentError()
                {
                    FileName     = fileName,
                    LineNumber   = item.ErrorListItem.Line - 1, //adjust line number by 1 because c# arrays are 0-based
                    Source       = DocumentErrorSource.Build,
                    ErrorMessage = item.ErrorListItem.Description
                };
                vm.RecordError(error);
            }

            //now find the line on which any runtime exception occurred on
            if (firstBuildException != null)
            {
                string        fileName = Path.GetFileName(firstBuildException.DocumentName);
                DocumentError error    = new DocumentError()
                {
                    FileName     = fileName,
                    LineNumber   = firstBuildException.LineNumber - 1, //adjust line number by 1 because c# arrays are 0-based
                    Source       = DocumentErrorSource.Debug,
                    ErrorMessage = firstBuildException.ExceptionDescription
                };
                vm.RecordError(error);
            }

            vm.OriginalBuild = first;
            vm.ModifiedBuild = second;
            return(vm);
        }