@@ -19,6 +19,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters
19
19
using Management . Internal . Resources ;
20
20
using Management . Internal . Resources . Models ;
21
21
using Properties ;
22
+ using Rest . Azure ;
22
23
using System ;
23
24
using System . Collections . Concurrent ;
24
25
using System . Collections . Generic ;
@@ -43,7 +44,7 @@ protected static IList<String> ResourceGroupNames
43
44
var contextHash = HashContext ( context ) ;
44
45
if ( ! _resourceGroupNamesDictionary . ContainsKey ( contextHash ) )
45
46
{
46
- _resourceGroupNamesDictionary [ contextHash ] = new List < string > ( ) ;
47
+ var tempResourceGroupList = new List < string > ( ) ;
47
48
try
48
49
{
49
50
var instance = AzureSession . Instance ;
@@ -56,20 +57,11 @@ protected static IList<String> ResourceGroupNames
56
57
var resourceGroups = client . ResourceGroups . ListAsync ( ) ;
57
58
if ( resourceGroups . Wait ( TimeSpan . FromSeconds ( 5 ) ) )
58
59
{
60
+ tempResourceGroupList = CreateResourceGroupList ( resourceGroups . Result ) ;
59
61
if ( resourceGroups . Result != null )
60
62
{
61
- var resourceGroupList = resourceGroups . Result ;
62
- foreach ( ResourceGroup resourceGroup in resourceGroupList )
63
- {
64
- _resourceGroupNamesDictionary [ contextHash ] . Add ( resourceGroup . Name ) ;
65
- }
63
+ _resourceGroupNamesDictionary [ contextHash ] = tempResourceGroupList ;
66
64
}
67
- #if DEBUG
68
- else
69
- {
70
- throw new Exception ( "Result from client.ResourceGroups is null" ) ;
71
- }
72
- #endif
73
65
}
74
66
#if DEBUG
75
67
else
@@ -85,9 +77,14 @@ protected static IList<String> ResourceGroupNames
85
77
throw ex ;
86
78
#endif
87
79
}
80
+
81
+ return tempResourceGroupList ;
88
82
}
89
83
90
- return _resourceGroupNamesDictionary [ contextHash ] ;
84
+ else
85
+ {
86
+ return _resourceGroupNamesDictionary [ contextHash ] ;
87
+ }
91
88
}
92
89
}
93
90
}
@@ -138,5 +135,24 @@ private static int HashContext(IAzureContext context)
138
135
{
139
136
return ( context . Account . Id + context . Environment . Name + context . Subscription . Id + context . Tenant . Id ) . GetHashCode ( ) ;
140
137
}
138
+
139
+ public static List < string > CreateResourceGroupList ( IPage < ResourceGroup > result )
140
+ {
141
+ var tempResourceGroupList = new List < string > ( ) ;
142
+ if ( result != null )
143
+ {
144
+ foreach ( ResourceGroup resourceGroup in result )
145
+ {
146
+ tempResourceGroupList . Add ( resourceGroup . Name ) ;
147
+ }
148
+ }
149
+ #if DEBUG
150
+ else
151
+ {
152
+ throw new Exception ( "Result from client.ResourceGroups is null" ) ;
153
+ }
154
+ #endif
155
+ return tempResourceGroupList ;
156
+ }
141
157
}
142
158
}
0 commit comments