|
|
@ -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"; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the <see cref="ClaimsPrincipal"/> for user associated with the executing action.
|
|
|
|
/// </summary>
|
|
|
|
protected ClaimsPrincipal User => HttpContext?.User!; |
|
|
|
/// <summary>
|
|
|
|
/// Gets the <see cref="Http.HttpContext"/> for the executing action.
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
protected HttpContext HttpContext => LazyServiceProvider.LazyGetService<IHttpContextAccessor>().HttpContext; |
|
|
|
|
|
|
|
protected IDecryptClaim DecryptClaim => LazyServiceProvider.LazyGetService<IDecryptClaim>(); |
|
|
|
|
|
|
|
//获得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") |
|
|
|