UPGRADE: FxCop レポート表示画面に、違反したソースコードの一部を表示する機能を追加
@@ -1,20 +1,52 @@ | ||
1 | 1 | using Sasa.QualityTools.DrFx.Explorer.Report; |
2 | 2 | using System; |
3 | 3 | using System.Collections.Generic; |
4 | +using System.Collections.ObjectModel; | |
4 | 5 | using System.IO; |
5 | 6 | using System.Windows; |
6 | 7 | using System.Windows.Controls; |
8 | +using System.Windows.Data; | |
7 | 9 | |
8 | 10 | namespace Sasa.QualityTools.DrFx.Explorer |
9 | 11 | { |
10 | 12 | public partial class FxCopIssueDetailWidget : UserControl |
11 | 13 | { |
14 | + public static DependencyProperty FxCopIssueRelationshipProperty = DependencyProperty.Register("FxCopIssueRelationship", typeof(FxCopIssueRelationship), typeof(FxCopIssueDetailWidget), new PropertyMetadata(OnFxCopIssueDetailWidgetChanged)); | |
15 | + | |
16 | + private ObservableCollection<SourceCodeLine> lines = new ObservableCollection<SourceCodeLine>(); | |
17 | + | |
18 | + | |
19 | + | |
20 | + public FxCopIssueRelationship FxCopIssueRelationship | |
21 | + { | |
22 | + get | |
23 | + { | |
24 | + return (FxCopIssueRelationship)GetValue(FxCopIssueRelationshipProperty); | |
25 | + } | |
26 | + set | |
27 | + { | |
28 | + SetValue(FxCopIssueRelationshipProperty, value); | |
29 | + | |
30 | + } | |
31 | + } | |
32 | + | |
33 | + public ObservableCollection<SourceCodeLine> Lines | |
34 | + { | |
35 | + get | |
36 | + { | |
37 | + return this.lines; | |
38 | + } | |
39 | + } | |
40 | + | |
41 | + | |
42 | + | |
12 | 43 | public FxCopIssueDetailWidget() |
13 | 44 | { |
14 | 45 | InitializeComponent(); |
15 | - DataContextChanged += OnDataContextChanged; | |
16 | 46 | } |
17 | 47 | |
48 | + | |
49 | + | |
18 | 50 | internal static List<SourceCodeLine> GetViolationCodeLines(string filePath, int lineNumber) |
19 | 51 | { |
20 | 52 | if (String.IsNullOrEmpty(filePath) || File.Exists(filePath) == false || lineNumber <= 0) |
@@ -22,7 +54,7 @@ | ||
22 | 54 | return new List<SourceCodeLine>(); |
23 | 55 | } |
24 | 56 | |
25 | - int start = (lineNumber < 6) ? 0 : lineNumber - 6; | |
57 | + int start = (lineNumber < 6) ? 0 : lineNumber -6; | |
26 | 58 | int end = lineNumber + 5; |
27 | 59 | |
28 | 60 | List<SourceCodeLine> lines = new List<SourceCodeLine>(); |
@@ -48,7 +80,6 @@ | ||
48 | 80 | } |
49 | 81 | lines.Add(new SourceCodeLine { LineNumber = i + 1, Text = line.Replace(Environment.NewLine, String.Empty), IsViolationLine = (i + 1 == lineNumber) }); |
50 | 82 | } |
51 | - return lines; | |
52 | 83 | } |
53 | 84 | } |
54 | 85 | catch (IOException) |
@@ -63,8 +94,9 @@ | ||
63 | 94 | return lines; |
64 | 95 | } |
65 | 96 | |
66 | - private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) | |
97 | + private static void OnFxCopIssueDetailWidgetChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) | |
67 | 98 | { |
99 | + FxCopIssueDetailWidget widget = (FxCopIssueDetailWidget)sender; | |
68 | 100 | FxCopIssueRelationship relationship = e.NewValue as FxCopIssueRelationship; |
69 | 101 | if (relationship == null) |
70 | 102 | { |
@@ -71,7 +103,14 @@ | ||
71 | 103 | return; |
72 | 104 | } |
73 | 105 | |
74 | - | |
106 | + widget.lines.Clear(); | |
107 | + if (relationship.Issue.Line.HasValue) | |
108 | + { | |
109 | + foreach (SourceCodeLine line in GetViolationCodeLines(relationship.Issue.FilePath, relationship.Issue.Line.Value)) | |
110 | + { | |
111 | + widget.lines.Add(line); | |
112 | + } | |
113 | + } | |
75 | 114 | } |
76 | 115 | } |
77 | 116 | } |