From c0b6a75c79f5f9f6423bf72222840105a41ad093 Mon Sep 17 00:00:00 2001
From: Linlccc <1610450962@qq.com>
Date: Wed, 23 Feb 2022 18:14:26 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BB=A5=E8=A1=A8=E6=A0=BC?=
=?UTF-8?q?=E6=96=B9=E5=BC=8F=E8=BE=93=E5=87=BA=E6=8E=A7=E5=88=B6=E5=8F=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Blog.Core.Api/Startup.cs | 3 +-
.../Helper/{ => Console}/ConsoleHelper.cs | 43 ++-
.../Helper/Console/Table/ColumnShowFormat.cs | 39 +++
.../Helper/Console/Table/ConsoleTable.cs | 330 ++++++++++++++++++
.../Helper/Console/Table/DrawTableInfo.cs | 35 ++
.../Helper/Console/Table/TableExtension.cs | 151 ++++++++
.../Helper/Console/Table/TableStyle.cs | 57 +++
.../RabbitMQPersistent/EventBusRabbitMQ.cs | 2 +-
.../BlogQueryIntegrationEventHandler.cs | 2 +-
.../NacosConfig/NacosListenNamingTask.cs | 3 +-
.../ServiceExtensions/AppConfigSetup.cs | 94 +++++
.../HostedService/Job1TimedService.cs | 2 +-
.../HostedService/Job2TimedService.cs | 2 +-
13 files changed, 735 insertions(+), 28 deletions(-)
rename Blog.Core.Common/Helper/{ => Console}/ConsoleHelper.cs (60%)
create mode 100644 Blog.Core.Common/Helper/Console/Table/ColumnShowFormat.cs
create mode 100644 Blog.Core.Common/Helper/Console/Table/ConsoleTable.cs
create mode 100644 Blog.Core.Common/Helper/Console/Table/DrawTableInfo.cs
create mode 100644 Blog.Core.Common/Helper/Console/Table/TableExtension.cs
create mode 100644 Blog.Core.Common/Helper/Console/Table/TableStyle.cs
diff --git a/Blog.Core.Api/Startup.cs b/Blog.Core.Api/Startup.cs
index 4148297..bc3d779 100644
--- a/Blog.Core.Api/Startup.cs
+++ b/Blog.Core.Api/Startup.cs
@@ -64,7 +64,8 @@ namespace Blog.Core
services.AddSwaggerSetup();
services.AddJobSetup();
services.AddHttpContextSetup();
- services.AddAppConfigSetup(Env);
+ //services.AddAppConfigSetup(Env);
+ services.AddAppTableConfigSetup(Env);//表格打印配置
services.AddHttpApi();
services.AddRedisInitMqSetup();
diff --git a/Blog.Core.Common/Helper/ConsoleHelper.cs b/Blog.Core.Common/Helper/Console/ConsoleHelper.cs
similarity index 60%
rename from Blog.Core.Common/Helper/ConsoleHelper.cs
rename to Blog.Core.Common/Helper/Console/ConsoleHelper.cs
index f0faef5..036c476 100644
--- a/Blog.Core.Common/Helper/ConsoleHelper.cs
+++ b/Blog.Core.Common/Helper/Console/ConsoleHelper.cs
@@ -1,15 +1,25 @@
using System;
-namespace Blog.Core.Common.Helper
+namespace Blog.Core.Common
{
public static class ConsoleHelper
{
+ private static readonly object _objLock = new();
+
+ ///
+ /// 在控制台输出
+ ///
+ /// 文本
+ /// 前颜色
public static void WriteColorLine(string str, ConsoleColor color)
{
- ConsoleColor currentForeColor = Console.ForegroundColor;
- Console.ForegroundColor = color;
- Console.WriteLine(str);
- Console.ForegroundColor = currentForeColor;
+ lock (_objLock)
+ {
+ ConsoleColor currentForeColor = Console.ForegroundColor;
+ Console.ForegroundColor = color;
+ Console.WriteLine(str);
+ Console.ForegroundColor = currentForeColor;
+ }
}
///
@@ -17,38 +27,27 @@ namespace Blog.Core.Common.Helper
///
/// 待打印的字符串
/// 想要打印的颜色
- public static void WriteErrorLine(this string str, ConsoleColor color = ConsoleColor.Red)
- {
- WriteColorLine(str, color);
- }
+ public static void WriteErrorLine(this string str, ConsoleColor color = ConsoleColor.Red)=> WriteColorLine(str, color);
///
/// 打印警告信息
///
/// 待打印的字符串
/// 想要打印的颜色
- public static void WriteWarningLine(this string str, ConsoleColor color = ConsoleColor.Yellow)
- {
- WriteColorLine(str, color);
- }
+ public static void WriteWarningLine(this string str, ConsoleColor color = ConsoleColor.Yellow)=> WriteColorLine(str, color);
+
///
/// 打印正常信息
///
/// 待打印的字符串
/// 想要打印的颜色
- public static void WriteInfoLine(this string str, ConsoleColor color = ConsoleColor.White)
- {
- WriteColorLine(str, color);
- }
+ public static void WriteInfoLine(this string str, ConsoleColor color = ConsoleColor.White)=> WriteColorLine(str, color);
+
///
/// 打印成功的信息
///
/// 待打印的字符串
/// 想要打印的颜色
- public static void WriteSuccessLine(this string str, ConsoleColor color = ConsoleColor.Green)
- {
- WriteColorLine(str, color);
- }
-
+ public static void WriteSuccessLine(this string str, ConsoleColor color = ConsoleColor.Green)=> WriteColorLine(str, color);
}
}
diff --git a/Blog.Core.Common/Helper/Console/Table/ColumnShowFormat.cs b/Blog.Core.Common/Helper/Console/Table/ColumnShowFormat.cs
new file mode 100644
index 0000000..0407025
--- /dev/null
+++ b/Blog.Core.Common/Helper/Console/Table/ColumnShowFormat.cs
@@ -0,0 +1,39 @@
+namespace System
+{
+ ///
+ /// 列显示格式信息
+ ///
+ public class ColumnShowFormat
+ {
+ public ColumnShowFormat(int index, int strLength, Alignment alignment)
+ {
+ Index = index;
+ StrLength = strLength;
+ Alignment = alignment;
+ }
+
+ ///
+ /// 索引,第几列数据
+ ///
+ public int Index { get; set; }
+
+ ///
+ /// 对其方式
+ ///
+ public Alignment Alignment { get; set; }
+
+ ///
+ /// 一列字符串长度
+ ///
+ public int StrLength { get; set; }
+ }
+
+ ///
+ /// 对其方式
+ ///
+ public enum Alignment
+ {
+ Left,
+ Right
+ }
+}
\ No newline at end of file
diff --git a/Blog.Core.Common/Helper/Console/Table/ConsoleTable.cs b/Blog.Core.Common/Helper/Console/Table/ConsoleTable.cs
new file mode 100644
index 0000000..b99a668
--- /dev/null
+++ b/Blog.Core.Common/Helper/Console/Table/ConsoleTable.cs
@@ -0,0 +1,330 @@
+using Blog.Core.Common;
+using Newtonsoft.Json.Linq;
+using Newtonsoft.Json;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace System
+{
+ public class ConsoleTable
+ {
+ #region 属性
+
+ ///
+ /// 表格头部字符串
+ ///
+ public string TitleString { get; set; }
+
+ ///
+ /// 表格的列
+ ///
+ public IList Columns
+ {
+ get
+ {
+ if (_columns == null) _columns = new List();
+ return _columns;
+ }
+ set
+ {
+ _columns = value;
+ _finalColumnWides = new List();
+ }
+ }
+
+ ///
+ /// 行
+ ///
+ public List Rows { get; set; } = new List();
+
+ ///
+ /// 列宽
+ ///
+ public List ColumnWides { get; set; } = new List();
+
+ ///
+ /// 空白字符数量
+ ///
+ public int ColumnBlankNum { get; set; } = 4;
+
+ ///
+ /// 对其方式
+ ///
+ public Alignment Alignment { get; set; } = Alignment.Left;
+
+ ///
+ /// 是否显示行数
+ ///
+ public bool EnableCount { get; set; } = false;
+
+ ///
+ /// 表格显示样式
+ /// 每次设置样子后就会重置 StyleInfo
+ ///
+ public TableStyle TableStyle
+ {
+ get
+ {
+ return _tableStyle;
+ }
+ set
+ {
+ if (_tableStyle == value) return;
+ _tableStyle = value;
+ _formatInfo = null;
+ }
+ }
+
+ #endregion 属性
+
+ #region 私有信息
+ private IList _columns;
+ private TableStyle _tableStyle;
+ private StyleInfo _formatInfo;
+ private List _columnShowFormats = new List();
+ private List _finalColumnWides = new List();
+
+ ///
+ /// 通过 Format 获得到表格显示样式
+ ///
+ private StyleInfo FormatInfo
+ {
+ get
+ {
+ if (_formatInfo == null)
+ _formatInfo = _tableStyle.GetFormatInfo();//得到样式信息
+ return _formatInfo;
+ }
+ set
+ {
+ _formatInfo = value;
+ }
+ }
+
+ ///
+ /// 每一列的宽度
+ ///
+ private List FinalColumnWides
+ {
+ get
+ {
+ if (_finalColumnWides is null || _finalColumnWides.Count < 1)
+ {
+ // 得到每一列最大的宽度
+ List _columnWides = Columns.GetColumnWides(Rows);
+ // 替换用户输入长度
+ ColumnWides ??= new List();
+ for (int i = 0; i < ColumnWides.Count; i++) _columnWides[i] = ColumnWides[i];
+ _finalColumnWides = _columnWides;
+ }
+ return _finalColumnWides;
+ }
+ }
+
+ ///
+ /// 每一列显示的基本信息
+ ///
+ private List ColumnShowFormats
+ {
+ get
+ {
+ if (_columnShowFormats.Count == 0)
+ {
+ for (int i = 0; i < Columns.Count; i++) _columnShowFormats.Add(new ColumnShowFormat(i, FinalColumnWides[i], Alignment));
+ }
+ return _columnShowFormats;
+ }
+ }
+
+ #endregion 私有信息
+
+ #region 配置数据
+
+ ///
+ /// 添加列
+ ///
+ /// 列明
+ /// 列的宽
+ ///
+ public ConsoleTable AddColumn(string columnName, int columnWide = 0)
+ {
+ Columns.Add(columnName);
+ columnWide = columnWide == 0 ? columnName.Length : columnWide;
+ _finalColumnWides.Add(columnWide);
+ return this;
+ }
+
+ ///
+ /// 添加行
+ ///
+ /// 该行数据
+ ///
+ public ConsoleTable AddRow(params string[] values)
+ {
+ _ = values ?? throw new ArgumentNullException(nameof(values));
+
+ Rows.Add(values);
+ return this;
+ }
+
+ ///
+ /// 加载 List 对象的数据
+ ///
+ ///
+ ///
+ ///
+ public static ConsoleTable From(IEnumerable values)
+ {
+ ConsoleTable table = new();
+
+ List columns = GetColumns().Where(c => !string.IsNullOrWhiteSpace(c)).ToList();
+ columns.ForEach(c =>
+ {
+ table.AddColumn(c);
+ });
+
+ values.ToList().ForEach(value =>
+ {
+ table.AddRow(columns.Select(c => GetColumnValue(value, c)).ToArray());
+ });
+
+ return table;
+ }
+
+ #endregion 配置数据
+
+ ///
+ /// 获取表格字符串
+ ///
+ ///
+ public override string ToString()
+ {
+ StringBuilder builder = new();
+
+ builder.AppendLine(GetHeader());
+ builder.AppendLine(GetExistData());
+ builder.AppendLine(GetEnd());
+
+ return builder.ToString();
+ }
+
+ ///
+ /// 绘制表格
+ ///
+ /// 样式
+ /// title颜色
+ public void Writer(ConsoleColor color = ConsoleColor.White)
+ {
+ ConsoleHelper.WriteColorLine(GetHeader(), color);
+ ConsoleHelper.WriteInfoLine(GetExistData());
+ ConsoleHelper.WriteColorLine(GetEnd(), color);
+ }
+
+ #region 帮助方法
+
+ ///
+ /// 获取完成头
+ ///
+ ///
+ public string GetHeader()
+ {
+ // 创建顶部和底部分隔线
+ string top_DownDividerdivider = FinalColumnWides.GetTopAndDwon(FormatInfo.AngleStr, ColumnBlankNum);
+ // 创建分隔线
+ string divider = FinalColumnWides.GetDivider(FormatInfo.AngleStr, ColumnBlankNum);
+ // 获取标题字符串
+ string tilte = FinalColumnWides.GetTitleStr(TitleString, ColumnBlankNum, FormatInfo.DelimiterStr);
+ // 得到头部字符串
+ string headers = ColumnShowFormats.FillFormatTostring(Columns.ToArray(), FormatInfo.DelimiterStr, ColumnBlankNum);
+
+ //绘制表格头
+ StringBuilder top = new();
+ if (FormatInfo.IsShowTop_Down_DataBorder) top.AppendLine(top_DownDividerdivider);
+ if (!string.IsNullOrWhiteSpace(tilte))
+ {
+ top.AppendLine(tilte);
+ top.AppendLine(divider);
+ }
+ top.AppendLine(headers);
+ top.AppendLine(divider);
+ return top.ToString().Trim();
+ }
+
+ ///
+ /// 获取现有数据
+ ///
+ ///
+ public string GetExistData()
+ {
+ // 创建分隔线
+ string divider = FinalColumnWides.GetDivider(FormatInfo.AngleStr, ColumnBlankNum);
+ // 得到每行数据的字符串
+ List rowStrs = Rows.Select(row => ColumnShowFormats.FillFormatTostring(row, FormatInfo.DelimiterStr, ColumnBlankNum)).ToList();
+ StringBuilder data = new();
+ for (int i = 0; i < rowStrs.Count; i++)
+ {
+ if (FormatInfo.IsShowTop_Down_DataBorder && i != 0) data.AppendLine(divider);
+ data.AppendLine(rowStrs[i]);
+ }
+ return data.ToString().Trim();
+ }
+
+ ///
+ /// 获取新行数据
+ ///
+ ///
+ ///
+ public string GetNewRow(string[] row)
+ {
+ if (row is null) return "";
+
+ Rows.Add(row);
+ //内容
+ StringBuilder data = new();
+ if (Rows.Count > 1) data.AppendLine(FinalColumnWides.GetDivider(FormatInfo.AngleStr, ColumnBlankNum));
+ data.AppendLine(ColumnShowFormats.FillFormatTostring(row, FormatInfo.DelimiterStr, ColumnBlankNum));
+ return data.ToString().Trim();
+ }
+
+ ///
+ /// 获取底
+ ///
+ ///
+ public string GetEnd()
+ {
+ StringBuilder down = new();
+ if (FormatInfo.IsShowTop_Down_DataBorder) down.AppendLine(FinalColumnWides.GetTopAndDwon(FormatInfo.AngleStr, ColumnBlankNum));
+ if (EnableCount) down.AppendLine($" Count: {Rows.Count}");
+ return down.ToString().Trim();
+ }
+
+ ///
+ /// 获取列名
+ ///
+ ///
+ ///
+ private static IEnumerable GetColumns()
+ {
+ return typeof(T).GetProperties().Select(x => x.Name).ToArray();
+ }
+
+ ///
+ /// 获取列值
+ ///
+ /// 类型
+ /// 数据
+ /// 列名
+ ///
+ private static string GetColumnValue(T obj, string column)
+ {
+ if (obj == null) return null;
+
+ JObject o = obj as JObject ?? (JObject)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(obj));
+
+ return o.GetValue(column).ToString();
+ }
+
+ #endregion 帮助方法
+ }
+}
\ No newline at end of file
diff --git a/Blog.Core.Common/Helper/Console/Table/DrawTableInfo.cs b/Blog.Core.Common/Helper/Console/Table/DrawTableInfo.cs
new file mode 100644
index 0000000..850f4ea
--- /dev/null
+++ b/Blog.Core.Common/Helper/Console/Table/DrawTableInfo.cs
@@ -0,0 +1,35 @@
+using System.Collections.Generic;
+
+namespace System
+{
+ ///
+ /// 绘制表格需要的信息
+ ///
+ public class DrawTableInfo
+ {
+ ///
+ /// 顶部和底部字符串分隔线
+ ///
+ public string Top_DownDivider { get; set; }
+
+ ///
+ /// 分隔线
+ ///
+ public string Divider { get; set; }
+
+ ///
+ /// 标题
+ ///
+ public string Title { get; set; }
+
+ ///
+ /// 头部
+ ///
+ public string Header { get; set; }
+
+ ///
+ /// 数据
+ ///
+ public List Data { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Blog.Core.Common/Helper/Console/Table/TableExtension.cs b/Blog.Core.Common/Helper/Console/Table/TableExtension.cs
new file mode 100644
index 0000000..6e26a71
--- /dev/null
+++ b/Blog.Core.Common/Helper/Console/Table/TableExtension.cs
@@ -0,0 +1,151 @@
+using Blog.Core;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.RegularExpressions;
+
+namespace System
+{
+ public static class TableExtension
+ {
+ ///
+ /// 按照现有数据计算每列最大宽度
+ ///
+ /// 列信息
+ /// 现有行数据
+ /// 每一列显示宽度
+ public static List GetColumnWides(this IList columns, IList rows)
+ {
+ List columnLengths = columns.Select((t, i) =>
+ rows.Select(x => x[i])//得到所有行当前列的数据
+ .Union(new[] { columns[i] })//连接当前列标题
+ .Where(x => x != null)
+ .Select(x => x.ObjToString().FullHalfLength())//得到该列每一行的字符串长度(计算中文占用两格)
+ .Max())//到该列中长度最大的以列
+ .ToList();
+ return columnLengths;
+ }
+
+ ///
+ /// 将填充格式转成字符串
+ /// 表头和数据行会用到
+ ///
+ /// 一行的显示格式信息
+ /// 一行要显示的数据
+ /// 间隔符
+ /// 每列留白数
+ ///
+ public static string FillFormatTostring(this List format, string[] objs, string delimiterStr, int columnBlankNum)
+ {
+ string formatStr = string.Empty;
+ format.ForEach(f =>
+ {
+ string ali = f.Alignment == Alignment.Right ? "" : "-";
+ string val = objs[f.Index].ObjToString();
+ if (val.Length > f.StrLength)
+ {
+ //val = val[0..f.StrLength];
+ //val = val[0..(val.Length - val.GetChineseText().Length)];
+ objs[f.Index] = "...";//标记超出长度
+ }
+
+ if (!string.IsNullOrWhiteSpace(formatStr)) formatStr += $"{"".PadLeft(columnBlankNum, ' ')}";
+ int alignmentStrLength = Math.Max(f.StrLength - objs[f.Index].ObjToString().GetChineseText().Length, 0);//对其填充空格数量
+ formatStr += $"{delimiterStr}{"".PadLeft(columnBlankNum, ' ')}{{{f.Index},{ali}{alignmentStrLength}}}";
+ });
+ formatStr += $"{"".PadLeft(columnBlankNum, ' ')}{delimiterStr}";
+ return string.Format(formatStr, objs);
+ }
+
+ ///
+ /// 获取title 字符串
+ ///
+ /// >
+ /// 标题字符串信息
+ /// 列两端留白数
+ /// 每列之间分割字符串
+ ///
+ public static string GetTitleStr(this List columnWides, string titleStr, int columnBlankNum, string delimiterStr)
+ {
+ if (string.IsNullOrWhiteSpace(titleStr)) return "";
+ //一行的宽度
+ int rowWide = columnWides.Sum() + columnWides.Count * 2 * columnBlankNum + columnWides.Count + 1;
+ int blankNum = (rowWide - titleStr.FullHalfLength()) / 2 - 1;
+ string tilte = $"{delimiterStr}{"".PadLeft(blankNum, ' ')}{titleStr}{"".PadLeft(blankNum, ' ')}{delimiterStr}";
+ if (tilte.FullHalfLength() != rowWide) tilte = tilte.Replace($" {delimiterStr}", $" {delimiterStr}");
+ return tilte;
+ }
+
+ ///
+ /// 获取每行之间的分割行字符串
+ ///
+ /// 列宽信息
+ /// 每列之间分割字符串
+ /// 列两端留白数
+ ///
+ public static string GetDivider(this List columnWides, string angleStr, int columnBlankNum)
+ {
+ string divider = "";
+ columnWides.ForEach(i =>
+ {
+ divider += $"{angleStr}{"".PadRight(i + columnBlankNum * 2, '-')}";
+ });
+ divider += angleStr;
+ return divider;
+ }
+
+ ///
+ /// 获取头部和底部字符串
+ ///
+ /// 列宽信息
+ /// 每列之间分割字符串
+ /// 列两端留白数
+ ///
+ public static string GetTopAndDwon(this List columnWides, string angleStr, int columnBlankNum)
+ {
+ string top_DownDividerdivider = "";
+ columnWides.ForEach(i =>
+ {
+ if (string.IsNullOrWhiteSpace(top_DownDividerdivider)) top_DownDividerdivider += $"{angleStr}{"".PadRight(i + columnBlankNum * 2, '-')}";
+ else top_DownDividerdivider += $"{"".PadRight(i + columnBlankNum * 2 + 1, '-')}";
+ });
+ top_DownDividerdivider += angleStr;
+ return top_DownDividerdivider;
+ }
+
+ ///
+ /// 获取表格显示样式
+ ///
+ ///
+ ///
+ public static StyleInfo GetFormatInfo(this TableStyle format)
+ {
+ return format switch
+ {
+ TableStyle.Default => new StyleInfo("|", true, "-"),
+ TableStyle.MarkDown => new StyleInfo("|", false, "|"),
+ TableStyle.Alternative => new StyleInfo("|", true, "+"),
+ TableStyle.Minimal => new StyleInfo("", false, "-"),
+ _ => new StyleInfo(),
+ };
+ }
+
+ ///
+ /// 获取文本长度,区分全角半角
+ /// 全角算两个字符
+ ///
+ ///
+ public static int FullHalfLength(this string text)
+ {
+ return Regex.Replace(text, "[^\x00-\xff]", "**").Length;
+ //可使用以下方法,不过要看在不同编码中字节数
+ //return Encoding.Default.GetByteCount(text);
+ }
+
+ ///
+ /// 获取中文文本
+ ///
+ ///
+ ///
+ public static string GetChineseText(this string text) => Regex.Replace(text, "[\x00-\xff]", "");
+ }
+}
\ No newline at end of file
diff --git a/Blog.Core.Common/Helper/Console/Table/TableStyle.cs b/Blog.Core.Common/Helper/Console/Table/TableStyle.cs
new file mode 100644
index 0000000..20a662d
--- /dev/null
+++ b/Blog.Core.Common/Helper/Console/Table/TableStyle.cs
@@ -0,0 +1,57 @@
+namespace System
+{
+ ///
+ /// 表格显示样式
+ ///
+ public enum TableStyle
+ {
+ ///
+ /// 默认格式的表格
+ ///
+ Default = 0,
+
+ ///
+ /// Markdwon格式的表格
+ ///
+ MarkDown = 1,
+
+ ///
+ /// 交替格式的表格
+ ///
+ Alternative = 2,
+
+ ///
+ /// 最简格式的表格
+ ///
+ Minimal = 3
+ }
+
+ ///
+ /// 表格显示样式信息
+ /// 通过 Format 获取到的
+ ///
+ public class StyleInfo
+ {
+ public StyleInfo(string delimiterStr = "|", bool isShowTop_Down_DataBorder = true, string angleStr = "-")
+ {
+ DelimiterStr = delimiterStr;
+ IsShowTop_Down_DataBorder = isShowTop_Down_DataBorder;
+ AngleStr = angleStr;
+ }
+
+ ///
+ /// 每一列数据之间的间隔字符串
+ ///
+ public string DelimiterStr { get; set; }
+
+ ///
+ /// 是否显示顶部,底部,和每一行数据之间的横向边框
+ ///
+ public bool IsShowTop_Down_DataBorder { get; set; }
+
+ ///
+ /// 边角字符串
+ ///
+ public string AngleStr { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Blog.Core.EventBus/RabbitMQPersistent/EventBusRabbitMQ.cs b/Blog.Core.EventBus/RabbitMQPersistent/EventBusRabbitMQ.cs
index 5eddad7..7438ddd 100644
--- a/Blog.Core.EventBus/RabbitMQPersistent/EventBusRabbitMQ.cs
+++ b/Blog.Core.EventBus/RabbitMQPersistent/EventBusRabbitMQ.cs
@@ -1,6 +1,6 @@
using Autofac;
using Blog.Core.Common.Extensions;
-using Blog.Core.Common.Helper;
+using Blog.Core.Common;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
diff --git a/Blog.Core.Extensions/EventHandling/BlogQueryIntegrationEventHandler.cs b/Blog.Core.Extensions/EventHandling/BlogQueryIntegrationEventHandler.cs
index 5d1a2d8..4e6384c 100644
--- a/Blog.Core.Extensions/EventHandling/BlogQueryIntegrationEventHandler.cs
+++ b/Blog.Core.Extensions/EventHandling/BlogQueryIntegrationEventHandler.cs
@@ -1,4 +1,4 @@
-using Blog.Core.Common.Helper;
+using Blog.Core.Common;
using Blog.Core.EventBus.EventHandling;
using Blog.Core.IServices;
using Microsoft.Extensions.Logging;
diff --git a/Blog.Core.Extensions/NacosConfig/NacosListenNamingTask.cs b/Blog.Core.Extensions/NacosConfig/NacosListenNamingTask.cs
index 60657bb..3215703 100644
--- a/Blog.Core.Extensions/NacosConfig/NacosListenNamingTask.cs
+++ b/Blog.Core.Extensions/NacosConfig/NacosListenNamingTask.cs
@@ -1,4 +1,5 @@
-using Blog.Core.Common.Helper;
+using Blog.Core.Common;
+using Blog.Core.Common.Helper;
using Microsoft.Extensions.Hosting;
using Nacos.V2;
using System;
diff --git a/Blog.Core.Extensions/ServiceExtensions/AppConfigSetup.cs b/Blog.Core.Extensions/ServiceExtensions/AppConfigSetup.cs
index c3d15f5..31ae349 100644
--- a/Blog.Core.Extensions/ServiceExtensions/AppConfigSetup.cs
+++ b/Blog.Core.Extensions/ServiceExtensions/AppConfigSetup.cs
@@ -1,9 +1,11 @@
using Blog.Core.Common;
using Blog.Core.Common.Helper;
+using Blog.Core.Common.LogHelper;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
+using System.Collections.Generic;
using System.Text;
namespace Blog.Core.Extensions
@@ -213,5 +215,97 @@ namespace Blog.Core.Extensions
}
}
+
+ public static void AddAppTableConfigSetup(this IServiceCollection services, IHostEnvironment env)
+ {
+ if (services == null) throw new ArgumentNullException(nameof(services));
+
+ if (Appsettings.app(new string[] { "Startup", "AppConfigAlert", "Enabled" }).ObjToBool())
+ {
+
+ if (env.IsDevelopment())
+ {
+ Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
+ Console.OutputEncoding = Encoding.GetEncoding("GB2312");
+ }
+
+ #region 程序配置
+ List configInfos = new()
+ {
+ new string[] { "当前环境", Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") },
+ new string[] { "当前的授权方案", Permissions.IsUseIds4 ? "Ids4" : "JWT" },
+ new string[] { "CORS跨域", Appsettings.app("Startup", "Cors", "EnableAllIPs") },
+ new string[] { "RabbitMQ消息列队", Appsettings.app("RabbitMQ", "Enabled") },
+ new string[] { "事件总线(必须开启消息列队)", Appsettings.app("EventBus", "Enabled") },
+ new string[] { "redis消息队列", Appsettings.app("Startup", "RedisMq", "Enabled") },
+ new string[] { "是否多库", Appsettings.app("MutiDBEnabled" ) },
+ new string[] { "读写分离", Appsettings.app("CQRSEnabled") },
+ };
+
+ new ConsoleTable()
+ {
+ TitleString = "Blog.Core 配置集",
+ Columns = new string[] { "配置名称", "配置信息/是否启动" },
+ Rows = configInfos,
+ EnableCount = false,
+ Alignment = Alignment.Left,
+ ColumnBlankNum = 4,
+ TableStyle = TableStyle.Alternative
+ }.Writer(ConsoleColor.Blue);
+ Console.WriteLine();
+ #endregion 程序配置
+
+ #region AOP
+ List aopInfos = new()
+{
+ new string[] { "Redis缓存AOP", Appsettings.app("AppSettings", "RedisCachingAOP", "Enabled") },
+ new string[] { "内存缓存AOP", Appsettings.app("AppSettings", "MemoryCachingAOP", "Enabled") },
+ new string[] { "服务日志AOP", Appsettings.app("AppSettings", "LogAOP", "Enabled" ) },
+ new string[] { "事务AOP", Appsettings.app("AppSettings", "TranAOP", "Enabled" ) },
+ new string[] { "Sql执行AOP", Appsettings.app("AppSettings", "SqlAOP", "OutToLogFile", "Enabled" ) },
+ new string[] { "Sql执行AOP控制台输出", Appsettings.app("AppSettings", "SqlAOP", "OutToConsole", "Enabled" ) },
+ };
+
+ new ConsoleTable
+ {
+ TitleString = "AOP",
+ Columns = new string[] { "配置名称", "配置信息/是否启动" },
+ Rows = aopInfos,
+ EnableCount = false,
+ Alignment = Alignment.Left,
+ ColumnBlankNum = 7,
+ TableStyle = TableStyle.Alternative
+ }.Writer(ConsoleColor.Blue);
+ Console.WriteLine();
+ #endregion AOP
+
+ #region 中间件
+ List MiddlewareInfos = new()
+ {
+ new string[] { "请求纪录中间件", Appsettings.app("Middleware", "RecordAccessLogs", "Enabled") },
+ new string[] { "IP记录中间件", Appsettings.app("Middleware", "IPLog", "Enabled" ) },
+ new string[] { "请求响应日志中间件", Appsettings.app("Middleware", "RequestResponseLog", "Enabled" ) },
+ new string[] { "SingnalR实时发送请求数据中间件", Appsettings.app("Middleware", "SignalR", "Enabled" ) },
+ new string[] { "IP限流中间件", Appsettings.app("Middleware", "IpRateLimit", "Enabled") },
+ new string[] { "性能分析中间件", Appsettings.app("Startup", "MiniProfiler", "Enabled") },
+ new string[] { "Consul注册服务", Appsettings.app("Middleware", "Consul", "Enabled") },
+ };
+
+ new ConsoleTable
+ {
+ TitleString = "中间件",
+ Columns = new string[] { "配置名称", "配置信息/是否启动" },
+ Rows = MiddlewareInfos,
+ EnableCount = false,
+ Alignment = Alignment.Left,
+ ColumnBlankNum = 3,
+ TableStyle = TableStyle.Alternative
+ }.Writer(ConsoleColor.Blue);
+ Console.WriteLine();
+ #endregion 中间件
+
+ }
+
+ }
}
}
diff --git a/Blog.Core.Tasks/HostedService/Job1TimedService.cs b/Blog.Core.Tasks/HostedService/Job1TimedService.cs
index 64032a4..9777aff 100644
--- a/Blog.Core.Tasks/HostedService/Job1TimedService.cs
+++ b/Blog.Core.Tasks/HostedService/Job1TimedService.cs
@@ -1,4 +1,4 @@
-using Blog.Core.Common.Helper;
+using Blog.Core.Common;
using Blog.Core.IServices;
using Microsoft.Extensions.Hosting;
using System;
diff --git a/Blog.Core.Tasks/HostedService/Job2TimedService.cs b/Blog.Core.Tasks/HostedService/Job2TimedService.cs
index 94cd27a..ee7f2c5 100644
--- a/Blog.Core.Tasks/HostedService/Job2TimedService.cs
+++ b/Blog.Core.Tasks/HostedService/Job2TimedService.cs
@@ -1,4 +1,4 @@
-using Blog.Core.Common.Helper;
+using Blog.Core.Common;
using Microsoft.Extensions.Hosting;
using System;
using System.Threading;