From 190a6c4a300d357cad57917aaf099683533dcbf7 Mon Sep 17 00:00:00 2001 From: zhaohuiyingxue Date: Sat, 18 May 2024 14:05:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0MIME=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=86=85=E5=AD=98?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=BB=84=E4=BB=B6=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E5=99=A8AOP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WeaveMicro/Startup.cs" | 14 +- .../WeaveMicro/config.json" | 19 +- .../gateway/Startup.cs" | 23 +- .../gateway/config.json" | 17 ++ .../wRPCService/Aop.cs" | 253 ++++++++++++++++++ .../wRPCService/CacheManager.cs" | 170 ++++++++++++ .../wRPCService/ServiceChannel.cs" | 61 ++--- .../wRPCService/wRPCService.csproj" | 1 + 8 files changed, 505 insertions(+), 53 deletions(-) create mode 100644 "\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/Aop.cs" create mode 100644 "\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/CacheManager.cs" diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveMicro/Startup.cs" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveMicro/Startup.cs" index 6b27616..72ee83d 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveMicro/Startup.cs" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveMicro/Startup.cs" @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.StaticFiles; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; @@ -23,9 +24,12 @@ namespace WeaveMicro public IConfiguration Configuration { get; } + static IConfigurationBuilder builder = new ConfigurationBuilder().SetBasePath(AppDomain.CurrentDomain.BaseDirectory).AddJsonFile("config.json"); + public static IConfigurationRoot config; // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + config = builder.Build(); services.AddRazorPages(); } @@ -45,7 +49,9 @@ namespace WeaveMicro string contentRoot = AppDomain.CurrentDomain.BaseDirectory; string runRoot = AppDomain.CurrentDomain.BaseDirectory; - IFileProvider fileProvider = new PhysicalFileProvider(Path.Combine(contentRoot, @"doc"));//静态文件存储目录 + //静态文件浏览支持,默认路径为www映射到Static。根据MIME配置添加支持的文件格式 + var mime = config.GetSection("MIME")?.Get>() ?? default; + IFileProvider fileProvider = new PhysicalFileProvider(Path.Combine(contentRoot, config.GetSection("StaticFilePath")?.Get() ?? @"doc"));//静态文件存储目录 IFileProvider runProvider = new PhysicalFileProvider(runRoot);//运行目录 string reqPath = runRoot.Replace(contentRoot, "").Replace("\\", "/").TrimEnd('/'); @@ -55,11 +61,13 @@ namespace WeaveMicro app.UseStaticFiles(new StaticFileOptions { FileProvider = fileProvider, - RequestPath = "/documents" + RequestPath = config.GetSection("StaticFileRequestPath")?.Get() ?? @"documents", + ContentTypeProvider = new FileExtensionContentTypeProvider(mime) }).UseStaticFiles(new StaticFileOptions { FileProvider = runProvider, - RequestPath = reqPath + RequestPath = reqPath, + ContentTypeProvider = new FileExtensionContentTypeProvider(mime) }); //app.UseFileServer(new FileServerOptions()//提供文件目录访问形式 //{ diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveMicro/config.json" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveMicro/config.json" index 9adf2b6..edb3cd1 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveMicro/config.json" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveMicro/config.json" @@ -1,5 +1,22 @@ { "version": "1.0.0", "port": 9001, - "url": "http://127.0.0.1:5022" + "url": "http://127.0.0.1:5022", + //闈欐佹祻瑙堢洰褰 + "StaticFilePath": "doc", + //闈欐佹祻瑙堣姹傚湴鍧鏄犲皠 + "StaticFileRequestPath": "documents", + //MIME淇℃伅鏀寔 + "MIME": { + ".apk": "application/vnd.android.package-archive", + ".png": "image/png", + ".jpg": "image/png", + ".gif": "image/png", + ".pdf": "application/pdf", + ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + ".doc": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + ".xslx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + ".xsl": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + ".json": "application/json" + } } \ No newline at end of file diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/Startup.cs" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/Startup.cs" index 4a4574f..2200f1e 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/Startup.cs" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/Startup.cs" @@ -21,6 +21,7 @@ using Microsoft.AspNetCore.StaticFiles; using static System.Net.WebRequestMethods; using static System.Net.Mime.MediaTypeNames; using System.Net.NetworkInformation; +using System.Xml.Linq; //[assembly: OwinStartup(typeof(gateway.Startup))] namespace gateway { @@ -82,26 +83,14 @@ namespace gateway // app.UseIdentityServer(); string contentRoot = AppDomain.CurrentDomain.BaseDirectory; string runRoot = AppDomain.CurrentDomain.BaseDirectory; - IFileProvider fileProvider = new PhysicalFileProvider(Path.Combine(contentRoot, @"www"));//闈欐佹枃浠跺瓨鍌ㄧ洰褰 - + //闈欐佹枃浠舵祻瑙堟敮鎸侊紝榛樿璺緞涓簑ww鏄犲皠鍒癝tatic銆傛牴鎹甅IME閰嶇疆娣诲姞鏀寔鐨勬枃浠舵牸寮 + var mime = config.GetSection("MIME")?.Get>() ?? default; + IFileProvider fileProvider = new PhysicalFileProvider(Path.Combine(contentRoot, config.GetSection("StaticFilePath")?.Get()??@"www"));//闈欐佹枃浠跺瓨鍌ㄧ洰褰 app.UseStaticFiles(new StaticFileOptions { FileProvider = fileProvider, - RequestPath = "/Static", - ContentTypeProvider = new FileExtensionContentTypeProvider(new Dictionary - { - { ".apk", "application/vnd.android.package-archive" }, - { ".png", "image/png" }, - { ".jpg", "image/jpeg" }, - { ".gif", "image/gif" }, - { ".pdf", "application/pdf" }, - { ".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document" }, - { ".doc", "application/vnd.openxmlformats-officedocument.wordprocessingml.document" }, - { ".xslx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }, - { ".xsl", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }, - { ".json", "application/json" } - //application/json - }) + RequestPath = config.GetSection("StaticFileRequestPath")?.Get() ?? @"Static", + ContentTypeProvider = new FileExtensionContentTypeProvider(mime) }); diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/config.json" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/config.json" index 9becbb7..4f311f7 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/config.json" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/config.json" @@ -7,6 +7,23 @@ "bindIP": "127.0.0.1", "Microcenter": "127.0.0.1:9001", "filetype": ".jpg,.png,.doc,.txt,.xlsx,.xls,.docx,.AVI,.mov,.rmvb,.rm,.FLV,.mp4,.3GP,.BMP,.DIB,.PCP,.DIF,.WMF,.GIF,.JPG,.TIF,.EPS,.PSD,.CDR,.IFF,.TGA,.PCD,.MPT,.PNG,.gif", + //闈欐佹祻瑙堢洰褰 + "StaticFilePath": "www", + //闈欐佹祻瑙堣姹傚湴鍧鏄犲皠 + "StaticFileRequestPath": "Static", + //MIME淇℃伅鏀寔 + "MIME": { + ".apk": "application/vnd.android.package-archive", + ".png": "image/png", + ".jpg": "image/png", + ".gif": "image/png", + ".pdf": "application/pdf", + ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + ".doc": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + ".xslx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + ".xsl": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + ".json": "application/json" + }, "httpspassword": "linezero", "Cookies": [ "Areacode", "Role", "UserId", "Name", "Phone" ], "distributed": false, //鍗曟満杩樻槸鍒嗗竷寮 diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/Aop.cs" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/Aop.cs" new file mode 100644 index 0000000..345f169 --- /dev/null +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/Aop.cs" @@ -0,0 +1,253 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using wRPC.DataLogic; +using wRPC; +using Microsoft.Extensions.Caching.Memory; +using Newtonsoft.Json; + +namespace wRPCService +{ + /// + /// Aop缁勪欢锛岀洰鍓嶄粎鏀寔鐗规э紝涓嶆敮鎸佸叏灞锛屽彲浠ュ啓鍦ㄧ被涓 + /// + public class Aop + { + /// + /// 璋冪敤鎸囧畾鏂规硶 + /// + /// 鏂规硶淇℃伅 + /// 瀹炰緥瀵硅薄 + /// 鏂规硶鍙傛暟 + /// 杩斿洖鍊 + public static object Invoke(MethodInfo method, object obj, object[] parameters) + { + //鑾峰彇鎵鏈堿OP鐗规 + var aop = method.GetCustomAttributes().Union( + method.ReflectedType.GetCustomAttributes() + ).OrderBy(d => d.Order).ToList(); + //缁勮涓婁笅鏂 + var context = new AopContext { Method = method, Instance = obj, Parameters = parameters }; + int aopNums = aop.Count();//AOP鐗规ф绘暟 + int maxAop = 0;//鏈夋晥鐨凙OP鏁伴噺 + bool needExecute = true;//鏄惁闇瑕佹墽琛屾柟娉曚綋 + //OnActionExecuting + for (int i = 0; i < aopNums; i++) + { + //璁板綍鏈鍚庝竴涓繍琛岀殑鐗规э紝濡傛灉杩斿洖false鍒欎笉鎵ц涔嬪悗鐨 + maxAop = i; + needExecute = aop[i].OnActionExecuting(context); + if (!needExecute) break; + } + //杩愯鏂规硶浣 + if (needExecute) + { + try + { + context.Result = method.Invoke(obj, parameters); + } + catch (Exception err) + { + context.Exception = err; + } + } + //OnActionExecuted + for (int i = aopNums; i >= 0; i--) + { + if (!aop[i].OnActionExecuted(context)) break; + } + return context.Result; + } + } + /// + /// Aop涓婁笅鏂囧璞 + /// + public class AopContext + { + /// + /// 鏂规硶淇℃伅 + /// + public MethodInfo Method { get; set; } + /// + /// 瀹炰緥瀵硅薄 + /// + public object Instance { get; set; } + /// + /// 鏂规硶鍙傛暟 + /// + public object[] Parameters { get; set; } + /// + /// 杩斿洖缁撴灉 + /// + public object Result { get; set; } + /// + /// 涓存椂鍙橀噺 + /// + public Dictionary Data { get; set; } = new Dictionary(); + /// + /// 寮傚父淇℃伅 + /// + public Exception Exception { get; set; } + } + /// + /// Aop鐗规э紝鎵鏈夐渶瑕丄op鎿嶄綔鐨勭壒鎬у潎搴旂户鎵挎鐗规 + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)] + public abstract class AopAttribute : Attribute + { + /// + /// 鎺掑簭锛岃秺灏忚秺澶栦晶杩愯銆 + /// + public virtual int Order { get; set; } = 100; + /// + /// 鍦ˋction鎵ц涔嬪墠 + /// + /// 涓婁笅鏂 + /// 鏄惁缁х画鎵ц锛岄粯璁rue + public virtual bool OnActionExecuting(AopContext context) => true; + /* + /// + /// 鍦ㄦ墽琛孯esult涔嬪墠 + /// + /// 涓婁笅鏂 + /// 鏄惁缁х画鎵ц锛岄粯璁rue + public abstract void OnResultExecuting(AopContext context); + /// + /// 鍦ㄦ墽琛孯esult涔嬪悗 + /// + /// 涓婁笅鏂 + /// 鏄惁缁х画鎵ц锛岄粯璁rue + public abstract void OnResultExecuted(AopContext context); + */ + /// + /// 鍦ˋction鎵ц涔嬪悗 + /// + /// 涓婁笅鏂 + /// 鏄惁缁х画鎵ц锛岄粯璁rue + public virtual bool OnActionExecuted(AopContext context) => true; + } + /// + /// TRY鏂规硶 + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)] + public class TryAttribute : AopAttribute + { + /// + /// Try鏀惧埌绗竴浣 + /// + public override int Order { get; set; } = int.MinValue; + public override bool OnActionExecuted(AopContext context) + { + var o = new ApiResult() { code = 200, message = "鎿嶄綔鎴愬姛" }; + if (context.Exception is null) + { + o.data = context.Result; + } + else + { + //寮傛鏀瑰悓姝ュ湪杩欓噷鍒ゆ柇寮傚父绫诲瀷 + if (context.Exception is AggregateException ae) + { + ae.Handle((x) => + { + if (x is ApiException) + { + o.code = 0; + o.message = $"鎿嶄綔澶辫触锛歿x.Message}"; + o.errData = (x as ApiException).data; + } + else + { + o.code = 500; + o.message = $"鎺ュ彛璋冪敤寮傚父锛歿x.Message}"; + } + return true; + }); + } + else if (context.Exception is ApiException e) + { + o.code = 0; + o.message = $"鎿嶄綔澶辫触锛歿e.Message}"; + o.errData = e.data; + } + else + { + o.code = 500; + o.message = $"鎺ュ彛璋冪敤寮傚父锛歿context.Exception.Message}"; + } + } + context.Result = o; + return base.OnActionExecuted(context); + } + } + /// + /// 鍐呭瓨缂撳瓨鐗规 + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)] + public class MemoryCacheAttribute : AopAttribute + { + /// + /// 缂撳瓨閿紝榛樿鍒欎负鏂规硶鍚+鍙傛暟鍝堝笇銆 + /// + public string Key { get; set; } + /// + /// 缂撳瓨婊戝姩绐楀彛锛屽崟浣嶇锛岄粯璁60绉掞紝鍙栨秷璇蜂娇鐢-1銆 + /// + public int SlidingExpiration { get; set; } = 60; + /// + /// 缂撳瓨鍥哄畾绐楀彛锛屽崟浣嶇锛岄粯璁3600绉掞紙60鍒嗛挓锛夛紝鍙栨秷璇蜂娇鐢-1锛屽洜姝ゆ棤娉曟敮鎸佹暣鐐硅繖鏍风殑闇姹 + /// + public int AbsoluteExpiration { get; set; } = 60 * 60; + /// + /// 缂撳瓨渚濊禆锛屽叾浠栫紦瀛橀敭 + /// + public string[] DependCache { get; set; } + /// + /// 鑾峰彇缂撳瓨閿 + /// + /// 缂撳瓨閿 + private object GetKey(AopContext context) + { + if (string.IsNullOrWhiteSpace(Key)) + { + var param = context.Parameters == null ? "0" + : string.Join("_", context.Parameters.Select(p => JsonConvert.SerializeObject(p).GetHashCode())); + Key = $"{context.Method.Name}_{param}"; + } + return Key; + } + public override int Order { get; set; } = int.MaxValue; + /// + /// 鏄惁瀛樺湪缂撳瓨 + /// + private bool hasCache = false; + public override bool OnActionExecuting(AopContext context) + { + if (CacheManager._cache.TryGetValue(this.GetKey(context), out var o)) + { + hasCache = true; + context.Result = o; + return false; + } + else + { + hasCache = false; + return true; + } + } + + public override bool OnActionExecuted(AopContext context) + { + if (context.Exception is null && hasCache == false) + { + CacheManager._cache.Set(this.GetKey(context), context.Result, + CacheManager.CreateCachePolicy( + AbsoluteExpiration == -1 ? TimeSpan.Zero : TimeSpan.FromSeconds(AbsoluteExpiration), + SlidingExpiration == -1 ? TimeSpan.Zero : TimeSpan.FromSeconds(SlidingExpiration), + DependCache)); + } + return base.OnActionExecuted(context); + } + } +} \ No newline at end of file diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/CacheManager.cs" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/CacheManager.cs" new file mode 100644 index 0000000..624dec4 --- /dev/null +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/CacheManager.cs" @@ -0,0 +1,170 @@ +锘縰sing Microsoft.Extensions.Caching.Memory; +using Microsoft.Extensions.Options; +using Microsoft.Extensions.Primitives; +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace wRPCService +{ + /// + /// 缂撳瓨绠$悊鍣 + /// + public class CacheManager + { + /// + /// 榛樿缂撳瓨婊戝姩绐楀彛 + /// + public static readonly TimeSpan defaultSlidingExpiration = TimeSpan.FromSeconds(60); + /// + /// 榛樿缂撳瓨鍥哄畾绐楀彛 + /// + public static readonly TimeSpan defaultAbsoluteExpiration = TimeSpan.FromMinutes(60); + /// + /// 榛樿鍐呭瓨缂撳瓨瀵硅薄 + /// + internal static MemoryCache _cache = new MemoryCache(Options.Create(new MemoryCacheOptions())); + /// + /// 渚濊禆鍏崇郴鍐呭瓨缂撳瓨瀵硅薄 + /// + private static MemoryCache _dependCache = new MemoryCache(Options.Create(new MemoryCacheOptions())); + /// + /// 缂撳瓨杩囨湡鍚庨氱煡Token鍙栨秷锛屼互渚夸娇鍏宠仈鐨勭紦瀛樹篃杩囨湡 + /// + private static PostEvictionDelegate EvictionCallback = (object key, object value, EvictionReason reason, object state) + => + { + _dependCache.GetOrCreate(key, o => new CancellationTokenSource()).Cancel(); + _dependCache.Remove(key); + }; + /// + /// 鍒涘缓缂撳瓨杩囨湡绛栫暐 + /// + /// 鍥哄畾绐楀彛 + /// 婊戝姩绐楀彛 + /// 渚濊禆缂撳瓨鍒楄〃 + /// 缂撳瓨杩囨湡绛栫暐 + public static MemoryCacheEntryOptions CreateCachePolicy(TimeSpan absoluteExpiration, TimeSpan slidingExpiration, params object[] dependCacheList) + { + var policy = new MemoryCacheEntryOptions(); + if (absoluteExpiration > TimeSpan.Zero) policy.SetAbsoluteExpiration(absoluteExpiration); + if (slidingExpiration > TimeSpan.Zero) policy.SetSlidingExpiration(slidingExpiration); + policy.RegisterPostEvictionCallback(EvictionCallback); + //渚濊禆缂撳瓨閿 + if (dependCacheList != null && dependCacheList.Count() > 0) + { + foreach (var depend in dependCacheList) + { + var cts = _dependCache.GetOrCreate(depend, o => new CancellationTokenSource()); + policy.AddExpirationToken(new CancellationChangeToken(cts.Token)); + } + } + return policy; + } + /// + /// 鍒涘缓缂撳瓨杩囨湡绛栫暐 + /// + /// 鍥哄畾绐楀彛 + /// 婊戝姩绐楀彛 + /// 缂撳瓨杩囨湡绛栫暐 + public static MemoryCacheEntryOptions CreateCachePolicy(TimeSpan absoluteExpiration, TimeSpan slidingExpiration) + => CreateCachePolicy(absoluteExpiration, slidingExpiration, null); + /// + /// 鍒涘缓缂撳瓨杩囨湡绛栫暐(榛樿绐楀彛鏃堕棿) + /// + /// 渚濊禆缂撳瓨鍒楄〃 + /// 缂撳瓨杩囨湡绛栫暐 + public static MemoryCacheEntryOptions CreateCachePolicy(params string[] dependCacheList) + => CreateCachePolicy(TimeSpan.Zero, TimeSpan.Zero, dependCacheList); + + /// + /// 鍘熺敓缂撳瓨鏂规硶璋冪敤 + /// + /// 缂撳瓨鏁版嵁绫诲瀷 + /// 缂撳瓨閿 + /// 缂撳瓨鍊艰幏鍙栨柟娉曪紝闇瑕佹墜鍔ㄥ疄鐜版潯鐩緷璧栫瓑淇℃伅 + /// 缂撳瓨鍊 + public static async Task GetOrCreateAsync(object key, Func> factory, MemoryCacheEntryOptions policy = null) + { + if (policy == null) policy = CreateCachePolicy(defaultAbsoluteExpiration, defaultSlidingExpiration); + return await _cache.GetOrCreateAsync(key,async entry => { entry.SetOptions(policy); return await factory(entry); }); + } + /// + /// 鍘熺敓缂撳瓨鏂规硶璋冪敤 + /// + /// 缂撳瓨鏁版嵁绫诲瀷 + /// 缂撳瓨閿 + /// 缂撳瓨鍊艰幏鍙栨柟娉曪紝闇瑕佹墜鍔ㄥ疄鐜版潯鐩緷璧栫瓑淇℃伅 + /// 缂撳瓨鍊 + public static TItem GetOrCreate(object key, Func factory, MemoryCacheEntryOptions policy = null) + { + if (policy == null) policy = CreateCachePolicy(defaultAbsoluteExpiration, defaultSlidingExpiration); + return _cache.GetOrCreate(key, entry => { entry.SetOptions(policy); return factory(entry); }); + } + + /// + /// 鑾峰彇鎴栧垱寤虹紦瀛 + /// + /// 瑕佽繑鍥炲肩殑绫诲瀷 + /// 缂撳瓨閿 + /// 鏈紦瀛樻椂鑾峰彇鍊肩殑鏂规硶 + /// 缂撳瓨杩囨湡绛栫暐锛屽彲浠ラ氳繃CacheManager.CreateCachePolicy鑾峰彇鍩烘湰绛栫暐锛屽鏋滀负null鍒欒缃负榛樿绛栫暐(鍥哄畾绐楀彛60鍒嗭紝婊戝姩绐楀彛1鍒) + /// 缂撳瓨鍚庣殑瀵硅薄 + public static TItem GetOrCreate(object key, Func factory, MemoryCacheEntryOptions policy = null) + { + if (policy == null) policy = CreateCachePolicy(defaultAbsoluteExpiration, defaultSlidingExpiration); + return _cache.GetOrCreate(key, entry => { entry.SetOptions(policy); return factory(); }); + } + + /// + /// 鑾峰彇鎴栧垱寤虹紦瀛 + /// + /// 瑕佽繑鍥炲肩殑绫诲瀷 + /// 缂撳瓨閿 + /// 鏈紦瀛樻椂鑾峰彇鍊肩殑鏂规硶 + /// 缂撳瓨杩囨湡绛栫暐锛屽彲浠ラ氳繃CacheManager.CreateCachePolicy鑾峰彇鍩烘湰绛栫暐锛屽鏋滀负null鍒欒缃负榛樿绛栫暐(鍥哄畾绐楀彛60鍒嗭紝婊戝姩绐楀彛1鍒) + /// 缂撳瓨鍚庣殑瀵硅薄 + public static async Task GetOrCreateAsync(object key, Func> factory, MemoryCacheEntryOptions policy = null) + { + if (policy == null) policy = CreateCachePolicy(defaultAbsoluteExpiration, defaultSlidingExpiration); + return await _cache.GetOrCreateAsync(key, async entry => { entry.SetOptions(policy); return await factory(); }); + } + + /// + /// 鑾峰彇鎴栧垱寤虹紦瀛 + /// + /// + /// 缂撳瓨閿 + /// 鏈紦瀛樻椂鑾峰彇鍊肩殑鏂规硶 + /// 缂撳瓨鍚庣殑瀵硅薄 + public static TItem GetOrCreate(object key, Func factory, MemoryCacheEntryOptions policy = null) + { + if (policy == null) policy = CreateCachePolicy(defaultAbsoluteExpiration, defaultSlidingExpiration); + return _cache.GetOrCreate(key, entry => { entry.SetOptions(policy); return factory(policy); }); + } + + /// + /// 鑾峰彇鎴栧垱寤虹紦瀛 + /// + /// + /// 缂撳瓨閿 + /// 鏈紦瀛樻椂鑾峰彇鍊肩殑鏂规硶 + /// 缂撳瓨鍚庣殑瀵硅薄 + public static async Task GetOrCreateAsync(object key, Func> factory, MemoryCacheEntryOptions policy = null) + { + if (policy == null) policy = CreateCachePolicy(defaultAbsoluteExpiration, defaultSlidingExpiration); + return await _cache.GetOrCreateAsync(key, async entry => { entry.SetOptions(policy); return await factory(policy); }); + } + + /// + /// 鍒犻櫎缂撳瓨 + /// + /// 缂撳瓨閿 + public static void Remove(object key) { + _cache.Remove(key); + _dependCache.GetOrCreate(key, o => new CancellationTokenSource()).Cancel(); + _dependCache.Remove(key); + } + } +} \ No newline at end of file diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/ServiceChannel.cs" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/ServiceChannel.cs" index b271527..a9b9018 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/ServiceChannel.cs" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/ServiceChannel.cs" @@ -1,52 +1,47 @@ 锘 using System; -using System.Collections.Concurrent; using System.Collections.Generic; -using System.IO; using System.Reflection; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using System.Threading.Tasks; -using System.Web; using wRPC; -using static wRPC.FunctionBase; namespace wRPCService { public class ServiceChannel { - public Weave.Server.WeaveP2Server P2Server = new Weave.Server.WeaveP2Server(Weave.Base.WeaveDataTypeEnum.Bytes); + public Weave.Server.WeaveP2Server P2Server = new Weave.Server.WeaveP2Server(Weave.Base.WeaveDataTypeEnum.Bytes); Dictionary keyValuePairs = new Dictionary(); int Port; - + public ServiceChannel(int port) { - // MM_BeginPeriod(1); + // MM_BeginPeriod(1); P2Server.resttime = 10; P2Server.weaveReceiveBitEvent += P2Server_weaveReceiveBitEvent; - Port = port; - - - + Port = port; + + + } private async void P2Server_weaveReceiveBitEvent(byte command, byte[] data, System.Net.Sockets.Socket soc) { try { - + String rdata = GZIP.GZipDecompress(data); Rpcdata rpdata = Newtonsoft.Json.JsonConvert.DeserializeObject>(rdata); if (!keyValuePairs.ContainsKey(rpdata.Route)) { - P2Server.Send(soc, 0x05, GZIP.GZipCompress( "server Route error")); + P2Server.Send(soc, 0x05, GZIP.GZipCompress("server Route error")); return; } //Type tt = keyValuePairs[rpdata.Route.Replace('/', '.')]; //Assembly ab = Assembly.GetAssembly(tt); - // object obj = ab.CreateInstance(tt.FullName); + // object obj = ab.CreateInstance(tt.FullName); object obj = keyValuePairs[rpdata.Route]; Type t = obj.GetType(); obj = t.Assembly.CreateInstance(t.FullName); @@ -67,14 +62,14 @@ namespace wRPCService (obj as FunctionBase).Headers = rpdata.Headers; - + } if (obj is FunctionBase && rpdata.Cookies != null) { - + (obj as FunctionBase).Cookies = rpdata.Cookies; } @@ -88,10 +83,10 @@ namespace wRPCService } ParameterInfo[] paramsInfo = mi.GetParameters();//寰楀埌鎸囧畾鏂规硶鐨勫弬鏁板垪琛 if (paramsInfo.Length != objs.Length) - { P2Server.Send(soc, 0x02, GZIP.GZipCompress("鍙傛暟涓嶆纭"));return; } - for (int i = 0; i < objs.Length; i++) + { P2Server.Send(soc, 0x02, GZIP.GZipCompress("鍙傛暟涓嶆纭")); return; } + for (int i = 0; i < objs.Length; i++) { - + Type tType = paramsInfo[i].ParameterType; //濡傛灉瀹冩槸鍊肩被鍨,鎴栬匰tring @@ -105,7 +100,7 @@ namespace wRPCService objs[i] = (Convert.ChangeType(objs[i], tType)); } - else if(tType.Equals(typeof(byte)) || tType.Equals(typeof(byte[])) || (!tType.IsInterface && !tType.IsClass)) + else if (tType.Equals(typeof(byte)) || tType.Equals(typeof(byte[])) || (!tType.IsInterface && !tType.IsClass)) { objs[i] = Convert.FromBase64String(objs[i].ToString()); } @@ -122,7 +117,7 @@ namespace wRPCService object rpcdata; if (Asyncmyattribute != null) { - var task = (mi.Invoke(obj, objs) as Task); + var task = (Aop.Invoke(mi, obj, objs) as Task); // task.Wait(); var resultProperty = task.GetType().GetProperty("Result"); @@ -132,15 +127,15 @@ namespace wRPCService } else { - - rpcdata = mi.Invoke(obj, objs); - - + + rpcdata = Aop.Invoke(mi, obj, objs); + + } if (rpcdata != null) { String tmpdata = Newtonsoft.Json.JsonConvert.SerializeObject(rpcdata); - + int sendlen = 1024 * 1024; if (tmpdata.Length > sendlen) { @@ -157,9 +152,11 @@ namespace wRPCService P2Server.Send(soc, 0x11, outdata); } P2Server.Send(soc, 0x10, GZIP.GZipCompress("鎴愬姛")); - }else - P2Server.Send(soc, 0x01, GZIP.GZipCompress(tmpdata)); - }else + } + else + P2Server.Send(soc, 0x01, GZIP.GZipCompress(tmpdata)); + } + else P2Server.Send(soc, 0x10, GZIP.GZipCompress("鎴愬姛")); //DateTime dt2 = DateTime.Now; @@ -168,7 +165,7 @@ namespace wRPCService } } - + } catch (Exception e) @@ -185,5 +182,5 @@ namespace wRPCService } } - + } diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/wRPCService.csproj" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/wRPCService.csproj" index 1a09fb6..2e31396 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/wRPCService.csproj" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/wRPCService.csproj" @@ -12,6 +12,7 @@ + -- Gitee From 8e0cfc3ca4bbf6811f1c97ff4c34b0fbb3b913fc Mon Sep 17 00:00:00 2001 From: zhaohuiyingxue Date: Sat, 18 May 2024 23:55:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=BF=87=E6=BB=A4=E5=99=A8AOP=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=8F=8A=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WeaveDoc/SwaggerExtensions.cs" | 2 +- .../WeaveDoc/WeaveDoc.csproj" | 2 +- .../WeaveMicro/Startup.cs" | 15 +- .../WeaveMicro/config.json" | 15 +- .../WeaveRemoteService.csproj" | 2 +- .../gateway/CallServer.cs" | 74 +++------ .../gateway/Startup.cs" | 18 +- .../gateway/config.json" | 15 +- .../testdll2/Class1.cs" | 7 +- .../wRPCService/Aop.cs" | 157 +++--------------- .../wRPCService/AopAttributes.cs" | 118 +++++++++++++ .../wRPCService/CacheManager.cs" | 8 +- .../wRPCService/ServiceChannel.cs" | 26 +-- .../wRPCService/wRPCService.csproj" | 2 +- 14 files changed, 213 insertions(+), 248 deletions(-) create mode 100644 "\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/AopAttributes.cs" diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveDoc/SwaggerExtensions.cs" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveDoc/SwaggerExtensions.cs" index 285a211..3cca022 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveDoc/SwaggerExtensions.cs" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveDoc/SwaggerExtensions.cs" @@ -32,7 +32,7 @@ namespace WeaveDoc if (File.Exists(path))//鐞嗚涓婅偗瀹氬瓨鍦ㄤ笖鏈夊硷紝绠鍗曞垽鏂笅 { var json = File.ReadAllText(path); - var config = JsonSerializer.Deserialize>(json, new JsonSerializerOptions() { AllowTrailingCommas = true }); + var config = JsonSerializer.Deserialize>(json, new JsonSerializerOptions() { AllowTrailingCommas = true , ReadCommentHandling= JsonCommentHandling.Skip }); //濡傛灉璁剧疆涓烘暟瀛楁垨鍏朵粬锛屼负鍏跺瓧绗︿覆褰㈠紡锛屽 1.23锛孴rue锛孾1,2,3]閮芥敮鎸侊紝浣嗗お澶嶆潅鐨勪笉鏀寔锛堝挨鍏跺甫鍥炶溅鐨勶級 if (config.ContainsKey("SwaggerPath")) swaggerPath = config["SwaggerPath"]?.ToString(); //濡傛灉璁剧疆涓篘ull锛屽垯涓嶅惎鐢ㄦ枃妗o紝鐢熶骇鐜涓嬪彲浠ユ寚瀹 diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveDoc/WeaveDoc.csproj" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveDoc/WeaveDoc.csproj" index 4bc2289..8715b0e 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveDoc/WeaveDoc.csproj" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveDoc/WeaveDoc.csproj" @@ -3,7 +3,7 @@ netstandard2.0 True - 1.0.6 + 1.0.7 WeaveMicro寰湇鍔★紝API鏂囨。鏀寔绫诲簱 dreamsfly900 diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveMicro/Startup.cs" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveMicro/Startup.cs" index 72ee83d..a5ece30 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveMicro/Startup.cs" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveMicro/Startup.cs" @@ -1,6 +1,5 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.StaticFiles; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -9,8 +8,6 @@ using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Threading.Tasks; using WeaveDoc; namespace WeaveMicro @@ -50,7 +47,14 @@ namespace WeaveMicro string contentRoot = AppDomain.CurrentDomain.BaseDirectory; string runRoot = AppDomain.CurrentDomain.BaseDirectory; //静态文件浏览支持,默认路径为www映射到Static。根据MIME配置添加支持的文件格式 - var mime = config.GetSection("MIME")?.Get>() ?? default; + var mime = new FileExtensionContentTypeProvider().Mappings; + mime[".apk"] = "application/vnd.android.package-archive"; + var mimeCustom = config.GetSection("MIME")?.Get>() ?? new Dictionary(); + foreach (var m in mimeCustom) + { + if (string.IsNullOrWhiteSpace(m.Value)) mime.Remove(m.Key); + else mime[m.Key] = m.Value; + } IFileProvider fileProvider = new PhysicalFileProvider(Path.Combine(contentRoot, config.GetSection("StaticFilePath")?.Get() ?? @"doc"));//静态文件存储目录 IFileProvider runProvider = new PhysicalFileProvider(runRoot);//运行目录 @@ -61,7 +65,8 @@ namespace WeaveMicro app.UseStaticFiles(new StaticFileOptions { FileProvider = fileProvider, - RequestPath = config.GetSection("StaticFileRequestPath")?.Get() ?? @"documents", + RequestPath = config.GetSection("StaticFileRequestPath") + ?.Get()?.TrimEnd('/') ?? @"/documents", ContentTypeProvider = new FileExtensionContentTypeProvider(mime) }).UseStaticFiles(new StaticFileOptions { diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveMicro/config.json" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveMicro/config.json" index edb3cd1..3a86c79 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveMicro/config.json" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveMicro/config.json" @@ -4,19 +4,10 @@ "url": "http://127.0.0.1:5022", //闈欐佹祻瑙堢洰褰 "StaticFilePath": "doc", - //闈欐佹祻瑙堣姹傚湴鍧鏄犲皠 - "StaticFileRequestPath": "documents", + //闈欐佹祻瑙堣姹傚湴鍧鏄犲皠锛屼互/寮澶 + "StaticFileRequestPath": "/", //MIME淇℃伅鏀寔 "MIME": { - ".apk": "application/vnd.android.package-archive", - ".png": "image/png", - ".jpg": "image/png", - ".gif": "image/png", - ".pdf": "application/pdf", - ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", - ".doc": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", - ".xslx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - ".xsl": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - ".json": "application/json" + ".apk": "application/vnd.android.package-archive" } } \ No newline at end of file diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveRemoteService/WeaveRemoteService.csproj" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveRemoteService/WeaveRemoteService.csproj" index 3c4824a..794a5df 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveRemoteService/WeaveRemoteService.csproj" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/WeaveRemoteService/WeaveRemoteService.csproj" @@ -5,7 +5,7 @@ true false WeaveMicro寰湇鍔★紝杩滅▼API鍚姩绫诲簱锛岃礋璐h繛鎺ユ敞鍐屼腑蹇冧笌鍚姩鏈湴鏂规硶鐨勭洃鍚 - 1.0.14 + 1.0.15 dreamsfly900 diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/CallServer.cs" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/CallServer.cs" index 819784b..868d62c 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/CallServer.cs" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/CallServer.cs" @@ -12,33 +12,34 @@ using static wRPCclient.ClientChannel; using System.Reflection; using System.Runtime.CompilerServices; using System.Xml.Linq; +using wRPCService; namespace gateway { public class CallServer { - static ConcurrentDictionary _serviceDic = new ConcurrentDictionary(); - public static Dictionary keyValuePairs = new Dictionary(); + static ConcurrentDictionary _serviceDic = new ConcurrentDictionary(); + public static Dictionary keyValuePairs = new Dictionary(); public static void heartbeat() { - - // System.Threading.ThreadPool.QueueUserWorkItem(new WaitCallback(keep),null); + + // System.Threading.ThreadPool.QueueUserWorkItem(new WaitCallback(keep),null); } - public static bool distributed=false; + public static bool distributed = false; public static string CallService(server ser, String rt, String rls, object[] objs, - Dictionary Headers, Dictionary keysCookies, ClientChannel.recdata rec=null, ClientChannel.recdataStream recStream=null, - wRPCclient.filedata fd =null) + Dictionary Headers, Dictionary keysCookies, ClientChannel.recdata rec = null, ClientChannel.recdataStream recStream = null, + wRPCclient.filedata fd = null) { bool locked = false; wRPCclient.ClientChannel clientChannel = null; - + ClientChannelQueue CCQ = null; - + try { if (distributed) { - + clientChannel = new wRPCclient.ClientChannel(ser.IP, ser.Port); CCQ = new ClientChannelQueue(); CCQ.clientChannel = clientChannel; @@ -62,9 +63,9 @@ namespace gateway //鍗曟満杩愯 if (!keyValuePairs.ContainsKey(rt)) { - + return JsonConvert.SerializeObject(new { code = 503, msg = "server Route error" }); - + } object obj = keyValuePairs[rt]; Type t = obj.GetType(); @@ -75,7 +76,7 @@ namespace gateway InstallFunAttribute myattribute = (InstallFunAttribute)Attribute.GetCustomAttribute(mi, typeof(InstallFunAttribute)); if (myattribute != null) { - + if (obj is FunctionBase) { (obj as FunctionBase).P2Server = null; @@ -99,8 +100,8 @@ namespace gateway } if (obj is FunctionBase && fd != null) { - wRPC.filedata ffd =new wRPC.filedata(); - ffd.data=fd.data; + wRPC.filedata ffd = new wRPC.filedata(); + ffd.data = fd.data; ffd.filename = fd.filename; ffd.filetype = fd.filetype; (obj as FunctionBase).Filedata = ffd; @@ -140,34 +141,9 @@ namespace gateway } } - AsyncStateMachineAttribute Asyncmyattribute = (AsyncStateMachineAttribute)Attribute.GetCustomAttribute(mi, typeof(AsyncStateMachineAttribute)); - object rpcdata; - if (Asyncmyattribute != null) - { - var task = (mi.Invoke(obj, objs) as Task); - // task.Wait(); - var resultProperty = task.GetType().GetProperty("Result"); - - rpcdata = resultProperty.GetValue(task); - //tassk.Wait(); - //rpcdata = tassk.Result; - } - else - { - - rpcdata = mi.Invoke(obj, objs); - - - } - if (rpcdata != null) - { - return Newtonsoft.Json.JsonConvert.SerializeObject(rpcdata); - - - } - else - return ""; - + //璋冪敤API鏂规硶锛屽悓姝ユ垨寮傛鐨勫鐞嗘斁鍒颁簡AOP鍐呴儴 + object rpcdata = Aop.Invoke(mi, obj, objs); + return rpcdata is null ? string.Empty : JsonConvert.SerializeObject(rpcdata); //DateTime dt2 = DateTime.Now; //Console.WriteLine("service:" + (dt2 - P2Server.dt).TotalMilliseconds); @@ -188,19 +164,19 @@ namespace gateway } finally { - if(clientChannel!=null) - clientChannel.Dispose(); - + if (clientChannel != null) + clientChannel.Dispose(); + } - + return JsonConvert.SerializeObject(new { code = 503, msg = "鏈嶅姟鍣ㄩ敊璇" }); } - + } public class ClientChannelQueue { public ClientChannel clientChannel; - public SpinLock _spinLock = new SpinLock(); + public SpinLock _spinLock = new SpinLock(); } } diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/Startup.cs" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/Startup.cs" index 2200f1e..65e34d3 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/Startup.cs" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/Startup.cs" @@ -64,7 +64,7 @@ namespace gateway public void Configure(IApplicationBuilder app, IHostingEnvironment env) { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); - // Proccessor.servers = Funconfig.getConfig(); + // Proccessor.servers = Funconfig.getConfig(); if (env.IsDevelopment()) { @@ -84,15 +84,23 @@ namespace gateway string contentRoot = AppDomain.CurrentDomain.BaseDirectory; string runRoot = AppDomain.CurrentDomain.BaseDirectory; //闈欐佹枃浠舵祻瑙堟敮鎸侊紝榛樿璺緞涓簑ww鏄犲皠鍒癝tatic銆傛牴鎹甅IME閰嶇疆娣诲姞鏀寔鐨勬枃浠舵牸寮 - var mime = config.GetSection("MIME")?.Get>() ?? default; - IFileProvider fileProvider = new PhysicalFileProvider(Path.Combine(contentRoot, config.GetSection("StaticFilePath")?.Get()??@"www"));//闈欐佹枃浠跺瓨鍌ㄧ洰褰 + var mime = new FileExtensionContentTypeProvider().Mappings; + mime[".apk"] = "application/vnd.android.package-archive"; + var mimeCustom = config.GetSection("MIME")?.Get>() ?? new Dictionary(); + foreach (var m in mimeCustom) + { + if (string.IsNullOrWhiteSpace(m.Value)) mime.Remove(m.Key); + else mime[m.Key] = m.Value; + } + IFileProvider fileProvider = new PhysicalFileProvider(Path.Combine(contentRoot, config.GetSection("StaticFilePath")?.Get() ?? @"www"));//闈欐佹枃浠跺瓨鍌ㄧ洰褰 app.UseStaticFiles(new StaticFileOptions { FileProvider = fileProvider, - RequestPath = config.GetSection("StaticFileRequestPath")?.Get() ?? @"Static", + RequestPath = config.GetSection("StaticFileRequestPath") + ?.Get()?.TrimEnd('/') ?? @"/Static", ContentTypeProvider = new FileExtensionContentTypeProvider(mime) }); - + // app.UseRouting(); if (Convert.ToBoolean(config["Authentication"])) diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/config.json" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/config.json" index 4f311f7..7930241 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/config.json" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/gateway/config.json" @@ -1,28 +1,19 @@ { "Authentication": false, - "IdentityServer": "http://172.18.152.11:5220", + "IdentityServer": "http://127.0.0.1:5220", "Audience": "api1", "defaultScheme": "Bearer", - "applicationUrl": "http://10.40.92.79:8081", + "applicationUrl": "http://127.0.0.1:8081", "bindIP": "127.0.0.1", "Microcenter": "127.0.0.1:9001", "filetype": ".jpg,.png,.doc,.txt,.xlsx,.xls,.docx,.AVI,.mov,.rmvb,.rm,.FLV,.mp4,.3GP,.BMP,.DIB,.PCP,.DIF,.WMF,.GIF,.JPG,.TIF,.EPS,.PSD,.CDR,.IFF,.TGA,.PCD,.MPT,.PNG,.gif", //闈欐佹祻瑙堢洰褰 "StaticFilePath": "www", //闈欐佹祻瑙堣姹傚湴鍧鏄犲皠 - "StaticFileRequestPath": "Static", + "StaticFileRequestPath": "/Static", //MIME淇℃伅鏀寔 "MIME": { ".apk": "application/vnd.android.package-archive", - ".png": "image/png", - ".jpg": "image/png", - ".gif": "image/png", - ".pdf": "application/pdf", - ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", - ".doc": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", - ".xslx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - ".xsl": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - ".json": "application/json" }, "httpspassword": "linezero", "Cookies": [ "Areacode", "Role", "UserId", "Name", "Phone" ], diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/testdll2/Class1.cs" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/testdll2/Class1.cs" index d5da128..cae5ee4 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/testdll2/Class1.cs" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/testdll2/Class1.cs" @@ -6,6 +6,7 @@ using System.Runtime.CompilerServices; using System.Threading.Tasks; using wRPC; using wRPC.DataLogic; +using wRPCService; namespace testdll2 { @@ -110,6 +111,8 @@ namespace testdll2 } } [Route("api/abcd")] + [UnifyResult] + [MemoryCache(AbsoluteExpiration = 20)] public class Class2 : FunctionBase { @@ -118,6 +121,7 @@ namespace testdll2 /// /// [InstallFun(FunAttribute.file, "姝ゆ柟娉曠敤浜庢祴璇")] + [MemoryCache(AbsoluteExpiration = 5)] public async Task ff() { object obj= this.Cookies; object obj2 = this.Headers; @@ -125,10 +129,11 @@ namespace testdll2 await Task.Delay(1000); - return await Task.Run(() => { ; return "aaaaaa"; } ) ; + return await Task.Run(() => { ; return DateTime.Now.ToString(); } ) ; } [Authorize] [InstallFun(FunAttribute.NONE, "姝ゆ柟娉曠敤浜庢祴璇")] + [UnifyResult(DontUse = true)] public String ff2([Param("鐢ㄦ埛鍚")] string name) { diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/Aop.cs" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/Aop.cs" index 345f169..0f094e2 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/Aop.cs" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/Aop.cs" @@ -2,10 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using wRPC.DataLogic; -using wRPC; -using Microsoft.Extensions.Caching.Memory; -using Newtonsoft.Json; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; namespace wRPCService { @@ -24,16 +22,24 @@ namespace wRPCService public static object Invoke(MethodInfo method, object obj, object[] parameters) { //鑾峰彇鎵鏈堿OP鐗规 - var aop = method.GetCustomAttributes().Union( - method.ReflectedType.GetCustomAttributes() - ).OrderBy(d => d.Order).ToList(); + var aopMethod = method.GetCustomAttributes(true); + var aopClass = method.ReflectedType.GetCustomAttributes(true).Where(d => + { + if (aopMethod.Any(t => t.TypeId == d.TypeId)) + { + var usage = d.GetType().GetCustomAttribute(); + return (usage == null || usage.AllowMultiple); + } + else return true; + }); + var aop = aopMethod.Union(aopClass).OrderBy(d=>d.Order).ToList(); //缁勮涓婁笅鏂 var context = new AopContext { Method = method, Instance = obj, Parameters = parameters }; - int aopNums = aop.Count();//AOP鐗规ф绘暟 - int maxAop = 0;//鏈夋晥鐨凙OP鏁伴噺 + int maxAop = -1;//鏈夋晥鐨凙OP鏁伴噺锛屽鏋滄湁AOP杩斿洖false琛ㄧず鍚庣画鍙婃柟娉曚綋鍧囦笉鏀寔 bool needExecute = true;//鏄惁闇瑕佹墽琛屾柟娉曚綋 + bool isAsync = method.GetCustomAttribute() != null;//鏄惁鏄紓姝ユ柟娉 //OnActionExecuting - for (int i = 0; i < aopNums; i++) + for (int i = 0; i < aop.Count(); i++) { //璁板綍鏈鍚庝竴涓繍琛岀殑鐗规э紝濡傛灉杩斿洖false鍒欎笉鎵ц涔嬪悗鐨 maxAop = i; @@ -45,7 +51,9 @@ namespace wRPCService { try { - context.Result = method.Invoke(obj, parameters); + var o = method.Invoke(obj, parameters); + if (isAsync) context.Result = (o as Task).GetType().GetProperty("Result").GetValue(o); + else context.Result = o; } catch (Exception err) { @@ -53,10 +61,12 @@ namespace wRPCService } } //OnActionExecuted - for (int i = aopNums; i >= 0; i--) + for (int i = maxAop; i >= 0; i--) { if (!aop[i].OnActionExecuted(context)) break; } + //鏈鍚庡睆闅滐紝闃叉鐧介〉闈 + if (context.Result == null && context.Exception != null) throw context.Exception; return context.Result; } } @@ -127,127 +137,4 @@ namespace wRPCService /// 鏄惁缁х画鎵ц锛岄粯璁rue public virtual bool OnActionExecuted(AopContext context) => true; } - /// - /// TRY鏂规硶 - /// - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)] - public class TryAttribute : AopAttribute - { - /// - /// Try鏀惧埌绗竴浣 - /// - public override int Order { get; set; } = int.MinValue; - public override bool OnActionExecuted(AopContext context) - { - var o = new ApiResult() { code = 200, message = "鎿嶄綔鎴愬姛" }; - if (context.Exception is null) - { - o.data = context.Result; - } - else - { - //寮傛鏀瑰悓姝ュ湪杩欓噷鍒ゆ柇寮傚父绫诲瀷 - if (context.Exception is AggregateException ae) - { - ae.Handle((x) => - { - if (x is ApiException) - { - o.code = 0; - o.message = $"鎿嶄綔澶辫触锛歿x.Message}"; - o.errData = (x as ApiException).data; - } - else - { - o.code = 500; - o.message = $"鎺ュ彛璋冪敤寮傚父锛歿x.Message}"; - } - return true; - }); - } - else if (context.Exception is ApiException e) - { - o.code = 0; - o.message = $"鎿嶄綔澶辫触锛歿e.Message}"; - o.errData = e.data; - } - else - { - o.code = 500; - o.message = $"鎺ュ彛璋冪敤寮傚父锛歿context.Exception.Message}"; - } - } - context.Result = o; - return base.OnActionExecuted(context); - } - } - /// - /// 鍐呭瓨缂撳瓨鐗规 - /// - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)] - public class MemoryCacheAttribute : AopAttribute - { - /// - /// 缂撳瓨閿紝榛樿鍒欎负鏂规硶鍚+鍙傛暟鍝堝笇銆 - /// - public string Key { get; set; } - /// - /// 缂撳瓨婊戝姩绐楀彛锛屽崟浣嶇锛岄粯璁60绉掞紝鍙栨秷璇蜂娇鐢-1銆 - /// - public int SlidingExpiration { get; set; } = 60; - /// - /// 缂撳瓨鍥哄畾绐楀彛锛屽崟浣嶇锛岄粯璁3600绉掞紙60鍒嗛挓锛夛紝鍙栨秷璇蜂娇鐢-1锛屽洜姝ゆ棤娉曟敮鎸佹暣鐐硅繖鏍风殑闇姹 - /// - public int AbsoluteExpiration { get; set; } = 60 * 60; - /// - /// 缂撳瓨渚濊禆锛屽叾浠栫紦瀛橀敭 - /// - public string[] DependCache { get; set; } - /// - /// 鑾峰彇缂撳瓨閿 - /// - /// 缂撳瓨閿 - private object GetKey(AopContext context) - { - if (string.IsNullOrWhiteSpace(Key)) - { - var param = context.Parameters == null ? "0" - : string.Join("_", context.Parameters.Select(p => JsonConvert.SerializeObject(p).GetHashCode())); - Key = $"{context.Method.Name}_{param}"; - } - return Key; - } - public override int Order { get; set; } = int.MaxValue; - /// - /// 鏄惁瀛樺湪缂撳瓨 - /// - private bool hasCache = false; - public override bool OnActionExecuting(AopContext context) - { - if (CacheManager._cache.TryGetValue(this.GetKey(context), out var o)) - { - hasCache = true; - context.Result = o; - return false; - } - else - { - hasCache = false; - return true; - } - } - - public override bool OnActionExecuted(AopContext context) - { - if (context.Exception is null && hasCache == false) - { - CacheManager._cache.Set(this.GetKey(context), context.Result, - CacheManager.CreateCachePolicy( - AbsoluteExpiration == -1 ? TimeSpan.Zero : TimeSpan.FromSeconds(AbsoluteExpiration), - SlidingExpiration == -1 ? TimeSpan.Zero : TimeSpan.FromSeconds(SlidingExpiration), - DependCache)); - } - return base.OnActionExecuted(context); - } - } } \ No newline at end of file diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/AopAttributes.cs" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/AopAttributes.cs" new file mode 100644 index 0000000..91f3e77 --- /dev/null +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/AopAttributes.cs" @@ -0,0 +1,118 @@ +锘縰sing Microsoft.Extensions.Caching.Memory; +using Newtonsoft.Json; +using System; +using System.Linq; +using wRPC; +using wRPC.DataLogic; + +namespace wRPCService +{ + /// + /// 缁熶竴杩斿洖缁撴灉锛屼綘涔熷彲浠ヨ嚜瀹氫箟瀹炵幇涓涓紝涔熷彲浠ョ户缁娇鐢═RY + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)] + public class UnifyResultAttribute : AopAttribute + { + public bool DontUse { get; set; } = false; + /// + /// Try鏀惧埌绗竴浣 + /// + public override int Order { get; set; } = int.MinValue; + public override bool OnActionExecuted(AopContext context) + { + if (DontUse) return true; + var o = new ApiResult() { code = 200, message = "鎿嶄綔鎴愬姛" }; + if (context.Exception is null) + { + o.data = context.Result; + } + else + { + context.Exception = context.Exception.GetBaseException(); + //寮傛鏀瑰悓姝ュ湪杩欓噷鍒ゆ柇寮傚父绫诲瀷 + if (context.Exception is ApiException e) + { + o.code = 0; + o.message = $"鎿嶄綔澶辫触锛歿e.Message}"; + o.errData = e.data; + } + else + { + o.code = 500; + o.message = $"鎺ュ彛璋冪敤寮傚父锛歿context.Exception.Message}"; + o.errData = context.Exception.StackTrace; + } + } + context.Result = o; + return base.OnActionExecuted(context); + } + } + /// + /// 鍐呭瓨缂撳瓨鐗规 + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)] + public class MemoryCacheAttribute : AopAttribute + { + /// + /// 缂撳瓨閿紝榛樿鍒欎负鏂规硶鍚+鍙傛暟鍝堝笇銆 + /// + public string Key { get; set; } + /// + /// 缂撳瓨婊戝姩绐楀彛锛屽崟浣嶇锛岄粯璁60绉掞紝鍙栨秷璇蜂娇鐢-1銆 + /// + public int SlidingExpiration { get; set; } = 60; + /// + /// 缂撳瓨鍥哄畾绐楀彛锛屽崟浣嶇锛岄粯璁3600绉掞紙60鍒嗛挓锛夛紝鍙栨秷璇蜂娇鐢-1锛屽洜姝ゆ棤娉曟敮鎸佹暣鐐硅繖鏍风殑闇姹 + /// + public int AbsoluteExpiration { get; set; } = 3600; + /// + /// 缂撳瓨渚濊禆锛屽叾浠栫紦瀛橀敭 + /// + public string[] DependCache { get; set; } + /// + /// 鑾峰彇缂撳瓨閿 + /// + /// 缂撳瓨閿 + private object GetKey(AopContext context) + { + if (string.IsNullOrWhiteSpace(Key)) + { + var param = string.Join("_", context.Parameters.Select(p => JsonConvert.SerializeObject(p).GetHashCode())); + Key = $"{context.Method.ReflectedType.FullName}_{context.Method.ReflectedType.AssemblyQualifiedName.GetHashCode()}_{context.Method.Name}_{param}"; + } + return Key; + } + public override int Order { get; set; } = int.MaxValue; + /// + /// 鏄惁瀛樺湪缂撳瓨 + /// + private bool hasCache = false; + public override bool OnActionExecuting(AopContext context) + { + if (CacheManager._cache.TryGetValue(this.GetKey(context), out var o)) + { + hasCache = true; + context.Result = o; + return false; + } + else + { + hasCache = false; + return true; + } + } + + public override bool OnActionExecuted(AopContext context) + { + if (context.Exception is null && hasCache == false) + { + CacheManager._cache.Set(this.GetKey(context), context.Result, + CacheManager.CreateCachePolicy( + AbsoluteExpiration == -1 ? TimeSpan.Zero : TimeSpan.FromSeconds(AbsoluteExpiration), + SlidingExpiration == -1 ? TimeSpan.Zero : TimeSpan.FromSeconds(SlidingExpiration), + DependCache)); + } + return base.OnActionExecuted(context); + } + } +} diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/CacheManager.cs" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/CacheManager.cs" index 624dec4..508762e 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/CacheManager.cs" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/CacheManager.cs" @@ -84,6 +84,7 @@ namespace wRPCService /// 缂撳瓨鏁版嵁绫诲瀷 /// 缂撳瓨閿 /// 缂撳瓨鍊艰幏鍙栨柟娉曪紝闇瑕佹墜鍔ㄥ疄鐜版潯鐩緷璧栫瓑淇℃伅 + /// 缂撳瓨杩囨湡绛栫暐锛屽彲浠ラ氳繃CacheManager.CreateCachePolicy鑾峰彇鍩烘湰绛栫暐锛屽鏋滀负null鍒欒缃负榛樿绛栫暐(鍥哄畾绐楀彛60鍒嗭紝婊戝姩绐楀彛1鍒)锛岃嚜瀹氫箟瀹炵幇闇鑷瀹炵幇缂撳瓨渚濊禆銆 /// 缂撳瓨鍊 public static async Task GetOrCreateAsync(object key, Func> factory, MemoryCacheEntryOptions policy = null) { @@ -96,6 +97,7 @@ namespace wRPCService /// 缂撳瓨鏁版嵁绫诲瀷 /// 缂撳瓨閿 /// 缂撳瓨鍊艰幏鍙栨柟娉曪紝闇瑕佹墜鍔ㄥ疄鐜版潯鐩緷璧栫瓑淇℃伅 + /// 缂撳瓨杩囨湡绛栫暐锛屽彲浠ラ氳繃CacheManager.CreateCachePolicy鑾峰彇鍩烘湰绛栫暐锛屽鏋滀负null鍒欒缃负榛樿绛栫暐(鍥哄畾绐楀彛60鍒嗭紝婊戝姩绐楀彛1鍒)锛岃嚜瀹氫箟瀹炵幇闇鑷瀹炵幇缂撳瓨渚濊禆銆 /// 缂撳瓨鍊 public static TItem GetOrCreate(object key, Func factory, MemoryCacheEntryOptions policy = null) { @@ -109,7 +111,7 @@ namespace wRPCService /// 瑕佽繑鍥炲肩殑绫诲瀷 /// 缂撳瓨閿 /// 鏈紦瀛樻椂鑾峰彇鍊肩殑鏂规硶 - /// 缂撳瓨杩囨湡绛栫暐锛屽彲浠ラ氳繃CacheManager.CreateCachePolicy鑾峰彇鍩烘湰绛栫暐锛屽鏋滀负null鍒欒缃负榛樿绛栫暐(鍥哄畾绐楀彛60鍒嗭紝婊戝姩绐楀彛1鍒) + /// 缂撳瓨杩囨湡绛栫暐锛屽彲浠ラ氳繃CacheManager.CreateCachePolicy鑾峰彇鍩烘湰绛栫暐锛屽鏋滀负null鍒欒缃负榛樿绛栫暐(鍥哄畾绐楀彛60鍒嗭紝婊戝姩绐楀彛1鍒)锛岃嚜瀹氫箟瀹炵幇闇鑷瀹炵幇缂撳瓨渚濊禆銆 /// 缂撳瓨鍚庣殑瀵硅薄 public static TItem GetOrCreate(object key, Func factory, MemoryCacheEntryOptions policy = null) { @@ -123,7 +125,7 @@ namespace wRPCService /// 瑕佽繑鍥炲肩殑绫诲瀷 /// 缂撳瓨閿 /// 鏈紦瀛樻椂鑾峰彇鍊肩殑鏂规硶 - /// 缂撳瓨杩囨湡绛栫暐锛屽彲浠ラ氳繃CacheManager.CreateCachePolicy鑾峰彇鍩烘湰绛栫暐锛屽鏋滀负null鍒欒缃负榛樿绛栫暐(鍥哄畾绐楀彛60鍒嗭紝婊戝姩绐楀彛1鍒) + /// 缂撳瓨杩囨湡绛栫暐锛屽彲浠ラ氳繃CacheManager.CreateCachePolicy鑾峰彇鍩烘湰绛栫暐锛屽鏋滀负null鍒欒缃负榛樿绛栫暐(鍥哄畾绐楀彛60鍒嗭紝婊戝姩绐楀彛1鍒)锛岃嚜瀹氫箟瀹炵幇闇鑷瀹炵幇缂撳瓨渚濊禆銆 /// 缂撳瓨鍚庣殑瀵硅薄 public static async Task GetOrCreateAsync(object key, Func> factory, MemoryCacheEntryOptions policy = null) { @@ -137,6 +139,7 @@ namespace wRPCService /// /// 缂撳瓨閿 /// 鏈紦瀛樻椂鑾峰彇鍊肩殑鏂规硶 + /// 缂撳瓨杩囨湡绛栫暐锛屽彲浠ラ氳繃CacheManager.CreateCachePolicy鑾峰彇鍩烘湰绛栫暐锛屽鏋滀负null鍒欒缃负榛樿绛栫暐(鍥哄畾绐楀彛60鍒嗭紝婊戝姩绐楀彛1鍒)锛岃嚜瀹氫箟瀹炵幇闇鑷瀹炵幇缂撳瓨渚濊禆銆 /// 缂撳瓨鍚庣殑瀵硅薄 public static TItem GetOrCreate(object key, Func factory, MemoryCacheEntryOptions policy = null) { @@ -150,6 +153,7 @@ namespace wRPCService /// /// 缂撳瓨閿 /// 鏈紦瀛樻椂鑾峰彇鍊肩殑鏂规硶 + /// 缂撳瓨杩囨湡绛栫暐锛屽彲浠ラ氳繃CacheManager.CreateCachePolicy鑾峰彇鍩烘湰绛栫暐锛屽鏋滀负null鍒欒缃负榛樿绛栫暐(鍥哄畾绐楀彛60鍒嗭紝婊戝姩绐楀彛1鍒)锛岃嚜瀹氫箟瀹炵幇闇鑷瀹炵幇缂撳瓨渚濊禆銆 /// 缂撳瓨鍚庣殑瀵硅薄 public static async Task GetOrCreateAsync(object key, Func> factory, MemoryCacheEntryOptions policy = null) { diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/ServiceChannel.cs" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/ServiceChannel.cs" index a9b9018..490279c 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/ServiceChannel.cs" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/ServiceChannel.cs" @@ -1,9 +1,6 @@ -锘 -using System; +锘縰sing System; using System.Collections.Generic; using System.Reflection; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; using wRPC; namespace wRPCService @@ -113,25 +110,8 @@ namespace wRPCService } } - AsyncStateMachineAttribute Asyncmyattribute = (AsyncStateMachineAttribute)Attribute.GetCustomAttribute(mi, typeof(AsyncStateMachineAttribute)); - object rpcdata; - if (Asyncmyattribute != null) - { - var task = (Aop.Invoke(mi, obj, objs) as Task); - // task.Wait(); - var resultProperty = task.GetType().GetProperty("Result"); - - rpcdata = resultProperty.GetValue(task); - //tassk.Wait(); - //rpcdata = tassk.Result; - } - else - { - - rpcdata = Aop.Invoke(mi, obj, objs); - - - } + //璋冪敤API鏂规硶锛屽悓姝ユ垨寮傛鐨勫鐞嗘斁鍒颁簡AOP鍐呴儴 + object rpcdata = Aop.Invoke(mi, obj, objs); if (rpcdata != null) { String tmpdata = Newtonsoft.Json.JsonConvert.SerializeObject(rpcdata); diff --git "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/wRPCService.csproj" "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/wRPCService.csproj" index 2e31396..b947d52 100644 --- "a/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/wRPCService.csproj" +++ "b/\345\276\256\346\234\215\345\212\241\346\236\266\346\236\204/wRPCService/wRPCService.csproj" @@ -4,7 +4,7 @@ netstandard2.0 true wRPC 鏈嶅姟绔被搴 - 1.0.14 + 1.0.15 -- Gitee