Skip to content

Commit dbae490

Browse files
committed
Merge pull request #216 from yadavbdev/dev
Adding RemoteApp cmdlet to release
2 parents 339e014 + e0e2839 commit dbae490

File tree

53 files changed

+5291
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+5291
-1
lines changed

setup/azurecmdfiles.wxi

Lines changed: 122 additions & 0 deletions
Large diffs are not rendered by default.

src/AzurePowershell.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio 2013
3-
VisualStudioVersion = 12.0.31101.0
3+
VisualStudioVersion = 12.0.30723.0
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8531411A-0137-4E27-9C5E-49E07C245048}"
66
ProjectSection(SolutionItems) = preProject
@@ -165,6 +165,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.Insights.Test", "R
165165
EndProject
166166
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.Websites", "ResourceManager\Websites\Commands.Websites\Commands.Websites.csproj", "{80A92297-7C92-456B-8EE7-9FB6CE30149D}"
167167
EndProject
168+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.RemoteApp", "ServiceManagement\RemoteApp\Commands.RemoteApp\Commands.RemoteApp.csproj", "{492D2AF2-950B-4F2E-8079-8794305313FD}"
169+
EndProject
168170
Global
169171
GlobalSection(SolutionConfigurationPlatforms) = preSolution
170172
Debug|Any CPU = Debug|Any CPU
@@ -403,6 +405,10 @@ Global
403405
{80A92297-7C92-456B-8EE7-9FB6CE30149D}.Debug|Any CPU.Build.0 = Debug|Any CPU
404406
{80A92297-7C92-456B-8EE7-9FB6CE30149D}.Release|Any CPU.ActiveCfg = Release|Any CPU
405407
{80A92297-7C92-456B-8EE7-9FB6CE30149D}.Release|Any CPU.Build.0 = Release|Any CPU
408+
{492D2AF2-950B-4F2E-8079-8794305313FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
409+
{492D2AF2-950B-4F2E-8079-8794305313FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
410+
{492D2AF2-950B-4F2E-8079-8794305313FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
411+
{492D2AF2-950B-4F2E-8079-8794305313FD}.Release|Any CPU.Build.0 = Release|Any CPU
406412
EndGlobalSection
407413
GlobalSection(SolutionProperties) = preSolution
408414
HideSolutionNode = FALSE

src/ResourceManager/Resources/Commands.Resources/Commands.Resources.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@
232232
<Project>{c60342b1-47d3-4a0e-8081-9b97ce60b7af}</Project>
233233
<Name>Commands.Profile</Name>
234234
</ProjectReference>
235+
<ProjectReference Include="..\..\..\ServiceManagement\RemoteApp\Commands.RemoteApp\Commands.RemoteApp.csproj">
236+
<Project>{492d2af2-950b-4f2e-8079-8794305313fd}</Project>
237+
<Name>Commands.RemoteApp</Name>
238+
</ProjectReference>
235239
<ProjectReference Include="..\..\..\ServiceManagement\StorSimple\Commands.StorSimple\Commands.StorSimple.csproj">
236240
<Project>{11524d98-6c40-4091-a8e1-86463fee607c}</Project>
237241
<Name>Commands.StorSimple</Name>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.RemoteApp;
16+
using Microsoft.Azure.Management.RemoteApp.Models;
17+
using System.Collections.Generic;
18+
using System.Management.Automation;
19+
20+
namespace Microsoft.Azure.Management.RemoteApp.Cmdlets
21+
{
22+
[Cmdlet(VerbsCommon.Get, "AzureRemoteAppPlan"), OutputType(typeof(BillingPlan))]
23+
public class GetAzureRemoteAppPlan : RdsCmdlet
24+
{
25+
public override void ExecuteCmdlet()
26+
{
27+
ListBillingPlansResult billingPlans = CallClient(() => Client.Account.ListBillingPlans(), Client.Account);
28+
29+
if (billingPlans.PlanList.Count > 0)
30+
{
31+
WriteObject(billingPlans.PlanList, true);
32+
}
33+
else
34+
{
35+
WriteVerboseWithTimestamp(Commands_RemoteApp.NoPlansFoundMessage);
36+
}
37+
}
38+
}
39+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.RemoteApp;
16+
using Microsoft.Azure.Management.RemoteApp;
17+
using Microsoft.Azure.Management.RemoteApp.Models;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Linq;
21+
using System.Management.Automation;
22+
23+
namespace Microsoft.Azure.Management.RemoteApp.Cmdlets
24+
{
25+
[Cmdlet(VerbsCommon.Get, "AzureRemoteAppCollection"), OutputType(typeof(LocalModels.Collection))]
26+
public class GetAzureRemoteAppCollection : RdsCmdlet
27+
{
28+
[Parameter(Mandatory = false,
29+
Position = 1,
30+
HelpMessage = "RemoteApp collection name. Wildcards are permitted.")]
31+
[ValidatePattern(NameValidatorStringWithWildCards)]
32+
public string CollectionName { get; set; }
33+
34+
private bool showAllCollections = false;
35+
36+
private bool found = false;
37+
38+
private bool GetAllCollections()
39+
{
40+
CollectionListResult response = null;
41+
IEnumerable<Collection> spList = null;
42+
LocalModels.Collection collection = null;
43+
44+
response = CallClient(() => Client.Collections.List(), Client.Collections);
45+
46+
if (response != null)
47+
{
48+
if (UseWildcard)
49+
{
50+
spList = response.Collections.Where(col => Wildcard.IsMatch(col.Name));
51+
}
52+
else
53+
{
54+
spList = response.Collections;
55+
}
56+
57+
if (spList != null && spList.Count() > 0)
58+
{
59+
foreach( Collection c in spList)
60+
{
61+
collection = new LocalModels.Collection(c);
62+
WriteObject(collection);
63+
}
64+
found = true;
65+
}
66+
}
67+
68+
return found;
69+
}
70+
71+
private bool GetCollection(string collectionName)
72+
{
73+
CollectionResult response = null;
74+
LocalModels.Collection collection = null;
75+
76+
response = CallClient(() => Client.Collections.Get(collectionName), Client.Collections);
77+
78+
if (response != null)
79+
{
80+
collection = new LocalModels.Collection(response.Collection);
81+
WriteObject(collection);
82+
found = true;
83+
}
84+
85+
return found;
86+
}
87+
88+
public override void ExecuteCmdlet()
89+
{
90+
showAllCollections = String.IsNullOrWhiteSpace(CollectionName);
91+
92+
if (showAllCollections == false)
93+
{
94+
CreateWildcardPattern(CollectionName);
95+
}
96+
97+
if (ExactMatch)
98+
{
99+
found = GetCollection(CollectionName);
100+
}
101+
else
102+
{
103+
found = GetAllCollections();
104+
}
105+
106+
if (!found)
107+
{
108+
WriteVerboseWithTimestamp(String.Format(Commands_RemoteApp.CollectionNotFoundByNameFormat, CollectionName));
109+
}
110+
}
111+
}
112+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.RemoteApp;
16+
using Microsoft.Azure.Management.RemoteApp;
17+
using Microsoft.Azure.Management.RemoteApp.Models;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.IO;
21+
using System.Linq;
22+
using System.Management.Automation;
23+
using System.Net;
24+
25+
namespace Microsoft.Azure.Management.RemoteApp.Cmdlets
26+
{
27+
28+
[Cmdlet(VerbsCommon.Get, "AzureRemoteAppCollectionUsageDetails"), OutputType(typeof(string))]
29+
public class GetAzureRemoteAppCollectionUsageDetails : RdsCmdlet
30+
{
31+
[Parameter(
32+
Position = 0,
33+
Mandatory = true,
34+
ValueFromPipelineByPropertyName = true,
35+
HelpMessage = "RemoteApp collection name")]
36+
public string CollectionName { get; set; }
37+
38+
[Parameter(Mandatory = false,
39+
Position = 1,
40+
HelpMessage = "Number of the month (MM) to report usage")]
41+
[ValidatePattern(TwoDigitMonthPattern)]
42+
public string UsageMonth { get; set; }
43+
44+
[Parameter(Mandatory = false,
45+
Position = 2,
46+
HelpMessage = "Year (YYYY) to report usage")]
47+
[ValidatePattern(FullYearPattern)]
48+
public string UsageYear { get; set; }
49+
50+
public override void ExecuteCmdlet()
51+
{
52+
DateTime today = DateTime.Now;
53+
CollectionUsageDetailsResult detailsUsage = null;
54+
string locale = String.Empty;
55+
RemoteAppOperationStatusResult operationResult = null;
56+
int maxRetryCount = 600;
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+
77+
// The request is async and we have to wait for the usage details to be produced here
78+
do
79+
{
80+
System.Threading.Thread.Sleep(5000);
81+
82+
operationResult = CallClient(() => Client.OperationResults.Get(detailsUsage.UsageDetails.OperationTrackingId), Client.OperationResults);
83+
}
84+
while(operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Success ||
85+
operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Failed ||
86+
--maxRetryCount > 0);
87+
88+
if (operationResult.RemoteAppOperationResult.Status == RemoteAppOperationStatus.Success)
89+
{
90+
WriteUsageDetails(detailsUsage);
91+
}
92+
else
93+
{
94+
if (operationResult.RemoteAppOperationResult.Status == RemoteAppOperationStatus.Failed)
95+
{
96+
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
97+
Commands_RemoteApp.DetailedUsageFailureMessage,
98+
String.Empty,
99+
Client.Collections,
100+
ErrorCategory.ResourceUnavailable);
101+
102+
WriteError(error);
103+
}
104+
else if (maxRetryCount <= 0)
105+
{
106+
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
107+
Commands_RemoteApp.RequestTimedOut,
108+
String.Empty,
109+
Client.Collections,
110+
ErrorCategory.OperationTimeout);
111+
112+
WriteError(error);
113+
}
114+
}
115+
}
116+
117+
private void WriteUsageDetails(CollectionUsageDetailsResult detailsUsage)
118+
{
119+
//
120+
// Display the content pointed to by the returned URI
121+
//
122+
WebResponse response = null;
123+
124+
WebRequest request = WebRequest.Create(detailsUsage.UsageDetails.SasUri);
125+
126+
try
127+
{
128+
response = (HttpWebResponse)request.GetResponse();
129+
}
130+
catch (Exception e)
131+
{
132+
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromException(e, String.Empty, Client.Collections, ErrorCategory.InvalidResult);
133+
WriteError(error);
134+
}
135+
136+
using (Stream dataStream = response.GetResponseStream())
137+
{
138+
using (StreamReader reader = new StreamReader(dataStream))
139+
{
140+
String csvContent = reader.ReadToEnd();
141+
WriteObject(csvContent);
142+
}
143+
}
144+
}
145+
}
146+
}

0 commit comments

Comments
 (0)