Skip to content

Commit 7df80e8

Browse files
committed
Bug fixes for: 1974862, 1907078
1 parent d9b6c1c commit 7df80e8

File tree

6 files changed

+85
-51
lines changed

6 files changed

+85
-51
lines changed

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

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Commands.RemoteApp;
16-
using Microsoft.Azure.Management.RemoteApp;
1716
using Microsoft.Azure.Management.RemoteApp.Models;
17+
using Microsoft.PowerShell.Commands;
1818
using System;
19-
using System.Collections.Generic;
20-
using System.IO;
21-
using System.Linq;
19+
using System.Collections.ObjectModel;
2220
using System.Management.Automation;
23-
using System.Net;
2421

2522
namespace Microsoft.Azure.Management.RemoteApp.Cmdlets
2623
{
@@ -33,6 +30,7 @@ public class GetAzureRemoteAppCollectionUsageDetails : RdsCmdlet
3330
Mandatory = true,
3431
ValueFromPipelineByPropertyName = true,
3532
HelpMessage = "RemoteApp collection name")]
33+
[ValidatePattern(NameValidatorString)]
3634
public string CollectionName { get; set; }
3735

3836
[Parameter(Mandatory = false,
@@ -47,33 +45,19 @@ public class GetAzureRemoteAppCollectionUsageDetails : RdsCmdlet
4745
[ValidatePattern(FullYearPattern)]
4846
public string UsageYear { get; set; }
4947

50-
public override void ExecuteCmdlet()
48+
[Parameter(Mandatory = false,
49+
HelpMessage = "Allows to run the cmdlet in the background as a PS job.")]
50+
public SwitchParameter AsJob { get; set; }
51+
52+
private LongRunningTask<GetAzureRemoteAppCollectionUsageDetails> task = null;
53+
54+
private void GetPublishedUsageDetails(CollectionUsageDetailsResult detailsUsage)
5155
{
52-
DateTime today = DateTime.Now;
53-
CollectionUsageDetailsResult detailsUsage = null;
54-
string locale = String.Empty;
5556
RemoteAppOperationStatusResult operationResult = null;
5657
int maxRetryCount = 60;
57-
58-
if (String.IsNullOrWhiteSpace(UsageMonth))
59-
{
60-
UsageMonth = today.Month.ToString();
61-
}
62-
63-
if (String.IsNullOrWhiteSpace(UsageYear))
64-
{
65-
UsageYear = today.Year.ToString();
66-
}
67-
68-
locale = System.Globalization.CultureInfo.CurrentCulture.ToString();
69-
70-
detailsUsage = CallClient(() => Client.Collections.GetUsageDetails(CollectionName, UsageYear, UsageMonth, locale), Client.Collections);
71-
72-
if (detailsUsage == null)
73-
{
74-
return;
75-
}
76-
58+
Collection<WebResponseObject> htmlWebResponse = null;
59+
string scriptBlock = "Invoke-WebRequest -Uri " + "\"" + detailsUsage.UsageDetails.SasUri + "\"";
60+
7761
// The request is async and we have to wait for the usage details to be produced here
7862
do
7963
{
@@ -82,13 +66,15 @@ public override void ExecuteCmdlet()
8266

8367
operationResult = CallClient(() => Client.OperationResults.Get(detailsUsage.UsageDetails.OperationTrackingId), Client.OperationResults);
8468
}
85-
while(operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Success &&
69+
while (operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Success &&
8670
operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Failed &&
8771
--maxRetryCount > 0);
8872

8973
if (operationResult.RemoteAppOperationResult.Status == RemoteAppOperationStatus.Success)
9074
{
91-
WriteUsageDetails(detailsUsage);
75+
htmlWebResponse = CallPowershellWithReturnType<WebResponseObject>(scriptBlock);
76+
string usage = new string(System.Text.Encoding.UTF8.GetChars(htmlWebResponse[0].Content));
77+
WriteObject(usage);
9278
}
9379
else
9480
{
@@ -105,7 +91,7 @@ public override void ExecuteCmdlet()
10591
else if (maxRetryCount <= 0)
10692
{
10793
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
108-
String.Format(System.Globalization.CultureInfo.InvariantCulture,
94+
String.Format(System.Globalization.CultureInfo.InvariantCulture,
10995
Commands_RemoteApp.RequestTimedOutFormat,
11096
detailsUsage.UsageDetails.OperationTrackingId),
11197
String.Empty,
@@ -117,32 +103,48 @@ public override void ExecuteCmdlet()
117103
}
118104
}
119105

120-
private void WriteUsageDetails(CollectionUsageDetailsResult detailsUsage)
106+
public override void ExecuteCmdlet()
121107
{
122-
//
123-
// Display the content pointed to by the returned URI
124-
//
125-
WebResponse response = null;
108+
DateTime today = DateTime.Now;
109+
CollectionUsageDetailsResult detailsUsage = null;
110+
string locale = String.Empty;
126111

127-
WebRequest request = WebRequest.Create(detailsUsage.UsageDetails.SasUri);
112+
if (String.IsNullOrWhiteSpace(UsageMonth))
113+
{
114+
UsageMonth = today.Month.ToString();
115+
}
128116

129-
try
117+
if (String.IsNullOrWhiteSpace(UsageYear))
130118
{
131-
response = (HttpWebResponse)request.GetResponse();
119+
UsageYear = today.Year.ToString();
132120
}
133-
catch (Exception e)
121+
122+
locale = System.Globalization.CultureInfo.CurrentCulture.ToString();
123+
124+
detailsUsage = CallClient(() => Client.Collections.GetUsageDetails(CollectionName, UsageYear, UsageMonth, locale), Client.Collections);
125+
126+
if (detailsUsage == null)
134127
{
135-
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromException(e, String.Empty, Client.Collections, ErrorCategory.InvalidResult);
136-
WriteError(error);
128+
return;
137129
}
138130

139-
using (Stream dataStream = response.GetResponseStream())
131+
if (AsJob.IsPresent)
140132
{
141-
using (StreamReader reader = new StreamReader(dataStream))
133+
task = new LongRunningTask<GetAzureRemoteAppCollectionUsageDetails>(this, "RemoteAppBackgroundTask", Commands_RemoteApp.UsageDetails);
134+
135+
task.ProcessJob(() =>
142136
{
143-
String csvContent = reader.ReadToEnd();
144-
WriteObject(csvContent);
145-
}
137+
task.SetStatus(Commands_RemoteApp.DownloadingUsageDetails);
138+
GetPublishedUsageDetails(detailsUsage);
139+
task.SetStatus(Commands_RemoteApp.JobComplete);
140+
});
141+
142+
WriteObject(task);
143+
144+
}
145+
else
146+
{
147+
GetPublishedUsageDetails(detailsUsage);
146148
}
147149
}
148150
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Management.RemoteApp;
1615
using Microsoft.Azure.Commands.RemoteApp;
1716
using Microsoft.Azure.Management.RemoteApp.Models;
1817
using System.Management.Automation;
@@ -38,6 +37,10 @@ public class UpdateAzureRemoteAppCollection : RdsCmdlet
3837
[ValidatePattern(TemplateNameValidatorString)]
3938
public string ImageName { get; set; }
4039

40+
[Parameter(Mandatory = false,
41+
HelpMessage = "Immediately log off users after update has successfully completed")]
42+
public SwitchParameter ForceLogoffWhenUpdateComplete { get; set; }
43+
4144
public override void ExecuteCmdlet()
4245
{
4346
CollectionCreationDetails details = null;
@@ -52,7 +55,8 @@ public override void ExecuteCmdlet()
5255
{
5356
Name = CollectionName,
5457
TemplateImageName = ImageName,
55-
PlanName = collection.PlanName
58+
PlanName = collection.PlanName,
59+
WaitBeforeShutdownInMinutes = ForceLogoffWhenUpdateComplete ? -1 : 0
5660
};
5761

5862
if (ShouldProcess(CollectionName, Commands_RemoteApp.UpdateCollection))

src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms">
9090
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.12.111071459\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll</HintPath>
9191
</Reference>
92+
<Reference Include="Microsoft.PowerShell.Commands.Utility, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
93+
<SpecificVersion>False</SpecificVersion>
94+
<HintPath>C:\WINDOWS\Microsoft.NET\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Utility\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.PowerShell.Commands.Utility.dll</HintPath>
95+
</Reference>
9296
<Reference Include="Microsoft.Threading.Tasks">
9397
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
9498
</Reference>

src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,10 @@
240240
<data name="UseageNotFound" xml:space="preserve">
241241
<value>No usage found for the requested period.</value>
242242
</data>
243+
<data name="DownloadingUsageDetails" xml:space="preserve">
244+
<value>Retrieving UsageDetails</value>
245+
</data>
246+
<data name="UsageDetails" xml:space="preserve">
247+
<value>Get UsageDetails</value>
248+
</data>
243249
</root>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public abstract partial class RdsCmdlet
3030

3131
protected const string UserPrincipalValdatorString = UserNameValidatorString + "@" + DomainNameValidatorString;
3232

33-
protected const string TemplateNameValidatorString = @"^[A-Za-z][._\-A-Za-z0-9]{1,61}[A-Z-a-z0-9]$";
33+
protected const string TemplateNameValidatorString = @"^[()A-Za-z][() ._\-A-Za-z0-9]{1,61}[A-Z-a-z0-9()]$";
3434

3535
protected const string IPv4ValidatorString = @"^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$";
3636

0 commit comments

Comments
 (0)