@@ -271,6 +271,14 @@ private void ProcessPath(string path)
271
271
272
272
}
273
273
274
+ ConcurrentBag < DiagnosticRecord > diagnostics ;
275
+ ConcurrentBag < SuppressedRecord > suppressed ;
276
+ Dictionary < string , List < RuleSuppression > > ruleSuppressions ;
277
+ List < Regex > includeRegexList ;
278
+ List < Regex > excludeRegexList ;
279
+ CountdownEvent cde ;
280
+ ConcurrentDictionary < string , List < object > > ruleDictionary ;
281
+
274
282
/// <summary>
275
283
/// Analyzes a single script file.
276
284
/// </summary>
@@ -287,8 +295,8 @@ private void AnalyzeFile(string filePath)
287
295
List < KeyValuePair < CommandInfo , IScriptExtent > > cmdInfoTable = new List < KeyValuePair < CommandInfo , IScriptExtent > > ( ) ;
288
296
289
297
//Check wild card input for the Include/ExcludeRules and create regex match patterns
290
- List < Regex > includeRegexList = new List < Regex > ( ) ;
291
- List < Regex > excludeRegexList = new List < Regex > ( ) ;
298
+ includeRegexList = new List < Regex > ( ) ;
299
+ excludeRegexList = new List < Regex > ( ) ;
292
300
if ( includeRule != null )
293
301
{
294
302
foreach ( string rule in includeRule )
@@ -336,7 +344,7 @@ private void AnalyzeFile(string filePath)
336
344
return ;
337
345
}
338
346
339
- Dictionary < string , List < RuleSuppression > > ruleSuppressions = Helper . Instance . GetRuleSuppression ( ast ) ;
347
+ ruleSuppressions = Helper . Instance . GetRuleSuppression ( ast ) ;
340
348
341
349
foreach ( List < RuleSuppression > ruleSuppressionsList in ruleSuppressions . Values )
342
350
{
@@ -665,6 +673,65 @@ private void AnalyzeFile(string filePath)
665
673
}
666
674
}
667
675
676
+ void bg_DoWork ( object sender , DoWorkEventArgs e )
677
+ {
678
+ bool includeRegexMatch = false ;
679
+ bool excludeRegexMatch = false ;
680
+
681
+ object [ ] parameters = e . Argument as object [ ] ;
682
+
683
+ IScriptRule scriptRule = parameters [ 0 ] as IScriptRule ;
684
+
685
+ foreach ( Regex include in includeRegexList )
686
+ {
687
+ if ( include . IsMatch ( scriptRule . GetName ( ) ) )
688
+ {
689
+ includeRegexMatch = true ;
690
+ break ;
691
+ }
692
+ }
693
+
694
+ foreach ( Regex exclude in excludeRegexList )
695
+ {
696
+ if ( exclude . IsMatch ( scriptRule . GetName ( ) ) )
697
+ {
698
+ excludeRegexMatch = true ;
699
+ break ;
700
+ }
701
+ }
702
+
703
+ List < object > result = new List < object > ( ) ;
704
+
705
+ if ( ( includeRule == null || includeRegexMatch ) && ( excludeRule == null || ! excludeRegexMatch ) )
706
+ {
707
+ //WriteVerbose(string.Format(CultureInfo.CurrentCulture, Strings.VerboseRunningMessage, scriptRule.GetName()));
708
+ result . Add ( string . Format ( CultureInfo . CurrentCulture , Strings . VerboseRunningMessage , scriptRule . GetName ( ) ) ) ;
709
+
710
+ // Ensure that any unhandled errors from Rules are converted to non-terminating errors
711
+ // We want the Engine to continue functioning even if one or more Rules throws an exception
712
+ try
713
+ {
714
+ var records = Helper . Instance . SuppressRule ( scriptRule . GetName ( ) , ruleSuppressions , scriptRule . AnalyzeScript ( ast , ast . Extent . File ) . ToList ( ) ) ;
715
+ foreach ( var record in records . Item2 )
716
+ {
717
+ diagnostics . Add ( record ) ;
718
+ }
719
+ foreach ( var suppressedRec in records . Item1 )
720
+ {
721
+ suppressed . Add ( suppressedRec ) ;
722
+ }
723
+ }
724
+ catch ( Exception scriptRuleException )
725
+ {
726
+ result . Add ( new ErrorRecord ( scriptRuleException , Strings . RuleErrorMessage , ErrorCategory . InvalidOperation , ast . Extent . File ) ) ;
727
+ }
728
+ }
729
+
730
+ ruleDictionary [ scriptRule . GetName ( ) ] = result ;
731
+
732
+ cde . Signal ( ) ;
733
+ }
734
+
668
735
#endregion
669
736
}
670
737
}
0 commit comments