Skip to content

Commit f13f98c

Browse files
committed
Update
1 parent f21377b commit f13f98c

File tree

7 files changed

+3470
-513
lines changed

7 files changed

+3470
-513
lines changed

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/Create-ParameterObject.ps1

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,22 @@ function Create-ParameterObjectImpl
2121
{
2222
param(
2323
[Parameter(Mandatory = $True)]
24-
[System.Type]$typeInfo
24+
[System.Type]$typeInfo,
25+
26+
[Parameter(Mandatory = $True)]
27+
[System.Collections.Hashtable]$typeList
2528
)
2629

27-
if ([string]::IsNullOrEmpty($typeInfo.FullName))
30+
if ([string]::IsNullOrEmpty($typeInfo.FullName) -or $typeList.ContainsKey($typeInfo.FullName))
2831
{
2932
return $null;
3033
}
3134

35+
if ($typeInfo.FullName -like "Microsoft.*Azure.Management.*.*" -and (-not ($typeInfo.FullName -like "Microsoft.*Azure.Management.*.SubResource")))
36+
{
37+
$typeList.Add($typeInfo.FullName, $typeInfo);
38+
}
39+
3240
if ($typeInfo.FullName -eq 'System.String' -or $typeInfo.FullName -eq 'string')
3341
{
3442
return '';
@@ -56,7 +64,7 @@ function Create-ParameterObjectImpl
5664
elseif ($typeInfo.FullName -like 'System.Collections.Generic.IList*' -or $typeInfo.FullName -like 'System.Collections.Generic.List*')
5765
{
5866
[System.Type]$itemType = $typeInfo.GetGenericArguments()[0];
59-
$itemObj = Create-ParameterObjectImpl $itemType;
67+
$itemObj = Create-ParameterObjectImpl $itemType $typeList;
6068

6169
$typeName = "System.Collections.Generic.List[" + $itemType.FullName + "]";
6270
$listObj = New-Object -TypeName $typeName;
@@ -89,7 +97,7 @@ function Create-ParameterObjectImpl
8997
if ($prop.PropertyType.IsGenericType -and $prop.PropertyType.FullName -like 'System.Collections.Generic.*List*')
9098
{
9199
[System.Type]$itemType = $prop.PropertyType.GetGenericArguments()[0];
92-
$itemObj = Create-ParameterObjectImpl $itemType;
100+
$itemObj = Create-ParameterObjectImpl $itemType $typeList;
93101
$listTypeName = "System.Collections.Generic.List[" + $itemType.FullName + "]";
94102

95103
$propObjList = New-Object -TypeName $listTypeName;
@@ -99,7 +107,7 @@ function Create-ParameterObjectImpl
99107
}
100108
else
101109
{
102-
$propObj = Create-ParameterObjectImpl $prop.PropertyType;
110+
$propObj = Create-ParameterObjectImpl $prop.PropertyType $typeList;
103111
$prop.SetValue($obj, $propObj);
104112
}
105113
}
@@ -108,4 +116,4 @@ function Create-ParameterObjectImpl
108116
return $obj;
109117
}
110118

111-
Write-Output (Create-ParameterObjectImpl $typeInfo);
119+
Write-Output (Create-ParameterObjectImpl $typeInfo @{});

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/Create-ParameterTree.ps1

Lines changed: 87 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function New-ParameterTreeNode
4040
$node | Add-Member -Type NoteProperty -Name Properties -Value @();
4141
$node | Add-Member -Type NoteProperty -Name SubNodes -Value @();
4242
$node | Add-Member -Type NoteProperty -Name IsPrimitive -Value $false;
43+
$node | Add-Member -Type NoteProperty -Name IsReference -Value $false;
4344

4445
return $node;
4546
}
@@ -53,6 +54,9 @@ function Create-ParameterTreeImpl
5354
[Parameter(Mandatory = $true)]
5455
[System.Type]$TypeInfo,
5556

57+
[Parameter(Mandatory = $true)]
58+
[System.Collections.Hashtable]$TypeList,
59+
5660
[Parameter(Mandatory = $false)]
5761
$Parent = $null,
5862

@@ -64,88 +68,110 @@ function Create-ParameterTreeImpl
6468
{
6569
return $null;
6670
}
67-
elseif (-not $TypeInfo.FullName.StartsWith($NameSpace + "."))
71+
72+
if (-not $TypeInfo.FullName.StartsWith($NameSpace + "."))
6873
{
6974
$node = New-ParameterTreeNode $ParameterName $TypeInfo $Parent;
7075
return $node;
7176
}
7277
else
7378
{
74-
$treeNode = New-ParameterTreeNode $ParameterName $TypeInfo $Parent;
75-
if (Contains-OnlyStringFields $TypeInfo)
76-
{
77-
$treeNode.AllStrings = $true;
78-
}
79-
elseif (Contains-OnlyStringList $TypeInfo)
80-
{
81-
$treeNode.OneStringList = $true;
82-
}
83-
84-
if (Contains-OnlySimpleFields $TypeInfo $NameSpace)
85-
{
86-
$treeNode.OnlySimple = $true;
87-
}
88-
89-
$padding = ($Depth.ToString() + (' ' * (4 * ($Depth + 1))));
90-
if ($Depth -gt 0)
79+
if ($TypeList.ContainsKey($TypeInfo.FullName))
9180
{
92-
Write-Verbose ($padding + "-----------------------------------------------------------");
81+
$treeNode = New-ParameterTreeNode $ParameterName $TypeInfo $Parent;
82+
$treeNode.IsReference = $true;
83+
return $treeNode;
9384
}
94-
95-
if ($treeNode.AllStrings)
85+
else
9686
{
97-
$annotation = " *";
98-
}
99-
elseif ($treeNode.OneStringList)
100-
{
101-
$annotation = " ^";
102-
}
87+
if ($TypeInfo.FullName -like "Microsoft.*Azure.Management.*.*" -and (-not ($typeInfo.FullName -like "Microsoft.*Azure.Management.*.SubResource")))
88+
{
89+
$TypeList.Add($TypeInfo.FullName, $TypeInfo);
90+
}
91+
92+
$treeNode = New-ParameterTreeNode $ParameterName $TypeInfo $Parent;
93+
if (Contains-OnlyStringFields $TypeInfo)
94+
{
95+
$treeNode.AllStrings = $true;
96+
}
97+
elseif (Contains-OnlyStringList $TypeInfo)
98+
{
99+
$treeNode.OneStringList = $true;
100+
}
103101

104-
Write-Verbose ($padding + "[ Node ] " + $treeNode.Name + $annotation);
105-
Write-Verbose ($padding + "[Parent] " + $Parent.Name);
102+
if (Contains-OnlySimpleFields $TypeInfo $NameSpace)
103+
{
104+
$treeNode.OnlySimple = $true;
105+
}
106106

107-
foreach ($item in $TypeInfo.GetProperties())
108-
{
109-
$itemProp = [System.Reflection.PropertyInfo]$item;
110-
$can_write = ($itemProp.GetSetMethod() -ne $null) -and $itemProp.CanWrite;
111-
$nodeProp = @{ Name = $itemProp.Name; Type = $itemProp.PropertyType; CanWrite = $can_write};
112-
$treeNode.Properties += $nodeProp;
107+
$padding = ($Depth.ToString() + (' ' * (4 * ($Depth + 1))));
108+
if ($Depth -gt 0)
109+
{
110+
Write-Verbose ($padding + "-----------------------------------------------------------");
111+
}
113112

114-
if ($itemProp.PropertyType.FullName.StartsWith($NameSpace + "."))
113+
if ($treeNode.AllStrings)
115114
{
116-
# Model Class Type - Recursive Call
117-
$subTreeNode = Create-ParameterTreeImpl $itemProp.Name $itemProp.PropertyType $treeNode ($Depth + 1);
118-
if ($subTreeNode -ne $null)
119-
{
120-
$treeNode.SubNodes += $subTreeNode;
121-
}
115+
$annotation = " *";
122116
}
123-
elseif ($itemProp.PropertyType.FullName.StartsWith("System.Collections.Generic.IList"))
117+
elseif ($treeNode.OneStringList)
124118
{
125-
# List Type
126-
$listItemType = $itemProp.PropertyType.GenericTypeArguments[0];
127-
128-
Write-Verbose ($padding + '-' + $itemProp.Name + ' : [List] ' + $listItemType.Name + "");
129-
130-
# ListItem is Model Class Type - Recursive Call
131-
$subTreeNode = Create-ParameterTreeImpl $itemProp.Name $listItemType $treeNode ($Depth + 1)
132-
$subTreeNode.IsListItem = $true;
133-
$treeNode.SubNodes += $subTreeNode;
119+
$annotation = " ^";
134120
}
135-
else
121+
122+
Write-Verbose ($padding + "[ Node ] " + $treeNode.Name + $annotation);
123+
Write-Verbose ($padding + "[Parent] " + $Parent.Name);
124+
125+
foreach ($item in $TypeInfo.GetProperties())
136126
{
137-
if ($nodeProp["Type"].IsEquivalentTo([System.Nullable[long]]) -or
138-
$nodeProp["Type"].IsEquivalentTo([System.Nullable[bool]]))
127+
$itemProp = [System.Reflection.PropertyInfo]$item;
128+
$can_write = ($itemProp.GetSetMethod() -ne $null) -and $itemProp.CanWrite;
129+
$nodeProp = @{ Name = $itemProp.Name; Type = $itemProp.PropertyType; CanWrite = $can_write};
130+
$treeNode.Properties += $nodeProp;
131+
132+
if ($itemProp.PropertyType.FullName.StartsWith($NameSpace + "."))
139133
{
140-
$nodeProp["IsPrimitive"] = $true;
134+
# Model Class Type - Recursive Call
135+
$subTreeNode = Create-ParameterTreeImpl $itemProp.Name $itemProp.PropertyType $TypeList $treeNode ($Depth + 1);
136+
if ($subTreeNode -ne $null)
137+
{
138+
$treeNode.SubNodes += $subTreeNode;
139+
}
140+
}
141+
elseif ($itemProp.PropertyType.FullName.StartsWith("System.Collections.Generic.IList"))
142+
{
143+
# List Type
144+
$listItemType = $itemProp.PropertyType.GenericTypeArguments[0];
145+
if ($TypeList.ContainsKey($listItemType.FullName))
146+
{
147+
$refSuffix = "`'";
148+
}
149+
Write-Verbose ($padding + '-' + $itemProp.Name + ' : [List] ' + $listItemType.Name + $refSuffix);
150+
151+
# ListItem is Model Class Type - Recursive Call
152+
$subTreeNode = Create-ParameterTreeImpl $itemProp.Name $listItemType $TypeList $treeNode ($Depth + 1)
153+
if ($subTreeNode -ne $null)
154+
{
155+
$subTreeNode.IsListItem = $true;
156+
$treeNode.SubNodes += $subTreeNode;
157+
}
158+
}
159+
else
160+
{
161+
if ($nodeProp["Type"].IsEquivalentTo([System.Nullable[long]]) -or
162+
$nodeProp["Type"].IsEquivalentTo([System.Nullable[bool]]))
163+
{
164+
$nodeProp["IsPrimitive"] = $true;
165+
}
166+
167+
# Primitive Type, e.g. int, string, Dictionary<string, string>, etc.
168+
Write-Verbose ($padding + '-' + $nodeProp["Name"] + " : " + $nodeProp["Type"]);
141169
}
142-
143-
# Primitive Type, e.g. int, string, Dictionary<string, string>, etc.
144-
Write-Verbose ($padding + '-' + $nodeProp["Name"] + " : " + $nodeProp["Type"]);
145170
}
171+
172+
return $treeNode;
146173
}
147-
return $treeNode;
148174
}
149175
}
150176

151-
Write-Output (Create-ParameterTreeImpl $ParameterName $TypeInfo);
177+
Write-Output (Create-ParameterTreeImpl $ParameterName $TypeInfo @{});

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/Generate-FunctionCommand.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ function Generate-CliFunctionCommandImpl
6161
$allStringFieldCheck = @{};
6262
$oneStringListCheck = @{};
6363

64+
$component_name = Get-ComponentName $ModelClassNameSpace;
65+
$component_name_lowercase = $component_name.ToLower();
66+
6467
# 3. CLI Code
6568
# 3.1 Types
6669
foreach ($paramItem in $methodParameters)
@@ -299,11 +302,11 @@ function Generate-CliFunctionCommandImpl
299302

300303
if ($ModelNameSpace.Contains(".WindowsAzure."))
301304
{
302-
$code += " var computeManagementClient = utils.createComputeClient(subscription);" + $NEW_LINE;
305+
$code += " var ${component_name_lowercase}ManagementClient = utils.create${component_name}Client(subscription);" + $NEW_LINE;
303306
}
304307
else
305308
{
306-
$code += " var computeManagementClient = utils.createComputeManagementClient(subscription);" + $NEW_LINE;
309+
$code += " var ${component_name_lowercase}ManagementClient = utils.create${component_name}ManagementClient(subscription);" + $NEW_LINE;
307310
}
308311

309312
if ($cliMethodName -eq 'delete')
@@ -315,7 +318,7 @@ function Generate-CliFunctionCommandImpl
315318
$cliMethodFuncName = $cliMethodName;
316319
}
317320

318-
$code += " var result = computeManagementClient.${cliOperationName}.${cliMethodFuncName}(";
321+
$code += " var result = ${component_name_lowercase}ManagementClient.${cliOperationName}.${cliMethodFuncName}(";
319322

320323
for ($index = 0; $index -lt $methodParamNameList.Count; $index++)
321324
{

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ param(
6565

6666
$client_model_namespace = $client_library_namespace + '.Models';
6767
$is_hyak_mode = $client_library_namespace -like "Microsoft.WindowsAzure.*.*";
68+
$component_name = $client_library_namespace.Substring($client_library_namespace.LastIndexOf('.') + 1);
6869

6970
$all_return_type_names = @();
7071

@@ -74,6 +75,7 @@ Write-Verbose "DLL Folder = $dllFolder";
7475
Write-Verbose "Out Folder = $outFolder";
7576
Write-Verbose "Client NameSpace = $client_library_namespace";
7677
Write-Verbose "Model NameSpace = $client_model_namespace";
78+
Write-Verbose "Component Name = $component_name";
7779
Write-Verbose "Base Cmdlet Full Name = $baseCmdletFullName";
7880
Write-Verbose "Base Client Name = $base_class_client_field";
7981
Write-Verbose "Cmdlet Flavor = $cmdletFlavor";
@@ -186,7 +188,7 @@ $code_using_strs
186188
187189
namespace ${code_common_namespace}
188190
{
189-
public abstract class ComputeAutomationBaseCmdlet : $baseCmdletFullName
191+
public abstract class ${component_name}AutomationBaseCmdlet : $baseCmdletFullName
190192
{
191193
protected static PSArgument[] ConvertFromObjectsToArguments(string[] names, object[] objects)
192194
{
@@ -1373,14 +1375,14 @@ ${create_local_param_code_content}
13731375
# Construct the Individual Cmdlet Code Content
13741376
$cmdlet_partial_class_code =
13751377
@"
1376-
public partial class ${invoke_cmdlet_class_name} : ComputeAutomationBaseCmdlet
1378+
public partial class ${invoke_cmdlet_class_name} : ${component_name}AutomationBaseCmdlet
13771379
{
13781380
$dynamic_param_source_template
13791381
13801382
$invoke_cmdlt_source_template
13811383
}
13821384
1383-
public partial class ${parameter_cmdlet_class_name} : ComputeAutomationBaseCmdlet
1385+
public partial class ${parameter_cmdlet_class_name} : ${component_name}AutomationBaseCmdlet
13841386
{
13851387
$parameter_cmdlt_source_template
13861388
}
@@ -1429,7 +1431,7 @@ namespace ${code_common_namespace}
14291431
{
14301432
[Cmdlet(${cmdlet_verb_code}, `"${cmdlet_noun}`")]
14311433
[OutputType(typeof(${normalized_output_type_name}))]
1432-
public class ${cmdlet_class_name} : ComputeAutomationBaseCmdlet
1434+
public class ${cmdlet_class_name} : ${component_name}AutomationBaseCmdlet
14331435
{
14341436
${cmdlet_generated_code}
14351437
}
@@ -1686,7 +1688,7 @@ function Process-ReturnType
16861688

16871689
$allrt += $rt.Name;
16881690

1689-
if ($rt.Name -like '*LongRunning*' -or $rt.Name -like '*computeoperationresponse*' -or $rt.Name -like '*AzureOperationResponse*')
1691+
if ($rt.Name -like '*LongRunning*' -or $rt.Name -like ('*' + $component_name + 'OperationResponse*') -or $rt.Name -like '*AzureOperationResponse*')
16901692
{
16911693
return @($result, $allrt);
16921694
}
@@ -1889,9 +1891,9 @@ else
18891891
return -1;
18901892
}
18911893

1892-
$auto_base_cmdlet_name = 'ComputeAutomationBaseCmdlet';
1894+
$auto_base_cmdlet_name = $component_name + 'AutomationBaseCmdlet';
18931895
$baseCmdletFileFullName = $outFolder + '\' + "$auto_base_cmdlet_name.cs";
1894-
$clientClassType = $types | where { $_.Namespace -eq $dllname -and $_.Name -eq 'IComputeManagementClient' };
1896+
$clientClassType = $types | where { $_.Namespace -eq $dllname -and $_.Name -eq ('I' + $component_name + 'ManagementClient') };
18951897
Write-BaseCmdletFile $baseCmdletFileFullName $opNameList $clientClassType;
18961898

18971899
# PSArgument File
@@ -1904,11 +1906,11 @@ else
19041906
$psargument_model_class_file_path = $model_class_out_folder + '\PSArgument.cs';
19051907
Write-PSArgumentFile $psargument_model_class_file_path;
19061908

1907-
$invoke_cmdlet_class_name = 'InvokeAzureComputeMethodCmdlet';
1909+
$invoke_cmdlet_class_name = 'InvokeAzure' + $component_name + 'MethodCmdlet';
19081910
$invoke_cmdlet_file_name = $outFolder + '\' + "$invoke_cmdlet_class_name.cs";
1909-
$parameter_cmdlet_class_name = 'NewAzureComputeArgumentListCmdlet';
1911+
$parameter_cmdlet_class_name = 'NewAzure' + $component_name + 'ArgumentListCmdlet';
19101912
$parameter_cmdlet_file_name = $outFolder + '\' + "$parameter_cmdlet_class_name.cs";
1911-
$new_object_cmdlet_class_name = 'NewAzureComputeParameterObjectCmdlet';
1913+
$new_object_cmdlet_class_name = 'NewAzure' + $component_name + 'ParameterObjectCmdlet';
19121914
$new_object_cmdlet_file_name = $outFolder + '\' + "$new_object_cmdlet_class_name.cs";
19131915

19141916
[System.Reflection.ParameterInfo[]]$parameter_type_info_list = @();

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/StringProcessingHelper.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,20 @@ function Get-SingularNoun
319319
return $noun;
320320
}
321321
}
322+
323+
function Get-ComponentName
324+
{
325+
# Sample: "Microsoft.Azure.Management.Compute";
326+
param
327+
(
328+
[Parameter(Mandatory = $true)]
329+
[string]$clientNS
330+
)
331+
332+
if ($clientNS.EndsWith('.Model') -or $clientNS.EndsWith('.Models'))
333+
{
334+
$clientNS = $clientNS.Substring(0, $clientNS.LastIndexOf('.'));
335+
}
336+
337+
return $clientNS.Substring($clientNS.LastIndexOf('.') + 1);
338+
}

0 commit comments

Comments
 (0)