Skip to content

Commit da5cf63

Browse files
authored
Merge branch 'preview' into ritwikbasu/public
2 parents 211983b + 69e474b commit da5cf63

File tree

309 files changed

+214314
-103737
lines changed

Some content is hidden

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

309 files changed

+214314
-103737
lines changed

src/Common/Commands.Common.Network/Models/EffectiveNetworkSecurityGroup.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ public EffectiveNetworkSecurityGroup()
3636
/// that is applied.</param>
3737
/// <param name="effectiveSecurityRules">A collection of effective
3838
/// security rules.</param>
39-
public EffectiveNetworkSecurityGroup(SubResource networkSecurityGroup = default(SubResource), EffectiveNetworkSecurityGroupAssociation association = default(EffectiveNetworkSecurityGroupAssociation), IList<EffectiveNetworkSecurityRule> effectiveSecurityRules = default(IList<EffectiveNetworkSecurityRule>))
39+
/// <param name="tagMap">Tag map.</param>
40+
public EffectiveNetworkSecurityGroup(SubResource networkSecurityGroup = default(SubResource), EffectiveNetworkSecurityGroupAssociation association = default(EffectiveNetworkSecurityGroupAssociation), IList<EffectiveNetworkSecurityRule> effectiveSecurityRules = default(IList<EffectiveNetworkSecurityRule>), IDictionary<string, List<string>> tagMap = default(IDictionary<string, List<string>>))
4041
{
4142
NetworkSecurityGroup = networkSecurityGroup;
4243
Association = association;
4344
EffectiveSecurityRules = effectiveSecurityRules;
45+
TagMap = tagMap;
4446
CustomInit();
4547
}
4648

@@ -66,5 +68,10 @@ public EffectiveNetworkSecurityGroup()
6668
[JsonProperty(PropertyName = "effectiveSecurityRules")]
6769
public IList<EffectiveNetworkSecurityRule> EffectiveSecurityRules { get; set; }
6870

71+
/// <summary>
72+
/// Gets or sets the tag map.
73+
/// </summary>
74+
[JsonProperty(PropertyName = "tagMap")]
75+
public IDictionary<string, List<string>> TagMap { get; set; }
6976
}
7077
}

src/Common/Commands.Common/AzurePSCmdlet.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ protected void LogQosEvent()
522522

523523
try
524524
{
525+
_metricHelper.SetPSHost(this.Host);
525526
_metricHelper.LogQoSEvent(_qosEvent, IsUsageMetricEnabled, IsErrorMetricEnabled);
526527
_metricHelper.FlushMetric();
527528
WriteDebug("Finish sending metric.");

src/Common/Commands.Common/DataCollectionController.cs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,32 @@ public abstract class DataCollectionController
2626

2727
static AzurePSDataCollectionProfile Initialize(IAzureSession session)
2828
{
29-
AzurePSDataCollectionProfile result = new AzurePSDataCollectionProfile();
29+
AzurePSDataCollectionProfile result = new AzurePSDataCollectionProfile(true);
3030
try
3131
{
32-
var store = session.DataStore;
33-
string dataPath = Path.Combine(session.ProfileDirectory, AzurePSDataCollectionProfile.DefaultFileName);
34-
if (store.FileExists(dataPath))
32+
var environmentValue = Environment.GetEnvironmentVariable(AzurePSDataCollectionProfile.EnvironmentVariableName);
33+
bool enabled = true;
34+
if (!string.IsNullOrWhiteSpace(environmentValue) && bool.TryParse(environmentValue, out enabled))
3535
{
36-
string contents = store.ReadFileAsText(dataPath);
37-
var localResult = JsonConvert.DeserializeObject<AzurePSDataCollectionProfile>(contents);
38-
if (localResult != null && localResult.EnableAzureDataCollection.HasValue)
39-
{
40-
result = localResult;
41-
}
36+
result.EnableAzureDataCollection = enabled;
4237
}
4338
else
4439
{
45-
WritePSDataCollectionProfile(session, new AzurePSDataCollectionProfile(true));
40+
var store = session.DataStore;
41+
string dataPath = Path.Combine(session.ProfileDirectory, AzurePSDataCollectionProfile.DefaultFileName);
42+
if (store.FileExists(dataPath))
43+
{
44+
string contents = store.ReadFileAsText(dataPath);
45+
var localResult = JsonConvert.DeserializeObject<AzurePSDataCollectionProfile>(contents);
46+
if (localResult != null && localResult.EnableAzureDataCollection.HasValue)
47+
{
48+
result = localResult;
49+
}
50+
}
51+
else
52+
{
53+
WritePSDataCollectionProfile(session, new AzurePSDataCollectionProfile(true));
54+
}
4655
}
4756
}
4857
catch

src/Common/Commands.Common/MetricHelper.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System;
2323
using System.Collections.Generic;
2424
using System.Diagnostics;
25+
using System.Management.Automation.Host;
2526
using System.Security.Cryptography;
2627
using System.Text;
2728

@@ -31,6 +32,8 @@ public class MetricHelper
3132
{
3233
protected INetworkHelper _networkHelper;
3334
private const int FlushTimeoutInMilli = 5000;
35+
private const string DefaultPSVersion = "3.0.0.0";
36+
private const string EventName = "cmdletInvocation";
3437

3538
/// <summary>
3639
/// The collection of telemetry clients.
@@ -58,6 +61,26 @@ public class MetricHelper
5861

5962
private AzurePSDataCollectionProfile _profile;
6063

64+
private static PSHost _host;
65+
66+
private static string _psVersion;
67+
68+
protected string PSVersion
69+
{
70+
get
71+
{
72+
if (_host != null)
73+
{
74+
_psVersion = _host.Version.ToString();
75+
}
76+
else
77+
{
78+
_psVersion = DefaultPSVersion;
79+
}
80+
return _psVersion;
81+
}
82+
}
83+
6184
public string HashMacAddress
6285
{
6386
get
@@ -171,7 +194,7 @@ private void LogUsageEvent(AzurePSQoSEvent qos)
171194
{
172195
var pageViewTelemetry = new PageViewTelemetry
173196
{
174-
Name = qos.CommandName ?? "empty",
197+
Name = EventName,
175198
Duration = qos.Duration,
176199
Timestamp = qos.StartTime
177200
};
@@ -217,13 +240,19 @@ private void LoadTelemetryClientContext(AzurePSQoSEvent qos, TelemetryContext cl
217240
}
218241
}
219242

243+
public void SetPSHost(PSHost host)
244+
{
245+
_host = host;
246+
}
247+
220248
private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string, string> eventProperties)
221249
{
222250
if (qos == null)
223251
{
224252
return;
225253
}
226254

255+
eventProperties.Add("Command", qos.CommandName);
227256
eventProperties.Add("IsSuccess", qos.IsSuccess.ToString());
228257
eventProperties.Add("ModuleName", qos.ModuleName);
229258
eventProperties.Add("ModuleVersion", qos.ModuleVersion);
@@ -234,6 +263,8 @@ private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string,
234263
eventProperties.Add("x-ms-client-request-id", qos.ClientRequestId);
235264
eventProperties.Add("UserAgent", AzurePowerShell.UserAgentValue.ToString());
236265
eventProperties.Add("HashMacAddress", HashMacAddress);
266+
eventProperties.Add("PowerShellVersion", PSVersion);
267+
eventProperties.Add("Version", AzurePowerShell.AssemblyVersion);
237268
if (qos.InputFromPipeline != null)
238269
{
239270
eventProperties.Add("InputFromPipeline", qos.InputFromPipeline.Value.ToString());

src/Common/Commands.Common/Utilities/GeneralUtilities.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,28 @@ public static void EnsureDefaultProfileDirectoryExists()
430430
}
431431
}
432432

433+
/// <summary>
434+
/// Checks if collection has more than one element
435+
/// </summary>
436+
/// <typeparam name="T">Type of the collection.</typeparam>
437+
/// <param name="collection">Collection.</param>
438+
/// <returns></returns>
439+
public static bool HasMoreThanOneElement<T>(ICollection<T> collection)
440+
{
441+
return collection != null && collection.Count > 1;
442+
}
443+
444+
/// <summary>
445+
/// Checks if collection has only one element
446+
/// </summary>
447+
/// <typeparam name="T">Type of the collection.</typeparam>
448+
/// <param name="collection">Collection.</param>
449+
/// <returns></returns>
450+
public static bool HasSingleElement<T>(ICollection<T> collection)
451+
{
452+
return collection != null && collection.Count == 1;
453+
}
454+
433455
/// <summary>
434456
/// Clear the current storage account from the context - guarantees that only one storage account will be active
435457
/// at a time.

src/ResourceManager/CognitiveServices/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Integrate with Cognitive Services Management SDK version 2.0.0.
22+
* Get-AzureRmCognitiveServicesAccount now can correctly support paging.
2123

2224
## Version 0.8.4
2325

src/ResourceManager/CognitiveServices/CognitiveServices.Test/Commands.Management.CognitiveServices.Test.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
<HintPath>..\..\..\packages\Microsoft.Azure.Gallery.2.6.2-preview\lib\net40\Microsoft.Azure.Gallery.dll</HintPath>
5050
</Reference>
5151
<Reference Include="Microsoft.Azure.Management.Authorization">
52-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
52+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.1.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
5353
</Reference>
54-
<Reference Include="Microsoft.Azure.Management.CognitiveServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
55-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.CognitiveServices.1.0.0\lib\net452\Microsoft.Azure.Management.CognitiveServices.dll</HintPath>
54+
<Reference Include="Microsoft.Azure.Management.CognitiveServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
55+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.CognitiveServices.2.0.0\lib\net452\Microsoft.Azure.Management.CognitiveServices.dll</HintPath>
5656
</Reference>
5757
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
5858
<SpecificVersion>False</SpecificVersion>
@@ -175,6 +175,9 @@
175175
<None Include="SessionRecords\CognitiveServices.Test.ScenarioTests.CognitiveServicesAccountTests\TestGetAccounts.json">
176176
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
177177
</None>
178+
<None Include="SessionRecords\CognitiveServices.Test.ScenarioTests.CognitiveServicesAccountTests\TestGetWithPaging.json">
179+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
180+
</None>
178181
<None Include="SessionRecords\CognitiveServices.Test.ScenarioTests.CognitiveServicesAccountTests\TestMinMaxAccountNames.json">
179182
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
180183
</None>

src/ResourceManager/CognitiveServices/CognitiveServices.Test/ScenarioTests/CognitiveServicesAccountTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,12 @@ public void TestMinMaxAccountNames()
118118
{
119119
TestController.NewInstance.RunPsTest("Test-MinMaxAccountName");
120120
}
121+
122+
[Fact]
123+
[Trait(Category.AcceptanceType, Category.CheckIn)]
124+
public void TestGetWithPaging()
125+
{
126+
TestController.NewInstance.RunPsTest("Test-GetWithPaging");
127+
}
121128
}
122129
}

src/ResourceManager/CognitiveServices/CognitiveServices.Test/ScenarioTests/CognitiveServicesAccountTests.ps1

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,3 +462,43 @@ function Test-MinMaxAccountName
462462
}
463463
}
464464

465+
<#
466+
.SYNOPSIS
467+
Test Test-GetWithPaging
468+
#>
469+
function Test-GetWithPaging
470+
{
471+
# Setup
472+
$rgname = Get-CognitiveServicesManagementTestResourceName
473+
$loc = 'West US'
474+
475+
try
476+
{
477+
$TotalCount = 100
478+
# Test
479+
New-AzureRmResourceGroup -Name $rgname -Location $loc
480+
481+
# 100 Face
482+
For($i = 0; $i -lt $TotalCount ; $i++)
483+
{
484+
New-AzureRmCognitiveServicesAccount -ResourceGroupName $rgname -Name "facepaging_wu_$i" -Type 'Face' -SkuName 'S0' -Location $loc -Force;
485+
}
486+
487+
# 100 Emotion
488+
For($i = 0; $i -lt $TotalCount ; $i++)
489+
{
490+
New-AzureRmCognitiveServicesAccount -ResourceGroupName $rgname -Name "emotionpaging_wu_$i" -Type 'Emotion' -SkuName 'S0' -Location $loc -Force;
491+
}
492+
493+
$accounts = Get-AzureRmCognitiveServicesAccount
494+
Assert-AreEqual 200 $accounts.Count
495+
496+
$accounts = Get-AzureRmCognitiveServicesAccount -ResourceGroupName $rgname
497+
Assert-AreEqual 200 $accounts.Count
498+
}
499+
finally
500+
{
501+
# Cleanup
502+
Clean-ResourceGroup $rgname
503+
}
504+
}

0 commit comments

Comments
 (0)