Framework/Abstracts/FixControl/FixSubscriptionBase.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Set-StrictMode -Version Latest 
class FixSubscriptionBase: FixControlBase
{ 
    [string] $ResourceGroupName = "";
    [string] $ResourceName = "";

    hidden [ResourceConfig] $ResourceConfig = $null;

    FixSubscriptionBase([string] $subscriptionId, [ArrayWrapper] $controls): 
        Base($subscriptionId)
    {
        if($controls)
        {
            $this.CreateInstance($controls.Values);
        }
        else
        {
            $this.CreateInstance(@());
        }
    }

    hidden [void] CreateInstance([ControlParam[]] $controls)
    {
        [Helpers]::AbstractClass($this, [FixSubscriptionBase]); 

        $typeMapping = [SVTMapping]::SubscriptionMapping;
        if (-not $typeMapping)
        {
            throw [System.ArgumentException] ("No subscription type mapping found");    
        }

        $this.LoadSvtConfig($typeMapping.JsonFileName);

        if(-not $controls)
        {
            throw [System.ArgumentException] ("No controls found to fix");    
        }

        $this.Controls += $controls;
    }

    [MessageData[]] FixStarted()
    { 
        return $this.PublishCustomMessage([Constants]::DoubleDashLine +
                "`r`nStarting control fixes: [FeatureName: $($this.SVTConfig.FeatureName)] [SubscriptionName: $($this.SubscriptionContext.SubscriptionName)] [SubscriptionId: $($this.SubscriptionContext.SubscriptionId)] `r`n" + 
                [Constants]::SingleDashLine);
    }

    [MessageData[]] FixCompleted()
    { 
        return $this.PublishCustomMessage([Constants]::SingleDashLine +
                "`r`nCompleted control fixes: [FeatureName: $($this.SVTConfig.FeatureName)] [SubscriptionName: $($this.SubscriptionContext.SubscriptionName)] [SubscriptionId: $($this.SubscriptionContext.SubscriptionId)] `r`n" + 
                [Constants]::DoubleDashLine, [MessageType]::Update);    
    }

}