From 2da11c7365160ae073bbc41c03eb2da2a6d87e84 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 14 Feb 2023 10:55:51 +0300 Subject: [PATCH] Create SuiteAppSettingsService.cs --- .../Services/SuiteAppSettingsService.cs | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/SuiteAppSettingsService.cs diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/SuiteAppSettingsService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/SuiteAppSettingsService.cs new file mode 100644 index 0000000000..c453c35349 --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/SuiteAppSettingsService.cs @@ -0,0 +1,73 @@ +using System; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Newtonsoft.Json.Linq; +using Volo.Abp.Cli.Utils; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.Cli.Commands.Services; + +public class SuiteAppSettingsService : ITransientDependency +{ + private const int DefaultPort = 3000; + + public CmdHelper CmdHelper { get; } + + public SuiteAppSettingsService(CmdHelper cmdHelper) + { + CmdHelper = cmdHelper; + } + public async Task GetSuitePortAsync(string version) + { + var filePath = GetFilePathOrNull(version); + + if (filePath == null) + { + return DefaultPort; + } + + var content = File.ReadAllText(filePath); + + var contentAsJson = JObject.Parse(content); + + var url = contentAsJson["AbpSuite"]?["ApplicationUrl"]?.ToString(); + + if (url == null) + { + return DefaultPort; + } + + return Convert.ToInt32(url.Split(":").Last()); + } + + private string GetFilePathOrNull(string version) + { + var suiteVersion = version; + + if (suiteVersion == null) + { + return null; + } + + var path = Path.Combine( + "%USERPROFILE%", + ".dotnet", + "tools", + ".store", + "volo.abp.suite", + suiteVersion, + "volo.abp.suite", + suiteVersion, + "content", + "appsettings.json" + ); + + if (!File.Exists(path)) + { + return null; + } + + return path; + } +} \ No newline at end of file