Skip to content

Commit 0ec01db

Browse files
committed
Updated to use the Azure RemoteApp v1.0.7
Included Amarpreet's changes for the new features
1 parent 07e643c commit 0ec01db

File tree

4 files changed

+371
-86
lines changed

4 files changed

+371
-86
lines changed

src/ServiceManagement/RemoteApp/Commands.RemoteApp/Collection/NewAzureRemoteAppCollection.cs

Lines changed: 150 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Management.RemoteApp;
16-
using Microsoft.Azure.Management.RemoteApp.Models;
17-
using System.Management.Automation;
18-
using System.Net;
19-
2015
namespace Microsoft.Azure.Management.RemoteApp.Cmdlets
2116
{
17+
using Microsoft.Azure.Management.RemoteApp;
18+
using Microsoft.Azure.Management.RemoteApp.Models;
19+
using Microsoft.WindowsAzure.Management.Network;
20+
using Microsoft.WindowsAzure.Management.Network.Models;
21+
using System;
22+
using System.Collections.Generic;
23+
using System.Management.Automation;
24+
using System.Net;
25+
using System.Threading.Tasks;
26+
2227
[Cmdlet(VerbsCommon.New, "AzureRemoteAppCollection", DefaultParameterSetName = NoDomain), OutputType(typeof(TrackingResult))]
28+
2329
public class NewAzureRemoteAppCollection : CmdletWithCollection
2430
{
2531
private const string DomainJoined = "DomainJoined";
@@ -55,6 +61,22 @@ public class NewAzureRemoteAppCollection : CmdletWithCollection
5561
)]
5662
public string VNetName { get; set; }
5763

64+
[Parameter(Mandatory = false,
65+
ValueFromPipelineByPropertyName = true,
66+
ParameterSetName = DomainJoined,
67+
HelpMessage = "For Azure VNets only, a comma-separated list of DNS servers for the VNet."
68+
)]
69+
[ValidateNotNullOrEmpty]
70+
public string DnsServers { get; set; }
71+
72+
[Parameter(Mandatory = false,
73+
ValueFromPipelineByPropertyName = true,
74+
ParameterSetName = DomainJoined,
75+
HelpMessage = "For Azure VNets only, the name of the subnet."
76+
)]
77+
[ValidateNotNullOrEmpty]
78+
public string SubnetName { get; set; }
79+
5880
[Parameter(Mandatory = true,
5981
Position = 4,
6082
ValueFromPipelineByPropertyName = true,
@@ -96,6 +118,10 @@ public class NewAzureRemoteAppCollection : CmdletWithCollection
96118

97119
public override void ExecuteCmdlet()
98120
{
121+
// register the subscription for this service if it has not been before
122+
// sebsequent call to register is redundent
123+
RegisterSubscriptionWithRdfeForRemoteApp();
124+
99125
NetworkCredential creds = null;
100126
CollectionCreationDetails details = new CollectionCreationDetails()
101127
{
@@ -112,39 +138,139 @@ public override void ExecuteCmdlet()
112138
switch (ParameterSetName)
113139
{
114140
case DomainJoined:
141+
{
142+
creds = Credential.GetNetworkCredential();
143+
details.VnetName = VNetName;
144+
145+
if (SubnetName != null && DnsServers != null)
115146
{
116-
creds = Credential.GetNetworkCredential();
117-
details.VnetName = VNetName;
118-
119-
details.AdInfo = new ActiveDirectoryConfig()
120-
{
121-
DomainName = Domain,
122-
OrganizationalUnit = OrganizationalUnit,
123-
UserName = creds.UserName,
124-
Password = creds.Password,
125-
};
126-
break;
147+
details.SubnetName = SubnetName;
148+
details.DnsServers = DnsServers.Split(new char[] { ',' });
149+
150+
ValidateCustomerVNetParams(details.VnetName, details.SubnetName, details.DnsServers);
127151
}
152+
153+
details.AdInfo = new ActiveDirectoryConfig()
154+
{
155+
DomainName = Domain,
156+
OrganizationalUnit = OrganizationalUnit,
157+
UserName = creds.UserName,
158+
Password = creds.Password,
159+
};
160+
break;
161+
}
128162
case NoDomain:
163+
{
164+
details.Region = Region;
165+
break;
166+
}
167+
}
168+
169+
response = CallClient(() => Client.Collections.Create(false, details), Client.Collections);
170+
171+
if (response != null)
172+
{
173+
TrackingResult trackingId = new TrackingResult(response);
174+
WriteObject(trackingId);
175+
}
176+
177+
}
178+
179+
private bool ValidateCustomerVNetParams(string name, string subnet, IEnumerable<string> dns)
180+
{
181+
NetworkListResponse.VirtualNetworkSite azureVNet = GetAzureVNet(name);
182+
bool isValidSubnetName = false;
183+
bool isValidDnsServers = true;
184+
185+
if (azureVNet == null)
186+
{
187+
ErrorRecord er = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
188+
String.Format("Invalid Argument VNetName: {0} not found", name),
189+
String.Empty,
190+
Client.Collections,
191+
ErrorCategory.InvalidArgument
192+
);
193+
194+
ThrowTerminatingError(er);
195+
}
196+
197+
foreach (NetworkListResponse.Subnet azureSubnet in azureVNet.Subnets)
198+
{
199+
if (string.Compare(azureSubnet.Name, subnet, true) == 0)
200+
{
201+
isValidSubnetName = true;
202+
break;
203+
}
204+
}
205+
206+
if (!isValidSubnetName)
207+
{
208+
ErrorRecord er = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
209+
String.Format("Invalid Argument SubnetName: {0} not found", subnet),
210+
String.Empty,
211+
Client.Collections,
212+
ErrorCategory.InvalidArgument
213+
);
214+
215+
ThrowTerminatingError(er);
216+
}
217+
218+
foreach (string dnsServerName in dns)
219+
{
220+
bool isValidDnsServer = false;
221+
222+
foreach (var dnsServer in azureVNet.DnsServers)
223+
{
224+
if (string.Compare(dnsServerName, dnsServer.Name, true) == 0)
129225
{
130-
details.Region = Region;
226+
isValidDnsServer = true;
131227
break;
132228
}
229+
}
230+
231+
if (!isValidDnsServer)
232+
{
233+
isValidDnsServers = false;
234+
break;
235+
}
133236
}
134237

135-
// register the subscription for this service if it has not been before
136-
// sebsequent call to register is redundent
238+
if (!isValidDnsServers)
239+
{
240+
ErrorRecord er = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
241+
String.Format("Invalid Argument DnsServers: {0} not found", dns),
242+
String.Empty,
243+
Client.Collections,
244+
ErrorCategory.InvalidArgument
245+
);
137246

138-
RegisterSubscriptionWithRdfeForRemoteApp();
247+
ThrowTerminatingError(er);
248+
}
139249

140-
response = CallClient(() => Client.Collections.Create(false, details), Client.Collections);
250+
return true;
251+
}
141252

142-
if (response != null)
253+
private NetworkListResponse.VirtualNetworkSite GetAzureVNet(string name)
254+
{
255+
NetworkManagementClient networkClient = new NetworkManagementClient(this.Client.Credentials, this.Client.BaseUri);
256+
Task<NetworkListResponse> listNetworkTask = networkClient.Networks.ListAsync();
257+
258+
listNetworkTask.Wait();
259+
260+
if (listNetworkTask.Status == TaskStatus.RanToCompletion)
143261
{
144-
TrackingResult trackingId = new TrackingResult(response);
145-
WriteObject(trackingId);
262+
NetworkListResponse networkList = listNetworkTask.Result;
263+
264+
foreach (NetworkListResponse.VirtualNetworkSite network in networkList.VirtualNetworkSites)
265+
{
266+
if (network.Name == name)
267+
{
268+
return network;
269+
}
270+
}
146271
}
147272

273+
return null;
148274
}
149275
}
150276
}

src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.csproj

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<StartupObject />
4141
</PropertyGroup>
4242
<ItemGroup>
43+
<None Include="app.config" />
4344
<None Include="packages.config">
4445
<SubType>Designer</SubType>
4546
</None>
@@ -73,6 +74,18 @@
7374
<SpecificVersion>False</SpecificVersion>
7475
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.14.1-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
7576
</Reference>
77+
<Reference Include="Microsoft.Data.Edm, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
78+
<SpecificVersion>False</SpecificVersion>
79+
<HintPath>..\..\..\packages\Microsoft.Data.Edm.5.6.2\lib\net40\Microsoft.Data.Edm.dll</HintPath>
80+
</Reference>
81+
<Reference Include="Microsoft.Data.OData, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
82+
<SpecificVersion>False</SpecificVersion>
83+
<HintPath>..\..\..\packages\Microsoft.Data.OData.5.6.2\lib\net40\Microsoft.Data.OData.dll</HintPath>
84+
</Reference>
85+
<Reference Include="Microsoft.Data.Services.Client, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
86+
<SpecificVersion>False</SpecificVersion>
87+
<HintPath>..\..\..\packages\Microsoft.Data.Services.Client.5.6.2\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
88+
</Reference>
7689
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory">
7790
<SpecificVersion>False</SpecificVersion>
7891
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.0.110281957-alpha\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
@@ -89,10 +102,27 @@
89102
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop">
90103
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
91104
</Reference>
105+
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
106+
<SpecificVersion>False</SpecificVersion>
107+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.1.8.0.0\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll</HintPath>
108+
</Reference>
92109
<Reference Include="Microsoft.WindowsAzure.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
93110
<SpecificVersion>False</SpecificVersion>
94111
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.0\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
95112
</Reference>
113+
<Reference Include="Microsoft.WindowsAzure.Management.Compute">
114+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Compute.9.1.0\lib\net40\Microsoft.WindowsAzure.Management.Compute.dll</HintPath>
115+
</Reference>
116+
<Reference Include="Microsoft.WindowsAzure.Management.Network">
117+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Network.6.1.2\lib\net40\Microsoft.WindowsAzure.Management.Network.dll</HintPath>
118+
</Reference>
119+
<Reference Include="Microsoft.WindowsAzure.Management.Storage">
120+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Storage.5.1.0\lib\net40\Microsoft.WindowsAzure.Management.Storage.dll</HintPath>
121+
</Reference>
122+
<Reference Include="Microsoft.WindowsAzure.Storage, Version=4.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
123+
<SpecificVersion>False</SpecificVersion>
124+
<HintPath>..\..\..\packages\WindowsAzure.Storage.4.3.0\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
125+
</Reference>
96126
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
97127
<SpecificVersion>False</SpecificVersion>
98128
<HintPath>..\..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
@@ -115,6 +145,10 @@
115145
</Reference>
116146
<Reference Include="System.Net.Http.WebRequest" />
117147
<Reference Include="System.Runtime.Serialization" />
148+
<Reference Include="System.Spatial, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
149+
<SpecificVersion>False</SpecificVersion>
150+
<HintPath>..\..\..\packages\System.Spatial.5.6.2\lib\net40\System.Spatial.dll</HintPath>
151+
</Reference>
118152
<Reference Include="System.Web.Extensions" />
119153
<Reference Include="System.Xml.Linq" />
120154
<Reference Include="System.Data.DataSetExtensions" />

0 commit comments

Comments
 (0)