22using System . IO ;
33using System . Text . Json ;
44using System . Windows ;
5- using Contracts . Graph ;
65using CSharpCodeAnalyst . Analyzers . ArchitecturalRules . Presentation ;
76using CSharpCodeAnalyst . Analyzers . ArchitecturalRules . Rules ;
87using CSharpCodeAnalyst . Common ;
@@ -13,13 +12,13 @@ namespace CSharpCodeAnalyst.Analyzers.ArchitecturalRules;
1312
1413public class Analyzer : IAnalyzer
1514{
16- private readonly IUserNotification _userNotification ;
1715 private readonly IPublisher _messaging ;
16+ private readonly IUserNotification _userNotification ;
17+ private CodeGraph . Graph . CodeGraph ? _currentGraph ;
18+ private bool _isDirty ;
19+ private ArchitecturalRulesDialog ? _openDialog ;
1820 private List < RuleBase > _rules = [ ] ;
1921 private string _rulesText ;
20- private ArchitecturalRulesDialog ? _openDialog ;
21- private CodeGraph ? _currentGraph ;
22- private bool _isDirty ;
2322
2423 public Analyzer ( IPublisher messaging , IUserNotification userNotification )
2524 {
@@ -35,7 +34,7 @@ public Analyzer(IPublisher messaging, IUserNotification userNotification)
3534 _rulesText = GetSampleRules ( ) ;
3635 }
3736
38- public void Analyze ( CodeGraph graph )
37+ public void Analyze ( CodeGraph . Graph . CodeGraph graph )
3938 {
4039 // If dialog is already open, just bring it to front
4140 if ( _openDialog != null )
@@ -70,43 +69,6 @@ public void Analyze(CodeGraph graph)
7069 _openDialog . Show ( ) ;
7170 }
7271
73- private void OnValidateRules ( string rulesText )
74- {
75- if ( _currentGraph == null )
76- {
77- return ;
78- }
79-
80- try
81- {
82- ParseAndStoreRules ( rulesText ) ;
83- }
84- catch ( Exception ex )
85- {
86- _userNotification . ShowError ( $ "Error parsing rules: { ex . Message } ") ;
87- return ;
88- }
89-
90- // Execute analysis
91- var violations = ExecuteAnalysis ( _currentGraph ) ;
92-
93- if ( violations . Count == 0 )
94- {
95- _userNotification . ShowSuccess ( "No rule violations found!" ) ;
96- }
97- else
98- {
99- // Show violations in tabular format
100- var violationsViewModel = new RuleViolationsViewModel ( violations , _currentGraph ) ;
101- _messaging . Publish ( new ShowTabularDataRequest ( violationsViewModel ) ) ;
102- }
103- }
104-
105- private void OnApplicationExit ( object sender , ExitEventArgs e )
106- {
107- _openDialog ? . Close ( ) ;
108- }
109-
11072 public string Name
11173 {
11274 get => "Architectural rules" ;
@@ -119,19 +81,10 @@ public string Id
11981 get => "ArchitecturalRules" ;
12082 }
12183
122- void SetDirty ( bool isDirty )
123- {
124- _isDirty = isDirty ;
125- if ( _isDirty )
126- {
127- DataChanged ? . Invoke ( this , EventArgs . Empty ) ;
128- }
129- }
130-
13184 public string ? GetPersistentData ( )
13285 {
13386 SetDirty ( false ) ;
134-
87+
13588 if ( string . IsNullOrEmpty ( _rulesText ) )
13689 {
13790 return null ;
@@ -151,7 +104,7 @@ public void SetPersistentData(string? data)
151104 {
152105 _rulesText = string . Empty ;
153106 _rules . Clear ( ) ;
154- SetDirty ( false ) ;
107+ SetDirty ( false ) ;
155108 return ;
156109 }
157110
@@ -181,10 +134,56 @@ public bool IsDirty()
181134
182135 public event EventHandler ? DataChanged ;
183136
137+ private void OnValidateRules ( string rulesText )
138+ {
139+ if ( _currentGraph == null )
140+ {
141+ return ;
142+ }
143+
144+ try
145+ {
146+ ParseAndStoreRules ( rulesText ) ;
147+ }
148+ catch ( Exception ex )
149+ {
150+ _userNotification . ShowError ( $ "Error parsing rules: { ex . Message } ") ;
151+ return ;
152+ }
153+
154+ // Execute analysis
155+ var violations = ExecuteAnalysis ( _currentGraph ) ;
156+
157+ if ( violations . Count == 0 )
158+ {
159+ _userNotification . ShowSuccess ( "No rule violations found!" ) ;
160+ }
161+ else
162+ {
163+ // Show violations in tabular format
164+ var violationsViewModel = new RuleViolationsViewModel ( violations , _currentGraph ) ;
165+ _messaging . Publish ( new ShowTabularDataRequest ( violationsViewModel ) ) ;
166+ }
167+ }
168+
169+ private void OnApplicationExit ( object sender , ExitEventArgs e )
170+ {
171+ _openDialog ? . Close ( ) ;
172+ }
173+
174+ private void SetDirty ( bool isDirty )
175+ {
176+ _isDirty = isDirty ;
177+ if ( _isDirty )
178+ {
179+ DataChanged ? . Invoke ( this , EventArgs . Empty ) ;
180+ }
181+ }
182+
184183 /// <summary>
185184 /// Direct analysis with rules from file (for command-line use)
186185 /// </summary>
187- public List < Violation > Analyze ( CodeGraph graph , string fileToRules )
186+ public List < Violation > Analyze ( CodeGraph . Graph . CodeGraph graph , string fileToRules )
188187 {
189188 ParseAndStoreRules ( File . ReadAllText ( fileToRules ) ) ;
190189 return ExecuteAnalysis ( graph ) ;
@@ -216,16 +215,16 @@ private static string GetSampleRules()
216215 private void ParseAndStoreRules ( string rulesText )
217216 {
218217 _rules = RuleParser . ParseRules ( rulesText ) ;
219-
218+
220219 if ( ! _isDirty && _rulesText != rulesText )
221220 {
222221 SetDirty ( true ) ;
223222 }
224-
223+
225224 _rulesText = rulesText ;
226225 }
227226
228- private List < Violation > ExecuteAnalysis ( CodeGraph graph )
227+ private List < Violation > ExecuteAnalysis ( CodeGraph . Graph . CodeGraph graph )
229228 {
230229 var violations = new List < Violation > ( ) ;
231230
0 commit comments