Browse Source

提交代码

master
Nice 2 years ago
parent
commit
b907777120
  1. 4
      Easy.Snowflakes/Easy/Realization/AutoDelayTimers.cs
  2. 9
      Easy.sln
  3. 2
      src/Easy.Abstract/Easy.Abstract.csproj
  4. 3
      src/Easy.Authorization/Easy/Authorization/Realization/PermissionDefinitionContext.cs
  5. 2
      src/Easy.Core/Easy.Core.csproj
  6. 18
      src/Easy.Core/Easy/Abstract/IPagingRequest.cs
  7. 23
      src/Easy.Core/Easy/Abstract/IPagingSortingRequest.cs
  8. 44
      src/Easy.Core/Easy/Check.cs
  9. 18
      src/Easy.Core/Easy/Exceptions/BusinessException.cs
  10. 20
      src/Easy.Core/Easy/Exceptions/EasyException.cs
  11. 21
      src/Easy.Core/Easy/When.cs
  12. 35
      src/Easy.Core/System/EnumDefineAttribute.cs
  13. 174
      src/Easy.Core/System/EnumExtension.cs
  14. 4
      src/Easy.DDD.Application/Easy.DDD.Application.csproj
  15. 4
      src/Easy.Result/Easy.Result.csproj

4
Easy.Snowflakes/Easy/Realization/AutoDelayTimers.cs

@ -1,6 +1,4 @@
using System; using System.Collections.Concurrent;
using System.Collections.Concurrent;
using System.Threading;
namespace Easy.Realization; namespace Easy.Realization;

9
Easy.sln

@ -37,8 +37,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Easy.EventBus", "src\Easy.E
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Guid.Test", "src\Guid.Test\Guid.Test.csproj", "{AB0828ED-6432-4647-8970-B57757ACD945}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Guid.Test", "src\Guid.Test\Guid.Test.csproj", "{AB0828ED-6432-4647-8970-B57757ACD945}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Easy.Abstract", "src\Easy.Abstract\Easy.Abstract.csproj", "{EE29B72B-407F-4360-BB38-7CC1F6561D98}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -101,10 +99,6 @@ Global
{AB0828ED-6432-4647-8970-B57757ACD945}.Debug|Any CPU.Build.0 = Debug|Any CPU {AB0828ED-6432-4647-8970-B57757ACD945}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB0828ED-6432-4647-8970-B57757ACD945}.Release|Any CPU.ActiveCfg = Release|Any CPU {AB0828ED-6432-4647-8970-B57757ACD945}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB0828ED-6432-4647-8970-B57757ACD945}.Release|Any CPU.Build.0 = Release|Any CPU {AB0828ED-6432-4647-8970-B57757ACD945}.Release|Any CPU.Build.0 = Release|Any CPU
{EE29B72B-407F-4360-BB38-7CC1F6561D98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE29B72B-407F-4360-BB38-7CC1F6561D98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE29B72B-407F-4360-BB38-7CC1F6561D98}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE29B72B-407F-4360-BB38-7CC1F6561D98}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -118,7 +112,7 @@ Global
{A263D7E3-0153-48D0-822D-E3E0B51A4890} = {A420E7C6-F5D7-43F5-9BA8-6FB3341177BC} {A263D7E3-0153-48D0-822D-E3E0B51A4890} = {A420E7C6-F5D7-43F5-9BA8-6FB3341177BC}
{E2F1B3BA-DD92-4729-BDD0-91BB936520C0} = {A420E7C6-F5D7-43F5-9BA8-6FB3341177BC} {E2F1B3BA-DD92-4729-BDD0-91BB936520C0} = {A420E7C6-F5D7-43F5-9BA8-6FB3341177BC}
{1B91E50D-7E98-4B94-9BCA-76BB0423FB97} = {E2F1B3BA-DD92-4729-BDD0-91BB936520C0} {1B91E50D-7E98-4B94-9BCA-76BB0423FB97} = {E2F1B3BA-DD92-4729-BDD0-91BB936520C0}
{EF3CD7D3-DC58-4A36-BB6D-BB87EDAE7408} = {A420E7C6-F5D7-43F5-9BA8-6FB3341177BC} {EF3CD7D3-DC58-4A36-BB6D-BB87EDAE7408} = {E2F1B3BA-DD92-4729-BDD0-91BB936520C0}
{8EC50AAD-EB45-402A-B474-A94EDBD342A3} = {A420E7C6-F5D7-43F5-9BA8-6FB3341177BC} {8EC50AAD-EB45-402A-B474-A94EDBD342A3} = {A420E7C6-F5D7-43F5-9BA8-6FB3341177BC}
{1029F049-FBC4-4706-8985-9F05296F989C} = {A420E7C6-F5D7-43F5-9BA8-6FB3341177BC} {1029F049-FBC4-4706-8985-9F05296F989C} = {A420E7C6-F5D7-43F5-9BA8-6FB3341177BC}
{4D135A3C-64AC-44DA-9386-877D7BBABFFB} = {E2F1B3BA-DD92-4729-BDD0-91BB936520C0} {4D135A3C-64AC-44DA-9386-877D7BBABFFB} = {E2F1B3BA-DD92-4729-BDD0-91BB936520C0}
@ -126,7 +120,6 @@ Global
{9D31086B-1333-4745-AEC2-7966141E503C} = {E2F1B3BA-DD92-4729-BDD0-91BB936520C0} {9D31086B-1333-4745-AEC2-7966141E503C} = {E2F1B3BA-DD92-4729-BDD0-91BB936520C0}
{F464D123-49B6-4DC7-AE88-2F78CA0B6A3D} = {E2F1B3BA-DD92-4729-BDD0-91BB936520C0} {F464D123-49B6-4DC7-AE88-2F78CA0B6A3D} = {E2F1B3BA-DD92-4729-BDD0-91BB936520C0}
{AB0828ED-6432-4647-8970-B57757ACD945} = {E2F1B3BA-DD92-4729-BDD0-91BB936520C0} {AB0828ED-6432-4647-8970-B57757ACD945} = {E2F1B3BA-DD92-4729-BDD0-91BB936520C0}
{EE29B72B-407F-4360-BB38-7CC1F6561D98} = {E2F1B3BA-DD92-4729-BDD0-91BB936520C0}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7260112B-0232-4725-AB84-EF4DCCABFD77} SolutionGuid = {7260112B-0232-4725-AB84-EF4DCCABFD77}

2
src/Easy.Abstract/Easy.Abstract.csproj

@ -5,6 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<!--<Nullable>enable</Nullable>--> <!--<Nullable>enable</Nullable>-->
<RootNamespace /> <RootNamespace />
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.1.0</Version>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

3
src/Easy.Authorization/Easy/Authorization/Realization/PermissionDefinitionContext.cs

@ -1,5 +1,4 @@
using Easy.Authorization.Abstractions; using Easy.Authorization.Abstractions;
using Easy.Exceptions;
namespace Easy.Authorization.Realization; namespace Easy.Authorization.Realization;
public class PermissionDefinitionContext : IPermissionDefinitionContext public class PermissionDefinitionContext : IPermissionDefinitionContext
@ -13,7 +12,7 @@ public class PermissionDefinitionContext : IPermissionDefinitionContext
{ {
if (Groups.ContainsKey(name)) if (Groups.ContainsKey(name))
{ {
throw new EasyException($"已经有一个名为{{ {name} }}的权限组"); //throw new EasyException($"已经有一个名为{{ {name} }}的权限组");
} }
return Groups[name] = new PermissionDefinitionGroup(name); return Groups[name] = new PermissionDefinitionGroup(name);

2
src/Easy.Core/Easy.Core.csproj

@ -4,6 +4,8 @@
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<!--<Nullable>enable</Nullable>--> <!--<Nullable>enable</Nullable>-->
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.1.5</Version>
<RootNamespace /> <RootNamespace />
</PropertyGroup> </PropertyGroup>

18
src/Easy.Core/Easy/Abstract/IPagingRequest.cs

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Easy.Abstract;
public interface IPagingRequest
{
/// <summary>
/// 页面索引
/// </summary>
public int PageIndex { get; set; }
/// <summary>
/// 页面大小
/// </summary>
public int PageSize { get; set; }
}

23
src/Easy.Core/Easy/Abstract/IPagingSortingRequest.cs

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Easy.Abstract;
public interface IPagingSortingRequest : IPagingRequest
{
/// <summary>
/// Sorting information.
/// 应包括排序字段和可选方向(ASC或DESC)
/// 可以包含多个由逗号(,)分隔的字段。
/// </summary>
/// <example>
/// 例子:
/// "Name"
/// "Name DESC"
/// "Name ASC, Age DESC"
/// "ClassName Name ASC, Age DESC"
/// </example>
public string Sorting { get; set; }
}

44
src/Easy.Core/Easy/Check.cs

@ -1,44 +0,0 @@
using System.Diagnostics.CodeAnalysis;
namespace Easy;
public static class Check
{
public static T NotNull<T>(T value, [NotNull] string parameterName)
{
if (value == null)
{
throw new ArgumentNullException(parameterName);
}
return value;
}
public static T NotNull<T>(T value, [NotNull] string parameterName, string message)
{
if (value == null)
{
throw new ArgumentNullException(parameterName, message);
}
return value;
}
public static string NotNullOrWhiteSpace(string value, [NotNull] string parameterName, int maxLength = int.MaxValue, int minLength = 0)
{
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException($"{parameterName} can not be null, empty or white space!", parameterName);
}
if (value.Length > maxLength)
{
throw new ArgumentException($"{parameterName} length must be equal to or lower than {maxLength}!", parameterName);
}
if (minLength > 0 && value.Length < minLength)
{
throw new ArgumentException($"{parameterName} length must be equal to or bigger than {minLength}!", parameterName);
}
return value;
}
}

18
src/Easy.Core/Easy/Exceptions/BusinessException.cs

@ -1,18 +0,0 @@
namespace Easy.Exceptions;
/// <summary>
/// 业务异常
/// </summary>
public class BusinessException : Exception
{
/// <summary>
/// 业务异常
/// </summary>
/// <param name="message">消息</param>
public BusinessException(string message)
: base(message)
{
}
}

20
src/Easy.Core/Easy/Exceptions/EasyException.cs

@ -1,20 +0,0 @@
namespace Easy.Exceptions;
public class EasyException : Exception
{
public EasyException()
{
}
public EasyException(string message)
: base(message)
{
}
public EasyException(string message, Exception innerException)
: base(message, innerException)
{
}
}

21
src/Easy.Core/Easy/When.cs

@ -1,21 +0,0 @@
using Easy.Exceptions;
namespace Easy;
/// <summary>
/// when 语句
/// </summary>
public class When
{
/// <summary>
/// 是
/// </summary>
/// <param name="isOk">是否</param>
/// <param name="message">消息</param>
/// <exception cref="BusinessException">服务异常会被中间件拦截</exception>
public static void Is(bool isOk, string message)
{
if (isOk) throw new BusinessException(message);
}
}

35
src/Easy.Core/System/EnumDefineAttribute.cs

@ -0,0 +1,35 @@
namespace System
{
[AttributeUsage(AttributeTargets.Field)]
public class EnumDefineAttribute : Attribute
{
/// <summary>
/// 枚举值。
/// </summary>
public int Value { get; internal set; }
/// <summary>
/// 枚举描述。
/// </summary>
public string Description { get; set; }
/// <summary>
/// 枚举获取列表分组标识。
/// </summary>
public string[] Group { get; set; }
/// <summary>
/// 枚举获取列表排序号,不指定则采用枚举值排序。
/// </summary>
public int? Sort { get; set; }
public EnumDefineAttribute()
{
}
public EnumDefineAttribute(string description)
{
Description = description;
}
}
}

174
src/Easy.Core/System/EnumExtension.cs

@ -0,0 +1,174 @@
using System.Collections;
using System.Reflection;
namespace System
{
public static class EnumExtension
{
/// <summary>
/// A T extension method to determines whether the object is equal to any of the provided values.
/// </summary>
/// <param name="this">The object to be compared.</param>
/// <param name="values">The value list to compare with the object.</param>
/// <returns>true if the values list contains the object, else false.</returns>
public static bool In(this Enum @this, params Enum[] values)
{
return Array.IndexOf(values, @this) >= 0;
}
/// <summary>
/// 根据枚举值获得枚举。
/// </summary>
public static TEnum GetEnum<TEnum>(this int enValue) where TEnum : struct
{
Type typeFromHandle = typeof(TEnum);
if (!typeFromHandle.IsEnum)
{
throw new Exception("GetEnum<TEnum> 中的 TEnum 必须为枚举类型!");
}
return (TEnum)Enum.Parse(typeFromHandle, Convert.ToString(enValue));
}
/// <summary>
/// 获得枚举值。
/// </summary>
public static int GetValue(this Enum en)
{
return Convert.ToInt32(en);
}
/// <summary>
/// 获得枚举项定义的名称。
/// </summary>
/// <param name="en"></param>
/// <returns></returns>
public static string GetName(this Enum en)
{
return Enum.GetName(en.GetType(), en);
}
/// <summary>
/// 获得枚举EnumDefineAttribute定义的Description内容。
/// </summary>
public static string GetDescription(this Enum en)
{
EnumDefineAttribute enumDefineAttribute = GetEnumDefineAttribute(en);
return enumDefineAttribute.Description;
}
/// <summary>
/// 根据枚举值获得EnumDefineAttribute定义的Description内容。
/// </summary>
public static string GetDescription<TEnum>(this int enValue) where TEnum : struct
{
return (GetEnum<TEnum>(enValue) as Enum).GetDescription();
}
/// <summary>
/// 获得枚举的EnumDefineAttribute定义。
/// </summary>
public static EnumDefineAttribute GetEnumDefineAttribute(this Enum en)
{
string name = Enum.GetName(en.GetType(), en);
FieldInfo field = en.GetType().GetField(name);
return Attribute.GetCustomAttribute(field, typeof(EnumDefineAttribute)) as EnumDefineAttribute;
}
/// <summary>
/// 返回类型为 IEnumerable 的输入。
/// </summary>
static IEnumerable<T> AsEnumerable<T>() where T : struct
{
Type typeFromHandle = typeof(T);
if (!typeFromHandle.IsEnum)
{
throw new Exception("AsEnumerable<T> 中的 T 必须为枚举类型!");
}
return new Enum<T>();
}
/// <summary>
/// 返回枚举项的EnumDefineAttribute集合。
/// </summary>
public static List<EnumDefineAttribute> GetEnumDefines<T>(string groupName) where T : struct
{
Type typeFromHandle = typeof(T);
if (!typeFromHandle.IsEnum)
{
throw new Exception("GetEnumDefineAttributes<T> 中的 T 必须为枚举类型!");
}
List<EnumDefineAttribute> list = new List<EnumDefineAttribute>();
EnumDefineAttribute eda = null;
foreach (var en in AsEnumerable<T>())
{
eda = GetEnumDefineAttribute(en as Enum);
eda.Value = Convert.ToInt32(en);
if (!eda.Sort.HasValue) eda.Sort = eda.Value;
if (!string.IsNullOrEmpty(groupName) && !eda.Group.Contains(groupName))
{
continue;
}
else
{
list.Add(eda);
}
}
return list.OrderBy(o => o.Sort).ToList();
}
}
/// <summary>
/// T 类型枚举列表
/// </summary>
/// <typeparam name="T">枚举类型</typeparam>
public class Enum<T> : IEnumerable<T>
{
#region IEnumerable<T> 成员
/// <summary>
/// 返回一个循环访问集合的枚举数。
/// </summary>
/// <returns>可用于循环访问集合的 IEnumerator。</returns>
public IEnumerator<T> GetEnumerator()
{
foreach (T item in Enum.GetValues(typeof(T)))
{
yield return item;
}
}
#endregion
#region IEnumerable 成员
/// <summary>
/// 返回一个循环访问集合的枚举数。
/// </summary>
/// <returns>可用于循环访问集合的 IEnumerator 。</returns>
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endregion
#region IEnumerable<T> 成员
/// <summary>
/// 返回一个循环访问集合的枚举数。
/// </summary>
/// <returns>
/// <returns>可用于循环访问集合的 IEnumerator&lt;T&gt; 。</returns>
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return GetEnumerator();
}
#endregion
}
}

4
src/Easy.DDD.Application/Easy.DDD.Application.csproj

@ -4,14 +4,14 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<RootNamespace /> <RootNamespace />
<Version>1.1.2</Version> <Version>1.1.3</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="6.0.0" /> <FrameworkReference Include="Microsoft.AspNetCore.App" Version="6.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Easy.Abstract\Easy.Abstract.csproj" /> <ProjectReference Include="..\Easy.Core\Easy.Core.csproj" />
<ProjectReference Include="..\Easy.DI\Easy.DI.csproj" /> <ProjectReference Include="..\Easy.DI\Easy.DI.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

4
src/Easy.Result/Easy.Result.csproj

@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.1.4</Version> <Version>1.1.5</Version>
<RootNamespace /> <RootNamespace />
<!--<Nullable>enable</Nullable>--> <!--<Nullable>enable</Nullable>-->
</PropertyGroup> </PropertyGroup>
@ -12,6 +12,6 @@
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="6.0.0" /> <FrameworkReference Include="Microsoft.AspNetCore.App" Version="6.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Easy.Abstract\Easy.Abstract.csproj" /> <ProjectReference Include="..\Easy.Core\Easy.Core.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

Loading…
Cancel
Save