Browse Source

Resolve #1160 Change ports of templates to randoms on template creation.

pull/1187/head
maliming 7 years ago
parent
commit
88c6e286ee
  1. 9
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/Mvc/MvcTemplate.cs
  2. 8
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/MvcModule/MvcModuleTemplate.cs
  3. 107
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/TemplateRandomSslPortStep.cs
  4. 6
      templates/mvc-module/host/MyCompanyName.MyProjectName.HttpApi.Host/Properties/launchSettings.json
  5. 6
      templates/mvc-module/host/MyCompanyName.MyProjectName.IdentityServer/Properties/launchSettings.json
  6. 6
      templates/mvc-module/host/MyCompanyName.MyProjectName.Web.Host/Properties/launchSettings.json
  7. 6
      templates/mvc-module/host/MyCompanyName.MyProjectName.Web.Unified/Properties/launchSettings.json
  8. 8
      templates/mvc/src/MyCompanyName.MyProjectName.HttpApi.Host/Properties/launchSettings.json
  9. 2
      templates/mvc/src/MyCompanyName.MyProjectName.HttpApi.Host/appsettings.json
  10. 8
      templates/mvc/src/MyCompanyName.MyProjectName.IdentityServer/Properties/launchSettings.json
  11. 2
      templates/mvc/src/MyCompanyName.MyProjectName.IdentityServer/appsettings.json
  12. 6
      templates/mvc/src/MyCompanyName.MyProjectName.Web.Host/Properties/launchSettings.json
  13. 6
      templates/mvc/src/MyCompanyName.MyProjectName.Web.Host/appsettings.json
  14. 6
      templates/mvc/src/MyCompanyName.MyProjectName.Web/Properties/launchSettings.json
  15. 4
      templates/mvc/src/MyCompanyName.MyProjectName.Web/appsettings.json

9
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/Mvc/MvcTemplate.cs

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using Volo.Abp.Cli.ProjectBuilding.Building; using Volo.Abp.Cli.ProjectBuilding.Building;
using Volo.Abp.Cli.ProjectBuilding.Building.Steps; using Volo.Abp.Cli.ProjectBuilding.Building.Steps;
using Volo.Abp.Cli.ProjectBuilding.Templates.MvcModule;
namespace Volo.Abp.Cli.ProjectBuilding.Templates.Mvc namespace Volo.Abp.Cli.ProjectBuilding.Templates.Mvc
{ {
@ -24,6 +25,14 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.Mvc
SwitchDatabaseProvider(context, steps); SwitchDatabaseProvider(context, steps);
DeleteUnrelatedProjects(context, steps); DeleteUnrelatedProjects(context, steps);
steps.Add(new TemplateRandomSslPortStep(new List<string>
{
"https://localhost:44300",
"https://localhost:44301",
"https://localhost:44302",
"https://localhost:44303"
}));
return steps; return steps;
} }

8
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/MvcModule/MvcModuleTemplate.cs

@ -23,6 +23,14 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.MvcModule
DeleteUnrelatedProjects(context, steps); DeleteUnrelatedProjects(context, steps);
steps.Add(new TemplateRandomSslPortStep(new List<string>
{
"https://localhost:44300",
"https://localhost:44301",
"https://localhost:44302",
"https://localhost:44303"
}));
return steps; return steps;
} }

107
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/TemplateRandomSslPortStep.cs

@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Volo.Abp.Cli.ProjectBuilding.Building;
namespace Volo.Abp.Cli.ProjectBuilding.Templates
{
public class TemplateRandomSslPortStep : ProjectBuildPipelineStep
{
private readonly int _minSslPort;
private readonly int _maxSslPort;
private readonly List<string> _buildInSslUrls;
public TemplateRandomSslPortStep(List<string> buildInSslSslUrls, int minSslPort = 44300,
int maxSslPort = 44399)
{
_buildInSslUrls = buildInSslSslUrls;
_minSslPort = minSslPort;
_maxSslPort = maxSslPort;
}
public override void Execute(ProjectBuildContext context)
{
var launchSettings = context.Files.Where(x =>
!x.IsDirectory && x.Name.EndsWith("launchSettings.json", StringComparison.InvariantCultureIgnoreCase))
.ToList();
var appSettings = context.Files.Where(x =>
!x.IsDirectory && x.Name.EndsWith("appSettings.json", StringComparison.InvariantCultureIgnoreCase))
.ToList();
var excludePorts = new List<string>();
excludePorts.AddRange(_buildInSslUrls.Select(GetUrlPort).ToList());
foreach (var buildInUrl in _buildInSslUrls)
{
var newPort = GetRandomPort(excludePorts);
excludePorts.Add(newPort);
var buildInUrlWithoutPort = GetUrlWithoutPort(buildInUrl);
var buildInUrlPort = GetUrlPort(buildInUrl);
foreach (var launchSetting in launchSettings)
{
launchSetting.NormalizeLineEndings();
var launchSettingLines = launchSetting.GetLines();
for (var i = 0; i < launchSettingLines.Length; i++)
{
if (launchSettingLines[i].Contains($"{buildInUrl}"))
{
launchSettingLines[i] = launchSettingLines[i].Replace($"{buildInUrl}", $"{buildInUrlWithoutPort}:{newPort}");
}
if (launchSettingLines[i].Contains($"\"sslPort\": {buildInUrlPort}"))
{
launchSettingLines[i] = launchSettingLines[i]
.Replace($"\"sslPort\": {buildInUrlPort}", $"\"sslPort\": {newPort}");
}
}
launchSetting.SetLines(launchSettingLines);
foreach (var appSetting in appSettings)
{
appSetting.NormalizeLineEndings();
var appSettingLines = appSetting.GetLines();
for (var i = 0; i < appSettingLines.Length; i++)
{
if (appSettingLines[i].Contains(buildInUrl))
{
appSettingLines[i] = appSettingLines[i].Replace(buildInUrl, $"{buildInUrlWithoutPort}:{newPort}");
}
}
appSetting.SetLines(appSettingLines);
}
}
}
}
private string GetRandomPort(IReadOnlyCollection<string> excludePort = null)
{
var ports = Enumerable.Range(_minSslPort, _maxSslPort).Select(p => p.ToString());
return RandomHelper.GetRandomOfList(excludePort != null
? ports.Except(excludePort).ToList()
: ports.ToList());
}
private string GetUrlPort(string url)
{
var match = Regex.Match(url, @":(\d+)");
return match.Success ? match.Groups[1].Value : "";
}
private string GetUrlWithoutPort(string url)
{
var match = Regex.Match(url, @"(^.+):");
return match.Success ? match.Groups[1].Value : "";
}
}
}

6
templates/mvc-module/host/MyCompanyName.MyProjectName.HttpApi.Host/Properties/launchSettings.json

@ -3,8 +3,8 @@
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:57992", "applicationUrl": "https://localhost:44300",
"sslPort": 44300 //44300 to 44399 (inclusive) "sslPort": 44300
} }
}, },
"profiles": { "profiles": {
@ -18,7 +18,7 @@
"MyCompanyName.MyProjectName.DemoApp": { "MyCompanyName.MyProjectName.DemoApp": {
"commandName": "Project", "commandName": "Project",
"launchBrowser": true, "launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000", "applicationUrl": "https://localhost:44300",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }

6
templates/mvc-module/host/MyCompanyName.MyProjectName.IdentityServer/Properties/launchSettings.json

@ -3,8 +3,8 @@
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:61517", "applicationUrl": "https://localhost:44301",
"sslPort": 44301 //44300 to 44399 (inclusive) "sslPort": 44301
} }
}, },
"profiles": { "profiles": {
@ -18,7 +18,7 @@
"IdentityServerHost": { "IdentityServerHost": {
"commandName": "Project", "commandName": "Project",
"launchBrowser": true, "launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000", "applicationUrl": "https://localhost:44301",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }

6
templates/mvc-module/host/MyCompanyName.MyProjectName.Web.Host/Properties/launchSettings.json

@ -3,8 +3,8 @@
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:55953", "applicationUrl": "https://localhost:44302",
"sslPort": 44302 //44300 to 44399 (inclusive) "sslPort": 44302
} }
}, },
"profiles": { "profiles": {
@ -18,7 +18,7 @@
"MyCompanyName.MyProjectName.Web.Host": { "MyCompanyName.MyProjectName.Web.Host": {
"commandName": "Project", "commandName": "Project",
"launchBrowser": true, "launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000", "applicationUrl": "https://localhost:44302",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }

6
templates/mvc-module/host/MyCompanyName.MyProjectName.Web.Unified/Properties/launchSettings.json

@ -3,8 +3,8 @@
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:57891", "applicationUrl": "https://localhost:44303",
"sslPort": 44303 //44300 to 44399 (inclusive) "sslPort": 44303
} }
}, },
"profiles": { "profiles": {
@ -18,7 +18,7 @@
"MyCompanyName.MyProjectName.DemoApp": { "MyCompanyName.MyProjectName.DemoApp": {
"commandName": "Project", "commandName": "Project",
"launchBrowser": true, "launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000", "applicationUrl": "https://localhost:44303",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }

8
templates/mvc/src/MyCompanyName.MyProjectName.HttpApi.Host/Properties/launchSettings.json

@ -1,10 +1,10 @@
{ {
"iisSettings": { "iisSettings": {
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:50904", "applicationUrl": "https://localhost:44300",
"sslPort": 44395 "sslPort": 44300
} }
}, },
"profiles": { "profiles": {
@ -18,7 +18,7 @@
"MyCompanyName.MyProjectName.HttpApi.Host": { "MyCompanyName.MyProjectName.HttpApi.Host": {
"commandName": "Project", "commandName": "Project",
"launchBrowser": true, "launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000", "applicationUrl": "https://localhost:44300",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }

2
templates/mvc/src/MyCompanyName.MyProjectName.HttpApi.Host/appsettings.json

@ -6,6 +6,6 @@
"Configuration": "127.0.0.1" "Configuration": "127.0.0.1"
}, },
"AuthServer": { "AuthServer": {
"Authority": "https://localhost:44348" "Authority": "https://localhost:44301"
} }
} }

8
templates/mvc/src/MyCompanyName.MyProjectName.IdentityServer/Properties/launchSettings.json

@ -1,10 +1,10 @@
{ {
"iisSettings": { "iisSettings": {
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:55993", "applicationUrl": "https://localhost:44301",
"sslPort": 44348 "sslPort": 44301
} }
}, },
"profiles": { "profiles": {
@ -18,7 +18,7 @@
"MyCompanyName.MyProjectName.IdentityServer": { "MyCompanyName.MyProjectName.IdentityServer": {
"commandName": "Project", "commandName": "Project",
"launchBrowser": true, "launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000", "applicationUrl": "https://localhost:44301",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }

2
templates/mvc/src/MyCompanyName.MyProjectName.IdentityServer/appsettings.json

@ -1,5 +1,5 @@
{ {
"AppSelfUrl": "https://localhost:44348", "AppSelfUrl": "https://localhost:44301",
"ConnectionStrings": { "ConnectionStrings": {
"Default": "Server=localhost;Database=MyProjectName;Trusted_Connection=True;MultipleActiveResultSets=true" "Default": "Server=localhost;Database=MyProjectName;Trusted_Connection=True;MultipleActiveResultSets=true"
}, },

6
templates/mvc/src/MyCompanyName.MyProjectName.Web.Host/Properties/launchSettings.json

@ -3,8 +3,8 @@
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:55953", "applicationUrl": "https://localhost:44302",
"sslPort": 44314 "sslPort": 44302
} }
}, },
"profiles": { "profiles": {
@ -18,7 +18,7 @@
"MyCompanyName.MyProjectName.Web.Host": { "MyCompanyName.MyProjectName.Web.Host": {
"commandName": "Project", "commandName": "Project",
"launchBrowser": true, "launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000", "applicationUrl": "https://localhost:44302",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }

6
templates/mvc/src/MyCompanyName.MyProjectName.Web.Host/appsettings.json

@ -1,15 +1,15 @@
{ {
"AppSelfUrl": "https://localhost:44314", "AppSelfUrl": "https://localhost:44302",
"RemoteServices": { "RemoteServices": {
"Default": { "Default": {
"BaseUrl": "https://localhost:44395/" "BaseUrl": "https://localhost:44300/"
} }
}, },
"Redis": { "Redis": {
"Configuration": "127.0.0.1" "Configuration": "127.0.0.1"
}, },
"AuthServer": { "AuthServer": {
"Authority": "https://localhost:44348", "Authority": "https://localhost:44301",
"ClientId": "MyProjectName_Web", "ClientId": "MyProjectName_Web",
"ClientSecret": "1q2w3e*" "ClientSecret": "1q2w3e*"
} }

6
templates/mvc/src/MyCompanyName.MyProjectName.Web/Properties/launchSettings.json

@ -3,8 +3,8 @@
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:53929/", "applicationUrl": "https://localhost:44303/",
"sslPort": 44361 "sslPort": 44303
} }
}, },
"profiles": { "profiles": {
@ -21,7 +21,7 @@
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
}, },
"applicationUrl": "http://localhost:53932/" "applicationUrl": "https://localhost:44303/"
} }
} }
} }

4
templates/mvc/src/MyCompanyName.MyProjectName.Web/appsettings.json

@ -1,10 +1,10 @@
{ {
"AppSelfUrl": "https://localhost:44361", "AppSelfUrl": "https://localhost:44303",
"ConnectionStrings": { "ConnectionStrings": {
"Default": "Server=localhost;Database=MyProjectName;Trusted_Connection=True;MultipleActiveResultSets=true" "Default": "Server=localhost;Database=MyProjectName;Trusted_Connection=True;MultipleActiveResultSets=true"
}, },
"AuthServer": { "AuthServer": {
"Authority": "https://localhost:44361" "Authority": "https://localhost:44301"
}, },
"IdentityServer": { "IdentityServer": {
"Clients": { "Clients": {

Loading…
Cancel
Save