You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.7 KiB

2 years ago
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<string>("ports");
if (port == null)
{
var urls = configuration.GetValue<string>("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;
}
}