Skip to content

Commit d90bcde

Browse files
committed
Reformtting websites output
1 parent 06248ee commit d90bcde

34 files changed

+925
-50
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 System.Collections.Generic;
16+
using System.IO;
17+
using System.Linq;
18+
using Newtonsoft.Json;
19+
using System.Reflection;
20+
21+
namespace Microsoft.Azure.Commands.Common.Resources
22+
{
23+
public static class SerializationHelpers
24+
{
25+
public static string SerializeJson<T>(this T property) where T : class
26+
{
27+
if (property == null)
28+
{
29+
return null;
30+
}
31+
32+
using (var stringWriter = new StringWriter())
33+
using (var writer = new JsonTextWriter(stringWriter))
34+
{
35+
36+
var serializer = new JsonSerializer {Formatting = Formatting.Indented};
37+
stringWriter.NewLine += " ";
38+
stringWriter.WriteLine();
39+
serializer.Serialize(writer, property);
40+
writer.Flush();
41+
return stringWriter.ToString();
42+
}
43+
}
44+
45+
public static string SerializeJsonCollection<T>(this IEnumerable<T> property)
46+
{
47+
if (property == null)
48+
{
49+
return null;
50+
}
51+
if (property.Count() < 3 && typeof (T) == typeof (string) || typeof (T).GetTypeInfo().IsValueType)
52+
{
53+
return JsonConvert.SerializeObject(property);
54+
}
55+
56+
using (var stringWriter = new StringWriter())
57+
using (var writer = new JsonTextWriter(stringWriter))
58+
{
59+
var serializer = new JsonSerializer { Formatting = Formatting.Indented };
60+
stringWriter.NewLine += " ";
61+
stringWriter.WriteLine();
62+
serializer.Serialize(writer, property);
63+
writer.Flush();
64+
return stringWriter.ToString();
65+
}
66+
}
67+
}
68+
}

src/CLU/Commands.ResourceManager.Common/Tags/TagsConversionHelper.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
using System;
1616
using System.Collections;
1717
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Text;
1820
using Commands.ResourceManager.Common.Properties;
21+
using Microsoft.Azure.Commands.Utilities.Common;
1922

2023
namespace Microsoft.Azure.Commands.Tags.Model
2124
{
@@ -97,5 +100,10 @@ public static Hashtable[] CreateTagHashtable(IDictionary<string, string> diction
97100
}
98101
return tagHashtable.ToArray();
99102
}
103+
104+
public static string SerializeTags(IDictionary<string, string> tags)
105+
{
106+
return tags == null? null : $"{{ {string.Join(",", tags.Where(t => !t.Key.StartsWith("hidden-")).Select(p => $"{p.Key}: {p.Value}"))} }}";
107+
}
100108
}
101109
}

src/CLU/Microsoft.Azure.Commands.Resources/Models.ResourceGroups/ResourceIdentifier.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public ResourceIdentifier(string idFromServer)
6565
{
6666
ParentResource = string.Join("/", parentResourceBuilder);
6767
}
68+
else
69+
{
70+
ParentResource = string.Empty;
71+
}
6872
if (resourceTypeBuilder.Count > 0)
6973
{
7074
ResourceType = string.Join("/", resourceTypeBuilder);

src/CLU/Microsoft.Azure.Commands.Websites/Cmdlets/AppServicePlans/GetAzureAppServicePlan.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.Linq;
1919
using System.Management.Automation;
2020
using Microsoft.Azure.Commands.WebApps.Models;
21+
using Microsoft.Azure.Commands.Websites.Models.WebApp;
2122
using Microsoft.Azure.Management.WebSites.Models;
2223
using PSResourceManagerModels = Microsoft.Azure.Commands.Resources.Models;
2324

@@ -26,7 +27,7 @@ namespace Microsoft.Azure.Commands.WebApps.Cmdlets.AppServicePlans
2627
/// <summary>
2728
/// this commandlet will let you Get an Azure App Service Plan using ARM APIs
2829
/// </summary>
29-
[Cmdlet(VerbsCommon.Get, "AzureRMAppServicePlan"), OutputType(typeof(ServerFarmWithRichSku), typeof(ServerFarmCollection))]
30+
[Cmdlet(VerbsCommon.Get, "AzureRMAppServicePlan"), OutputType(typeof(PSServerFarmWithRichSku), typeof(ServerFarmCollection))]
3031
public class GetAppServicePlanCmdlet : WebAppBaseClientCmdLet
3132
{
3233
private const string ParameterSet1 = "S1";
@@ -78,7 +79,7 @@ protected override void ProcessRecord()
7879

7980
private void GetAppServicePlan()
8081
{
81-
WriteObject(WebsitesClient.GetAppServicePlan(ResourceGroupName, Name), true);
82+
WriteObject((PSServerFarmWithRichSku)WebsitesClient.GetAppServicePlan(ResourceGroupName, Name), true);
8283
}
8384

8485
private void GetByAppServicePlanName()
@@ -115,12 +116,12 @@ private void GetByAppServicePlanName()
115116
WriteProgress(progressRecord);
116117
}
117118

118-
WriteObject(list, true);
119+
WriteObject(list.Select(f => (PSServerFarmWithRichSku)f), true);
119120
}
120121

121122
private void GetByResourceGroup()
122123
{
123-
WriteObject(WebsitesClient.ListAppServicePlans(ResourceGroupName).Value, true);
124+
WriteObject(WebsitesClient.ListAppServicePlans(ResourceGroupName).GetValues(), true);
124125
}
125126

126127
private void GetBySubscription()
@@ -164,7 +165,7 @@ private void GetBySubscription()
164165
WriteProgress(progressRecord);
165166
}
166167

167-
WriteObject(list, true);
168+
WriteObject(list.Select(f => (PSServerFarmWithRichSku)f), true);
168169
}
169170

170171
private void GetByLocation()
@@ -201,7 +202,7 @@ private void GetByLocation()
201202
WriteProgress(progressRecord);
202203
}
203204

204-
WriteObject(list, true);
205+
WriteObject(list.Select(f => (PSServerFarmWithRichSku)f), true);
205206
}
206207
}
207208
}

src/CLU/Microsoft.Azure.Commands.Websites/Cmdlets/AppServicePlans/GetAzureAppServicePlanMetrics.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515

1616
using System;
1717
using System.Management.Automation;
18+
using Microsoft.Azure.Commands.Websites.Models.WebApp;
19+
using Microsoft.Azure.Management.WebSites.Models;
20+
using System.Linq;
1821

1922
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps
2023
{
2124
/// <summary>
2225
/// this commandlet will let you get Azure servce plan metrics
2326
/// </summary>
24-
[Cmdlet(VerbsCommon.Get, "AzureRMAppServicePlanMetrics")]
27+
[Cmdlet(VerbsCommon.Get, "AzureRMAppServicePlanMetrics"), OutputType(typeof(PSResourceMetric))]
2528
public class GetAzureAppServicePlanMetricsCmdlet : AppServicePlanBaseCmdlet
2629
{
2730
[Parameter(Position = 2, Mandatory = true, HelpMessage = "Names of web app metrics")]
@@ -47,7 +50,7 @@ public class GetAzureAppServicePlanMetricsCmdlet : AppServicePlanBaseCmdlet
4750
protected override void ProcessRecord()
4851
{
4952
base.ProcessRecord();
50-
WriteObject(WebsitesClient.GetAppServicePlanHistoricalUsageMetrics(ResourceGroupName, Name, Metrics, StartTime, EndTime, Granularity, InstanceDetails.IsPresent));
53+
WriteObject(WebsitesClient.GetAppServicePlanHistoricalUsageMetrics(ResourceGroupName, Name, Metrics, StartTime, EndTime, Granularity, InstanceDetails.IsPresent).Select(m => (PSResourceMetric)m), true);
5154
}
5255
}
5356
}

src/CLU/Microsoft.Azure.Commands.Websites/Cmdlets/AppServicePlans/NewAzureAppServicePlan.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
using System.Management.Automation;
1717
using Microsoft.Azure.Commands.WebApps.Utilities;
18+
using Microsoft.Azure.Commands.Websites.Models.WebApp;
1819
using Microsoft.Azure.Management.WebSites.Models;
1920

2021
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.AppServicePlans
@@ -66,7 +67,7 @@ protected override void ProcessRecord()
6667
Capacity = capacity
6768
};
6869

69-
WriteObject(WebsitesClient.CreateAppServicePlan(ResourceGroupName, Name, Location, null, sku), true);
70+
WriteObject((PSServerFarmWithRichSku)WebsitesClient.CreateAppServicePlan(ResourceGroupName, Name, Location, null, sku), true);
7071
}
7172
}
7273
}

src/CLU/Microsoft.Azure.Commands.Websites/Cmdlets/AppServicePlans/RemoveAppServicePlan.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515

1616
using System.Management.Automation;
17+
using System.Net;
1718
using Microsoft.Azure.Commands.WebApps.Models;
1819
using Microsoft.Azure.Commands.WebApps.Utilities;
1920
using Microsoft.Azure.Commands.WebApps.Validations;
@@ -25,7 +26,7 @@ namespace Microsoft.Azure.Commands.WebApps.Cmdlets.AppServicePlans
2526
/// <summary>
2627
/// this commandlet will let you delete an Azure App Service Plan using ARM APIs
2728
/// </summary>
28-
[Cmdlet(VerbsCommon.Remove, "AzureRmAppServicePlan"), OutputType(typeof(AzureOperationResponse))]
29+
[Cmdlet(VerbsCommon.Remove, "AzureRmAppServicePlan"), OutputType(typeof(HttpStatusCode))]
2930
public class RemoveAppServicePlanCmdlet : AppServicePlanBaseCmdlet
3031
{
3132
[Parameter(Mandatory = false, HelpMessage = "Do not ask for confirmation.")]

src/CLU/Microsoft.Azure.Commands.Websites/Cmdlets/AppServicePlans/SetAzureAppServicePlan.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Management.Automation;
1616
using Microsoft.Azure.Commands.WebApps.Utilities;
1717
using Microsoft.Azure.Commands.WebApps.Validations;
18+
using Microsoft.Azure.Commands.Websites.Models.WebApp;
1819
using Microsoft.Azure.Management.WebSites.Models;
1920

2021
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.AppServicePlans
@@ -61,7 +62,7 @@ protected override void ProcessRecord()
6162
AppServicePlan.Sku.Size = AppServicePlan.Sku.Name;
6263
AppServicePlan.Sku.Family = AppServicePlan.Sku.Name.Substring(0, 1);
6364

64-
WriteObject(WebsitesClient.CreateAppServicePlan(ResourceGroupName, Name, AppServicePlan.Location, AdminSiteName, AppServicePlan.Sku), true);
65+
WriteObject((PSServerFarmWithRichSku)WebsitesClient.CreateAppServicePlan(ResourceGroupName, Name, AppServicePlan.Location, AdminSiteName, AppServicePlan.Sku), true);
6566
}
6667
}
6768
}

src/CLU/Microsoft.Azure.Commands.Websites/Cmdlets/DeploymentSlots/GetAzureWebAppSlot.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
using System.Management.Automation;
1818
using Microsoft.Azure.Commands.WebApps.Models;
1919
using Microsoft.Azure.Commands.WebApps.Utilities;
20+
using Microsoft.Azure.Commands.Websites.Models.WebApp;
2021
using Microsoft.Azure.Management.WebSites.Models;
2122
using PSResourceManagerModels = Microsoft.Azure.Commands.Resources.Models;
23+
using System.Linq;
2224

2325
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.DeploymentSlots
2426
{
2527
/// <summary>
2628
/// this commandlet will let you get a new Azure Web app slot using ARM APIs
2729
/// </summary>
2830
[Cmdlet(VerbsCommon.Get, "AzureRMWebAppSlot")]
31+
[OutputType(typeof(PSSite))]
2932
public class GetAzureWebAppSlotCmdlet : WebAppBaseClientCmdLet
3033
{
3134
protected const string ParameterSet1Name = "S1";
@@ -66,11 +69,11 @@ protected override void ProcessRecord()
6669

6770
if (string.IsNullOrWhiteSpace(Slot))
6871
{
69-
WriteObject(WebsitesClient.ListWebApps(ResourceGroupName, Name));
72+
WriteObject(WebsitesClient.ListWebApps(ResourceGroupName, Name).Select(s => (PSSite)s));
7073
}
7174
else
7275
{
73-
WriteObject(WebsitesClient.GetWebApp(ResourceGroupName, Name, Slot));
76+
WriteObject((PSSite)WebsitesClient.GetWebApp(ResourceGroupName, Name, Slot));
7477
}
7578
}
7679
}

src/CLU/Microsoft.Azure.Commands.Websites/Cmdlets/DeploymentSlots/GetAzureWebAppSlotMetrics.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515

1616
using System;
1717
using System.Management.Automation;
18+
using Microsoft.Azure.Commands.Websites.Models.WebApp;
19+
using System.Linq;
1820

1921
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.DeploymentSlots
2022
{
2123
/// <summary>
2224
/// this commandlet will let you get Azure Web App slot metrics
2325
/// </summary>
2426
[Cmdlet(VerbsCommon.Get, "AzureRMWebAppSlotMetrics")]
27+
[OutputType(typeof(PSResourceMetric))]
2528
public class GetAzureWebAppSlotMetricsCmdlet : WebAppSlotBaseCmdlet
2629
{
2730
[Parameter(Position = 3, Mandatory = true, HelpMessage = "Names of web app metrics")]
@@ -47,7 +50,7 @@ public class GetAzureWebAppSlotMetricsCmdlet : WebAppSlotBaseCmdlet
4750
protected override void ProcessRecord()
4851
{
4952
base.ProcessRecord();
50-
WriteObject(WebsitesClient.GetWebAppUsageMetrics(ResourceGroupName, Name, Slot, Metrics, StartTime, EndTime, Granularity, InstanceDetails.IsPresent));
53+
WriteObject(WebsitesClient.GetWebAppUsageMetrics(ResourceGroupName, Name, Slot, Metrics, StartTime, EndTime, Granularity, InstanceDetails.IsPresent).Select(m => (PSResourceMetric)m), true);
5154
}
5255
}
5356
}

src/CLU/Microsoft.Azure.Commands.Websites/Cmdlets/DeploymentSlots/GetAzureWebAppSlotPublishingProfile.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace Microsoft.Azure.Commands.WebApps.Cmdlets.DeploymentSlots
2424
/// this commandlet will get the publishing creds of the given Azure Web app slot using ARM APIs
2525
/// </summary>
2626
[Cmdlet(VerbsCommon.Get, "AzureRMWebAppSlotPublishingProfile")]
27+
[OutputType(typeof(string))]
2728
public class GetAzureWebAppSlotPublishingProfileCmdlet : WebAppSlotBaseCmdlet
2829
{
2930
private const string DefaultFormat = "WebDeploy";

src/CLU/Microsoft.Azure.Commands.Websites/Cmdlets/DeploymentSlots/NewAzureWebAppSlot.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Linq;
2020
using System.Management.Automation;
2121
using Microsoft.Azure.Commands.WebApps.Models;
22+
using Microsoft.Azure.Commands.Websites.Models.WebApp;
2223
using Microsoft.Azure.Management.WebSites.Models;
2324

2425
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.DeploymentSlots
@@ -27,6 +28,7 @@ namespace Microsoft.Azure.Commands.WebApps.Cmdlets.DeploymentSlots
2728
/// this commandlet will let you create a new Azure Web app slot using ARM APIs
2829
/// </summary>
2930
[Cmdlet(VerbsCommon.New, "AzureRMWebAppSlot")]
31+
[OutputType(typeof(PSSite))]
3032
public class NewAzureWebAppSlotCmdlet : WebAppBaseClientCmdLet
3133
{
3234
[Parameter(Position = 0, Mandatory = true, HelpMessage = "The name of the resource group.")]
@@ -81,7 +83,7 @@ protected override void ProcessRecord()
8183

8284
var webApp = WebsitesClient.GetWebApp(ResourceGroupName, Name, null);
8385

84-
WriteObject(WebsitesClient.CreateWebApp(ResourceGroupName, Name, Slot, webApp.Location, AppServicePlan, cloningInfo));
86+
WriteObject((PSSite)WebsitesClient.CreateWebApp(ResourceGroupName, Name, Slot, webApp.Location, AppServicePlan, cloningInfo));
8587
}
8688
}
8789
}

src/CLU/Microsoft.Azure.Commands.Websites/Cmdlets/DeploymentSlots/RemoveAzureWebAppSlot.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616

1717
using Microsoft.Rest.Azure;
1818
using System.Management.Automation;
19+
using System.Net;
1920

2021
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.DeploymentSlots
2122
{
2223
/// <summary>
2324
/// this commandlet will let you delete an Azure web app slot
2425
/// </summary>
25-
[Cmdlet(VerbsCommon.Remove, "AzureRMWebAppSlot"), OutputType(typeof(AzureOperationResponse))]
26+
[Cmdlet(VerbsCommon.Remove, "AzureRMWebAppSlot"), OutputType(typeof(HttpStatusCode))]
2627
public class RemoveAzureWebAppSlotCmdlet : WebAppSlotBaseCmdlet
2728
{
2829
//always delete the slots,

src/CLU/Microsoft.Azure.Commands.Websites/Cmdlets/DeploymentSlots/ResetAzureWebAppSlotPublishingProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Microsoft.Azure.Commands.WebApps.Cmdlets.DeploymentSlots
2121
/// <summary>
2222
/// This commandlet resets the publishing creds of the given Azure Web app slot
2323
/// </summary>
24-
[Cmdlet(VerbsCommon.Reset, "AzureRMWebAppSlotPublishingProfile")]
24+
[Cmdlet(VerbsCommon.Reset, "AzureRMWebAppSlotPublishingProfile"), OutputType(typeof(string))]
2525
public class ResetAzureWebAppPSlotublishingProfileCmdlet : WebAppSlotBaseCmdlet
2626
{
2727
protected override void ProcessRecord()

src/CLU/Microsoft.Azure.Commands.Websites/Cmdlets/DeploymentSlots/RestartAzureWebAppSlot.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,22 @@
1515

1616

1717
using System.Management.Automation;
18+
using Microsoft.Azure.Commands.Websites.Models.WebApp;
19+
using Microsoft.Azure.Management.WebSites.Models;
1820

1921
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.DeploymentSlots
2022
{
2123
/// <summary>
2224
/// this commandlet will let you restart an Azure Web app slot
2325
/// </summary>
24-
[Cmdlet(VerbsLifecycle.Restart, "AzureRMWebAppSlot")]
26+
[Cmdlet(VerbsLifecycle.Restart, "AzureRMWebAppSlot"), OutputType(typeof(PSSite))]
2527
public class RestartAzureWebAppSlotCmdlet : WebAppSlotBaseCmdlet
2628
{
2729
protected override void ProcessRecord()
2830
{
2931
base.ProcessRecord();
3032
WebsitesClient.RestartWebApp(ResourceGroupName, Name, Slot);
31-
WriteObject(WebsitesClient.GetWebApp(ResourceGroupName, Name, Slot));
33+
WriteObject((PSSite)WebsitesClient.GetWebApp(ResourceGroupName, Name, Slot));
3234
}
3335
}
3436
}

0 commit comments

Comments
 (0)