Skip to content

Commit 7c3fe40

Browse files
Refactor link next page'
1 parent 9f5b5af commit 7c3fe40

26 files changed

+73
-320
lines changed

src/ResourceManager/Network/Commands.Network/ApplicationGateway/ApplicationGatewayBaseCmdlet.cs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,6 @@ public PSApplicationGateway ToPsApplicationGateway(ApplicationGateway appGw)
7373
psAppGw.Tag = TagsConversionHelper.CreateTagHashtable(appGw.Tags);
7474

7575
return psAppGw;
76-
}
77-
78-
public List<ApplicationGateway> GetAllResourcesByPollingNextLink(IPage<ApplicationGateway> resourcePage)
79-
{
80-
var resourceList = new List<ApplicationGateway>();
81-
82-
var nextPageLink = this.AddResourceToListAndReturnNextPageLink(resourcePage, resourceList);
83-
84-
while (!string.IsNullOrEmpty(nextPageLink))
85-
{
86-
var nextVnetPage = this.ApplicationGatewayClient.ListNext(nextPageLink);
87-
nextPageLink = this.AddResourceToListAndReturnNextPageLink(nextVnetPage, resourceList);
88-
}
89-
90-
return resourceList;
91-
}
92-
93-
private string AddResourceToListAndReturnNextPageLink(IPage<ApplicationGateway> resourcePage, List<ApplicationGateway> resourceList)
94-
{
95-
foreach (var resource in resourcePage)
96-
{
97-
resourceList.Add(resource);
98-
}
99-
100-
return resourcePage.NextPageLink;
101-
}
76+
}
10277
}
10378
}

src/ResourceManager/Network/Commands.Network/ApplicationGateway/GetAzureApplicationGatewayCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public override void ExecuteCmdlet()
6161
}
6262

6363
// Get all resources by polling on next page link
64-
var appGwResponseList = this.GetAllResourcesByPollingNextLink(appGatewayPage);
64+
var appGwResponseList = ListNextLink<ApplicationGateway>.GetAllResourcesByPollingNextLink(appGatewayPage, this.ApplicationGatewayClient.ListNext);
6565

6666
var psApplicationGateways = new List<PSApplicationGateway>();
6767

src/ResourceManager/Network/Commands.Network/Commands.Network.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@
244244
<Compile Include="ApplicationGateway\UrlPathMap\NewAzureApplicationGatewayUrlPathMapConfigCommand.cs" />
245245
<Compile Include="ApplicationGateway\UrlPathMap\RemoveAzureApplicationGatewayUrlPathMapConfigCommand.cs" />
246246
<Compile Include="ApplicationGateway\UrlPathMap\SetAzureApplicationGatewayUrlPathMapConfigCommand.cs" />
247+
<Compile Include="Common\ListNextLink.cs" />
247248
<Compile Include="Common\NetworkBaseCmdlet.cs" />
248249
<Compile Include="Common\NetworkClient.cs" />
249250
<Compile Include="Common\NetworkCloudException.cs" />
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using Microsoft.Rest.Azure;
18+
19+
namespace Microsoft.Azure.Commands.Network
20+
{
21+
public static class ListNextLink<T>
22+
{
23+
public static List<T> GetAllResourcesByPollingNextLink(IPage<T> resourcePage, Func<string, IPage<T>> getNextLink)
24+
{
25+
var resourceList = new List<T>();
26+
27+
var nextPageLink = AddResourceToListAndReturnNextPageLink(resourcePage, resourceList);
28+
29+
while (!string.IsNullOrEmpty(nextPageLink))
30+
{
31+
var nextVnetPage = getNextLink(nextPageLink);
32+
nextPageLink = AddResourceToListAndReturnNextPageLink(nextVnetPage, resourceList);
33+
}
34+
35+
return resourceList;
36+
}
37+
38+
private static string AddResourceToListAndReturnNextPageLink(IPage<T> resourcePage, List<T> resourceList)
39+
{
40+
foreach (var resource in resourcePage)
41+
{
42+
resourceList.Add(resource);
43+
}
44+
45+
return resourcePage.NextPageLink;
46+
}
47+
}
48+
}

src/ResourceManager/Network/Commands.Network/ExpressRouteCircuit/ExpressRouteCircuitBaseCmdlet.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,5 @@ public PSExpressRouteCircuit ToPsExpressRouteCircuit(Management.Network.Models.E
7575

7676
return psCircuit;
7777
}
78-
79-
public List<ExpressRouteCircuit> GetAllResourcesByPollingNextLink(IPage<ExpressRouteCircuit> resourcePage)
80-
{
81-
var resourceList = new List<ExpressRouteCircuit>();
82-
83-
var nextPageLink = this.AddResourceToListAndReturnNextPageLink(resourcePage, resourceList);
84-
85-
while (!string.IsNullOrEmpty(nextPageLink))
86-
{
87-
var nextVnetPage = this.ExpressRouteCircuitClient.ListNext(nextPageLink);
88-
nextPageLink = this.AddResourceToListAndReturnNextPageLink(nextVnetPage, resourceList);
89-
}
90-
91-
return resourceList;
92-
}
93-
94-
private string AddResourceToListAndReturnNextPageLink(IPage<ExpressRouteCircuit> resourcePage, List<ExpressRouteCircuit> resourceList)
95-
{
96-
foreach (var resource in resourcePage)
97-
{
98-
resourceList.Add(resource);
99-
}
100-
101-
return resourcePage.NextPageLink;
102-
}
10378
}
10479
}

src/ResourceManager/Network/Commands.Network/ExpressRouteCircuit/GetAzureExpressRouteCircuitCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public override void Execute()
6161
}
6262

6363
// Get all resources by polling on next page link
64-
var circuitList = this.GetAllResourcesByPollingNextLink(circuitPage);
64+
var circuitList = ListNextLink<ExpressRouteCircuit>.GetAllResourcesByPollingNextLink(circuitPage, this.ExpressRouteCircuitClient.ListNext);
6565

6666
var psCircuits = new List<PSExpressRouteCircuit>();
6767
foreach (var ExpressRouteCircuit in circuitList)

src/ResourceManager/Network/Commands.Network/LoadBalancer/GetAzureLoadBalancerCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public override void Execute()
8282
}
8383

8484
// Get all resources by polling on next page link
85-
var lbList = this.GetAllResourcesByPollingNextLink(lbPage);
85+
var lbList = ListNextLink<LoadBalancer>.GetAllResourcesByPollingNextLink(lbPage, this.LoadBalancerClient.ListNext);
8686

8787
var psLoadBalancers = new List<PSLoadBalancer>();
8888

src/ResourceManager/Network/Commands.Network/LoadBalancer/LoadBalancerBaseCmdlet.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,5 @@ public PSLoadBalancer ToPsLoadBalancer(LoadBalancer lb)
7474

7575
return psLb;
7676
}
77-
78-
public List<LoadBalancer> GetAllResourcesByPollingNextLink(IPage<LoadBalancer> resourcePage)
79-
{
80-
var resourceList = new List<LoadBalancer>();
81-
82-
var nextPageLink = this.AddResourceToListAndReturnNextPageLink(resourcePage, resourceList);
83-
84-
while (!string.IsNullOrEmpty(nextPageLink))
85-
{
86-
var nextVnetPage = this.LoadBalancerClient.ListNext(nextPageLink);
87-
nextPageLink = this.AddResourceToListAndReturnNextPageLink(nextVnetPage, resourceList);
88-
}
89-
90-
return resourceList;
91-
}
92-
93-
private string AddResourceToListAndReturnNextPageLink(IPage<LoadBalancer> resourcePage, List<LoadBalancer> resourceList)
94-
{
95-
foreach (var resource in resourcePage)
96-
{
97-
resourceList.Add(resource);
98-
}
99-
100-
return resourcePage.NextPageLink;
101-
}
10277
}
10378
}

src/ResourceManager/Network/Commands.Network/LocalNetworkGateway/GetAzureLocalNetworkGatewayCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using Microsoft.Azure.Commands.Network.Models;
1616
using Microsoft.Azure.Management.Network;
17+
using Microsoft.Azure.Management.Network.Models;
1718
using System.Collections.Generic;
1819
using System.Management.Automation;
1920

@@ -51,7 +52,7 @@ public override void Execute()
5152
var localnetGatewayPage = this.LocalNetworkGatewayClient.List(this.ResourceGroupName);
5253

5354
// Get all resources by polling on next page link
54-
var localnetGatewayList = this.GetAllResourcesByPollingNextLink(localnetGatewayPage);
55+
var localnetGatewayList = ListNextLink<LocalNetworkGateway>.GetAllResourcesByPollingNextLink(localnetGatewayPage, this.LocalNetworkGatewayClient.ListNext);
5556

5657
var psLocalnetGateways = new List<PSLocalNetworkGateway>();
5758
foreach (var localNetworkGateway in localnetGatewayList)

src/ResourceManager/Network/Commands.Network/LocalNetworkGateway/LocalNetworkGatewayBaseCmdlet.cs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,6 @@ public PSLocalNetworkGateway ToPsLocalNetworkGateway(LocalNetworkGateway localne
7070
psLocalNetworkGateway.Tag = TagsConversionHelper.CreateTagHashtable(localnetGateway.Tags);
7171

7272
return psLocalNetworkGateway;
73-
}
74-
75-
public List<LocalNetworkGateway> GetAllResourcesByPollingNextLink(IPage<LocalNetworkGateway> resourcePage)
76-
{
77-
var resourceList = new List<LocalNetworkGateway>();
78-
79-
var nextPageLink = this.AddResourceToListAndReturnNextPageLink(resourcePage, resourceList);
80-
81-
while (!string.IsNullOrEmpty(nextPageLink))
82-
{
83-
var nextVnetPage = this.LocalNetworkGatewayClient.ListNext(nextPageLink);
84-
nextPageLink = this.AddResourceToListAndReturnNextPageLink(nextVnetPage, resourceList);
85-
}
86-
87-
return resourceList;
88-
}
89-
90-
private string AddResourceToListAndReturnNextPageLink(IPage<LocalNetworkGateway> resourcePage, List<LocalNetworkGateway> resourceList)
91-
{
92-
foreach (var resource in resourcePage)
93-
{
94-
resourceList.Add(resource);
95-
}
96-
97-
return resourcePage.NextPageLink;
98-
}
73+
}
9974
}
10075
}

src/ResourceManager/Network/Commands.Network/NetworkInterface/GetAzureNetworkInterfaceCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
using Microsoft.Azure.Commands.Network.Models;
1818
using Microsoft.Azure.Management.Network;
19+
using Microsoft.Azure.Management.Network.Models;
1920
using System.Collections.Generic;
2021
using System.Management.Automation;
2122
using MNM = Microsoft.Azure.Management.Network.Models;
@@ -165,7 +166,7 @@ public override void Execute()
165166
}
166167

167168
// Get all resources by polling on next page link
168-
var nicList = this.GetAllResourcesByPollingNextLink(nicPage);
169+
var nicList = ListNextLink<NetworkInterface>.GetAllResourcesByPollingNextLink(nicPage, this.NetworkInterfaceClient.ListNext);
169170

170171
var psNetworkInterfaces = new List<PSNetworkInterface>();
171172

src/ResourceManager/Network/Commands.Network/NetworkInterface/NetworkInterfaceBaseCmdlet.cs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,31 +92,6 @@ public PSNetworkInterface ToPsNetworkInterface(NetworkInterface nic)
9292
}
9393

9494
return psNic;
95-
}
96-
97-
public List<NetworkInterface> GetAllResourcesByPollingNextLink(IPage<NetworkInterface> resourcePage)
98-
{
99-
var resourceList = new List<NetworkInterface>();
100-
101-
var nextPageLink = this.AddResourceToListAndReturnNextPageLink(resourcePage, resourceList);
102-
103-
while (!string.IsNullOrEmpty(nextPageLink))
104-
{
105-
var nextVnetPage = this.NetworkInterfaceClient.ListNext(nextPageLink);
106-
nextPageLink = this.AddResourceToListAndReturnNextPageLink(nextVnetPage, resourceList);
107-
}
108-
109-
return resourceList;
110-
}
111-
112-
private string AddResourceToListAndReturnNextPageLink(IPage<NetworkInterface> resourcePage, List<NetworkInterface> resourceList)
113-
{
114-
foreach (var resource in resourcePage)
115-
{
116-
resourceList.Add(resource);
117-
}
118-
119-
return resourcePage.NextPageLink;
120-
}
95+
}
12196
}
12297
}

src/ResourceManager/Network/Commands.Network/NetworkSecurityGroup/GetAzureNetworkSecurityGroupCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public override void Execute()
8181
}
8282

8383
// Get all resources by polling on next page link
84-
var nsgList = this.GetAllResourcesByPollingNextLink(nsgPage);
84+
var nsgList = ListNextLink<NetworkSecurityGroup>.GetAllResourcesByPollingNextLink(nsgPage, this.NetworkSecurityGroupClient.ListNext);
8585

8686
var psNsgs = new List<PSNetworkSecurityGroup>();
8787

src/ResourceManager/Network/Commands.Network/NetworkSecurityGroup/NetworkSecurityGroupBaseCmdlet.cs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,6 @@ public PSNetworkSecurityGroup ToPsNetworkSecurityGroup(NetworkSecurityGroup nsg)
7373
psNsg.Tag = TagsConversionHelper.CreateTagHashtable(nsg.Tags);
7474

7575
return psNsg;
76-
}
77-
78-
public List<NetworkSecurityGroup> GetAllResourcesByPollingNextLink(IPage<NetworkSecurityGroup> resourcePage)
79-
{
80-
var resourceList = new List<NetworkSecurityGroup>();
81-
82-
var nextPageLink = this.AddResourceToListAndReturnNextPageLink(resourcePage, resourceList);
83-
84-
while (!string.IsNullOrEmpty(nextPageLink))
85-
{
86-
var nextVnetPage = this.NetworkSecurityGroupClient.ListNext(nextPageLink);
87-
nextPageLink = this.AddResourceToListAndReturnNextPageLink(nextVnetPage, resourceList);
88-
}
89-
90-
return resourceList;
91-
}
92-
93-
private string AddResourceToListAndReturnNextPageLink(IPage<NetworkSecurityGroup> resourcePage, List<NetworkSecurityGroup> resourceList)
94-
{
95-
foreach (var resource in resourcePage)
96-
{
97-
resourceList.Add(resource);
98-
}
99-
100-
return resourcePage.NextPageLink;
101-
}
76+
}
10277
}
10378
}

src/ResourceManager/Network/Commands.Network/PublicIpAddress/GetAzurePublicIpAddressCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public override void Execute()
8181
}
8282

8383
// Get all resources by polling on next page link
84-
var publicIPList = this.GetAllResourcesByPollingNextLink(publicipPage);
84+
var publicIPList = ListNextLink<PublicIPAddress>.GetAllResourcesByPollingNextLink(publicipPage, this.PublicIpAddressClient.ListNext);
8585

8686
var psPublicIps = new List<PSPublicIpAddress>();
8787

src/ResourceManager/Network/Commands.Network/PublicIpAddress/PublicIpAddressBaseCmdlet.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,30 +76,5 @@ public PSPublicIpAddress ToPsPublicIpAddress(PublicIPAddress publicIp)
7676
}
7777
return psPublicIpAddress;
7878
}
79-
80-
public List<PublicIPAddress> GetAllResourcesByPollingNextLink(IPage<PublicIPAddress> resourcePage)
81-
{
82-
var resourceList = new List<PublicIPAddress>();
83-
84-
var nextPageLink = this.AddResourceToListAndReturnNextPageLink(resourcePage, resourceList);
85-
86-
while (!string.IsNullOrEmpty(nextPageLink))
87-
{
88-
var nextVnetPage = this.PublicIpAddressClient.ListNext(nextPageLink);
89-
nextPageLink = this.AddResourceToListAndReturnNextPageLink(nextVnetPage, resourceList);
90-
}
91-
92-
return resourceList;
93-
}
94-
95-
private string AddResourceToListAndReturnNextPageLink(IPage<PublicIPAddress> resourcePage, List<PublicIPAddress> resourceList)
96-
{
97-
foreach (var resource in resourcePage)
98-
{
99-
resourceList.Add(resource);
100-
}
101-
102-
return resourcePage.NextPageLink;
103-
}
10479
}
10580
}

src/ResourceManager/Network/Commands.Network/RouteFilter/GetAzureRouteFilterCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public override void Execute()
8282
}
8383

8484
// Get all resources by polling on next page link
85-
var routeFilterList = this.GetAllResourcesByPollingNextLink(routeFilterPage);
85+
var routeFilterList = ListNextLink<RouteFilter>.GetAllResourcesByPollingNextLink(routeFilterPage, this.RouteFilterClient.ListNext);
8686

8787
var psRouteFilters = new List<PSRouteFilter>();
8888

0 commit comments

Comments
 (0)