Framework/Models/SVT/SVTEvent.ps1

Set-StrictMode -Version Latest

class SVTEvent
{
    #First level event

    #Command level event
    static [string] $CommandStarted = "AzSdk.SVT.Command.Started"; #Initialize listeners #Function execution started
    static [string] $CommandCompleted = "AzSdk.SVT.Command.Completed"; #Cleanup listeners #Function execution completed
    static [string] $CommandError = "AzSdk.SVT.Command.Error"; 

    #Second level event for every resource
    static [string] $EvaluationStarted = "AzSdk.SVT.Evaluation.Started"; #Individual Resource execution started
    static [string] $EvaluationCompleted = "AzSdk.SVT.Evaluation.Completed"; #Individual Resource execution completed
    static [string] $EvaluationError = "AzSdk.SVT.Evaluation.Error";

    #Control level events
    static [string] $ControlStarted = "AzSdk.SVT.Control.Started"; #No DataObject
    static [string] $ControlCompleted = "AzSdk.SVT.Control.Completed"; #All DataObjects
    static [string] $ControlError = "AzSdk.SVT.Control.Error"; 
    static [string] $ControlDisabled = "AzSdk.SVT.Control.Disabled"; #No DataObject
    #static [string] $ControlProcessing = "AzSdk.SVT.Control.Processing"; #Individual DataObject
}

class ResourceContext : AzureContext
{
    [string] $FeatureName = ""
    [string] $Reference = ""
    [string] $ResourceId =""
    [string] $ResourceGroupName = "" 
    [string] $ResourceName = "" 
    [string] $ResourceType = "" 
}

class ControlResult
{
    [string] $ChildResourceName = "" 
    [VerificationResult] $VerificationResult = [VerificationResult]::Manual  
    [SubStatus] $SubStatus = [SubStatus]::None  
    [MessageData[]] $Messages = @()

    [void] AddMessage([MessageData] $messageData) 
    {
        if((-not [string]::IsNullOrEmpty($messageData.Message)) -or ($null -ne $messageData.DataObject))
        {
            $this.Messages += $messageData;
        }
    }

    [void] AddMessage([VerificationResult] $result, [MessageData] $messageData) 
    {
        $this.VerificationResult = $result;
        $this.AddMessage($messageData);
    }

    [void] AddMessage([VerificationResult] $result, [string] $message, [PSObject] $dataObject) 
    {
        $this.VerificationResult = $result;
        $this.AddMessage([MessageData]::new($message, $dataObject));
    }

    [void] AddMessage([VerificationResult] $result, [string] $message, [PSObject] $dataObject, [bool] $maintainState,  [string] $dataObjectType) 
    {
        $this.VerificationResult = $result;
        $this.AddMessage([MessageData]::new($message, $dataObject, $maintainState, $dataObjectType));
    }

    [void] AddMessage([string] $message, [PSObject] $dataObject) 
    {
        $this.AddMessage([MessageData]::new($message, $dataObject));
    }

    [void] AddMessage([string] $message, [PSObject] $dataObject, [bool] $maintainState, [string] $dataObjectType) 
    {
        $this.AddMessage([MessageData]::new($message, $dataObject, $maintainState, $dataObjectType));
    }

    [void] AddMessage([PSObject] $dataObject, [bool] $maintainState, [string] $dataObjectType) 
    {
        $this.AddMessage([MessageData]::new($dataObject,$maintainState,$dataObjectType));
    }

    [void] AddMessage([PSObject] $dataObject) 
    {
        $this.AddMessage([MessageData]::new($dataObject));
    }
    [void] AddMessage([string] $message) 
    {
        $this.AddMessage([MessageData]::new($message));
    }

    [void] AddError([System.Management.Automation.ErrorRecord] $exception) 
    {
        $this.AddMessage([MessageData]::new($exception, [MessageType]::Error));
    }
   
}

class SVTEventContext
{   
    [ResourceContext] $ResourceContext
    [ControlItem] $ControlItem
    [ControlResult[]] $ControlResults = @()
    hidden [System.Management.Automation.ErrorRecord] $ExceptionMessage
    # Available only on command started
    [MessageData[]] $Messages = @();
}