Skip to content

Commit 1c3634c

Browse files
author
Samuel Anudeep
committed
Merge pull request #138 from MabOneSdk/dev1-anudeeb
Fix for Bug 4308340. Signed off by SureshT. Will incorporate comments in a separate PR.
2 parents bf04b6d + 4ab2c88 commit 1c3634c

File tree

7 files changed

+80
-7
lines changed

7 files changed

+80
-7
lines changed

src/ResourceManager/AzureBackup/Commands.AzureBackup.Test/Commands.AzureBackup.Test.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.1.3-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
4141
</Reference>
4242
<Reference Include="Microsoft.Azure.Management.BackupServicesManagement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
43-
<SpecificVersion>False</SpecificVersion>
44-
<HintPath>..\Commands.AzureBackup\Resources\Microsoft.Azure.Management.BackupServicesManagement.dll</HintPath>
43+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.BackupServices.1.0.4-preview\lib\net40\Microsoft.Azure.Management.BackupServicesManagement.dll</HintPath>
4544
</Reference>
4645
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
4746
<SpecificVersion>False</SpecificVersion>

src/ResourceManager/AzureBackup/Commands.AzureBackup.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
55
<package id="Microsoft.Azure.Common.Authentication" version="1.1.3-preview" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
7-
<package id="Microsoft.Azure.Management.BackupServices" version="1.0.3-preview" targetFramework="net45" />
7+
<package id="Microsoft.Azure.Management.BackupServices" version="1.0.4-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
99
<package id="Microsoft.Azure.Test.Framework" version="1.0.5687.28567-prerelease" targetFramework="net45" />
1010
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.0.5687.28567-prerelease" targetFramework="net45" />

src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@
5757
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
5858
</Reference>
5959
<Reference Include="Microsoft.Azure.Management.BackupServicesManagement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
60-
<SpecificVersion>False</SpecificVersion>
61-
<HintPath>Resources\Microsoft.Azure.Management.BackupServicesManagement.dll</HintPath>
60+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.BackupServices.1.0.4-preview\lib\net40\Microsoft.Azure.Management.BackupServicesManagement.dll</HintPath>
6261
</Reference>
6362
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6463
<SpecificVersion>False</SpecificVersion>

src/ResourceManager/AzureBackup/Commands.AzureBackup/Helpers/VaultHelpers.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System;
16+
using System.Collections;
17+
using System.Collections.Generic;
18+
using System.Linq;
1619
using ClientModel = Microsoft.Azure.Management.BackupServices.Models;
1720
using CmdletModel = Microsoft.Azure.Commands.AzureBackup.Models;
1821

@@ -50,5 +53,76 @@ public static string GetResourceGroup(string vaultId)
5053
string[] tokens = vaultId.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
5154
return tokens[3];
5255
}
56+
57+
/// <summary>
58+
/// Extension to convert enumerable Hashtable into a dictionary
59+
/// </summary>
60+
/// <param name="tags"></param>
61+
/// <returns></returns>
62+
public static Dictionary<string, string> ConvertToDictionary(this Hashtable[] tags)
63+
{
64+
return tags == null
65+
? null
66+
: tags
67+
.CoalesceEnumerable()
68+
.Select(hashTable => hashTable.OfType<DictionaryEntry>()
69+
.ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value))
70+
.Where(tagDictionary => tagDictionary.ContainsKey("Name"))
71+
.Select(tagDictionary => Tuple
72+
.Create(
73+
tagDictionary["Name"].ToString(),
74+
tagDictionary.ContainsKey("Value") ? tagDictionary["Value"].ToString() : string.Empty))
75+
.Distinct(kvp => kvp.Item1)
76+
.ToDictionary(kvp => kvp.Item1, kvp => kvp.Item2);
77+
}
78+
79+
/// <summary>
80+
/// Extension to coalesce enumerable
81+
/// </summary>
82+
/// <typeparam name="TSource">Enumerable type</typeparam>
83+
/// <param name="source">Enumerable</param>
84+
/// <returns></returns>
85+
public static IEnumerable<TSource> CoalesceEnumerable<TSource>(this IEnumerable<TSource> source)
86+
{
87+
return source ?? Enumerable.Empty<TSource>();
88+
}
89+
90+
/// <summary>
91+
/// Extension to remove duplicates from enumerable based on a provided key selector
92+
/// </summary>
93+
/// <typeparam name="TSource">Enumerable type</typeparam>
94+
/// <typeparam name="TKeyType">Type of key</typeparam>
95+
/// <param name="source">Input enumerable to remove duplicates from</param>
96+
/// <param name="keySelector">Lambda to select key</param>
97+
/// <returns></returns>
98+
public static IEnumerable<TSource> Distinct<TSource, TKeyType>(this IEnumerable<TSource> source, Func<TSource, TKeyType> keySelector)
99+
{
100+
var set = new Dictionary<TKeyType, TSource>(EqualityComparer<TKeyType>.Default);
101+
foreach (TSource element in source)
102+
{
103+
TSource value;
104+
var key = keySelector(element);
105+
if (!set.TryGetValue(key, out value))
106+
{
107+
yield return element;
108+
}
109+
else
110+
{
111+
set[key] = value;
112+
}
113+
}
114+
}
115+
116+
/// <summary>
117+
/// Extension to convert dictionary to hashtable enumerable
118+
/// </summary>
119+
/// <param name="tags"></param>
120+
/// <returns></returns>
121+
public static Hashtable[] GetTagsHashtables(this IDictionary<string, string> tags)
122+
{
123+
return tags == null
124+
? null
125+
: tags.Select(kvp => new Hashtable { { "Name", kvp.Key }, { "Value", kvp.Value } }).ToArray();
126+
}
53127
}
54128
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/AzurePSBackupVault.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public class AzureRMBackupVault
3030

3131
public string Region { get; set; }
3232

33-
// public Hashtable[] Tags { get; protected set; }
33+
// TODO: Add support for tags
34+
//public Hashtable[] Tags { get; set; }
3435

3536
public string Storage { get; set; }
3637

src/ResourceManager/AzureBackup/Commands.AzureBackup/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
55
<package id="Microsoft.Azure.Common.Authentication" version="1.1.3-preview" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
7-
<package id="Microsoft.Azure.Management.BackupServices" version="1.0.3-preview" targetFramework="net45" />
7+
<package id="Microsoft.Azure.Management.BackupServices" version="1.0.4-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
99
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
1010
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />

0 commit comments

Comments
 (0)