-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestUtility.ps1
More file actions
162 lines (140 loc) · 4.7 KB
/
Copy pathTestUtility.ps1
File metadata and controls
162 lines (140 loc) · 4.7 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<#
https://docs.microsoft.com/en-us/azure/architecture/best-practices/naming-conventions
#>
<#
Summary - Basic menu class that will allow the developer to create simple menus from a [System.Collections.Generic.List[System.Collections.Hashtable]]
#>
class BaseMenu {
<# Start Hidden Properties #>
[string] hidden $MenuTitle
<# End Hidden Properties #>
<# Start Public Properties #>
[System.Collections.Generic.List[System.Collections.Hashtable]] $MenuItems
[System.Collections.Hashtable] $SelectedMenuItem ;
<# End Public Properties #>
<# Start Constructors #>
<#
Initilizes the menu title and the MenuItems properties
#>
BaseMenu(
[string]$title)
{
$this.Initilization($title);
}
<#
Initilizes the menu title and sets MenuItems properties from the passed in Hashtable
#>
BaseMenu(
[string]$title,
[System.Collections.Generic.List[System.Collections.Hashtable]] $items)
{
$this.MenuTitle = $title ;
$this.MenuItems = $items
}
<#
Initilizes the menu title property
Initilizes the MenuItems property and creates count List elements that are all initilized to null.
This is usually used when you are populating the menu items from a CLI call that returns a collection of items
that you wish to populate into the MenuItems
#>
BaseMenu(
[string]$title,
[int] $count)
{
$this.Initilization($title);
for($i = 0; i -lt $count;$i++) {
}
}
<# End Constructors #>
<# Start Hidden Methods #>
hidden [void] Initilization([string]$title) {
$this.MenuTitle = $title ;
$this.MenuItems = New-Object -TypeName 'System.Collections.Generic.List[System.Collections.Hashtable]'
}
<# End Hidden Methods #>
<# Start Public Methods #>
[void] Add([System.Collections.Hashtable] $hashTable) {
$this.MenuItems.Add($hashTable) ;
}
[void] DisplayMenu ([string] $readHostPrompt,[string] $invalidSelectionFormatString) {
[System.Collections.Hashtable] $returnValue = $null;
Write-Host;
$this.SelectedMenuItem = $null ;
$displayText = [String]::Format("================ {0} ================",$this.MenuTitle);
Write-Host $displayText
[int]$index = 0;
foreach ($menuItem in $this.MenuItems)
{
$index++;
$text = "Press $($index) for " + $menuItem.DisplayName;
Write-Host $text;
}
[bool]$menuDoLoopExit = $false ;
$start = 1;
$end = $index ;
do {
$input = Read-Host $readHostPrompt
if ($input -eq 'Q') {
exit;
}
if ($input -ge $start.ToString() -and $input -le $end.ToString()) {
$index = [Int32]::Parse($input) - 1;
$this.SelectedMenuItem = $this.MenuItems[$index] ;
$menuDoLoopExit = $true;
}
else {
if([String]::IsNullOrEmpty($input)) {
$input = "CRLF" ;
}
$displayText = [String]::Format($invalidSelectionFormatString,$input);
Write-Host $displayText ;
}
}
until ($menuDoLoopExit);
}
<# End Public Methods #>
}
class NamingConventionItems {
[BaseMenu] $DepartmentMenus ;
[BaseMenu] $EnvironmentMenus ;
hidden static [String] $ResourceGroup = "rg";
hidden static [String] $AzureSqlServer = "sql";
hidden static [String] $ApplicationGateway = "agw";
hidden static [String] $FailoverGroup = "fg";
hidden static [String] $StorageAccount = "sa";
hidden static [String] $AppServicePlan = "sp";
hidden static [String] $WebAppService = "app";
hidden static [String] $KeyVault = "kv";
hidden static [String] $VNet = "vn";
hidden static [String] $Subnet = "sbn";
hidden static [String] $FunctionApp = "func";
hidden static [String] $VirtualMachine = "vm{0}";
<# End Public Properties #>
<# Start Constructors #>
<#
Initilizes the menu title and the MenuItems properties
#>
NamingConventionItems()
{
$this.InitilizeDepartments() ;
$this.InitilizeEnvironments() ;
}
hidden [void] InitilizeDepartments() {
$this.DepartmentMenus = [BaseMenu]::new("Available Departments") ;
$this.DepartmentMenus.Add(@{DisplayName="SocialGaming";affix = "sg" });
$this.DepartmentMenus.Add(@{DisplayName="IT";affix = "it" });
}
hidden [void] InitilizeEnvironments() {
$this.EnvironmentMenus = [BaseMenu]::new("Available Environments") ;
$this.EnvironmentMenus.Add(@{DisplayName="Development";affix = "dev" });
$this.EnvironmentMenus.Add(@{DisplayName="Production";affix = "prod" });
$this.EnvironmentMenus.Add(@{DisplayName="QA";affix = "qa" });
}
}
cls
$ErrorActionPreference = 'Stop';
$Global:azureSubscription= $null;
$HOST.UI.RawUI.ForegroundColor = "Gray"
[NamingConventionItems]$menus = [NamingConventionItems]::new() ;
$menus.DepartmentMenus.DisplayMenu("Please select an department or Press 'Q' to quit.","'{0}' was not a valid department selection") ;
$menus.EnvironmentMenus.DisplayMenu("Please select an environment or Press 'Q' to quit.","'{0}' was not a valid environment selection") ;