Skip to content

Commit 2e23bad

Browse files
committed
Merge pull request #297 from yadavbdev/dev
RemoteApp cmdlet bug fixes
2 parents 7e05149 + 85f0d14 commit 2e23bad

File tree

10 files changed

+382
-123
lines changed

10 files changed

+382
-123
lines changed

src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Collection/RemoteAppCollection.cs

Lines changed: 290 additions & 31 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
</Reference>
9696
<Reference Include="Microsoft.Azure.Management.RemoteApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
9797
<SpecificVersion>False</SpecificVersion>
98-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RemoteApp.1.0.8\lib\net40\Microsoft.Azure.Management.RemoteApp.dll</HintPath>
98+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RemoteApp.1.0.9\lib\net40\Microsoft.Azure.Management.RemoteApp.dll</HintPath>
9999
</Reference>
100100
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
101101
<SpecificVersion>False</SpecificVersion>

src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/CollectionObjects.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,14 @@ public static int SetUpDefaultRemoteAppCollectionSet(Mock<IRemoteAppManagementCl
188188
new TrackingResult(response)
189189
};
190190

191-
ISetup<IRemoteAppManagementClient, Task<OperationResultWithTrackingId>> setup = clientMock.Setup(c => c.Collections.SetAsync(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<CollectionCreationDetails>(), It.IsAny<CancellationToken>()));
191+
ISetup<IRemoteAppManagementClient, Task<OperationResultWithTrackingId>> setup =
192+
clientMock.Setup(
193+
c => c.Collections.SetAsync(
194+
collectionName,
195+
It.IsAny<bool>(),
196+
It.IsAny<bool>(),
197+
It.IsAny<CollectionUpdateDetails>(),
198+
It.IsAny<CancellationToken>()));
192199
setup.Returns(Task.Factory.StartNew(() => response));
193200

194201
mockCollectionList = collectionList;

src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/RemoteAppClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected RemoteAppClientTest()
8484
StatusCode = System.Net.HttpStatusCode.OK
8585
};
8686
mgmtClient = new Mock<WindowsAzure.Management.ManagementClient>();
87-
setup = mgmtClient.Setup(c => c.Subscriptions.RegisterResourceAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()));
87+
setup = mgmtClient.Setup(c => c.Subscriptions.RegisterResourceAsync("remoteapp", It.IsAny<CancellationToken>()));
8888
setup.Returns(Task.Factory.StartNew(() => response));
8989

9090
RemoteAppCmdlet = new T()

src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<package id="Hyak.Common" version="1.0.2" targetFramework="net45" />
44
<package id="Microsoft.Azure.Common" version="2.0.4" targetFramework="net45" />
55
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
6-
<package id="Microsoft.Azure.Management.RemoteApp" version="1.0.8" targetFramework="net45" />
6+
<package id="Microsoft.Azure.Management.RemoteApp" version="1.0.9" targetFramework="net45" />
77
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
88
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
99
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />

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

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Commands.RemoteApp;
16-
using Microsoft.Azure.Management.RemoteApp;
1716
using Microsoft.Azure.Management.RemoteApp.Models;
1817
using System;
1918
using System.Management.Automation;
2019
using System.Net;
2120

2221
namespace Microsoft.Azure.Management.RemoteApp.Cmdlets
2322
{
24-
[Cmdlet(VerbsCommon.Set, "AzureRemoteAppCollection"), OutputType(typeof(TrackingResult))]
23+
[Cmdlet(VerbsCommon.Set, "AzureRemoteAppCollection", DefaultParameterSetName = DescriptionOnly), OutputType(typeof(TrackingResult))]
2524
public class SetAzureRemoteAppCollection : RdsCmdlet
2625
{
2726
private const string DomainJoined = "DomainJoined";
28-
private const string NoDomain = "NoDomain";
27+
private const string RdpPropertyOnly = "RdpPropertyOnly";
28+
private const string DescriptionOnly = "DescriptionOnly";
29+
private const string PlanOnly = "PlanOnly";
2930

3031
[Parameter(Mandatory = true,
3132
Position = 0,
@@ -35,37 +36,38 @@ public class SetAzureRemoteAppCollection : RdsCmdlet
3536
[Alias("Name")]
3637
public string CollectionName { get; set; }
3738

38-
[Parameter(Mandatory = false,
39-
Position = 1,
39+
[Parameter(Mandatory = true,
4040
ValueFromPipelineByPropertyName = true,
41+
ParameterSetName = PlanOnly,
4142
HelpMessage = "Plan to use for this collection. Use Get-AzureRemoteAppPlan to see the plans available.")]
4243
[ValidateNotNullOrEmpty]
4344
public string Plan { get; set; }
4445

45-
[Parameter(Mandatory = false,
46-
Position = 2,
46+
[Parameter(Mandatory = true,
4747
ValueFromPipelineByPropertyName = true,
4848
ParameterSetName = DomainJoined,
4949
HelpMessage = "Credentials of a user that has permission to add computers to the domain.")]
5050
[ValidateNotNull]
5151
public PSCredential Credential { get; set; }
5252

53-
[Parameter(Mandatory = false,
53+
[Parameter(Mandatory = true,
5454
ValueFromPipelineByPropertyName = true,
55+
ParameterSetName = DescriptionOnly,
5556
HelpMessage = "Description of what this collection is used for.")]
56-
[ValidateNotNullOrEmpty]
57+
[ValidateNotNull]
5758
public string Description { get; set; }
5859

59-
[Parameter(Mandatory = false,
60+
[Parameter(Mandatory = true,
6061
ValueFromPipelineByPropertyName = true,
62+
ParameterSetName = RdpPropertyOnly,
6163
HelpMessage = "Used to allow RDP redirection.")]
62-
[ValidateNotNullOrEmpty]
64+
[ValidateNotNull]
6365
public string CustomRdpProperty { get; set; }
6466

6567
public override void ExecuteCmdlet()
6668
{
6769
NetworkCredential creds = null;
68-
CollectionCreationDetails details = null;
70+
CollectionUpdateDetails details = null;
6971
OperationResultWithTrackingId response = null;
7072
Collection collection = null;
7173
bool forceRedeploy = false;
@@ -76,57 +78,61 @@ public override void ExecuteCmdlet()
7678
return;
7779
}
7880

79-
details = new CollectionCreationDetails()
80-
{
81-
Name = CollectionName,
82-
PlanName = String.IsNullOrWhiteSpace(Plan) ? collection.PlanName : Plan,
83-
Description = String.IsNullOrWhiteSpace(Description) ? collection.Description : Description,
84-
CustomRdpProperty = String.IsNullOrWhiteSpace(CustomRdpProperty) ? collection.CustomRdpProperty : CustomRdpProperty,
85-
TemplateImageName = collection.TemplateImageName
86-
};
81+
details = new CollectionUpdateDetails();
8782

88-
switch (ParameterSetName)
83+
if (Credential != null)
8984
{
90-
case DomainJoined:
91-
{
92-
if (collection.AdInfo == null)
93-
{
94-
ErrorRecord er = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
95-
Commands_RemoteApp.AadInfoCanNotBeAddedToCloudOnlyCollectionMessage,
96-
String.Empty,
97-
Client.Collections,
98-
ErrorCategory.InvalidArgument);
99-
ThrowTerminatingError(er);
100-
}
101-
102-
details.AdInfo = new ActiveDirectoryConfig();
103-
details.VNetName = collection.VNetName;
104-
details.AdInfo.DomainName = collection.AdInfo.DomainName;
105-
details.AdInfo.OrganizationalUnit = collection.AdInfo.OrganizationalUnit;
106-
107-
if (Credential != null)
108-
{
109-
creds = Credential.GetNetworkCredential();
110-
details.AdInfo.UserName = creds.UserName;
111-
details.AdInfo.Password = creds.Password;
112-
}
113-
114-
if (String.Equals("Inactive", collection.Status, StringComparison.OrdinalIgnoreCase))
115-
{
116-
// the collection may have failed due to bad domain join information before,
117-
// re-trying with the new information
118-
forceRedeploy = true;
119-
}
120-
121-
break;
122-
}
85+
if (collection.AdInfo == null)
86+
{
87+
ErrorRecord er = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
88+
Commands_RemoteApp.AadInfoCanNotBeAddedToCloudOnlyCollectionMessage,
89+
String.Empty,
90+
Client.Collections,
91+
ErrorCategory.InvalidArgument);
92+
ThrowTerminatingError(er);
93+
}
94+
95+
details.AdInfo = new ActiveDirectoryConfig();
96+
97+
creds = Credential.GetNetworkCredential();
98+
details.AdInfo.UserName = Credential.UserName;
99+
details.AdInfo.Password = creds.Password;
100+
details.AdInfo.DomainName = collection.AdInfo.DomainName;
101+
details.AdInfo.OrganizationalUnit = collection.AdInfo.OrganizationalUnit;
102+
103+
if (String.Equals("Inactive", collection.Status, StringComparison.OrdinalIgnoreCase))
104+
{
105+
// the collection may have failed due to bad domain join information before,
106+
// re-trying with the new information
107+
forceRedeploy = true;
108+
}
109+
}
110+
else if (Plan != null)
111+
{
112+
details.PlanName = Plan;
113+
}
114+
else if (Description != null)
115+
{
116+
details.Description = Description;
117+
}
118+
else if (CustomRdpProperty != null)
119+
{
120+
details.CustomRdpProperty = CustomRdpProperty;
121+
}
122+
else
123+
{
124+
ErrorRecord er = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
125+
"At least one parameter must be set with this cmdlet",
126+
String.Empty,
127+
Client.Collections,
128+
ErrorCategory.InvalidArgument);
129+
ThrowTerminatingError(er);
123130
}
124131

125132
response = CallClient(() => Client.Collections.Set(CollectionName, forceRedeploy, false, details), Client.Collections);
126133
if (response != null)
127134
{
128-
TrackingResult trackingId = new TrackingResult(response);
129-
WriteObject(trackingId);
135+
WriteTrackingId(response);
130136
}
131137
}
132138
}

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,35 @@ public class UpdateAzureRemoteAppCollection : RdsCmdlet
3838
public string ImageName { get; set; }
3939

4040
[Parameter(Mandatory = false,
41-
HelpMessage = "Immediately log off users after update has successfully completed")]
41+
HelpMessage = "Log off users immediately after the update has successfully completed")]
4242
public SwitchParameter ForceLogoffWhenUpdateComplete { get; set; }
4343

4444
public override void ExecuteCmdlet()
4545
{
46-
CollectionCreationDetails details = null;
46+
CollectionUpdateDetails details = null;
4747
OperationResultWithTrackingId response = null;
4848
Collection collection = null;
4949

5050
collection = FindCollection(CollectionName);
51+
if (collection == null)
52+
{
53+
return;
54+
}
5155

52-
if (collection != null)
56+
details = new CollectionUpdateDetails()
5357
{
54-
details = new CollectionCreationDetails()
55-
{
56-
Name = CollectionName,
57-
TemplateImageName = ImageName,
58-
PlanName = collection.PlanName,
59-
WaitBeforeShutdownInMinutes = ForceLogoffWhenUpdateComplete ? -1 : 0
60-
};
58+
TemplateImageName = ImageName,
59+
WaitBeforeShutdownInMinutes = ForceLogoffWhenUpdateComplete ? -1 : 0
60+
};
6161

62-
if (ShouldProcess(CollectionName, Commands_RemoteApp.UpdateCollection))
63-
{
64-
response = CallClient(() => Client.Collections.Set(CollectionName, true, false, details), Client.Collections);
65-
}
62+
if (ShouldProcess(CollectionName, Commands_RemoteApp.UpdateCollection))
63+
{
64+
response = CallClient(() => Client.Collections.Set(CollectionName, true, false, details), Client.Collections);
65+
}
6666

67-
if (response != null)
68-
{
69-
WriteTrackingId(response);
70-
}
67+
if (response != null)
68+
{
69+
WriteTrackingId(response);
7170
}
7271
}
7372
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
</Reference>
7272
<Reference Include="Microsoft.Azure.Management.RemoteApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7373
<SpecificVersion>False</SpecificVersion>
74-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RemoteApp.1.0.8\lib\net40\Microsoft.Azure.Management.RemoteApp.dll</HintPath>
74+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RemoteApp.1.0.9\lib\net40\Microsoft.Azure.Management.RemoteApp.dll</HintPath>
7575
</Reference>
7676
<Reference Include="Microsoft.Data.Edm, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7777
<HintPath>..\..\..\packages\Microsoft.Data.Edm.5.6.0\lib\net40\Microsoft.Data.Edm.dll</HintPath>

src/ServiceManagement/RemoteApp/Commands.RemoteApp/Common/RdsCmdlet.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,6 @@ protected Collection FindCollection(string CollectionName)
211211
ErrorCategory.ObjectNotFound
212212
);
213213

214-
WriteError(er);
215-
}
216-
else if (!String.Equals(response.Collection.Status, "Active", StringComparison.OrdinalIgnoreCase))
217-
{
218-
ErrorRecord er = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
219-
String.Format("Collection {0} is not in the Active state",
220-
response.Collection.Name),
221-
String.Empty,
222-
Client.Collections,
223-
ErrorCategory.InvalidOperation
224-
);
225-
226214
WriteError(er);
227215
}
228216
}

src/ServiceManagement/RemoteApp/Commands.RemoteApp/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<package id="Microsoft.Azure.Common" version="2.0.4" targetFramework="net45" />
55
<package id="Microsoft.Azure.Common.Authentication" version="1.0.17-preview" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
7-
<package id="Microsoft.Azure.Management.RemoteApp" version="1.0.8" targetFramework="net45" />
7+
<package id="Microsoft.Azure.Management.RemoteApp" version="1.0.9" targetFramework="net45" />
88
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
99
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
1010
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />

0 commit comments

Comments
 (0)