UPGRADE: ルール一覧表示機能を実装
@@ -18,16 +18,56 @@ | ||
18 | 18 | |
19 | 19 | |
20 | 20 | |
21 | +using Sasa.QualityTools.DrFx.Core; | |
22 | +using Sasa.QualityTools.DrFx.Explorer.Rule; | |
21 | 23 | using System; |
24 | +using System.Collections.ObjectModel; | |
25 | +using System.ComponentModel; | |
26 | +using System.IO; | |
22 | 27 | using System.Windows; |
28 | +using System.Windows.Controls; | |
29 | +using System.Windows.Data; | |
30 | +using System.Windows.Navigation; | |
23 | 31 | |
24 | 32 | namespace Sasa.QualityTools.DrFx.Explorer |
25 | 33 | { |
26 | 34 | public partial class FxCopRuleWindow : Window |
27 | 35 | { |
36 | + public Collection<FxCopRule> Rules { get; private set; } | |
37 | + | |
38 | + | |
39 | + | |
28 | 40 | public FxCopRuleWindow() |
29 | 41 | { |
30 | 42 | InitializeComponent(); |
31 | 43 | } |
44 | + | |
45 | + | |
46 | + | |
47 | + protected override void OnContentRendered(EventArgs e) | |
48 | + { | |
49 | + base.OnContentRendered(e); | |
50 | + | |
51 | + FxCopProcessConfiguration configuration = new FxCopProcessConfiguration(); | |
52 | + string rulesDir = Path.Combine(configuration.FxCopInstallDirectory, "Rules"); | |
53 | + | |
54 | + FxCopRuleLoader loader = new FxCopRuleLoader(); | |
55 | + foreach (string path in Directory.GetFiles(rulesDir)) | |
56 | + { | |
57 | + loader.AssemblyPaths.Add(path); | |
58 | + } | |
59 | + Rules = loader.Load(); | |
60 | + loader.Translate(Rules); | |
61 | + | |
62 | + this.frame.Navigate(new Uri("/FxCopRuleListPage.xaml", UriKind.Relative)); | |
63 | + } | |
64 | + | |
65 | + private void OnNavigateCompleted(object sender, NavigationEventArgs e) | |
66 | + { | |
67 | + Page page = (Page)e.Content; | |
68 | + page.DataContext = Rules; | |
69 | + ICollectionView collectionView = CollectionViewSource.GetDefaultView(page.DataContext); | |
70 | + collectionView.GroupDescriptions.Add(new PropertyGroupDescription("Category")); | |
71 | + } | |
32 | 72 | } |
33 | 73 | } |
@@ -31,6 +31,8 @@ | ||
31 | 31 | InitializeComponent(); |
32 | 32 | } |
33 | 33 | |
34 | + | |
35 | + | |
34 | 36 | private void NavigateToExplorerPage(object sender, RoutedEventArgs e) |
35 | 37 | { |
36 | 38 | NavigationService.Navigate(new Uri("/FxCopRuleExplorerPage.xaml", UriKind.Relative)); |
@@ -20,6 +20,7 @@ | ||
20 | 20 | |
21 | 21 | using Sasa.QualityTools.DrFx.Core.Translation; |
22 | 22 | using System; |
23 | +using System.Collections.Generic; | |
23 | 24 | using System.Collections.ObjectModel; |
24 | 25 | using System.IO; |
25 | 26 | using System.Reflection; |
@@ -44,6 +45,27 @@ | ||
44 | 45 | |
45 | 46 | |
46 | 47 | |
48 | + public void Translate(IEnumerable<FxCopRule> rules) | |
49 | + { | |
50 | + // TODO: 再検討 | |
51 | + List<TranslationRule> translationRules = new List<TranslationRule>(); | |
52 | + string directory = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "Resources"); | |
53 | + foreach (string file in Directory.GetFiles(directory, "*.xml")) | |
54 | + { | |
55 | + string rule = File.ReadAllText(file); | |
56 | + translationRules.AddRange(TranslationRule.Parse(rule)); | |
57 | + } | |
58 | + var lookup = translationRules.ToLookup(r => r.CheckId); | |
59 | + | |
60 | + foreach (FxCopRule rule in rules) | |
61 | + { | |
62 | + if (lookup.Contains(rule.CheckId)) | |
63 | + { | |
64 | + rule.Name = lookup[rule.CheckId].ElementAt(0).Name; | |
65 | + } | |
66 | + } | |
67 | + } | |
68 | + | |
47 | 69 | public Collection<FxCopRule> Load() |
48 | 70 | { |
49 | 71 | Collection<FxCopRule> rules = new Collection<FxCopRule>(); |
@@ -25,12 +25,12 @@ | ||
25 | 25 | /// <summary> |
26 | 26 | /// 違反の解決方法を翻訳するための情報を表します。 |
27 | 27 | /// </summary> |
28 | - internal class Resolution | |
28 | + public class Resolution | |
29 | 29 | { |
30 | 30 | /// <summary> |
31 | 31 | /// 翻訳結果。 |
32 | 32 | /// </summary> |
33 | - internal string Content { get; set; } | |
33 | + public string Content { get; set; } | |
34 | 34 | |
35 | 35 | /// <summary> |
36 | 36 | /// 翻訳前のメッセージを特定するパターン。 |
@@ -39,6 +39,6 @@ | ||
39 | 39 | /// 解決方法メッセージに埋め込まれている識別子を翻訳結果に埋め込むために、正規表現に |
40 | 40 | /// よるパターンマッチングを行って、識別子を取り出す必要がある。 |
41 | 41 | /// </remarks> |
42 | - internal string Pattern { get; set; } | |
42 | + public string Pattern { get; set; } | |
43 | 43 | } |
44 | 44 | } |
@@ -42,22 +42,22 @@ | ||
42 | 42 | /// <summary> |
43 | 43 | /// FxCop ルールのチェック ID。 |
44 | 44 | /// </summary> |
45 | - internal string CheckId { get; private set; } | |
45 | + public string CheckId { get; private set; } | |
46 | 46 | |
47 | 47 | /// <summary> |
48 | 48 | /// FxCop ルールのカテゴリ。 |
49 | 49 | /// </summary> |
50 | - internal string Category { get; private set; } | |
50 | + public string Category { get; private set; } | |
51 | 51 | |
52 | 52 | /// <summary> |
53 | 53 | /// FxCop ルール名。 |
54 | 54 | /// </summary> |
55 | - internal string Name { get; private set; } | |
55 | + public string Name { get; private set; } | |
56 | 56 | |
57 | 57 | /// <summary> |
58 | 58 | /// ルール違反の解決方法を表すオブジェクトのコレクション。 |
59 | 59 | /// </summary> |
60 | - internal IList<Resolution> Resolutions | |
60 | + public IList<Resolution> Resolutions | |
61 | 61 | { |
62 | 62 | get |
63 | 63 | { |