diff --git a/Gear.Test.Api/Controllers/WeatherForecastController.cs b/Gear.Test.Api/Controllers/WeatherForecastController.cs index d2fca9f..d9df035 100644 --- a/Gear.Test.Api/Controllers/WeatherForecastController.cs +++ b/Gear.Test.Api/Controllers/WeatherForecastController.cs @@ -18,7 +18,7 @@ namespace Gear.Test.Api.Controllers }; private ITestUse TestUse => LazyServiceProvider.LazyGetService(); - public IEnumerable Get() + public IEnumerable GetPostersAsync() { var d = LazyServiceProvider; var c = Configuration; diff --git a/Gear.Test.Api/Program.cs b/Gear.Test.Api/Program.cs index d9f843e..7641f26 100644 --- a/Gear.Test.Api/Program.cs +++ b/Gear.Test.Api/Program.cs @@ -1,3 +1,5 @@ +using Gear.Generations; +using IdGen; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; @@ -13,6 +15,20 @@ namespace Gear.Test.Api { public static void Main(string[] args) { + //var generator = new IdGenerator(0); + //var id = generator.CreateId(); + //List ls = new List(); + + //var id1 = new SequentialGuidGenerator().Create(); + //var id2 = new SequentialGuidGenerator().Create(); + //var id3 = new SequentialGuidGenerator().Create(); + //var id4 = new SequentialGuidGenerator().Create(); + //ls.Add(id1); + //ls.Add(id2); + //ls.Add(id3); + //ls.Add(id4); + + CreateHostBuilder(args).Build().Run(); } diff --git a/Gear.sln b/Gear.sln index 7643ef7..dc85ac0 100644 --- a/Gear.sln +++ b/Gear.sln @@ -5,7 +5,7 @@ VisualStudioVersion = 16.0.31605.320 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gear", "Gear\Gear.csproj", "{E98AD43A-28B5-4046-805E-313EF48D9AEE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gear.Test.Api", "Gear.Test.Api\Gear.Test.Api.csproj", "{D8E0FF08-B8FA-45AE-B20A-6393B1DBCF18}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gear.Test.Api", "Gear.Test.Api\Gear.Test.Api.csproj", "{D8E0FF08-B8FA-45AE-B20A-6393B1DBCF18}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Gear/Gear.csproj b/Gear/Gear.csproj index 7bdb9b0..68da99e 100644 --- a/Gear/Gear.csproj +++ b/Gear/Gear.csproj @@ -8,7 +8,7 @@ 全网科技 true Gear - 0.1.8 + 0.2.1 Gear Gear diff --git a/Gear/Gear/Abstractions/AppService.cs b/Gear/Gear/Abstractions/AppService.cs index dcfe81e..6addf35 100644 --- a/Gear/Gear/Abstractions/AppService.cs +++ b/Gear/Gear/Abstractions/AppService.cs @@ -13,7 +13,7 @@ namespace Gear.Abstractions public abstract class AppService : Use { public static string[] CommonPostfixes { get; } = { "AppService", "Service" }; - public static string[] ActionPostfixes { get; } = { "Async", + public static string[] ActionPostfixes { get; } = { "GetAll", "GetList", "Get", "Post", "Create", "Add", "Insert", "Put", "Update", @@ -21,24 +21,16 @@ namespace Gear.Abstractions "Patch" }; - - protected const string DaprPubSubName = "pubsub"; protected const string DaprStoreName = "store"; - /// - /// Gets the for user associated with the executing action. - /// protected ClaimsPrincipal User => HttpContext?.User!; - /// - /// Gets the for the executing action. - /// + protected HttpContext HttpContext => LazyServiceProvider.LazyGetService().HttpContext; protected IDecryptClaim DecryptClaim => LazyServiceProvider.LazyGetService(); - //获得HttpMethod - public static string GetHttpMethod(string actionName) + public static string GetHttpMethod(string actionName) //获得HttpMethod { if (actionName.StartsWith("Get")) return "GET"; @@ -55,8 +47,7 @@ namespace Gear.Abstractions return "POST"; } - //获得一个自定义的路由 - public static string RouteTemplate(string controllerTypeName, string actionMethodName, string idStr) + public static string RouteTemplate(string controllerTypeName, string actionMethodName, string idStr) //获得一个自定义的路由 { string url = "api"; @@ -79,21 +70,40 @@ namespace Gear.Abstractions return url; } - // 过滤控制器 - public static string FiterControllerName(string controllerName) + public static string FiterControllerName(string controllerName) // 过滤控制器 { foreach (var commonPostfixe in CommonPostfixes) - controllerName = controllerName.Replace(commonPostfixe, ""); + { + if (controllerName.EndsWith(commonPostfixe)) + { + controllerName = controllerName.Remove(controllerName.IndexOf(commonPostfixe)); + break; + } + } + return controllerName; } - // 过滤方法 - public static string FiterActionName(string actionName) + + public static string FiterActionName(string actionName) // 过滤方法 { //对外方法不能有这些关键字 - foreach (var old in ActionPostfixes) - actionName = actionName.Replace(old, ""); + foreach (var actionPostfixe in ActionPostfixes) + { + if (actionName.StartsWith(actionPostfixe)) + { + actionName = actionName.Remove(actionName.IndexOf(actionPostfixe), actionPostfixe.Count()); + + if (actionName.EndsWith("Async")) + { + actionName = actionName.Remove(actionName.IndexOf("Async")); + } + break; + } + } + return actionName; } + protected long GetUserId() { if ((Configuration["LocalDebug"] ?? "") == "true") diff --git a/Gear/Gear/Abstractions/Use.cs b/Gear/Gear/Abstractions/Use.cs index 0c2721e..74dad8e 100644 --- a/Gear/Gear/Abstractions/Use.cs +++ b/Gear/Gear/Abstractions/Use.cs @@ -49,7 +49,6 @@ namespace Gear.Abstractions return ApiResponse.DROP(); } - // 代码优化之最佳WHEN 参考 IF protected static void When(bool isOk, string errMessage) //卫语句 { OVerify.When(isOk, errMessage); diff --git a/Gear/Gear/Generations/SequentialGuidGenerator.cs b/Gear/Gear/Generations/SequentialGuidGenerator.cs index c6c14cb..a3f6553 100644 --- a/Gear/Gear/Generations/SequentialGuidGenerator.cs +++ b/Gear/Gear/Generations/SequentialGuidGenerator.cs @@ -2,7 +2,7 @@ using System; using System.Security.Cryptography; -namespace Gear.Gear.Generations +namespace Gear.Generations { public class SequentialGuidGenerator : ISequentialGuidGenerator, ITransientDependency { @@ -10,49 +10,23 @@ namespace Gear.Gear.Generations /// /// 现在是SQLServer 的 算法 Guid 这个如果切库 需要换 - /// 源码地址: https://github.com/abpframework/abp/blob/48c52625f4c4df007f04d5ac6368b07411aa7521/framework/src/Volo.Abp.Guids/Volo/Abp/Guids/SequentialGuidGenerator.cs + /// ABP:https://docs.abp.io/zh-Hans/abp/latest/Guid-Generation#abpsequentialguidgeneratoroptions + /// 源码地址:https://github.com/abpframework/abp/blob/48c52625f4c4df007f04d5ac6368b07411aa7521/framework/src/Volo.Abp.Guids/Volo/Abp/Guids/SequentialGuidGenerator.cs /// public Guid Create() { - // We start with 16 bytes of cryptographically strong random data. var randomBytes = new byte[10]; RandomNumberGenerator.GetBytes(randomBytes); - // An alternate method: use a normally-created GUID to get our initial - // random data: - // byte[] randomBytes = Guid.NewGuid().ToByteArray(); - // This is faster than using RNGCryptoServiceProvider, but I don't - // recommend it because the .NET Framework makes no guarantee of the - // randomness of GUID data, and future versions (or different - // implementations like Mono) might use a different method. - - // Now we have the random basis for our GUID. Next, we need to - // create the six-byte block which will be our timestamp. - - // We start with the number of milliseconds that have elapsed since - // DateTime.MinValue. This will form the timestamp. There's no use - // being more specific than milliseconds, since DateTime.Now has - // limited resolution. - - // Using millisecond resolution for our 48-bit timestamp gives us - // about 5900 years before the timestamp overflows and cycles. - // Hopefully this should be sufficient for most purposes. :) long timestamp = DateTime.UtcNow.Ticks / 10000L; - // Then get the bytes byte[] timestampBytes = BitConverter.GetBytes(timestamp); - - // Since we're converting from an Int64, we have to reverse on - // little-endian systems. if (BitConverter.IsLittleEndian) { Array.Reverse(timestampBytes); } byte[] guidBytes = new byte[16]; - - // For sequential-at-the-end versions, we copy the random data first, - // followed by the timestamp. Buffer.BlockCopy(randomBytes, 0, guidBytes, 0, 10); Buffer.BlockCopy(timestampBytes, 2, guidBytes, 10, 6); diff --git a/Gear/Gear/Infrastructure/Extensions/ServiceCollectionServiceExtensions.cs b/Gear/Gear/Infrastructure/Extensions/ServiceCollectionServiceExtensions.cs index aca647a..698fd5e 100644 --- a/Gear/Gear/Infrastructure/Extensions/ServiceCollectionServiceExtensions.cs +++ b/Gear/Gear/Infrastructure/Extensions/ServiceCollectionServiceExtensions.cs @@ -32,10 +32,7 @@ namespace Gear.Infrastructure.Extensions public static IServiceCollection AddGear(this IServiceCollection services) { var assemblies = DependencyContext.Default.CompileLibraries. - Where(lib => - !lib.Serviceable && - lib.Type != "package" && - lib.Type != "referenceassembly"). + Where(lib => !lib.Serviceable && lib.Type != "package" && lib.Type != "referenceassembly"). Select(lib => AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(lib.Name))).ToList(); if (!assemblies.Contains(typeof(ServiceCollectionServiceExtensions).Assembly)) diff --git a/Gear/Gear/Infrastructure/Wapper/Base/EventBase.cs b/Gear/Gear/Infrastructure/Wapper/Base/EventBase.cs index b6ffabc..fbd1dc9 100644 --- a/Gear/Gear/Infrastructure/Wapper/Base/EventBase.cs +++ b/Gear/Gear/Infrastructure/Wapper/Base/EventBase.cs @@ -1,4 +1,5 @@ -using System; +using AutoMapper; +using System; namespace Gear.Wapper.Base { @@ -12,7 +13,6 @@ namespace Gear.Wapper.Base EventId = Guid.NewGuid(); EventCreationDate = DateTime.UtcNow; } - public Guid EventId { get; private set; } public DateTime EventCreationDate { get; private set; }