Browse Source

Close Suite after code generation #12231

pull/12231/head
Ebicoglu 5 years ago
parent
commit
e3c4c5ebe2
  1. 52
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs

52
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs

@ -36,6 +36,8 @@ public class SuiteCommand : IConsoleCommand, ITransientDependency
private const string SuitePackageName = "Volo.Abp.Suite"; private const string SuitePackageName = "Volo.Abp.Suite";
public ILogger<SuiteCommand> Logger { get; set; } public ILogger<SuiteCommand> Logger { get; set; }
private const string AbpSuiteHost = "http://localhost:3000";
public SuiteCommand( public SuiteCommand(
AbpNuGetIndexUrlService nuGetIndexUrlService, AbpNuGetIndexUrlService nuGetIndexUrlService,
NuGetService nuGetService, NuGetService nuGetService,
@ -68,9 +70,14 @@ public class SuiteCommand : IConsoleCommand, ITransientDependency
case "generate": case "generate":
await InstallSuiteIfNotInstalledAsync(); await InstallSuiteIfNotInstalledAsync();
var suiteProcess = RunSuiteTemporary(); var suiteProcess = StartSuite();
await GenerateCrudOnSuiteAsync(commandLineArgs); System.Threading.Thread.Sleep(500); //wait for initialization of the app
suiteProcess?.Kill(); await GenerateCrudPageAsync(commandLineArgs);
if (suiteProcess != null)
{
KillSuite();
}
break; break;
case "install": case "install":
@ -88,7 +95,7 @@ public class SuiteCommand : IConsoleCommand, ITransientDependency
} }
} }
private async Task GenerateCrudOnSuiteAsync(CommandLineArgs args) private async Task GenerateCrudPageAsync(CommandLineArgs args)
{ {
var entityFile = args.Options.GetOrNull(Options.Crud.Entity.Short, Options.Crud.Entity.Long); var entityFile = args.Options.GetOrNull(Options.Crud.Entity.Short, Options.Crud.Entity.Long);
var solutionFile = args.Options.GetOrNull(Options.Crud.Solution.Short, Options.Crud.Solution.Long); var solutionFile = args.Options.GetOrNull(Options.Crud.Solution.Short, Options.Crud.Solution.Long);
@ -98,7 +105,7 @@ public class SuiteCommand : IConsoleCommand, ITransientDependency
{ {
throw new UserFriendlyException("Invalid Arguments!"); throw new UserFriendlyException("Invalid Arguments!");
} }
Logger.LogInformation("Generating CRUD Page..."); Logger.LogInformation("Generating CRUD Page...");
var client = _cliHttpClientFactory.CreateClient(false); var client = _cliHttpClientFactory.CreateClient(false);
@ -108,7 +115,7 @@ public class SuiteCommand : IConsoleCommand, ITransientDependency
{ {
return; return;
} }
var entityContent = new StringContent( var entityContent = new StringContent(
File.ReadAllText(entityFile), File.ReadAllText(entityFile),
Encoding.UTF8, Encoding.UTF8,
@ -116,7 +123,7 @@ public class SuiteCommand : IConsoleCommand, ITransientDependency
); );
var responseMessage = await client.PostAsync( var responseMessage = await client.PostAsync(
$"http://localhost:3000/api/abpSuite/crudPageGenerator/{solutionId.ToString()}/save-and-generate-entity", $"{AbpSuiteHost}/api/abpSuite/crudPageGenerator/{solutionId.ToString()}/save-and-generate-entity",
entityContent entityContent
); );
@ -128,7 +135,7 @@ public class SuiteCommand : IConsoleCommand, ITransientDependency
} }
else else
{ {
Logger.LogInformation("CRUD page generated."); Logger.LogInformation("CRUD page generation successfully completed.");
} }
} }
@ -148,7 +155,7 @@ public class SuiteCommand : IConsoleCommand, ITransientDependency
var response = await responseMessage.Content.ReadAsStringAsync(); var response = await responseMessage.Content.ReadAsStringAsync();
JArray solutions; JArray solutions;
try try
{ {
solutions = (JArray)(JObject.Parse(response)["solutions"]); solutions = (JArray)(JObject.Parse(response)["solutions"]);
@ -185,7 +192,7 @@ public class SuiteCommand : IConsoleCommand, ITransientDependency
); );
var response = await responseMessage.Content.ReadAsStringAsync(); var response = await responseMessage.Content.ReadAsStringAsync();
try try
{ {
return Guid.Parse(JObject.Parse(response)["id"].ToString()); return Guid.Parse(JObject.Parse(response)["id"].ToString());
@ -396,14 +403,13 @@ public class SuiteCommand : IConsoleCommand, ITransientDependency
CmdHelper.RunCmd("abp-suite"); CmdHelper.RunCmd("abp-suite");
} }
private Process RunSuiteTemporary() private Process StartSuite()
{ {
try try
{ {
if (!GlobalToolHelper.IsGlobalToolInstalled("abp-suite")) if (!GlobalToolHelper.IsGlobalToolInstalled("abp-suite"))
{ {
Logger.LogWarning( Logger.LogWarning("ABP Suite is not installed! To install it you can run the command: \"abp suite install\"");
"ABP Suite is not installed! To install it you can run the command: \"abp suite install\"");
return null; return null;
} }
} }
@ -427,6 +433,26 @@ public class SuiteCommand : IConsoleCommand, ITransientDependency
return endpoints.Any(e => e.Port == 3000); return endpoints.Any(e => e.Port == 3000);
} }
private void KillSuite()
{
try
{
var suiteProcesses = (from p in Process.GetProcesses()
where p.ProcessName.ToLower().Contains("abp-suite")
select p);
foreach (var suiteProcess in suiteProcesses)
{
suiteProcess.Kill();
Logger.LogInformation("Suite closed.");
}
}
catch (Exception ex)
{
Logger.LogInformation("Cannot close Suite." + ex.Message);
}
}
public string GetUsageInfo() public string GetUsageInfo()
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();

Loading…
Cancel
Save