Skip to content

Commit e4ed748

Browse files
committed
Add implementation for NetCore
1 parent 97fc505 commit e4ed748

File tree

6 files changed

+95
-7
lines changed

6 files changed

+95
-7
lines changed

src/ResourceManager/Websites/Commands.Websites/Cmdlets/WebApps/NewAzureWebApp.cs

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void ExecuteCmdletActions(SessionState state)
132132
if (ParameterSetName == SimpleParameterSet)
133133
{
134134
ValidateWebAppName(Name);
135-
if (ShouldProcess(string.Format(Resources.SimpleWebAppCreateTarget, Name), Resources.SimpleWebAppCreateAction))
135+
if (ShouldProcess(string.Format(Microsoft.Azure.Commands.WebApps.Properties.Resources.SimpleWebAppCreateTarget, Name), Microsoft.Azure.Commands.WebApps.Properties.Resources.SimpleWebAppCreateAction))
136136
{
137137
var adapter = new PSCmdletAdapter(this, state);
138138
adapter.WaitForCompletion(CreateWithSimpleParameters);
@@ -150,11 +150,19 @@ public void ExecuteCmdletActions(SessionState state)
150150

151151
private void ValidateWebAppName(string name)
152152
{
153+
#if !NETSTANDARD
153154
var available = WebsitesClient.WrappedWebsitesClient.GlobalModel.CheckNameAvailability(new ResourceNameAvailabilityRequest { Name = name, Type = "Site" });
154155
if (available.NameAvailable.HasValue && !available.NameAvailable.Value)
155156
{
156157
throw new InvalidOperationException(string.Format("Website name '{0}' is not available. Please try a different name.", name));
157158
}
159+
#else
160+
var available = WebsitesClient.WrappedWebsitesClient.CheckNameAvailability(name,"Site");
161+
if (available.NameAvailable.HasValue && !available.NameAvailable.Value)
162+
{
163+
throw new InvalidOperationException(string.Format("Website name '{0}' is not available. Please try a different name.", name));
164+
}
165+
#endif
158166
}
159167

160168
public void CreateWithClonedWebApp()
@@ -202,7 +210,7 @@ public void CreateWithClonedWebApp()
202210
CloneSlots(slotNames);
203211
}
204212
}
205-
213+
#if !NETSTANDARD
206214
private async Task<ServerFarmWithRichSku> GetDefaultServerFarm(string location)
207215
{
208216
var websiteLocation = string.IsNullOrWhiteSpace(location) ? new LocationConstraint() : new LocationConstraint(location);
@@ -225,6 +233,31 @@ private async Task<ServerFarmWithRichSku> GetDefaultServerFarm(string location)
225233

226234
return defaultFarm;
227235
}
236+
#else
237+
private async Task<AppServicePlan> GetDefaultServerFarm(string location)
238+
{
239+
var websiteLocation = string.IsNullOrWhiteSpace(location) ? new LocationConstraint() : new LocationConstraint(location);
240+
var farmResources = await ResourcesClient.ResourceManagementClient.Resources.ListAsync(new ODataQuery<GenericResourceFilter>(r => r.ResourceType == "Microsoft.Web/serverFarms"));
241+
AppServicePlan defaultFarm = null;
242+
foreach (var resource in farmResources)
243+
{
244+
// Try to find a policy with Sku=Free and available site capacity
245+
var id = new ResourceIdentifier(resource.Id);
246+
var farm = await WebsitesClient.WrappedWebsitesClient.AppServicePlans.GetAsync(id.ResourceGroupName, id.ResourceName);
247+
if (websiteLocation.Match(farm.Location)
248+
&& string.Equals("free", farm.Sku?.Tier?.ToLower(), StringComparison.OrdinalIgnoreCase)
249+
&& farm.NumberOfSites < MaxFreeSites)
250+
{
251+
defaultFarm = farm;
252+
break;
253+
}
254+
255+
}
256+
257+
return defaultFarm;
258+
}
259+
260+
#endif
228261

229262
bool TryGetServerFarmFromResourceId(string serverFarm, out string resourceGroup, out string serverFarmName)
230263
{
@@ -269,7 +302,11 @@ public async Task CreateWithSimpleParameters(ICmdletAdapter adapter)
269302
if (farm != null)
270303
{
271304
planResourceGroup = farm.ResourceGroup;
305+
#if !NETSTANDARD
272306
planName = farm.ServerFarmWithRichSkuName;
307+
#else
308+
planName = farm.Name;
309+
#endif
273310
planRG = ResourceGroupStrategy.CreateResourceGroupConfig(planResourceGroup);
274311
}
275312
}
@@ -295,7 +332,11 @@ public async Task CreateWithSimpleParameters(ICmdletAdapter adapter)
295332
var scmHostName = output.EnabledHostNames.FirstOrDefault(s => s.Contains(".scm."));
296333
if (!string.IsNullOrWhiteSpace(scmHostName))
297334
{
335+
#if !NETSTANDARD
298336
var profile = await WebsitesClient.WrappedWebsitesClient.Sites.ListSitePublishingProfileXmlAsync(output.ResourceGroup, output.SiteName, new CsmPublishingProfileOptions { Format = "WebDeploy" });
337+
#else
338+
var profile = await WebsitesClient.WrappedWebsitesClient.WebApps.ListPublishingProfileXmlWithSecretsAsync(output.ResourceGroup, output.Name, new CsmPublishingProfileOptions { Format = "WebDeploy" });
339+
#endif
299340
var doc = new XmlDocument();
300341
doc.Load(profile);
301342
userName = doc.SelectSingleNode("//publishProfile[@publishMethod=\"MSDeploy\"]/@userName").Value;
@@ -318,7 +359,7 @@ public async Task CreateWithSimpleParameters(ICmdletAdapter adapter)
318359
else if (!string.IsNullOrWhiteSpace(userName) && !string.IsNullOrWhiteSpace(password))
319360
{
320361
await git.AddRemoteRepository("azure", $"https://{userName}:{password}@{scmHostName}");
321-
adapter.WriteVerboseAsync(Resources.GitRemoteMessage);
362+
adapter.WriteVerboseAsync(Microsoft.Azure.Commands.WebApps.Properties.Resources.GitRemoteMessage);
322363
newOutput.GitRemoteName = "azure";
323364
}
324365
}
@@ -328,9 +369,8 @@ public async Task CreateWithSimpleParameters(ICmdletAdapter adapter)
328369
{
329370
// do not write errors for problems with adding git repository
330371
var repoPath = GitRepositoryPath ?? adapter?.SessionState?.Path?.CurrentFileSystemLocation?.Path;
331-
adapter.WriteWarningAsync(String.Format(Resources.GitRemoteAddFailure, repoPath, exception.Message));
372+
adapter.WriteWarningAsync(String.Format(Microsoft.Azure.Commands.WebApps.Properties.Resources.GitRemoteAddFailure, repoPath, exception.Message));
332373
}
333-
334374
adapter.WriteObjectAsync(output);
335375
}
336376

src/ResourceManager/Websites/Commands.Websites/Models.WebApp/PSSite.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public PSSite(Site other)
2626
name: other.Name,
2727
type: other.Type,
2828
tags: other.Tags,
29+
#if !NETSTANDARD
2930
siteName: other.SiteName,
31+
#endif
3032
state: other.State,
3133
hostNames: other.HostNames,
3234
repositorySiteName: other.RepositorySiteName,

src/ResourceManager/Websites/Commands.Websites/Strategies/ExternalCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public ExternalCommand(PathIntrinsics pathIntrinsics, string commandName, string
3737
WorkingDirectory = PathInfo.GetUnresolvedProviderPathFromPSPath(workingDirectory);
3838
if (!Directory.Exists(WorkingDirectory))
3939
{
40-
throw new ArgumentOutOfRangeException(nameof(workingDirectory), string.Format(Resources.GitDirectoryDoesNotExist, workingDirectory));
40+
throw new ArgumentOutOfRangeException(nameof(workingDirectory), string.Format(Microsoft.Azure.Commands.WebApps.Properties.Resources.GitDirectoryDoesNotExist, workingDirectory));
4141
}
4242
}
4343
}

src/ResourceManager/Websites/Commands.Websites/Strategies/GitCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public override string InstallationInstructions
3434
{
3535
get
3636
{
37-
return Resources.GitInstallMessage;
37+
return Microsoft.Azure.Commands.WebApps.Properties.Resources.GitInstallMessage;
3838
}
3939
}
4040

src/ResourceManager/Websites/Commands.Websites/Strategies/ServerFarmStrategy.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Microsoft.Azure.Commands.Common.Strategies.WebApps
2020
{
2121
static class ServerFarmStrategy
2222
{
23+
#if !NETSTANDARD
2324
public static ResourceStrategy<ServerFarmWithRichSku> Strategy { get; } = AppServicePolicy.Create(
2425
provider: "serverFarms",
2526
getOperations: client => client.ServerFarms,
@@ -40,5 +41,28 @@ public static ResourceConfig<ServerFarmWithRichSku> CreateServerFarmConfig(
4041
Name = name,
4142
Sku = new SkuDescription {Tier = "Basic", Capacity = 1, Name = CmdletHelpers.GetSkuName("Basic", 1) }
4243
});
44+
#else
45+
public static ResourceStrategy<AppServicePlan> Strategy { get; } = AppServicePolicy.Create(
46+
provider: "serverFarms",
47+
getOperations: client => client.AppServicePlans,
48+
getAsync: (o, p) => o.GetAsync(p.ResourceGroupName, p.Name, p.CancellationToken),
49+
createOrUpdateAsync: (o, p) => o.CreateOrUpdateAsync(p.ResourceGroupName, p.Name, p.Model, cancellationToken: p.CancellationToken),
50+
createTime: _ => 5,
51+
compulsoryLocation: true);
52+
53+
public static ResourceConfig<AppServicePlan> CreateServerFarmConfig(
54+
this ResourceConfig<ResourceGroup> resourceGroup,
55+
string resourceGroupName,
56+
string name) => Strategy.CreateResourceConfig(
57+
resourceGroup,
58+
name,
59+
createModel: _ =>
60+
new AppServicePlan
61+
{
62+
Name = name,
63+
Sku = new SkuDescription { Tier = "Basic", Capacity = 1, Name = CmdletHelpers.GetSkuName("Basic", 1) }
64+
});
65+
66+
#endif
4367
}
4468
}

src/ResourceManager/Websites/Commands.Websites/Strategies/SiteStrategy.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Microsoft.Azure.Commands.Common.Strategies.WebApps
2020
{
2121
static class SiteStrategy
2222
{
23+
#if !NETSTANDARD
2324
public static ResourceStrategy<Site> Strategy { get; } = AppServicePolicy.Create(
2425
provider: "sites",
2526
getOperations: client => client.Sites,
@@ -40,5 +41,26 @@ public static ResourceConfig<Site> CreateSiteConfig(this ResourceConfig<Resource
4041
Name = siteName,
4142
ServerFarmId = engine.GetId(plan)
4243
});
44+
#else
45+
public static ResourceStrategy<Site> Strategy { get; } = AppServicePolicy.Create(
46+
provider: "sites",
47+
getOperations: client => client.WebApps,
48+
getAsync: (o, p) => o.GetAsync(p.ResourceGroupName, p.Name, p.CancellationToken),
49+
createOrUpdateAsync: (o, p) => o.CreateOrUpdateAsync(p.ResourceGroupName, p.Name, p.Model, cancellationToken: p.CancellationToken),
50+
createTime: _ => 20,
51+
compulsoryLocation: true);
52+
53+
public static ResourceConfig<Site> CreateSiteConfig(this ResourceConfig<ResourceGroup> resourceGroup,
54+
ResourceConfig<AppServicePlan> plan, string siteName) =>
55+
Strategy.CreateResourceConfig(
56+
resourceGroup,
57+
siteName,
58+
createModel: engine =>
59+
new Site
60+
{
61+
Name = siteName,
62+
ServerFarmId = engine.GetId(plan)
63+
});
64+
#endif
4365
}
4466
}

0 commit comments

Comments
 (0)