Skip to content

Commit 6ef56c4

Browse files
committed
Fix Get-AzureRmCognitiveServicesAccount to support paging
Integrate with Cognitive Services Management SDK version 2.0.0. Get-AzureRmCognitiveServicesAccount now can correctly support paging.
1 parent 3bd6314 commit 6ef56c4

File tree

7 files changed

+29
-11
lines changed

7 files changed

+29
-11
lines changed

src/ResourceManager/CognitiveServices/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
-->
2020
## Current Release
2121

22+
## Version 0.8.5
23+
* Integrate with Cognitive Services Management SDK version 2.0.0.
24+
* Get-AzureRmCognitiveServicesAccount now can correctly support paging.
25+
2226
## Version 0.8.4
2327

2428
## Version 0.8.3

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
<Reference Include="Microsoft.Azure.Management.Authorization">
5252
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.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>

src/ResourceManager/CognitiveServices/CognitiveServices.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
66
<package id="Microsoft.Azure.Gallery" version="2.6.2-preview" targetFramework="net45" />
77
<package id="Microsoft.Azure.Management.Authorization" version="1.0.0" targetFramework="net45" />
8-
<package id="Microsoft.Azure.Management.CognitiveServices" version="1.0.0" targetFramework="net452" />
8+
<package id="Microsoft.Azure.Management.CognitiveServices" version="2.0.0" targetFramework="net452" />
99
<package id="Microsoft.Azure.Management.Resources" version="2.20.0-preview" targetFramework="net45" />
1010
<package id="Microsoft.Azure.Management.Storage" version="3.0.0" targetFramework="net45" />
1111
<package id="Microsoft.Azure.Test.Framework" version="1.0.6179.26854-prerelease" targetFramework="net45" />

src/ResourceManager/CognitiveServices/Commands.Management.CognitiveServices/CognitiveServicesAccount/GetAzureCognitiveServicesAccount.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
using Microsoft.Azure.Commands.Management.CognitiveServices.Models;
1616
using Microsoft.Azure.Management.CognitiveServices;
1717
using Microsoft.Azure.Management.CognitiveServices.Models;
18-
using System.Globalization;
18+
using Microsoft.Rest.Azure;
19+
using System.Collections.Generic;
1920
using System.Management.Automation;
2021

2122
namespace Microsoft.Azure.Commands.Management.CognitiveServices
@@ -62,13 +63,13 @@ public override void ExecuteCmdlet()
6263
{
6364
if (string.IsNullOrEmpty(this.ResourceGroupName))
6465
{
65-
var cognitiveServicesAccounts = this.CognitiveServicesClient.Accounts.List();
66+
var cognitiveServicesAccounts = GetWithPaging(this.CognitiveServicesClient.Accounts.List());
6667

6768
WriteCognitiveServicesAccountList(cognitiveServicesAccounts);
6869
}
6970
else if (string.IsNullOrEmpty(this.Name))
7071
{
71-
var cognitiveServicesAccounts = this.CognitiveServicesClient.Accounts.ListByResourceGroup(this.ResourceGroupName);
72+
var cognitiveServicesAccounts = GetWithPaging(this.CognitiveServicesClient.Accounts.ListByResourceGroup(this.ResourceGroupName));
7273
if (cognitiveServicesAccounts == null)
7374
{
7475
WriteWarningWithTimestamp("Received empty accounts list");
@@ -85,5 +86,18 @@ public override void ExecuteCmdlet()
8586
}
8687
});
8788
}
89+
90+
private IEnumerable<CognitiveServicesAccount> GetWithPaging(IPage<CognitiveServicesAccount> firstPage)
91+
{
92+
var cognitiveServicesAccounts = new List<CognitiveServicesAccount>(firstPage);
93+
IPage<CognitiveServicesAccount> nextPage = null;
94+
for (var nextLink = firstPage.NextPageLink; !string.IsNullOrEmpty(nextLink); nextLink = nextPage.NextPageLink)
95+
{
96+
nextPage = this.CognitiveServicesClient.Accounts.ListNext(nextLink);
97+
cognitiveServicesAccounts.AddRange(nextPage);
98+
}
99+
100+
return cognitiveServicesAccounts;
101+
}
88102
}
89103
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
<Prefer32Bit>false</Prefer32Bit>
4949
</PropertyGroup>
5050
<ItemGroup>
51-
<Reference Include="Microsoft.Azure.Management.CognitiveServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
52-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.CognitiveServices.1.0.0\lib\net452\Microsoft.Azure.Management.CognitiveServices.dll</HintPath>
51+
<Reference Include="Microsoft.Azure.Management.CognitiveServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
52+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.CognitiveServices.2.0.0\lib\net452\Microsoft.Azure.Management.CognitiveServices.dll</HintPath>
5353
</Reference>
5454
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
5555
</ItemGroup>

src/ResourceManager/CognitiveServices/Commands.Management.CognitiveServices/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@
4646
// You can specify all the values or you can default the Build and Revision Numbers
4747
// by using the '*' as shown below:
4848

49-
[assembly: AssemblyVersion("0.8.4")]
50-
[assembly: AssemblyFileVersion("0.8.4")]
49+
[assembly: AssemblyVersion("0.8.5")]
50+
[assembly: AssemblyFileVersion("0.8.5")]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Azure.Management.CognitiveServices" version="1.0.0" targetFramework="net452" />
3+
<package id="Microsoft.Azure.Management.CognitiveServices" version="2.0.0" targetFramework="net452" />
44
</packages>

0 commit comments

Comments
 (0)