Skip to content

Commit 3a965ac

Browse files
authored
Merge pull request #2679 from TianoMS/tiano-d2
Change the type of parameter "Tags" to Hashtable
2 parents 6fbf06b + 19e804f commit 3a965ac

File tree

105 files changed

+441
-534
lines changed

Some content is hidden

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

105 files changed

+441
-534
lines changed

src/ResourceManager/AzureBatch/Commands.Batch.Test/Accounts/SetBatchAccountCommandTests.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,11 @@ public void UpdateAccountTest()
4848
string resourceGroup = "resourceGroup";
4949
string storageId = "storageId";
5050

51-
Hashtable[] tags = new[]
52-
{
53-
new Hashtable
51+
Hashtable tags = new Hashtable
5452
{
5553
{"Name", "tagName"},
5654
{"Value", "tagValue"}
57-
}
58-
};
55+
};
5956

6057
AccountResource accountResource = BatchTestHelpers.CreateAccountResource(accountName, resourceGroup, tags);
6158
BatchAccountContext expected = BatchAccountContext.ConvertAccountResourceToNewAccountContext(accountResource);

src/ResourceManager/AzureBatch/Commands.Batch.Test/BatchTestHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static class BatchTestHelpers
4646
/// <summary>
4747
/// Builds an AccountResource object using the specified parameters
4848
/// </summary>
49-
public static AccountResource CreateAccountResource(string accountName, string resourceGroupName, Hashtable[] tags = null, string storageId = null)
49+
public static AccountResource CreateAccountResource(string accountName, string resourceGroupName, Hashtable tags = null, string storageId = null)
5050
{
5151
string tenantUrlEnding = "batch-test.windows-int.net";
5252
string endpoint = string.Format("{0}.{1}", accountName, tenantUrlEnding);

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/BatchAccountTests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function Test-CreatesNewBatchAccount
4646
Assert-AreEqual $expected.AccountName $actual.AccountName
4747
Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName
4848
Assert-AreEqual $expected.Location $actual.Location
49-
Assert-AreEqual $expected.Tags[0][$tagName] $actual.Tags[0][$tagName]
49+
Assert-AreEqual $expected.Tags[$tagName] $actual.Tags[$tagName]
5050
Assert-True { $actual.CoreQuota -gt 0 }
5151
Assert-True { $actual.PoolQuota -gt 0 }
5252
Assert-True { $actual.ActiveJobAndJobScheduleQuota -gt 0 }
@@ -91,8 +91,8 @@ function Test-UpdatesExistingBatchAccount
9191
Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName
9292
Assert-AreEqual $expected.Location $actual.Location
9393
Assert-AreEqual 1 $expected.Tags.Count
94-
Assert-AreEqual $tagValue2 $expected.Tags[0][$tagName2]
95-
Assert-AreEqual $expected.Tags[0][$tagName2] $actual.Tags[0][$tagName2]
94+
Assert-AreEqual $tagValue2 $expected.Tags[$tagName2]
95+
Assert-AreEqual $expected.Tags[$tagName2] $actual.Tags[$tagName2]
9696

9797
}
9898
finally

src/ResourceManager/AzureBatch/Commands.Batch/Accounts/Helpers.cs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,47 +30,35 @@ internal class Helpers
3030
// copied from Resources\Commands.Resources
3131
private const string ExcludedTagPrefix = "hidden-related:/";
3232

33-
public static string FormatTagsTable(Hashtable[] tags)
33+
public static string FormatTagsTable(Hashtable tags)
3434
{
35-
if (tags == null)
35+
if (tags == null || tags.Count == 0)
3636
{
3737
return null;
3838
}
3939

40-
Hashtable emptyHashtable = new Hashtable
41-
{
42-
{"Name", string.Empty},
43-
{"Value", string.Empty}
44-
};
4540
StringBuilder resourcesTable = new StringBuilder();
4641

47-
if (tags.Length > 0)
48-
{
49-
int maxNameLength = Math.Max("Name".Length, tags.Where(ht => ht.ContainsKey("Name")).DefaultIfEmpty(emptyHashtable).Max(ht => ht["Name"].ToString().Length));
50-
int maxValueLength = Math.Max("Value".Length, tags.Where(ht => ht.ContainsKey("Value")).DefaultIfEmpty(emptyHashtable).Max(ht => ht["Value"].ToString().Length));
51-
52-
string rowFormat = "{0, -" + maxNameLength + "} {1, -" + maxValueLength + "}\r\n";
53-
resourcesTable.AppendLine();
54-
resourcesTable.AppendFormat(rowFormat, "Name", "Value");
42+
var tagsDictionary = TagsConversionHelper.CreateTagDictionary(tags, false);
5543

56-
foreach (Hashtable tag in tags)
57-
{
58-
PSTagValuePair tagValuePair = TagsConversionHelper.Create(tag);
44+
int maxNameLength = Math.Max("Name".Length, tagsDictionary.Max(tag => tag.Key.Length));
45+
int maxValueLength = Math.Max("Value".Length, tagsDictionary.Max(tag => tag.Value.Length));
5946

60-
if (tagValuePair != null)
61-
{
62-
if (tagValuePair.Name.StartsWith(ExcludedTagPrefix))
63-
{
64-
continue;
65-
}
47+
string rowFormat = "{0, -" + maxNameLength + "} {1, -" + maxValueLength + "}\r\n";
48+
resourcesTable.AppendLine();
49+
resourcesTable.AppendFormat(rowFormat, "Name", "Value");
50+
resourcesTable.AppendFormat(rowFormat,
51+
GeneralUtilities.GenerateSeparator(maxNameLength, "="),
52+
GeneralUtilities.GenerateSeparator(maxValueLength, "="));
6653

67-
if (tagValuePair.Value == null)
68-
{
69-
tagValuePair.Value = string.Empty;
70-
}
71-
resourcesTable.AppendFormat(rowFormat, tagValuePair.Name, tagValuePair.Value);
72-
}
54+
foreach (var tag in tagsDictionary)
55+
{
56+
if (tag.Key.StartsWith(ExcludedTagPrefix))
57+
{
58+
continue;
7359
}
60+
61+
resourcesTable.AppendFormat(rowFormat, tag.Key, tag.Value);
7462
}
7563

7664
return resourcesTable.ToString();

src/ResourceManager/AzureBatch/Commands.Batch/Accounts/NewBatchAccountCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class NewBatchAccountCommand : BatchCmdletBase
4242

4343
[Alias("Tags")]
4444
[Parameter(ValueFromPipelineByPropertyName = true)]
45-
public Hashtable[] Tag { get; set; }
45+
public Hashtable Tag { get; set; }
4646

4747
public override void ExecuteCmdlet()
4848
{

src/ResourceManager/AzureBatch/Commands.Batch/Accounts/SetBatchAccountCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public class SetBatchAccountCommand : BatchCmdletBase
2929

3030
[Alias("Tags")]
3131
[Parameter(Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true,
32-
HelpMessage = "An array of hashtables which represents the tags to set on the account.")]
33-
public Hashtable[] Tag { get; set; }
32+
HelpMessage = "A hashtable which represents the tags to set on the account.")]
33+
public Hashtable Tag { get; set; }
3434

3535
[Parameter(ValueFromPipelineByPropertyName = true)]
3636
public string ResourceGroupName { get; set; }

src/ResourceManager/AzureBatch/Commands.Batch/Microsoft.Azure.Commands.Batch.dll-Help.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8294,9 +8294,9 @@
82948294
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="named">
82958295
<maml:name>Tag</maml:name>
82968296
<maml:description>
8297-
<maml:para>Specifies an array of hash tables of tags for the account.</maml:para>
8297+
<maml:para>Specifies a hash table of tags for the account.</maml:para>
82988298
</maml:description>
8299-
<command:parameterValue required="true" variableLength="true">Hashtable[]</command:parameterValue>
8299+
<command:parameterValue required="true" variableLength="true">Hashtable</command:parameterValue>
83008300
</command:parameter>
83018301
</command:syntaxItem>
83028302
</command:syntax>
@@ -8353,11 +8353,11 @@
83538353
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="named">
83548354
<maml:name>Tag</maml:name>
83558355
<maml:description>
8356-
<maml:para>Specifies an array of hash tables of tags for the account.</maml:para>
8356+
<maml:para>Specifies a hash table of tags for the account.</maml:para>
83578357
</maml:description>
8358-
<command:parameterValue required="true" variableLength="true">Hashtable[]</command:parameterValue>
8358+
<command:parameterValue required="true" variableLength="true">Hashtable</command:parameterValue>
83598359
<dev:type>
8360-
<maml:name>Hashtable[]</maml:name>
8360+
<maml:name>Hashtable</maml:name>
83618361
<maml:uri/>
83628362
</dev:type>
83638363
<dev:defaultValue>none</dev:defaultValue>
@@ -12201,9 +12201,9 @@
1220112201
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="1">
1220212202
<maml:name>Tag</maml:name>
1220312203
<maml:description>
12204-
<maml:para>Specifies an array of hash tables of tags for the account.</maml:para>
12204+
<maml:para>Specifies a hash table of tags for the account.</maml:para>
1220512205
</maml:description>
12206-
<command:parameterValue required="true" variableLength="true">Hashtable[]</command:parameterValue>
12206+
<command:parameterValue required="true" variableLength="true">Hashtable</command:parameterValue>
1220712207
</command:parameter>
1220812208
</command:syntaxItem>
1220912209
</command:syntax>
@@ -12247,11 +12247,11 @@
1224712247
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="1">
1224812248
<maml:name>Tag</maml:name>
1224912249
<maml:description>
12250-
<maml:para>Specifies an array of hash tables of tags for the account.</maml:para>
12250+
<maml:para>Specifies a hash table of tags for the account.</maml:para>
1225112251
</maml:description>
12252-
<command:parameterValue required="true" variableLength="true">Hashtable[]</command:parameterValue>
12252+
<command:parameterValue required="true" variableLength="true">Hashtable</command:parameterValue>
1225312253
<dev:type>
12254-
<maml:name>Hashtable[]</maml:name>
12254+
<maml:name>Hashtable</maml:name>
1225512255
<maml:uri/>
1225612256
</dev:type>
1225712257
<dev:defaultValue>none</dev:defaultValue>
@@ -12278,7 +12278,7 @@
1227812278
<maml:introduction>
1227912279
<maml:paragraph>PS C:\&gt;</maml:paragraph>
1228012280
</maml:introduction>
12281-
<dev:code>PS C:\&gt;Set-AzureRmBatchAccount -AccountName &quot;cmdletexample&quot; -Tag @(@{Name = &quot;tag1&quot;;Value = &quot;value1&quot;},@{Name = &quot;tag2&quot;;Value = &quot;value2&quot;})
12281+
<dev:code>PS C:\&gt;Set-AzureRmBatchAccount -AccountName &quot;cmdletexample&quot; -Tag @{tag1 = &quot;value1&quot;; tag2 = &quot;value2&quot;}
1228212282
AccountName : cmdletexample
1228312283

1228412284
Location : westus

src/ResourceManager/AzureBatch/Commands.Batch/Models/BatchAccountContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public class BatchAccountContext
8686
/// <summary>
8787
/// Tags associated with the account resource.
8888
/// </summary>
89-
public Hashtable[] Tags { get; private set; }
89+
public Hashtable Tags { get; private set; }
9090

9191
/// <summary>
9292
/// A string representation of the Tags property.

src/ResourceManager/AzureBatch/Commands.Batch/Models/BatchClient.Accounts.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public partial class BatchClient
3939
/// <param name="tags">The tags to associate with the account</param>
4040
/// <param name="autoStorageAccountId">The resource id of the storage account to be used for auto storage.</param>
4141
/// <returns>A BatchAccountContext object representing the new account</returns>
42-
public virtual BatchAccountContext CreateAccount(string resourceGroupName, string accountName, string location, Hashtable[] tags, string autoStorageAccountId)
42+
public virtual BatchAccountContext CreateAccount(string resourceGroupName, string accountName, string location, Hashtable tags, string autoStorageAccountId)
4343
{
4444
Dictionary<string, string> tagDictionary = TagsConversionHelper.CreateTagDictionary(tags, validate: true);
4545

@@ -67,7 +67,7 @@ public virtual BatchAccountContext CreateAccount(string resourceGroupName, strin
6767
/// <param name="tags">New tags to associate with the account</param>
6868
/// <param name="autoStorageAccountId">The resource id of the storage account to be used for auto storage.</param>
6969
/// <returns>A BatchAccountContext object representing the updated account</returns>
70-
public virtual BatchAccountContext UpdateAccount(string resourceGroupName, string accountName, Hashtable[] tags, string autoStorageAccountId)
70+
public virtual BatchAccountContext UpdateAccount(string resourceGroupName, string accountName, Hashtable tags, string autoStorageAccountId)
7171
{
7272
if (string.IsNullOrEmpty(resourceGroupName))
7373
{

src/ResourceManager/Common/Commands.ResourceManager.Common/Properties/Resources.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/Common/Commands.ResourceManager.Common/Properties/Resources.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Select Y to enable data collection [Y/N]:</value>
152152
<value>No default subscription has been designated. Use Select-AzureSubscription -Default &lt;subscriptionName&gt; to set the default subscription.</value>
153153
</data>
154154
<data name="InvalidTagFormat" xml:space="preserve">
155-
<value>Invalid tag format. Expect @{Name = "tagName"} or @{Name = "tagName"; Value = "tagValue"}</value>
155+
<value>Invalid tag format. Expect @{tagName = $null} or @{tagName = "tagValue"}</value>
156156
</data>
157157
<data name="NoSubscriptionFound" xml:space="preserve">
158158
<value>The provided account {0} does not have access to any subscriptions. Please try logging in with different credentials.</value>

src/ResourceManager/Common/Commands.ResourceManager.Common/Tags/TagsConversionHelper.cs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,32 @@ public static PSTagValuePair Create(Hashtable hashtable)
4343
return tagValuePair;
4444
}
4545

46-
public static Dictionary<string, string> CreateTagDictionary(Hashtable[] hashtableArray, bool validate)
46+
public static Dictionary<string, string> CreateTagDictionary(Hashtable tags, bool validate)
4747
{
4848
Dictionary<string, string> tagDictionary = null;
49-
if (hashtableArray != null && hashtableArray.Length > 0)
49+
if (tags != null)
5050
{
5151
tagDictionary = new Dictionary<string, string>();
5252
PSTagValuePair tvPair = new PSTagValuePair();
53-
foreach (var tag in hashtableArray)
53+
54+
foreach(DictionaryEntry entry in tags)
5455
{
55-
foreach(DictionaryEntry entry in tag)
56+
tvPair.Name = entry.Key.ToString();
57+
if (entry.Value != null)
58+
{
59+
tvPair.Value = entry.Value.ToString();
60+
}
61+
else
5662
{
57-
tvPair.Name = entry.Key.ToString();
58-
if (entry.Value != null)
59-
{
60-
tvPair.Value = entry.Value.ToString();
61-
}
62-
else
63-
{
64-
tvPair.Value = string.Empty;
65-
}
66-
tagDictionary[tvPair.Name] = tvPair.Value;
63+
tvPair.Value = string.Empty;
6764
}
65+
tagDictionary[tvPair.Name] = tvPair.Value;
6866
}
67+
6968
}
7069
if (validate)
7170
{
72-
if (hashtableArray != null && hashtableArray.Length > 0 && hashtableArray[0].Count > 0 &&
71+
if (tags != null && tags.Count > 0 &&
7372
(tagDictionary == null || tagDictionary.Count == 0))
7473
{
7574
throw new ArgumentException(ProjectResources.InvalidTagFormat);
@@ -79,22 +78,20 @@ public static Dictionary<string, string> CreateTagDictionary(Hashtable[] hashtab
7978
return tagDictionary;
8079
}
8180

82-
public static Hashtable[] CreateTagHashtable(IDictionary<string, string> dictionary)
81+
public static Hashtable CreateTagHashtable(IDictionary<string, string> dictionary)
8382
{
8483
if (dictionary == null)
8584
{
86-
return new Hashtable[0];
85+
return null;
8786
}
8887

89-
List<Hashtable> tagHashtable = new List<Hashtable>();
88+
Hashtable tagsHashtable = new Hashtable();
89+
9090
foreach (string key in dictionary.Keys)
9191
{
92-
tagHashtable.Add(new Hashtable
93-
{
94-
{key, dictionary[key]}
95-
});
92+
tagsHashtable[key] = dictionary[key];
9693
}
97-
return tagHashtable.ToArray();
94+
return tagsHashtable;
9895
}
9996
}
10097
}

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,7 @@ function Test-VirtualMachineTags
16331633
$p = ($imgRef | Set-AzureRmVMSourceImage -VM $p);
16341634

16351635
# Test Tags
1636-
$tags = @{Name = "test1"; Value = "testval1"}, @{ Name = "test2"; Value = "testval2" };
1636+
$tags = @{test1 = "testval1"; test2 = "testval2" };
16371637
$st = New-AzureRmVM -ResourceGroupName $rgname -Location $loc -VM $p -Tags $tags;
16381638
#Assert-NotNull $st.RequestId;
16391639
Assert-NotNull $st.StatusCode;
@@ -1647,8 +1647,8 @@ function Test-VirtualMachineTags
16471647
Assert-NotNull $vm.StatusCode;
16481648

16491649
# Assert
1650-
Assert-AreEqual $tags[0].Value $vm.Tags[$tags[0].Name];
1651-
Assert-AreEqual $tags[1].Value $vm.Tags[$tags[1].Name];
1650+
Assert-AreEqual "testval1" $vm.Tags["test1"];
1651+
Assert-AreEqual "testval2" $vm.Tags["test2"];
16521652
}
16531653
finally
16541654
{

src/ResourceManager/Compute/Commands.Compute/Common/HashTableExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Microsoft.Azure.Commands.Compute.Common
2020
{
2121
public static class HashTableExtensions
2222
{
23-
public static Dictionary<string, string> ToDictionary(this Hashtable[] tags)
23+
public static Dictionary<string, string> ToDictionary(this Hashtable tags)
2424
{
2525
return TagsConversionHelper.CreateTagDictionary(tags, true);
2626
}

0 commit comments

Comments
 (0)