Skip to content

Commit 66926b2

Browse files
committed
1. 代码生成器客户端配置新增 Microfrontend 属性,用于控制是否启用微前端模板.
2. 随机数辅助操作类 Util.Helpers.Random 新增 GetValues 方法, 用于从集合中随机获取指定数量子集. 3. 新增Razor页面监听服务 IRazorWatchService 及相关类型,用于监视Razor页面更改时自动生成Html文件. 4. 修复表格组件复选框,单选框,序号在有合并表头的情况下显示不正确的错误.
1 parent 47539d9 commit 66926b2

File tree

112 files changed

+1897
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+1897
-228
lines changed

build/version.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<VersionMajor>8</VersionMajor>
44
<VersionMinor>0</VersionMinor>
5-
<VersionPatch>7</VersionPatch>
5+
<VersionPatch>8</VersionPatch>
66
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
77
<VersionSuffix></VersionSuffix>
88
</PropertyGroup>

src/Util.Application.WebApi/Logging/LogContextAccessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class LogContextAccessor : ILogContextAccessor {
1616
/// 日志上下文
1717
/// </summary>
1818
public LogContext Context {
19-
get => Util.Helpers.Convert.To<LogContext>( Web.HttpContext.Items[LogContextKey] );
19+
get => Util.Helpers.Convert.To<LogContext>( Web.HttpContext?.Items[LogContextKey] );
2020
set => Web.HttpContext.Items[LogContextKey] = value;
2121
}
2222
}

src/Util.AspNetCore/08-Util.AspNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</ItemGroup>
3232

3333
<ItemGroup>
34-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.2" />
34+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.3" />
3535
</ItemGroup>
3636

3737
<ItemGroup>

src/Util.Core/Helpers/FileWatcher.cs

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
namespace Util.Helpers;
2+
3+
/// <summary>
4+
/// 文件监视器
5+
/// </summary>
6+
public class FileWatcher : IDisposable {
7+
/// <summary>
8+
/// 文件系统监视器
9+
/// </summary>
10+
private readonly FileSystemWatcher _watcher;
11+
12+
/// <summary>
13+
/// 初始化文件监视器
14+
/// </summary>
15+
public FileWatcher() {
16+
_watcher = new FileSystemWatcher();
17+
_watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
18+
}
19+
20+
/// <summary>
21+
/// 设置监听目录路径
22+
/// </summary>
23+
/// <param name="path">目录绝对路径</param>
24+
/// <param name="includeSubdirectories">是否监听子目录,默认值: true</param>
25+
public FileWatcher Path( string path, bool includeSubdirectories = true ) {
26+
_watcher.Path = path;
27+
_watcher.IncludeSubdirectories = includeSubdirectories;
28+
return this;
29+
}
30+
31+
/// <summary>
32+
/// 设置监听通知过滤
33+
/// </summary>
34+
/// <param name="notifyFilters">监听通知过滤</param>
35+
public FileWatcher NotifyFilter( NotifyFilters notifyFilters ) {
36+
_watcher.NotifyFilter = notifyFilters;
37+
return this;
38+
}
39+
40+
/// <summary>
41+
/// 设置过滤模式
42+
/// </summary>
43+
/// <param name="filter">过滤模式,默认值: *.* ,范例: *.cshtml 可过滤cshtml文件</param>
44+
public FileWatcher Filter( string filter ) {
45+
_watcher.Filter = filter;
46+
return this;
47+
}
48+
49+
/// <summary>
50+
/// 处理文件创建监听事件
51+
/// </summary>
52+
/// <param name="action">文件创建监听事件处理器</param>
53+
public FileWatcher OnCreated( Action<object, FileSystemEventArgs> action ) {
54+
_watcher.Created += ( source, e ) => {
55+
action( source, e );
56+
};
57+
return this;
58+
}
59+
60+
/// <summary>
61+
/// 处理文件创建监听事件
62+
/// </summary>
63+
/// <param name="action">文件创建监听事件处理器</param>
64+
public FileWatcher OnCreatedAsync( Func<object, FileSystemEventArgs, Task> action ) {
65+
_watcher.Created += async ( source, e ) => {
66+
await action( source, e );
67+
};
68+
return this;
69+
}
70+
71+
/// <summary>
72+
/// 处理文件变更监听事件
73+
/// </summary>
74+
/// <param name="action">文件变更监听事件处理器</param>
75+
public FileWatcher OnChanged( Action<object, FileSystemEventArgs> action ) {
76+
_watcher.Changed += ( source, e ) => {
77+
action( source, e );
78+
};
79+
return this;
80+
}
81+
82+
/// <summary>
83+
/// 处理文件变更监听事件
84+
/// </summary>
85+
/// <param name="action">文件变更监听事件处理器</param>
86+
public FileWatcher OnChangedAsync( Func<object, FileSystemEventArgs, Task> action ) {
87+
_watcher.Changed += async ( source, e ) => {
88+
await action( source, e );
89+
};
90+
return this;
91+
}
92+
93+
/// <summary>
94+
/// 处理文件删除监听事件
95+
/// </summary>
96+
/// <param name="action">文件删除监听事件处理器</param>
97+
public FileWatcher OnDeleted( Action<object, FileSystemEventArgs> action ) {
98+
_watcher.Deleted += ( source, e ) => {
99+
action( source, e );
100+
};
101+
return this;
102+
}
103+
104+
/// <summary>
105+
/// 处理文件删除监听事件
106+
/// </summary>
107+
/// <param name="action">文件删除监听事件处理器</param>
108+
public FileWatcher OnDeletedAsync( Func<object, FileSystemEventArgs, Task> action ) {
109+
_watcher.Deleted += async ( source, e ) => {
110+
await action( source, e );
111+
};
112+
return this;
113+
}
114+
115+
/// <summary>
116+
/// 处理文件重命名监听事件
117+
/// </summary>
118+
/// <param name="action">文件重命名监听事件处理器</param>
119+
public FileWatcher OnRenamed( Action<object, RenamedEventArgs> action ) {
120+
_watcher.Renamed += ( source, e ) => {
121+
action( source, e );
122+
};
123+
return this;
124+
}
125+
126+
/// <summary>
127+
/// 处理文件重命名监听事件
128+
/// </summary>
129+
/// <param name="action">文件重命名监听事件处理器</param>
130+
public FileWatcher OnRenamedAsync( Func<object, RenamedEventArgs, Task> action ) {
131+
_watcher.Renamed += async ( source, e ) => {
132+
await action( source, e );
133+
};
134+
return this;
135+
}
136+
137+
/// <summary>
138+
/// 处理文件错误监听事件
139+
/// </summary>
140+
/// <param name="action">文件错误监听事件处理器</param>
141+
public FileWatcher OnError( Action<object, ErrorEventArgs> action ) {
142+
_watcher.Error += ( source, e ) => {
143+
action( source, e );
144+
};
145+
return this;
146+
}
147+
148+
/// <summary>
149+
/// 处理文件错误监听事件
150+
/// </summary>
151+
/// <param name="action">文件错误监听事件处理器</param>
152+
public FileWatcher OnErrorAsync( Func<object, ErrorEventArgs, Task> action ) {
153+
_watcher.Error += async ( source, e ) => {
154+
await action( source, e );
155+
};
156+
return this;
157+
}
158+
159+
/// <summary>
160+
/// 处理文件监听器释放事件
161+
/// </summary>
162+
/// <param name="action">文件监听器释放事件处理器</param>
163+
public FileWatcher OnDisposed( Action<object, EventArgs> action ) {
164+
_watcher.Disposed += ( source, e ) => {
165+
action( source, e );
166+
};
167+
return this;
168+
}
169+
170+
/// <summary>
171+
/// 处理文件监听器释放事件
172+
/// </summary>
173+
/// <param name="action">文件监听器释放事件处理器</param>
174+
public FileWatcher OnDisposedAsync( Func<object, EventArgs, Task> action ) {
175+
_watcher.Disposed += async ( source, e ) => {
176+
await action( source, e );
177+
};
178+
return this;
179+
}
180+
181+
/// <summary>
182+
/// 启动监听
183+
/// </summary>
184+
public FileWatcher Start() {
185+
_watcher.EnableRaisingEvents = true;
186+
return this;
187+
}
188+
189+
/// <summary>
190+
/// 停止监听
191+
/// </summary>
192+
public FileWatcher Stop() {
193+
_watcher.EnableRaisingEvents = false;
194+
return this;
195+
}
196+
197+
/// <summary>
198+
/// 释放
199+
/// </summary>
200+
public void Dispose() {
201+
_watcher?.Dispose();
202+
}
203+
}

src/Util.Core/Helpers/Random.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Util.Helpers;
1+
namespace Util.Helpers;
22

33
/// <summary>
44
/// 随机数操作
@@ -45,19 +45,38 @@ public static T GetValue<T>( IEnumerable<T> array ) {
4545
return list[index];
4646
}
4747

48+
/// <summary>
49+
/// 从集合中随机获取值列表
50+
/// </summary>
51+
/// <param name="array">集合</param>
52+
/// <param name="count">获取数量</param>
53+
public static List<T> GetValues<T>( IEnumerable<T> array, int count ) {
54+
var result = new List<T>();
55+
if ( array == null )
56+
return result;
57+
var list = array.ToList();
58+
while ( list.Count > 0 && result.Count < count ) {
59+
var index = System.Random.Shared.Next( 0, list.Count );
60+
var item = list[index];
61+
result.Add( item );
62+
list.Remove( item );
63+
}
64+
return result;
65+
}
66+
4867
/// <summary>
4968
/// 对集合随机排序
5069
/// </summary>
5170
/// <typeparam name="T">集合元素类型</typeparam>
5271
/// <param name="array">集合</param>
5372
public static List<T> Sort<T>( IEnumerable<T> array ) {
54-
if( array == null )
73+
if ( array == null )
5574
return null;
5675
var list = array.ToList();
57-
for( int i = 0; i < list.Count; i++ ) {
76+
for ( int i = 0; i < list.Count; i++ ) {
5877
int index1 = System.Random.Shared.Next( 0, list.Count );
5978
int index2 = System.Random.Shared.Next( 0, list.Count );
60-
( list[index1], list[index2] ) = ( list[index2], list[index1] );
79+
(list[index1], list[index2]) = (list[index2], list[index1]);
6180
}
6281
return list;
6382
}

src/Util.Core/Helpers/String.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ public static string FirstUpperCase( string value ) {
6666
/// </summary>
6767
/// <param name="value">值</param>
6868
/// <param name="start">要移除的值</param>
69-
public static string RemoveStart( string value, string start ) {
69+
/// <param name="ignoreCase">是否忽略大小写,默认值: true</param>
70+
public static string RemoveStart( string value, string start, bool ignoreCase = true ) {
7071
if ( string.IsNullOrWhiteSpace( value ) )
7172
return string.Empty;
7273
if ( string.IsNullOrEmpty( start ) )
7374
return value;
74-
if ( value.StartsWith( start, StringComparison.Ordinal ) == false )
75+
var options = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
76+
if ( value.StartsWith( start, options ) == false )
7577
return value;
7678
return value.Substring( start.Length, value.Length - start.Length );
7779
}
@@ -105,14 +107,16 @@ public static StringBuilder RemoveStart( StringBuilder value, string start ) {
105107
/// </summary>
106108
/// <param name="value">值</param>
107109
/// <param name="end">要移除的值</param>
108-
public static string RemoveEnd( string value, string end ) {
110+
/// <param name="ignoreCase">是否忽略大小写,默认值: true</param>
111+
public static string RemoveEnd( string value, string end,bool ignoreCase = true ) {
109112
if ( string.IsNullOrWhiteSpace( value ) )
110113
return string.Empty;
111114
if ( string.IsNullOrEmpty( end ) )
112115
return value;
113-
if ( value.EndsWith( end, StringComparison.Ordinal ) == false )
116+
var options = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
117+
if ( value.EndsWith( end, options ) == false )
114118
return value;
115-
return value.Substring( 0, value.LastIndexOf( end, StringComparison.Ordinal ) );
119+
return value.Substring( 0, value.LastIndexOf( end, options ) );
116120
}
117121

118122
/// <summary>

src/Util.Core/Helpers/Url.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Util.Helpers;
1+
namespace Util.Helpers;
22

33
/// <summary>
44
/// Url操作
@@ -18,6 +18,10 @@ public static string JoinPath( params string[] paths ) {
1818
var lastPath = paths.Last();
1919
paths = paths.Select( t => t.Trim( '/' ) ).ToArray();
2020
var result = Path.Combine( paths ).Replace( @"\", "/" );
21+
if ( paths.Any( path => path.StartsWith( "." ) ) ) {
22+
result = Path.GetFullPath( Path.Combine( paths ) );
23+
result = result.RemoveStart( AppContext.BaseDirectory ).Replace( @"\", "/" );
24+
}
2125
if ( firstPath.StartsWith( '/' ) )
2226
result = $"/{result}";
2327
if ( lastPath.EndsWith( '/' ) )

src/Util.Core/StringExtensions.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using String = Util.Helpers.String;
22

3-
namespace Util;
3+
namespace Util;
44

55
/// <summary>
66
/// 字符串扩展
@@ -11,17 +11,19 @@ public static class StringExtensions {
1111
/// </summary>
1212
/// <param name="value">值</param>
1313
/// <param name="start">要移除的值</param>
14-
public static string RemoveStart( this string value, string start ) {
15-
return String.RemoveStart( value, start );
14+
/// <param name="ignoreCase">是否忽略大小写,默认值: true</param>
15+
public static string RemoveStart( this string value, string start, bool ignoreCase = true ) {
16+
return String.RemoveStart( value, start, ignoreCase );
1617
}
1718

1819
/// <summary>
1920
/// 移除末尾字符串
2021
/// </summary>
2122
/// <param name="value">值</param>
2223
/// <param name="end">要移除的值</param>
23-
public static string RemoveEnd( this string value, string end ) {
24-
return String.RemoveEnd( value, end );
24+
/// <param name="ignoreCase">是否忽略大小写,默认值: true</param>
25+
public static string RemoveEnd( this string value, string end, bool ignoreCase = true ) {
26+
return String.RemoveEnd( value, end, ignoreCase );
2527
}
2628

2729
/// <summary>
@@ -61,7 +63,7 @@ public static StringWriter RemoveStart( this StringWriter writer, string start )
6163
/// <param name="writer">字符串写入器</param>
6264
/// <param name="end">要移除的值</param>
6365
public static StringWriter RemoveEnd( this StringWriter writer, string end ) {
64-
if( writer == null )
66+
if ( writer == null )
6567
return null;
6668
var builder = writer.GetStringBuilder();
6769
builder.RemoveEnd( end );

src/Util.Data.Dapper.MySql/04-Util.Data.Dapper.MySql.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</ItemGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="MySqlConnector" Version="2.3.5" />
30+
<PackageReference Include="MySqlConnector" Version="2.3.6" />
3131
</ItemGroup>
3232

3333
<ItemGroup>

src/Util.Data.EntityFrameworkCore.MySql/04-Util.Data.EntityFrameworkCore.MySql.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</ItemGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.1" />
30+
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
3131
</ItemGroup>
3232

3333
<ItemGroup>

0 commit comments

Comments
 (0)