using System; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Volo.Abp; using Volo.Abp.Modularity; namespace Win_in.Sfs.Shared.Host; public static class ServiceConfigurationContextExtensions { public static void SetConsoleTitleOfWebApp( this ServiceConfigurationContext context, string appName = null, ConsoleColor backgroundColor = ConsoleColor.Black, ConsoleColor foregroundColor = ConsoleColor.White) { var configuration = context.Services.GetConfiguration(); var env = context.Services.GetHostingEnvironment(); if (string.IsNullOrEmpty(appName)) { appName = env.ApplicationName; } var port = configuration.GetValue("ports"); if (port == null) { var urls = configuration.GetValue("urls"); if (urls != null) { var arr = urls.Split(':'); port = arr.Length > 1 ? arr[1] : "80"; } else { port = ""; } } Console.Title = $"{appName} {port} {env.EnvironmentName}"; Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; } public static void SetConsoleTitleOfConsoleApp( this ServiceConfigurationContext context, string appName, string envName = "", ConsoleColor backgroundColor = ConsoleColor.Black, ConsoleColor foregroundColor = ConsoleColor.White) { Console.Title = $"{appName} {envName}"; Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; } }