Skip to content

Commit d43dab7

Browse files
committed
Bug fixes: 1908985, 1907418, 1898689,1901426
1 parent 8b315c5 commit d43dab7

File tree

4 files changed

+56
-39
lines changed

4 files changed

+56
-39
lines changed

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

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Commands.RemoteApp;
16+
using Microsoft.Azure.Management.RemoteApp;
1617
using Microsoft.Azure.Management.RemoteApp.Models;
17-
using Microsoft.PowerShell.Commands;
1818
using System;
1919
using System.Collections.ObjectModel;
2020
using System.Management.Automation;
21+
using System.IO;
22+
using System.Linq;
23+
using System.Management.Automation;
24+
using System.Net;
2125

2226
namespace Microsoft.Azure.Management.RemoteApp.Cmdlets
2327
{
@@ -46,18 +50,15 @@ public class GetAzureRemoteAppCollectionUsageDetails : RdsCmdlet
4650
public string UsageYear { get; set; }
4751

4852
[Parameter(Mandatory = false,
49-
HelpMessage = "Allows to run the cmdlet in the background as a PS job.")]
53+
HelpMessage = "Allows running the cmdlet in the background as a PS job.")]
5054
public SwitchParameter AsJob { get; set; }
5155

5256
private LongRunningTask<GetAzureRemoteAppCollectionUsageDetails> task = null;
5357

5458
private void GetPublishedUsageDetails(CollectionUsageDetailsResult detailsUsage)
5559
{
5660
RemoteAppOperationStatusResult operationResult = null;
57-
int maxRetryCount = 60;
58-
Collection<WebResponseObject> htmlWebResponse = null;
59-
string scriptBlock = "Invoke-WebRequest -Uri " + "\"" + detailsUsage.UsageDetails.SasUri + "\"";
60-
61+
6162
// The request is async and we have to wait for the usage details to be produced here
6263
do
6364
{
@@ -67,38 +68,49 @@ private void GetPublishedUsageDetails(CollectionUsageDetailsResult detailsUsage)
6768
operationResult = CallClient(() => Client.OperationResults.Get(detailsUsage.UsageDetails.OperationTrackingId), Client.OperationResults);
6869
}
6970
while (operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Success &&
70-
operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Failed &&
71-
--maxRetryCount > 0);
71+
operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Failed);
7272

7373
if (operationResult.RemoteAppOperationResult.Status == RemoteAppOperationStatus.Success)
7474
{
75-
htmlWebResponse = CallPowershellWithReturnType<WebResponseObject>(scriptBlock);
76-
string usage = new string(System.Text.Encoding.UTF8.GetChars(htmlWebResponse[0].Content));
77-
WriteObject(usage);
75+
WriteUsageDetails(detailsUsage);
7876
}
7977
else
8078
{
81-
if (operationResult.RemoteAppOperationResult.Status == RemoteAppOperationStatus.Failed)
82-
{
83-
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
84-
Commands_RemoteApp.DetailedUsageFailureMessage,
85-
String.Empty,
86-
Client.Collections,
87-
ErrorCategory.ResourceUnavailable);
79+
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
80+
Commands_RemoteApp.DetailedUsageFailureMessage,
81+
String.Empty,
82+
Client.Collections,
83+
ErrorCategory.ResourceUnavailable);
8884

89-
WriteError(error);
90-
}
91-
else if (maxRetryCount <= 0)
85+
WriteError(error);
86+
}
87+
}
88+
89+
private void WriteUsageDetails(CollectionUsageDetailsResult detailsUsage)
90+
{
91+
//
92+
// Display the content pointed to by the returned URI
93+
//
94+
WebResponse response = null;
95+
96+
WebRequest request = WebRequest.Create(detailsUsage.UsageDetails.SasUri);
97+
98+
try
99+
{
100+
response = (HttpWebResponse)request.GetResponse();
101+
}
102+
catch (Exception e)
103+
{
104+
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromException(e, String.Empty, Client.Collections, ErrorCategory.InvalidResult);
105+
WriteError(error);
106+
}
107+
108+
using (Stream dataStream = response.GetResponseStream())
109+
{
110+
using (StreamReader reader = new StreamReader(dataStream))
92111
{
93-
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
94-
String.Format(System.Globalization.CultureInfo.InvariantCulture,
95-
Commands_RemoteApp.RequestTimedOutFormat,
96-
detailsUsage.UsageDetails.OperationTrackingId),
97-
String.Empty,
98-
Client.Collections,
99-
ErrorCategory.OperationTimeout);
100-
101-
WriteError(error);
112+
String csvContent = reader.ReadToEnd();
113+
WriteObject(csvContent);
102114
}
103115
}
104116
}

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

Lines changed: 3 additions & 3 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: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@
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>
9692
<Reference Include="Microsoft.Threading.Tasks">
9793
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
9894
</Reference>

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,18 @@
241241
<value>No usage found for the requested period.</value>
242242
</data>
243243
<data name="DownloadingUsageDetails" xml:space="preserve">
244-
<value>Retrieving UsageDetails</value>
244+
<value>Retrieving usage details</value>
245+
</data>
246+
<data name="RequestFailed" xml:space="preserve">
247+
<value>The request failed.</value>
248+
</data>
249+
<data name="RequestSuccessful" xml:space="preserve">
250+
<value>The request completed successfully.</value>
251+
</data>
252+
<data name="VNetTimeout" xml:space="preserve">
253+
<value>The request took too long to complete.</value>
245254
</data>
246255
<data name="UsageDetails" xml:space="preserve">
247-
<value>Get UsageDetails</value>
256+
<value>Get usage details</value>
248257
</data>
249258
</root>

0 commit comments

Comments
 (0)