Partager via


CodeAnalysisService Class

Definition

A service that runs code analysis against a model and provides results to the caller.

Note that this class is not thread-safe since multiple simulataneous calls to Analyze(TSqlModel) are not supported. However it is possible to call Cancel() from a thread while a separate thread is waiting on the Analyze(TSqlModel) method to complete.

public sealed class CodeAnalysisService
type CodeAnalysisService = class
Public NotInheritable Class CodeAnalysisService
Inheritance
CodeAnalysisService

Properties

CancellationToken

The CancellationToken used to indicate whether execution should be canceled.

CodeAnalysisSucceededFile

Optional path to a file that is created if analysis succeeds. This can be used to check whether analysis should be run or not - for instance if analyzing a dacpac, comparing the modification time for the dacpac versus the analysis success file can tell you whether the dacpac is more recent than the last analysis.

ResultsFile

Optional path to a results file. If this is specified, the analysis service will save all results to an XML file at the end of analysis. If no file path is specified then this will not be done automatically, but SerializeResultsToXml(String) can be used to output the results after analysis has completed.

ValidationMode

Determines the validation performed on the model prior to code analysis. This can be used to bypass the requirement that a TSqlModel be valid prior to analysis by a code analysis rule.

Methods

Analyze(TSqlModel)

Performs the analysis of the model. This will initialize all required resources, run analysis and report back results to the caller.

If the ResultsFile and/or CodeAnalysisSucceededFile are specified then these will be deleted at the start of the analysis, and new files created at the end of the analysis

ApplyRuleSettings(CodeAnalysisRuleSettings)

Applies the specified rule settings against the service's configuration.

Cancel()

Cancels execution of the analysis service

GetRuleLoadErrors()

Gets any errors that may have occurred during loading of the analysis rules. This causes rules to be loaded by the service.

GetRules()

Gets the rules loaded by the service. The current state of these rules (enabled, disabled, rule problem severity) can be queried, as can information about the rule such as its ID and metadata.

SetProblemSuppressor(Predicate<SqlRuleProblemSuppressionContext>)

Sets the problem suppression predicate to be applied when suppressing rules. This is an optional feature that supports ignoring problems raised by a rule. The problem might be suppressed based on the element the problem was raised against, or the source that the problem was found in.

Applies to