Framework/Abstracts/SVTCommandBase.ps1
using namespace System.Management.Automation Set-StrictMode -Version Latest # Base class for SVT classes being called from PS commands # Provides functionality to fire important events at command call class SVTCommandBase: CommandBase { [string[]] $ExcludeTags = @(); [string[]] $ControlIds = @(); SVTCommandBase([string] $subscriptionId, [InvocationInfo] $invocationContext): Base($subscriptionId, $invocationContext) { [Helpers]::AbstractClass($this, [SVTCommandBase]); } hidden [void] CommandStarted() { [SVTEventContext] $arg = [SVTEventContext]@{ ResourceContext = [ResourceContext]@{ SubscriptionId = ($this.Context.SubscriptionId); SubscriptionName = ($this.Context.SubscriptionName); }; }; $versionMessage = $this.CheckModuleVersion(); if($versionMessage) { $arg.Messages += $versionMessage; } $this.PublishEvent([SVTEvent]::CommandStarted, $arg); } hidden [void] CommandError([System.Management.Automation.ErrorRecord] $exception) { [SVTEventContext] $arg = [SVTEventContext]@{ ResourceContext = [ResourceContext]@{ SubscriptionId = ($this.Context.SubscriptionId); SubscriptionName = ($this.Context.SubscriptionName); }; ExceptionMessage = $exception; }; $this.PublishEvent([SVTEvent]::CommandError, $arg); } hidden [void] CommandCompleted([SVTEventContext[]] $arguments) { $this.PublishEvent([SVTEvent]::CommandCompleted, $arguments); } [string] InvokeFunction([PSMethod] $methodToCall) { throw [System.NotSupportedException] "The method is not supported in the class" } [string] EvaluateControlStatus() { return ([CommandBase]$this).InvokeFunction($this.RunAllControls); } # Dummy function declaration to define the function signature # Function is supposed to override in derived class hidden [SVTEventContext[]] RunAllControls() { return @(); } } |