Skip to content

Commit b855ded

Browse files
committed
Changed the cmdlet suffix to 'Method'
1 parent b743aa9 commit b855ded

File tree

160 files changed

+1113
-1064
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+1113
-1064
lines changed

src/ServiceManagement/Compute/Commands.ServiceManagement.PlatformImageRepository/Automation/RunCodeGeneration.ps1

Lines changed: 83 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
11
[CmdletBinding()]
22
param(
3-
[Parameter(Mandatory = $true)]
4-
[string]$dllFolder,
3+
[Parameter(Mandatory = $true)]
4+
[string]$dllFolder,
55

6-
[Parameter(Mandatory = $true)]
7-
[string]$outFolder,
8-
9-
# The base cmdlet from which all automation cmdlets derive
10-
[Parameter(Mandatory = $false)]
11-
[string]$baseCmdlet = 'ServiceManagementBaseCmdlet',
6+
[Parameter(Mandatory = $true)]
7+
[string]$outFolder,
8+
9+
# The base cmdlet from which all automation cmdlets derive
10+
[Parameter(Mandatory = $false)]
11+
[string]$baseCmdlet = 'ServiceManagementBaseCmdlet',
12+
13+
# The property field to access the client wrapper class from the base cmdlet
14+
[Parameter(Mandatory = $false)]
15+
[string]$base_class_client_field = 'ComputeClient',
1216

13-
# Cmdlet Code Generation Style
14-
# 1. Invoke (default) that uses Invoke as the verb, and Operation + Method (e.g. VirtualMachine + Get)
15-
# 2. Verb style that maps the method name to a certain common PS verb (e.g. CreateOrUpdate -> New)
16-
[Parameter(Mandatory = $false)]
17-
[string]$cmdletStyle = 'Invoke'
17+
# Cmdlet Code Generation Style
18+
# 1. Invoke (default) that uses Invoke as the verb, and Operation + Method (e.g. VirtualMachine + Get)
19+
# 2. Verb style that maps the method name to a certain common PS verb (e.g. CreateOrUpdate -> New)
20+
[Parameter(Mandatory = $false)]
21+
[string]$cmdletStyle = 'Invoke'
1822
)
1923

24+
$client_library_namespace = 'Microsoft.WindowsAzure.Management.Compute';
25+
$code_common_namespace = ($client_library_namespace.Replace('.Management.', '.Commands.')) + '.Automation';
26+
27+
$code_common_usings = @(
28+
'System.Management.Automation',
29+
'Microsoft.Azure',
30+
'Microsoft.WindowsAzure.Commands.ServiceManagement',
31+
'Microsoft.WindowsAzure.Commands.Utilities.Common'
32+
);
33+
2034
$code_common_header =
2135
@"
2236
//
@@ -41,12 +55,35 @@ $code_common_header =
4155
// code is regenerated.
4256
"@;
4357

44-
$client_library_namespace = 'Microsoft.WindowsAzure.Management.Compute';
45-
$code_common_namespace = ($client_library_namespace.Replace('.Management.', '.Commands.')) + '.Automation';
58+
$new_line_str = "`r`n";
59+
60+
function Get-SortedUsings
61+
{
62+
param(
63+
# Sample: @('System.Management.Automation', 'Microsoft.Azure', ...)
64+
[Parameter(Mandatory = $true)]
65+
$common_using_str_list,
66+
67+
# Sample: 'Microsoft.WindowsAzure.Management.Compute'
68+
[Parameter(Mandatory = $true)]
69+
$client_library_namespace
70+
)
71+
72+
$a1 = @() + $common_using_str_list + $client_library_namespace;
73+
$a2 = Sort-Object -Descending -Unique -InputObject $a1;
74+
$a3 = $a2 | foreach { "using ${_};" };
75+
76+
$text = [string]::Join($new_line_str, $a3);
77+
78+
return $text;
79+
}
80+
81+
$code_using_strs = Get-SortedUsings $code_common_usings $client_library_namespace;
4682

4783
function Get-NormalizedName
4884
{
4985
param(
86+
# Sample: 'vmName' => 'VMName', 'resourceGroup' => 'ResourceGroup', etc.
5087
[Parameter(Mandatory = $True)]
5188
[string]$inputName
5289
)
@@ -73,6 +110,8 @@ function Get-NormalizedName
73110
function Get-OperationShortName
74111
{
75112
param(
113+
# Sample #1: 'IVirtualMachineOperations' => 'VirtualMachine'
114+
# Sample #2: 'IDeploymentOperations' => 'Deployment'
76115
[Parameter(Mandatory = $True)]
77116
[string]$opFullName
78117
)
@@ -83,7 +122,8 @@ function Get-OperationShortName
83122

84123
if ($opFullName.StartsWith($prefix) -and $opShortName.EndsWith($suffix))
85124
{
86-
$opShortName = $opShortName.Substring($prefix.Length, ($opShortName.Length - $prefix.Length - $suffix.Length));
125+
$lenOpShortName = ($opShortName.Length - $prefix.Length - $suffix.Length);
126+
$opShortName = $opShortName.Substring($prefix.Length, $lenOpShortName);
87127
}
88128

89129
return $opShortName;
@@ -93,20 +133,19 @@ function Write-BaseCmdletFile
93133
{
94134
param(
95135
[Parameter(Mandatory = $True)]
96-
[string]$fileFullPath,
136+
[string]$file_full_path,
97137

98138
[Parameter(Mandatory = $True)]
99-
$operationNameList,
139+
$operation_name_list,
100140

101141
[Parameter(Mandatory = $True)]
102-
$clientClass
142+
$client_class_info
103143
)
104144

105-
106-
[System.Reflection.PropertyInfo[]]$propItems = $clientClass.GetProperties();
145+
[System.Reflection.PropertyInfo[]]$propItems = $client_class_info.GetProperties();
107146

108147
$operation_get_code = "";
109-
foreach ($opFullName in $operationNameList)
148+
foreach ($opFullName in $operation_name_list)
110149
{
111150
[string]$sOpFullName = $opFullName;
112151
Write-Output ('$sOpFullName = ' + $sOpFullName);
@@ -131,26 +170,25 @@ function Write-BaseCmdletFile
131170
{
132171
get
133172
{
134-
return ComputeClient.${opPropName};
173+
return ${base_class_client_field}.${opPropName};
135174
}
136175
}
137176
"@;
138177

139-
if (-not ($operation_get_code -eq ''))
178+
if (-not ($operation_get_code -eq ""))
140179
{
141-
$operation_get_code += "`r`n";
180+
$operation_get_code += ($new_line_str * 2);
142181
}
143182

144183
$operation_get_code += $operation_get_template;
145184
}
146185
}
147186

148-
$source_template =
187+
$cmdlet_source_code_text =
149188
@"
150189
${code_common_header}
151190
152-
using ${client_library_namespace};
153-
using Microsoft.WindowsAzure.Commands.Utilities.Common;
191+
$code_using_strs
154192
155193
namespace ${code_common_namespace}
156194
{
@@ -161,7 +199,7 @@ ${operation_get_code}
161199
}
162200
"@;
163201

164-
Set-Content -Path $fileFullPath -Value ($source_template | Out-String) -Force;
202+
$st = Set-Content -Path $file_full_path -Value $cmdlet_source_code_text -Force;
165203
}
166204

167205
function Write-OperationCmdletFile
@@ -179,15 +217,16 @@ function Write-OperationCmdletFile
179217

180218
$methodName = ($operationMethodInfo.Name.Replace('Async', ''));
181219
$cmdlet_verb = "Invoke";
182-
$cmdlet_noun = "Azure" + $opShortName + $methodName;
183-
$cmdlet_class_name = $cmdlet_verb + $cmdlet_noun + 'Cmdlet';
220+
$cmdlet_noun_prefix = 'Azure';
221+
$cmdlet_noun_suffix = 'Method';
222+
$cmdlet_noun = $cmdlet_noun_prefix + $opShortName + $methodName + $cmdlet_noun_suffix;
223+
$cmdlet_class_name = $cmdlet_verb + $cmdlet_noun;
184224

185225
$indents = " " * 8;
186-
$new_line = "`r`n";
187226
$get_set_block = '{ get; set; }';
188227

189228
$cmdlet_generated_code = '';
190-
# $cmdlet_generated_code += $indents + '// ' + $operationMethodInfo + $new_line;
229+
# $cmdlet_generated_code += $indents + '// ' + $operationMethodInfo + $new_line_str;
191230

192231
$params = $operationMethodInfo.GetParameters();
193232
[System.Collections.ArrayList]$param_names = @();
@@ -200,13 +239,13 @@ function Write-OperationCmdletFile
200239

201240
Write-Output (' ' + $paramTypeFullName + ' ' + $normalized_param_name);
202241

203-
$param_attributes = $indents + "[Parameter(Mandatory = true), ValidateNotNullOrEmpty]" + $new_line;
204-
$param_definition = $indents + "public ${paramTypeFullName} ${normalized_param_name} " + $get_set_block + $new_line;
242+
$param_attributes = $indents + "[Parameter(Mandatory = true)]" + $new_line_str;
243+
$param_definition = $indents + "public ${paramTypeFullName} ${normalized_param_name} " + $get_set_block + $new_line_str;
205244
$param_code_content = $param_attributes + $param_definition;
206245

207-
$cmdlet_generated_code += $param_code_content + $new_line;
246+
$cmdlet_generated_code += $param_code_content + $new_line_str;
208247

209-
$param_names.Add($normalized_param_name);
248+
$st = $param_names.Add($normalized_param_name);
210249
}
211250
}
212251

@@ -233,13 +272,9 @@ function Write-OperationCmdletFile
233272
@"
234273
${code_common_header}
235274
236-
using Microsoft.Azure;
237-
using Microsoft.WindowsAzure.Commands.ServiceManagement;
238-
using Microsoft.WindowsAzure.Commands.Utilities.Common;
239-
using Microsoft.WindowsAzure.Management.Compute;
240-
using System.Management.Automation;
275+
$code_using_strs
241276
242-
namespace Microsoft.WindowsAzure.Commands.Compute.Automation
277+
namespace ${code_common_namespace}
243278
{
244279
[Cmdlet(`"${cmdlet_verb}`", `"${cmdlet_noun}`")]
245280
public class ${cmdlet_class_name} : ComputeAutomationBaseCmdlet
@@ -249,10 +284,11 @@ ${cmdlet_generated_code}
249284
}
250285
"@;
251286

252-
$fileFullPath = $fileOutputFolder + '/' + $cmdlet_class_name + '.cs';
253-
Set-Content -Path $fileFullPath -Value $cmdlt_source_template -Force;
287+
$file_full_path = $fileOutputFolder + '/' + $cmdlet_class_name + '.cs';
288+
$st = Set-Content -Path $file_full_path -Value $cmdlt_source_template -Force;
254289
}
255290

291+
# Code Generation Main:
256292
Write-Output $dllFolder;
257293
Write-Output $outFolder;
258294

@@ -264,7 +300,7 @@ $output = Get-ChildItem -Path $dllFolder | Out-String;
264300
Write-Output $output;
265301

266302

267-
$dllname = 'Microsoft.WindowsAzure.Management.Compute';
303+
$dllname = $client_library_namespace;
268304
$dllfile = $dllname + '.dll';
269305
$dllFileFullPath = $dllFolder + '\' + $dllfile;
270306

@@ -302,7 +338,7 @@ else
302338
$methods = $ft.GetMethods();
303339
foreach ($mt in $methods)
304340
{
305-
Write-Output ($mt.Name.Replace('Async', ''));
341+
Write-Output ($new_line_str + $mt.Name.Replace('Async', ''));
306342
Write-OperationCmdletFile $opOutFolder $opShortName $mt;
307343
}
308344
}

0 commit comments

Comments
 (0)