|
@@ -1,12 +1,15 @@
|
|
|
using AspectCore.Extensions.Reflection;
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Reflection;
|
|
|
using System.Reflection.Metadata;
|
|
|
+using TEAMModelOS.Filter;
|
|
|
using TEAMModelOS.SDK.Context.Attributes.Azure;
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
|
|
|
namespace TEAMModelOS.SDK.Helper.Common.ReflectorExtensions
|
|
|
{
|
|
@@ -65,8 +68,9 @@ namespace TEAMModelOS.SDK.Helper.Common.ReflectorExtensions
|
|
|
/// </summary>
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
/// <returns></returns>
|
|
|
- public static List<Attribute> GetMethodCustomAttribute<T,V>(string[] ScanModel)
|
|
|
+ public static (List<OpenApi>,List<Attribute>) GetMethodCustomAttribute<T,V>(string[] ScanModel)
|
|
|
{
|
|
|
+ List<OpenApi> openApis = new List<OpenApi>();
|
|
|
Type attrT = typeof(T);
|
|
|
Type attrV = typeof(V);
|
|
|
string currentDirectory = Path.GetDirectoryName(attrT.Assembly.Location);
|
|
@@ -77,19 +81,34 @@ namespace TEAMModelOS.SDK.Helper.Common.ReflectorExtensions
|
|
|
{
|
|
|
Assembly assembly = Assembly.LoadFrom(currentDirectory + "\\" + model + ".dll");
|
|
|
var TypeInModelS = assembly.GetTypes().SelectMany(x => x.GetMethods()).GroupBy(z => z.Name).ToList();
|
|
|
- // var TypeInModelSS = assembly.GetTypes().SelectMany(x => x.GetMethods()).Where(x=>);
|
|
|
- TypeInModelS.ForEach(x => {
|
|
|
- if (x.Key.Equals("GetTeacherInfo"))
|
|
|
- {
|
|
|
- var at = x.ToList().SelectMany(z => z.GetCustomAttributes()).Where(m => m.GetType().Equals(attrT));
|
|
|
- string ke = x.Key;
|
|
|
+ // var TypeInModelSS = assembly.GetTypes().SelectMany(x => x.GetMethods()).Where(x=>);
|
|
|
+
|
|
|
+ var TypeInModelTV = assembly.GetTypes().SelectMany(x => x.GetMethods()).Where(m=>m.GetCustomAttributes().Where(t=>t.GetType().Equals(attrT)).Any() && m.GetCustomAttributes().Where(t => t.GetType().Equals(attrV)).Any());
|
|
|
+ Type attrR = typeof(RouteAttribute);
|
|
|
+ foreach (var item in TypeInModelTV) {
|
|
|
+ var routeAttr = item.ReflectedType.GetCustomAttribute<RouteAttribute>();
|
|
|
+ var postAttr = item.GetCustomAttribute(attrV,true);
|
|
|
+ var apiAttr = item.GetCustomAttribute(attrT, true);
|
|
|
+ if (routeAttr!=null && postAttr!=null && apiAttr!=null) {
|
|
|
+ ApiTokenAttribute apiTokenAttribute = (ApiTokenAttribute)apiAttr;
|
|
|
+ HttpPostAttribute httpPostAttribute = (HttpPostAttribute)postAttr;
|
|
|
+ OpenApi openApi = new OpenApi
|
|
|
+ {
|
|
|
+ PartitionKey = "IES5-API",
|
|
|
+ RowKey = apiTokenAttribute.Auth,
|
|
|
+ auth = int.Parse(apiTokenAttribute.Auth),
|
|
|
+ method = "POST",
|
|
|
+ name = apiTokenAttribute.Name,
|
|
|
+ type= apiTokenAttribute.RW,
|
|
|
+ url =$"/{routeAttr.Template}/{httpPostAttribute.Template}"
|
|
|
+ };
|
|
|
+ openApis.Add(openApi);
|
|
|
+ attributes.Add(apiTokenAttribute);
|
|
|
}
|
|
|
- });
|
|
|
- var TypeInModel = assembly.GetTypes().Select(x => x.GetMethods()).SelectMany(y => y).Select(z => z.GetCustomAttribute(attrT, true)).Where(n => n != null);
|
|
|
- attributes.AddRange(TypeInModel);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- return attributes;
|
|
|
+ return (openApis, attributes) ;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取T类型属性标记的类集合
|