Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.1.3-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.BackupServicesManagement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Commands.AzureBackup\Resources\Microsoft.Azure.Management.BackupServicesManagement.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.BackupServices.1.0.4-preview\lib\net40\Microsoft.Azure.Management.BackupServicesManagement.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Azure.Common.Authentication" version="1.1.3-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Management.BackupServices" version="1.0.3-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.BackupServices" version="1.0.4-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Test.Framework" version="1.0.5687.28567-prerelease" targetFramework="net45" />
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.0.5687.28567-prerelease" targetFramework="net45" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.BackupServicesManagement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Resources\Microsoft.Azure.Management.BackupServicesManagement.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.BackupServices.1.0.4-preview\lib\net40\Microsoft.Azure.Management.BackupServicesManagement.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// ----------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using ClientModel = Microsoft.Azure.Management.BackupServices.Models;
using CmdletModel = Microsoft.Azure.Commands.AzureBackup.Models;

Expand Down Expand Up @@ -50,5 +53,76 @@ public static string GetResourceGroup(string vaultId)
string[] tokens = vaultId.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
return tokens[3];
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should comment out all this code if it is unused.

/// <summary>
/// Extension to convert enumerable Hashtable into a dictionary
/// </summary>
/// <param name="tags"></param>
/// <returns></returns>
public static Dictionary<string, string> ConvertToDictionary(this Hashtable[] tags)
{
return tags == null
? null
: tags
.CoalesceEnumerable()
.Select(hashTable => hashTable.OfType<DictionaryEntry>()
.ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value))
.Where(tagDictionary => tagDictionary.ContainsKey("Name"))
.Select(tagDictionary => Tuple
.Create(
tagDictionary["Name"].ToString(),
tagDictionary.ContainsKey("Value") ? tagDictionary["Value"].ToString() : string.Empty))
.Distinct(kvp => kvp.Item1)
.ToDictionary(kvp => kvp.Item1, kvp => kvp.Item2);
}

/// <summary>
/// Extension to coalesce enumerable
/// </summary>
/// <typeparam name="TSource">Enumerable type</typeparam>
/// <param name="source">Enumerable</param>
/// <returns></returns>
public static IEnumerable<TSource> CoalesceEnumerable<TSource>(this IEnumerable<TSource> source)
{
return source ?? Enumerable.Empty<TSource>();
}

/// <summary>
/// Extension to remove duplicates from enumerable based on a provided key selector
/// </summary>
/// <typeparam name="TSource">Enumerable type</typeparam>
/// <typeparam name="TKeyType">Type of key</typeparam>
/// <param name="source">Input enumerable to remove duplicates from</param>
/// <param name="keySelector">Lambda to select key</param>
/// <returns></returns>
public static IEnumerable<TSource> Distinct<TSource, TKeyType>(this IEnumerable<TSource> source, Func<TSource, TKeyType> keySelector)
{
var set = new Dictionary<TKeyType, TSource>(EqualityComparer<TKeyType>.Default);
foreach (TSource element in source)
{
TSource value;
var key = keySelector(element);
if (!set.TryGetValue(key, out value))
{
yield return element;
}
else
{
set[key] = value;
}
}
}

/// <summary>
/// Extension to convert dictionary to hashtable enumerable
/// </summary>
/// <param name="tags"></param>
/// <returns></returns>
public static Hashtable[] GetTagsHashtables(this IDictionary<string, string> tags)
{
return tags == null
? null
: tags.Select(kvp => new Hashtable { { "Name", kvp.Key }, { "Value", kvp.Value } }).ToArray();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class AzureRMBackupVault

public string Region { get; set; }

// public Hashtable[] Tags { get; protected set; }
// TODO: Add support for tags
//public Hashtable[] Tags { get; set; }

public string Storage { get; set; }

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Azure.Common.Authentication" version="1.1.3-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Management.BackupServices" version="1.0.3-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.BackupServices" version="1.0.4-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
Expand Down