Browse Source

优化 RpcContextData ,使用实体取代JObject
GoverManager 改为 GoverApiCenterService

lith 4 năm trước cách đây
mục cha
commit
47897574cd
60 tập tin đã thay đổi với 1144 bổ sung1147 xóa
  1. 20 25
      dotnet/Gateway/Sers.Gateway/Sers.Gateway/GatewayHelp.cs
  2. 7 9
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/ApiClient.cs
  3. 4 4
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/ApiEvent/BeforeCallApi/AccountInCookie/AccountInCookie.cs
  4. 3 3
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/ApiEvent/BeforeCallApi/Bearer/Bearer.cs
  5. 0 32
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/ApiEvent/BeforeCallApi/Bearer/Extensions/IRpcContextDataExtensions.cs
  6. 31 0
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/ApiEvent/BeforeCallApi/Bearer/Extensions/RpcContextDataExtensions.cs
  7. 1 1
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/ApiEvent/BeforeCallApi/IBeforeCallApi.cs
  8. 2 2
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/ApiEvent/EventBuilder.cs
  9. 2 2
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/Data/ApiSysError.cs
  10. 2 2
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/LocalApi/ApiNodeMng.cs
  11. 1 1
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/LocalApi/ApiTrace/ApiTraceLog.cs
  12. 1 1
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/LocalApi/Event/LocalApiEvent.cs
  13. 1 1
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/LocalApi/Event/LocalApiEventMng.cs
  14. 1 2
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/LocalApi/LocalApiService.cs
  15. 15 13
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/LocalApi/StaticFileTransmit/StaticFileMap.cs
  16. 0 504
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/Rpc/Extendsions/IRpcContextDataExtensions.cs
  17. 0 160
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/Rpc/RpcContextData.cs
  18. 2 2
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Message/ApiMessage.cs
  19. 8 8
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Message/Extendsions/ApiMessageExtensions.cs
  20. 1 3
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Rpc/ECallerSource.cs
  21. 2 2
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Rpc/Extensions/ECallerSourceExtensions.cs
  22. 204 0
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Rpc/Extensions/RpcContextDataExtensions.cs
  23. 0 45
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Rpc/IRpcContextData.cs
  24. 2 2
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Rpc/RpcContext.cs
  25. 115 0
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Rpc/RpcContextData.cs
  26. 1 4
      dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Rpc/RpcFactory.cs
  27. 2 1
      dotnet/Library/Sers/Sers.Core/Sers.Core/SersLoader/ApiDesc/Attribute/Valid/SsCallerSourceAttribute.cs
  28. 6 4
      dotnet/Library/Sers/Sers.Core/Test/Sers.Core.Module.Rpc.MsTest/UnitTest1.cs
  29. 1 1
      dotnet/Library/Vit/Vit.Core/Test/Vit.Core.MsTest/Module/SerializationTest.cs
  30. 1 1
      dotnet/Library/Vit/Vit.Core/Vit.Core/Extensions/EnumExtensions.cs
  31. 6 4
      dotnet/Library/Vit/Vit.Core/Vit.Core/Extensions/byte/ArraySegmentByteExtensions.cs
  32. 30 0
      dotnet/Library/Vit/Vit.Core/Vit.Core/Extensions/byte/SpanExtensions.cs
  33. 35 0
      dotnet/Library/Vit/Vit.Core/Vit.Core/Module/Serialization/Extensions/EncodingExtensions.cs
  34. 142 179
      dotnet/Library/Vit/Vit.Core/Vit.Core/Module/Serialization/Serialization.cs
  35. 126 0
      dotnet/Library/Vit/Vit.Core/Vit.Core/Module/Serialization/Serialization_Newtonsoft.cs
  36. 222 0
      dotnet/Library/Vit/Vit.Core/Vit.Core/Module/Serialization/Serialization_Text.cs
  37. 28 26
      dotnet/Library/Vit/Vit.Core/Vit.Core/Vit.Core.csproj
  38. 21 4
      dotnet/ServiceCenter/Sers.ServiceCenter/Apm/Sers.Gover.Apm.Zipkin/AppEvent.cs
  39. 1 1
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Base/ApiLoadBalancingMng.cs
  40. 2 2
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Base/ApiLoadBalancingMng_RESTful.cs
  41. 2 2
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Base/ApiStationMng.cs
  42. 34 17
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Base/GoverApiCenterService.cs
  43. 2 2
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Base/ServiceStationMng.cs
  44. 3 3
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Controllers/ApiControllers/ApiDescController.cs
  45. 4 4
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Controllers/ApiControllers/ApiStationController.cs
  46. 2 2
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Controllers/ApiControllers/RateLimitController.cs
  47. 1 1
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Controllers/ApiControllers/ServiceCenterController.cs
  48. 5 5
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Controllers/ApiControllers/ServiceStationController.cs
  49. 1 1
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Controllers/Subscribers/UsageSubController.cs
  50. 5 5
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Extensions/ServiceCenter_GoverExtensions.cs
  51. 2 2
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/RateLimit/FixedWindow.cs
  52. 2 2
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/RateLimit/IRateLimit.cs
  53. 2 2
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/RateLimit/RateLimitMng.cs
  54. 3 6
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.ServiceCenter/ApiCenter/ApiCenterService.cs
  55. 1 1
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.ServiceCenter/Controllers/ServiceStationController.cs
  56. 1 1
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.ServiceCenter/Entity/ApiNode.cs
  57. 10 15
      dotnet/ServiceStation/ApiLoader/Sers.Serslot/Extensions/SerslotServer_ProcessRequest_Extensions.cs
  58. 13 23
      dotnet/ServiceStation/Demo/SersLoader/Did.SersLoader.Demo/Controllers/Demo/SampleController.cs
  59. 1 1
      dotnet/ServiceStation/Demo/StressTest/App.Robot.Station/Controllers/TaskController.cs
  60. 1 1
      dotnet/todo.txt

+ 20 - 25
dotnet/Gateway/Sers.Gateway/Sers.Gateway/GatewayHelp.cs

@@ -85,7 +85,7 @@ namespace Sers.Gateway
         /// <summary>
         /// BeforeCallApi(IRpcContextData rpcData, ApiMessage requestMessage)
         /// </summary>
-        public Action<IRpcContextData, ApiMessage> BeforeCallApi;
+        public Action<RpcContextData, ApiMessage> BeforeCallApi;
 
 
 
@@ -119,16 +119,16 @@ namespace Sers.Gateway
 
         #region BuildHttp
         static string prefixOfCopyIpToHeader = Vit.Core.Util.ConfigurationManager.ConfigurationManager.Instance.GetStringByPath("Sers.Gateway.WebHost.prefixOfCopyIpToHeader");
-        protected JObject BuildHttp(HttpRequest request)
+        protected void BuildHttp(RpcContextData rpcData,HttpRequest request)
         {
-            var http = new JObject();
+            var http = rpcData.http;
 
             #region (x.1) url
-            http["url"] = request.GetAbsoluteUri();
+            http.url = request.GetAbsoluteUri();
             #endregion
 
             #region (x.2) headers
-            var headers = http["headers"] = new JObject();
+            var headers = http.headers;
             foreach (var kv in request.Headers)
             {
                 headers[kv.Key] = kv.Value.ToString();
@@ -138,29 +138,28 @@ namespace Sers.Gateway
             if(prefixOfCopyIpToHeader!=null)
             {
                 headers[prefixOfCopyIpToHeader+"RemoteIpAddress"] = request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
-                headers[prefixOfCopyIpToHeader + "RemotePort"] = request.HttpContext.Connection.RemotePort;
+                headers[prefixOfCopyIpToHeader + "RemotePort"] = ""+request.HttpContext.Connection.RemotePort;
 
                 headers[prefixOfCopyIpToHeader + "LocalIpAddress"] = request.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString();
-                headers[prefixOfCopyIpToHeader + "LocalPort"] = request.HttpContext.Connection.LocalPort;
+                headers[prefixOfCopyIpToHeader + "LocalPort"] = ""+request.HttpContext.Connection.LocalPort;
             }
             #endregion
 
             #region (x.3) method
-            http["method"] = request.Method;
+            http.method = request.Method;
             #endregion
 
             #region (x.4) protocol
-            http["protocol"] = request.Protocol;
-            #endregion         
-
-            return http;
+            http.protocol = request.Protocol;
+            #endregion        
+   
              
         }
 
         #endregion
 
         #region BuildBody
-        byte[] BuildBody(HttpRequest request, IRpcContextData rpcData)
+        byte[] BuildBody(HttpRequest request, RpcContextData rpcData)
         {
             #region (x.1)二进制数据
             using (MemoryStream ms = new MemoryStream())
@@ -200,13 +199,13 @@ namespace Sers.Gateway
         protected ApiMessage BuildApiRequestMessage(HttpRequest request)
         {      
    
-            var rpcData = RpcFactory.CreateRpcContextData().Init(Rpc_CallerSource);
+            var rpcData = new RpcContextData().Init(Rpc_CallerSource);
 
             rpcData.route = request.Path.Value;
- 
+
 
             #region (x.1)构建http
-            rpcData.http_Set(BuildHttp(request));
+            BuildHttp(rpcData, request);
             #endregion
 
             //(x.2) 构建body
@@ -246,7 +245,7 @@ namespace Sers.Gateway
             var replyRpcData = GetReplyRpcData();
 
             #region (x.1)statusCode
-            var statusCode = replyRpcData?.http_statusCode_Get();
+            var statusCode = replyRpcData?.http.statusCode;
             if (statusCode.HasValue)
             {
                 response.StatusCode = statusCode.Value;
@@ -259,13 +258,9 @@ namespace Sers.Gateway
             var headers = response.Headers; 
             if (null != replyRpcData)
             {
-                var joHeaders=replyRpcData.http_headers_Get();
-                if (null != joHeaders)
+                foreach (var item in replyRpcData.http.headers)
                 {
-                    foreach (var item in joHeaders)
-                    {
-                        headers[item.Key] = item.Value.ConvertToString();
-                    }
+                    headers[item.Key] = item.Value;
                 }
             }
 
@@ -287,12 +282,12 @@ namespace Sers.Gateway
             }
 
             #region function GetReplyRpcData
-            IRpcContextData GetReplyRpcData()
+            RpcContextData GetReplyRpcData()
             {
                 var rpcContextData_OriData = apiReply.rpcContextData_OriData;
                 if (null != rpcContextData_OriData && rpcContextData_OriData.Count > 0)
                 {
-                    return RpcFactory.CreateRpcContextData().UnpackOriData(rpcContextData_OriData);  
+                    return RpcContextData.FromBytes(rpcContextData_OriData);  
                 }
                 return null;
             }

+ 7 - 9
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/ApiClient.cs

@@ -1,5 +1,4 @@
 using System;
-using System.Collections.Generic;
 using Vit.Core.Module.Log;
 using Vit.Extensions;
 using System.Threading;
@@ -7,7 +6,6 @@ using System.Threading.Tasks;
 using Sers.Core.Module.Message;
 using Vit.Core.Util.ComponentModel.SsError;
 using Sers.Core.Module.Rpc;
-using Vit.Core.Util.Pipelines;
 using System.Runtime.CompilerServices;
 
 namespace Sers.Core.Module.Api
@@ -118,7 +116,7 @@ namespace Sers.Core.Module.Api
         /// <param name="InitRpc">对Rpc的额外处理,如添加header</param>
         /// <returns></returns>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public ReturnType CallApi<ReturnType>(string route, Object arg = null, string httpMethod = null, Action<IRpcContextData> InitRpc = null)
+        public ReturnType CallApi<ReturnType>(string route, Object arg = null, string httpMethod = null, Action<RpcContextData> InitRpc = null)
         {
             var apiRequestMessage = new ApiMessage().InitAsApiRequestMessage(route, arg, httpMethod, InitRpc);
 
@@ -136,7 +134,7 @@ namespace Sers.Core.Module.Api
         /// <param name="InitRpc">对Rpc的额外处理,如添加header</param>
         /// <returns></returns>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public string CallApi(string route, Object arg = null, string httpMethod = null, Action<IRpcContextData> InitRpc = null)
+        public string CallApi(string route, Object arg = null, string httpMethod = null, Action<RpcContextData> InitRpc = null)
         {
             return CallApi<string>(route, arg, httpMethod, InitRpc);
         }
@@ -152,7 +150,7 @@ namespace Sers.Core.Module.Api
         /// <param name="InitRpc">对Rpc的额外处理,如添加header</param>
         /// <returns></returns>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public async Task<ReturnType> CallApiAsync<ReturnType>(string route, Object arg = null, string httpMethod = null, Action<IRpcContextData> InitRpc = null)
+        public async Task<ReturnType> CallApiAsync<ReturnType>(string route, Object arg = null, string httpMethod = null, Action<RpcContextData> InitRpc = null)
         {
             ReturnType ret = default(ReturnType);
             await Task.Run(() => { ret = CallApi<ReturnType>(route, arg, httpMethod,InitRpc); });
@@ -188,7 +186,7 @@ namespace Sers.Core.Module.Api
         /// <param name="httpMethod">可为 GET、POST、DELETE、PUT等,可不指定</param>
         /// <param name="InitRpc">对Rpc的额外处理,如添加header</param>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static string CallRemoteApi(string route, string arg, string httpMethod = null, Action<IRpcContextData> InitRpc = null)
+        public static string CallRemoteApi(string route, string arg, string httpMethod = null, Action<RpcContextData> InitRpc = null)
         {
             return Instance.CallApi(route, arg, httpMethod, InitRpc);
         }
@@ -202,7 +200,7 @@ namespace Sers.Core.Module.Api
         /// <param name="httpMethod">可为 GET、POST、DELETE、PUT等,可不指定</param>
         /// <param name="InitRpc">对Rpc的额外处理,如添加header</param>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static string CallRemoteApi(string route, Object arg = null, string httpMethod = null, Action<IRpcContextData> InitRpc = null)
+        public static string CallRemoteApi(string route, Object arg = null, string httpMethod = null, Action<RpcContextData> InitRpc = null)
         {
             return Instance.CallApi(route, arg, httpMethod, InitRpc);
         }
@@ -217,7 +215,7 @@ namespace Sers.Core.Module.Api
         /// <param name="InitRpc">对Rpc的额外处理,如添加header</param>
         /// <returns></returns>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static ReturnType CallRemoteApi<ReturnType>(string route, Object arg = null, string httpMethod = null, Action<IRpcContextData> InitRpc = null)
+        public static ReturnType CallRemoteApi<ReturnType>(string route, Object arg = null, string httpMethod = null, Action<RpcContextData> InitRpc = null)
         {
             return Instance.CallApi<ReturnType>(route, arg, httpMethod, InitRpc);
         }
@@ -248,7 +246,7 @@ namespace Sers.Core.Module.Api
         /// <param name="InitRpc">对Rpc的额外处理,如添加header</param>
         /// <returns></returns>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static async Task<ReturnType> CallRemoteApiAsync<ReturnType>(string route, Object arg = null, string httpMethod = null, Action<IRpcContextData> InitRpc = null)
+        public static async Task<ReturnType> CallRemoteApiAsync<ReturnType>(string route, Object arg = null, string httpMethod = null, Action<RpcContextData> InitRpc = null)
         {
             return await Instance.CallApiAsync<ReturnType>(route, arg, httpMethod, InitRpc);
         }

+ 4 - 4
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/ApiEvent/BeforeCallApi/AccountInCookie/AccountInCookie.cs

@@ -57,12 +57,12 @@ namespace Sers.Core.Module.Api.ApiEvent.BeforeCallApi.AccountInCookie
         /// </summary>
         /// <param name="rpcData"></param>
         /// <param name="requestMessage"></param>
-        public void BeforeCallApi(IRpcContextData rpcData, ApiMessage requestMessage)
+        public void BeforeCallApi(RpcContextData rpcData, ApiMessage requestMessage)
         {
             try
             {
                 #region (x.x.x.1)获取cookie 中的用户令牌
-                var cookie = rpcData.http_header_Get("Cookie");
+                var cookie = rpcData.http.GetHeader("Cookie");
                 if (string.IsNullOrEmpty(cookie)) return;
 
                 string authUserFromCookie = null;
@@ -90,11 +90,11 @@ namespace Sers.Core.Module.Api.ApiEvent.BeforeCallApi.AccountInCookie
                 {
                     if (account.CallerSource != null)
                     {
-                        rpcData.caller_source_Set(account.CallerSource);
+                        rpcData.caller.source=account.CallerSource;
                     }
                     if (account.userInfo != null)
                     {
-                        rpcData.user_userInfo_Set(account.userInfo);
+                        rpcData.user=new { account.userInfo };
                     }
                     requestMessage.rpcContextData_OriData = ArraySegmentByteExtensions.Null;
                 }

+ 3 - 3
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/ApiEvent/BeforeCallApi/Bearer/Bearer.cs

@@ -39,7 +39,7 @@ namespace Sers.Core.Module.Api.ApiEvent.BeforeCallApi.Bearer
         /// </summary>
         /// <param name="rpcData"></param>
         /// <param name="requestMessage"></param>
-        public void BeforeCallApi(IRpcContextData rpcData, ApiMessage requestMessage)
+        public void BeforeCallApi(RpcContextData rpcData, ApiMessage requestMessage)
         {
             try
             {
@@ -48,7 +48,7 @@ namespace Sers.Core.Module.Api.ApiEvent.BeforeCallApi.Bearer
                 if (string.IsNullOrWhiteSpace(bear))
                     return;
 
-                if (null != rpcData.user_userInfo_Get()) return;
+                if (null != rpcData.user) return;
 
                 ApiReturn<JObject> ret;
                 using (var rpcContext = RpcFactory.CreateRpcContext())
@@ -60,7 +60,7 @@ namespace Sers.Core.Module.Api.ApiEvent.BeforeCallApi.Bearer
 
                 if (null != ret && ret.success)
                 {
-                    rpcData.user_userInfo_Set(ret.data);
+                    rpcData.user=new { userInfo = ret.data };
                     requestMessage.rpcContextData_OriData = ArraySegmentByteExtensions.Null;
                 }
                 #endregion

+ 0 - 32
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/ApiEvent/BeforeCallApi/Bearer/Extensions/IRpcContextDataExtensions.cs

@@ -1,32 +0,0 @@
-using Sers.Core.Module.Rpc;
-
-namespace Vit.Extensions
-{
-    /// <summary>
-    /// Extension methods for RpcContextData
-    /// </summary>
-    public static partial class IRpcContextDataExtensions
-    {
-
-        public static string Bearer_Get(this IRpcContextData context)
-        {
-            //http.headers.Authorization = "Bearer atxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
-            var headers = context?.oriJson?["http"]?["headers"];
-            if (null == headers) return null;
-
-            var Authorization =   (headers["Authorization"] ?? headers["authorization"])?.ConvertToString() ;
-            if (null == Authorization) return null;
-            var bear = (Authorization+ " ").Split(' ')[1];           
-            return bear;
-        }
-
-        public static void Bearer_Set(this IRpcContextData context,string value)
-        {
-            if (null == context || string.IsNullOrWhiteSpace(value)) return;        
-
-            context.oriJson.GetOrCreateJObject("http").GetOrCreateJObject("headers")["Authorization"] = "Bearer "+value;
-        } 
-   
-
-    }
-}

+ 31 - 0
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/ApiEvent/BeforeCallApi/Bearer/Extensions/RpcContextDataExtensions.cs

@@ -0,0 +1,31 @@
+using Sers.Core.Module.Rpc;
+
+namespace Vit.Extensions
+{
+    /// <summary>
+    /// Extension methods for RpcContextData
+    /// </summary>
+    public static partial class RpcContextDataExtensions
+    {
+
+        public static string Bearer_Get(this RpcContextData rpcData)
+        {
+            //http.headers.Authorization = "Bearer atxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ 
+
+            var Authorization =   (rpcData.http.GetHeader("Authorization") ?? rpcData.http.GetHeader("authorization")) ;
+            if (null == Authorization) return null;
+            var bear = (Authorization+ " ").Split(' ')[1];           
+            return bear;
+        }
+
+        public static void Bearer_Set(this RpcContextData rpcData, string value)
+        {
+            if (null == rpcData || string.IsNullOrWhiteSpace(value)) return;
+
+            rpcData.http.headers["Authorization"] = "Bearer "+value;
+        } 
+   
+
+    }
+}

+ 1 - 1
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/ApiEvent/BeforeCallApi/IBeforeCallApi.cs

@@ -12,6 +12,6 @@ namespace Sers.Core.Module.Api.ApiEvent.BeforeCallApi
         void Init(JObject config);
 
 
-        void BeforeCallApi(IRpcContextData rpcData, ApiMessage requestMessage);
+        void BeforeCallApi(RpcContextData rpcData, ApiMessage requestMessage);
     }
 }

+ 2 - 2
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/ApiEvent/EventBuilder.cs

@@ -22,11 +22,11 @@ namespace Sers.Core.Module.Api.ApiEvent
         /// </summary>
         /// <param name="events"></param>
         /// <returns></returns>
-        public static Action<IRpcContextData, ApiMessage> LoadEvent_BeforeCallApi(JArray events)
+        public static Action<RpcContextData, ApiMessage> LoadEvent_BeforeCallApi(JArray events)
         {
             if (events == null || events.Count == 0) return null;
 
-            Action<IRpcContextData, ApiMessage> BeforeCallApi = null;           
+            Action<RpcContextData, ApiMessage> BeforeCallApi = null;           
 
             foreach (JObject config in events)
             {

+ 2 - 2
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/Data/ApiSysError.cs

@@ -10,13 +10,13 @@ namespace Sers.Core.Module.Api.Data
     public class ApiSysError
     {
 
-        public static void LogSysError(IRpcContextData rpcContextData, ApiMessage reqMessage, SsError error)
+        public static void LogSysError(RpcContextData rpcContextData, ApiMessage reqMessage, SsError error)
         {
             try
             {
                 string msg = "[ApiCallError]route:" + rpcContextData.route;
                 msg += Environment.NewLine+"error:" + error.Serialize();
-                msg += Environment.NewLine + "rpcData:" + rpcContextData.oriJson;
+                msg += Environment.NewLine + "rpcData:" + rpcContextData.Serialize();
                 try
                 {
                     msg += Environment.NewLine + "RequestBody:" + reqMessage.value_OriData.ArraySegmentByteToString();

+ 2 - 2
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/LocalApi/ApiNodeMng.cs

@@ -53,10 +53,10 @@ namespace Sers.Core.Module.Api.LocalApi
 
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public bool TryGet(IRpcContextData rpcData, out IApiNode apiNode)
+        public bool TryGet(RpcContextData rpcData, out IApiNode apiNode)
         {
             var route = rpcData.route;
-            var method = rpcData.http_method_Get()?.ToUpper();
+            var method = rpcData.http.method?.ToUpper();
            
             if (!string.IsNullOrEmpty(method))
             {

+ 1 - 1
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/LocalApi/ApiTrace/ApiTraceLog.cs

@@ -30,7 +30,7 @@ namespace Sers.Core.Module.Api.LocalApi.ApiTrace
             msg.Append(Environment.NewLine).Append("--duration :").Append((trace.endTime - trace.beginTime).TotalMilliseconds).Append(" ms");
 
 
-            msg.Append(Environment.NewLine).Append("--Req rpc  :").Append(rpcContext.rpcData.oriJson);
+            msg.Append(Environment.NewLine).Append("--Req rpc  :").Append(rpcContext.rpcData.Serialize());
 
             try
             {

+ 1 - 1
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/LocalApi/Event/LocalApiEvent.cs

@@ -20,7 +20,7 @@ namespace Sers.Core.Module.Api.LocalApi.Event
 
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public void BeforeCallApi(IRpcContextData rpcData, ApiMessage requestMessage) 
+        public void BeforeCallApi(RpcContextData rpcData, ApiMessage requestMessage) 
         {
             LocalApiEventMng.Instance.BeforeCallApi?.Invoke(rpcData, requestMessage);
         }

+ 1 - 1
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/LocalApi/Event/LocalApiEventMng.cs

@@ -83,7 +83,7 @@ namespace Sers.Core.Module.Api.LocalApi.Event
         /// <summary>
         /// BeforeCallApi(IRpcContextData rpcData, ApiMessage requestMessage)
         /// </summary>
-        internal Action<IRpcContextData, ApiMessage> BeforeCallApi = null;
+        internal Action<RpcContextData, ApiMessage> BeforeCallApi = null;
 
 
     }

+ 1 - 2
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/LocalApi/LocalApiService.cs

@@ -108,8 +108,7 @@ namespace Sers.Core.Module.Api.LocalApi
                     rpcContext.apiRequestMessage = apiRequest;
                     rpcContext.apiReplyMessage = new ApiMessage();
 
-                    var rpcData = RpcFactory.CreateRpcContextData();
-                    rpcData.UnpackOriData(apiRequest.rpcContextData_OriData);
+                    var rpcData = RpcContextData.FromBytes(apiRequest.rpcContextData_OriData);
                     rpcContext.rpcData = rpcData;
 
                     //(x.2) BeforeCallApi

+ 15 - 13
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/LocalApi/StaticFileTransmit/StaticFileMap.cs

@@ -134,23 +134,24 @@ namespace Sers.Core.Module.Api.LocalApi.StaticFileTransmit
             }
 
             #region reply header
-            var replyRpcData = RpcFactory.CreateRpcContextData();
+            var replyRpcData = new RpcContextData();
 
             if (responseHeaders != null) 
             {
                 foreach (var item in responseHeaders)
                 {
-                    replyRpcData.http_header_Set(item.Key, item.Value);
+                    replyRpcData.http.headers[item.Key]=item.Value;
                 }
             }
 
             if (contentTypeProvider.TryGetContentType(absFilePath, out var contentType))
             {
-                replyRpcData.http_header_Set("Content-Type", contentType);             
+                replyRpcData.http.headers["Content-Type"] = contentType;             
             }
-            //replyRpcData.http_header_Set("Cache-Control", "public,max-age=6000");        
- 
-            RpcContext.Current.apiReplyMessage.rpcContextData_OriData= replyRpcData.PackageOriData();
+       
+            //replyRpcData.http.headers["Cache-Control"] = "public,max-age=6000";
+
+            RpcContext.Current.apiReplyMessage.rpcContextData_OriData= replyRpcData.ToBytes().BytesToArraySegmentByte();
             #endregion
 
           
@@ -197,13 +198,13 @@ namespace Sers.Core.Module.Api.LocalApi.StaticFileTransmit
             }
 
             #region reply header
-            var replyRpcData = RpcFactory.CreateRpcContextData();
+            var replyRpcData = new RpcContextData();
 
-            var header = new JObject();
+            var headers = new Dictionary<string, string>();
 
             if (!string.IsNullOrEmpty(contentType))
             {
-                header["Content-Type"] = contentType;
+                headers["Content-Type"] = contentType;
             }
 
             if (string.IsNullOrEmpty(fileName))
@@ -212,12 +213,13 @@ namespace Sers.Core.Module.Api.LocalApi.StaticFileTransmit
             }
 
             #region 填充文件头
-            header["Content-Disposition"] = "attachment;filename=" + HttpUtility.UrlEncode(fileName, Vit.Core.Module.Serialization.Serialization.Instance.encoding);
-            header["Content-Length"] = info.Length.ToString();
+            headers["Content-Disposition"] = "attachment;filename=" + HttpUtility.UrlEncode(fileName, Vit.Core.Module.Serialization.Serialization.Instance.encoding);
+            headers["Content-Length"] = info.Length.ToString();
             #endregion
 
-            replyRpcData.http_headers_Set(header);
-            RpcContext.Current.apiReplyMessage.rpcContextData_OriData = replyRpcData.PackageOriData();
+            replyRpcData.http.headers = headers;
+
+            RpcContext.Current.apiReplyMessage.rpcContextData_OriData = replyRpcData.ToBytes().BytesToArraySegmentByte();
             #endregion
 
 

+ 0 - 504
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/Rpc/Extendsions/IRpcContextDataExtensions.cs

@@ -1,504 +0,0 @@
-
-using Newtonsoft.Json.Linq;
-using System;
-using Sers.Core.Module.Rpc;
-using Sers.Core.Module.Api.Rpc;
-using Vit.Core.Util.Common;
-using System.IO;
-using Vit.Core.Util.ComponentModel.SsError;
-using System.Linq;
-
-namespace Vit.Extensions
-{
-    /// <summary>
-    /// Extension methods for RpcContextData
-    /// </summary>
-    public static partial class IRpcContextDataExtensions
-    {
-
-
-
-        #region Init
-
-        public static IRpcContextData Init(this IRpcContextData rpcData, String callerSource)
-        {
-            var rid = CommonHelp.NewGuid();
-
-
-            var caller = rpcData.oriJson.GetOrCreateJObject("caller");
-            caller["rid"] = rid;
-            caller["source"] = callerSource;
-
-            //rpcData.caller_rid_Set(rid);
-            //rpcData.caller_source_Set(callerSource);
-
-            return rpcData;
-        }
-
-        public static IRpcContextData Init(this IRpcContextData rpcData, ECallerSource callerSource = ECallerSource.Internal)
-        {
-            return Init(rpcData, callerSource.EnumToString());
-        }
-
-
-        public static IRpcContextData Init(this IRpcContextData rpcData, string url, string httpMethod = null)
-        {
-            //(x.1)设置url
-            rpcData.http_url_Set("http://sers.internal" + url);       
-
-            #region (x.2)设置route
-            //去除query string(url ?后面的字符串)           
-            {
-                //问号的位置
-                var queryIndex = url.IndexOf('?');
-
-                // b2?a=c
-                if (queryIndex >= 0)
-                {
-                    rpcData.route = url.Substring(0, queryIndex);
-                }
-                else
-                {
-                    rpcData.route = url;
-                }
-            }
-            #endregion
-
-            //(x.3)设置httpMethod
-            if (httpMethod != null) rpcData.http_method_Set(httpMethod);   
-
-            return rpcData;
-        }
-
-        #endregion
-
-        #region InitFromRpcContext
-
-        public static IRpcContextData InitFromRpcContext(this IRpcContextData rpcData)
-        {
-            rpcData.Init();
-
-            var rpcDataFromContext = RpcContext.RpcData;
-            if (null == rpcDataFromContext) return rpcData;
-
-
-            #region (x.2) caller_callStack
-            String parentRid = rpcDataFromContext.caller_rid_Get();
-            var callStack = rpcDataFromContext.caller_callStack_Get();
-            if (null == callStack || callStack.Count == 0)
-            {
-                callStack = new JArray();
-            }
-            else
-            {
-                callStack = new JArray(callStack);
-                //callStack = callStack.ConvertBySerialize<JArray>();
-            }
-            callStack.Add(parentRid);
-            rpcData.caller_callStack_Set(callStack);
-            #endregion
-
-
-            //(x.3) http
-            //rpcData.http_Set(rpcDataFromContext.http_Get());
-
-            //(x.4) user
-            rpcData.user_Set(rpcDataFromContext.user_Get());
-
-
-            return rpcData;
-        }
-        #endregion
-
-
-        #region ValueSetByPath
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="data"></param>
-        /// <param name="value"></param>
-        /// <param name="path">value在data中的路径,至少一层,例如:new []{"taskList"}</param>
-        public static void ValueSetByPath(this IRpcContextData data,object value, params object[] path)
-        {
-            data?.oriJson?.ValueSetByPath(value, path);
-        }
-        #endregion
-
-        #region StringGetByPath
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="data"></param>
-        /// <param name="path">value在data中的路径,至少一层,例如:new []{"taskList"}</param>
-        /// <returns></returns>
-        public static String StringGetByPath(this IRpcContextData data, params object[] path)
-        {
-            if (data?.oriJson == null) return null;
-            return data.oriJson.StringGetByPath(path);
-        }
-        #endregion
-
-
-
-        #region apiStationName_Get
-        public static string apiStationName_Get(this IRpcContextData data)
-        {
-            var arr = data.route?.Split('/');
-            if (arr == null || arr.Length <= 1) return null;
-            return arr[1];
-        }        
-        #endregion
-
-        #region caller
-
-        #region caller
-        public static JObject caller_Get(this IRpcContextData data)
-        {
-            return data.oriJson.GetOrCreateJObject("caller");
-        }
-
-        public static void caller_Set(this IRpcContextData data, JObject value)
-        {
-            if (null == data) return;
-            data.oriJson["caller"] = value;
-        }
-        #endregion
-
-
-        #region caller_source
-        public static String caller_source_Get(this IRpcContextData data)
-        {
-            return data?.oriJson?["caller"]?["source"]?.ConvertToString();
-        }
-
-        public static void caller_source_Set(this IRpcContextData data, String value)
-        {
-            if (null == data) return;
-            data.oriJson.GetOrCreateJObject("caller")["source"] = value;
-        }
-
-
-        public static ECallerSource? caller_source_GetEnum(this IRpcContextData data)
-        {
-            return data.caller_source_Get()?.ToECallerSource();
-        }
-        public static void caller_source_Set(this IRpcContextData data, ECallerSource? value)
-        {
-            data?.caller_source_Set(null == value ? null : value.Value.EnumToString());
-        }
-        #endregion
-
-
-        #region caller_rid
-        public static String caller_rid_Get(this IRpcContextData data)
-        {
-            return data?.oriJson?["caller"]?["rid"]?.ConvertToString();
-        }
-
-        public static void caller_rid_Set(this IRpcContextData data, String value)
-        {
-            if (null == data) return;
-            data.oriJson.GetOrCreateJObject("caller")["rid"] = value;
-        }
-        #endregion
-
-        #region caller_callStack
-        public static JArray caller_callStack_Get(this IRpcContextData data)
-        {
-            JArray ja = null;
-            data?.oriJson?["caller"]?["callStack"]?.TryParse(out ja);
-            return ja;
-        }
-
-        public static void caller_callStack_Set(this IRpcContextData data, JArray value)
-        {
-            if (null == data) return;
-            data.oriJson.GetOrCreateJObject("caller")["callStack"] = value;
-        }
-
-        
-        public static String caller_parentRid_Get(this IRpcContextData data)
-        {
-            JArray ja = caller_callStack_Get(data);
-            if (null == ja || ja.Count == 0) return null;
-            return ja[ja.Count - 1].ConvertToString();
-        }
-        public static String caller_rootRid_Get(this IRpcContextData data)
-        {
-            JArray ja = caller_callStack_Get(data);
-            if (null == ja || ja.Count == 0) return null;
-            return ja[0].ConvertToString();
-        }
-        #endregion
-
-        #endregion
-
-
-
-
-        #region http
-
-        #region http
-        public static JObject http_Get(this IRpcContextData data)
-        {
-           return data.oriJson.GetOrCreateJObject("http");
-        }
-
-        public static void http_Set(this IRpcContextData data, JObject value)
-        {
-            if (null == data) return;        
-            data.oriJson["http"] = value;
-        }
-        #endregion
-
-
-        #region http_url
-        /// <summary>
-        /// 若为内部调用,在调用时构建的url前缀为  "http://sers.internal"。
-        /// 如 "http://sers.internal/Station1/getName"
-        /// </summary>
-        /// <param name="data"></param>
-        /// <returns></returns>
-        public static String http_url_Get(this IRpcContextData data)
-        {
-            return data?.oriJson?["http"]?["url"]?.ConvertToString();
-        }
-
-        /// <summary>
-        /// 若为内部调用,手动添加url前缀 "http://sers.internal"。
-        /// 如 "http://sers.internal/Station1/getName"
-        /// </summary>
-        /// <param name="data"></param>
-        /// <param name="url"></param>
-        public static void http_url_Set(this IRpcContextData data, String url)
-        {
-            if (null == data) return;
-            data.oriJson.GetOrCreateJObject("http")["url"] = url;
-        }
-        #endregion
-
-
-        #region http_url_search_Get
-        /// <summary>
-        /// 获取泛接口 路由 * 实际传递的内容。
-        /// <para>(若 route为"/Station1/fold1/a/*",url为"http://127.0.0.1/Station1/fold1/a/1/2.html?c=9",则search为"1/2.html?c=9")</para>
-        /// </summary>
-        /// <param name="data"></param>
-        /// <returns></returns>
-        public static String http_url_search_Get(this IRpcContextData data)
-        {
-            // "http://127.0.0.1/Station1/fold1/a/1/2.html?c=9"
-            var http_url = data.http_url_Get();
-
-            // "/Station1/fold1/a/*"
-            var route = data.route;
-
-            int index = http_url.IndexOf(route.Substring(0, route.Length - 1));
-            if (index < 0) return null;
-
-            return http_url.Substring(index + route.Length - 1);   
-        }
-        #endregion
-
-
-        #region http_url_RelativePath_Get
-
-        /// <summary>
-        /// 获取当前url对应的相对文件路径(若不合法,则返回null)。demo:"rpc/2.html"
-        /// <para>(若 route为"/Station1/fold1/a/*",url为"http://127.0.0.1/Station1/fold1/a/1/2.html?c=9",则 relativePath为"1/2.html")</para>
-        /// </summary>
-        /// <returns></returns>
-        public static string http_url_RelativeUrl_Get(this IRpcContextData rpcData)
-        {
-            // "1/2.html?c=9"
-            var search = rpcData.http_url_search_Get();
-            if (String.IsNullOrEmpty(search)) return null;
-            var index = search.IndexOf('?');
-
-            String relativePath = search;
-            if (index >= 0)
-            {
-                relativePath = relativePath.Substring(0, index);
-            }
-            return relativePath;
-        }
-        #endregion
-
-
-        #region http_url_RelativePath_Get
-
-        /// <summary>
-        /// 获取当前url对应的相对文件路径(若不合法,则返回null,会自动转换文件夹分隔符)。demo:"rpc\\2.html"
-        /// <para>(若 route为"/Station1/fold1/a/*",url为"http://127.0.0.1/Station1/fold1/a/1/2.html?c=9",则 relativePath为"1\\2.html")</para>
-        /// </summary>
-        /// <returns></returns>
-        public static string http_url_RelativePath_Get(this IRpcContextData rpcData)
-        {
-            String relativePath= http_url_RelativeUrl_Get(rpcData);
-            
-            return relativePath?.Replace('/', Path.DirectorySeparatorChar).Replace("..","");
-        }
-        #endregion
-
-        #region http_method
-
-        public static String http_method_Get(this IRpcContextData data)
-        {
-            return data?.StringGetByPath("http", "method");
-        }
-
-        public static IRpcContextData http_method_Set(this IRpcContextData data, String value)
-        {
-            data?.ValueSetByPath(value, "http", "method");
-            return data;
-        }
-        #endregion
-
-        #region http_statusCode
-
-        public static int? http_statusCode_Get(this IRpcContextData data)
-        {
-            int status=200;
-            if (data?.oriJson?.JTokenGetByPath("http", "statusCode")?.TryParseIgnore(out status) ?? false)
-            {
-                return status;
-            }
-            return null;           
-        }
-
-        public static IRpcContextData http_statusCode_Set(this IRpcContextData data, int? value)
-        {
-            data?.ValueSetByPath(value, "http", "statusCode");
-            return data;
-        }
-        #endregion
-
-        #region http_protocol
-        /// <summary>
-        /// 如 "HTTP/2.0"
-        /// </summary>
-        /// <param name="data"></param>
-        /// <returns></returns>
-        public static String http_protocol_Get(this IRpcContextData data)
-        {
-            return data?.StringGetByPath("http", "protocol");
-        }
-
-        /// <summary>
-        /// 如 "HTTP/2.0"
-        /// </summary>
-        /// <param name="data"></param>
-        /// <param name="value"></param>
-        /// <returns></returns>
-        public static IRpcContextData http_protocol_Set(this IRpcContextData data, String value)
-        {
-            data?.ValueSetByPath(value, "http", "protocol");
-            return data;
-        }
-        #endregion      
-
-        #region http_headers
-        /// <summary>
-        /// 若没指定headers则返回null
-        /// </summary>
-        /// <param name="data"></param>
-        /// <returns></returns>
-        public static JObject http_headers_Get(this IRpcContextData data)
-        {
-            return data?.oriJson?.JTokenGetByPath("http", "headers") as JObject;
-        }
-
-        public static IRpcContextData http_headers_Set(this IRpcContextData data, JObject value)
-        {
-            data?.ValueSetByPath(value, "http", "headers");
-            return data;
-        }
-
-
-
-
-        public static String http_header_Get(this IRpcContextData data, String key)
-        {
-            return data?.StringGetByPath("http", "headers", key);
-        }       
-
-        public static IRpcContextData http_header_Set(this IRpcContextData data,String key,String value)
-        {
-            data?.ValueSetByPath(value, "http", "headers", key);
-            return data;
-        }
-
-
-        #region Content-Type
-        public static String http_header_ContentType_Get(this IRpcContextData data)
-        {
-            return http_header_Get(data,"Content-Type");
-        }
-
-        public static IRpcContextData http_header_ContentType_Set(this IRpcContextData data, String value)
-        {         
-            return http_header_Set(data,"Content-Type", value);
-        }
-        #endregion
-
-        #endregion
-
-
-        #endregion
-
-
-        #region user
-
-        #region user
-        public static JObject user_Get(this IRpcContextData data)
-        {
-            return data.oriJson.GetOrCreateJObject("user");
-        }
-
-        public static void user_Set(this IRpcContextData data, JObject value)
-        {
-            if (null == data) return;
-            data.oriJson["user"] = value;
-        }
-        #endregion
-
-        #region user_userInfo
-        public static JObject user_userInfo_Get(this IRpcContextData data)
-        {
-            return data?.oriJson?["user"]?["userInfo"].GetValue() as JObject;
-        }
-        public static void user_userInfo_Set(this IRpcContextData data, JObject value)
-        {
-            if (null == data) return;
-            data.oriJson.GetOrCreateJObject("user")["userInfo"] = value;
-        }
-        #endregion
-
-        #endregion
-
-
-        #region error
-        public static SsError error_Get(this IRpcContextData data)
-        {
-            return data.oriJson["error"].Deserialize<SsError>();
-        }
-
-        public static void error_Set(this IRpcContextData data, SsError value)
-        {
-            data.oriJson["error"] = value.ConvertBySerialize<JObject>();
-
-            //data.http_statusCode_Set(value.errorCode);
-        }
-        #endregion
-
-
-
-
-
-
-
-
-
-
-    }
-}

+ 0 - 160
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/Rpc/RpcContextData.cs

@@ -1,160 +0,0 @@
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using Vit.Extensions;
-using Sers.Core.Module.Rpc;
-using System;
-using System.Runtime.CompilerServices;
-
-namespace Sers.Core.Module.Api.Rpc
-{
-    /// <summary>
-    ///
-    /// </summary>
-    [JsonObject(MemberSerialization.OptIn)]
-    public class RpcContextData: IRpcContextData
-    {
-
-        ArraySegment<byte> oriData;
-
-
-        public RpcContextData() { }
-
-
-
-        /// <summary>
-        ///
-        /// </summary>
-        /// <param name="oriData"></param>
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public IRpcContextData UnpackOriData(ArraySegment<byte> oriData)
-        {
-            Clear(oriData);
-            return this;
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <returns></returns>
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public ArraySegment<byte> PackageOriData()
-        {
-            string strOriData = (_oriJson==null  ? "{}": _oriJson.ToString());
-            return strOriData.StringToArraySegmentByte();
-        }
-
-
-
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        private JObject GetJsonFromOriData()
-        {
-            if (null == oriData|| oriData.Count==0) return new JObject();
-
-            try
-            {
-                string oriString = oriData.ArraySegmentByteToString();
-                return /*String.IsNullOrEmpty(oriString)? new JObject():*/JObject.Parse(oriString);                
-            }
-            catch (Exception)
-            {
-            }
-            return new JObject();
-
-        }
-
-
-        #region oriJson        
-
-        JObject _oriJson;
-        public JObject oriJson=>(_oriJson??(_oriJson = GetJsonFromOriData()));
-        #endregion
-
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        void Clear(ArraySegment<byte> oriData)
-        {
-            this.oriData = oriData;
-     
-            _oriJson = null;
-      
-        }
-
-
-
-
-        #region route
-        [JsonProperty]
-        public string route
-        {
-            get
-            {
-                //string oriString = oriData.ArraySegmentByteToString();
-
-                //\"route\": \"/_sys_/serviceStation/regist\",
-                //var  index_key = oriString.IndexOf("route");
-                //var index_start = oriString.IndexOf('"', index_key + 7);
-                //var index_end = oriString.IndexOf('"', index_start+1);
-                //return oriString.Substring(index_start + 1, index_end - index_start - 1);
-
-                return oriJson["route"].ConvertToString();
-            }
-            set
-            {
-                oriJson["route"] = value;
-            }
-        }
-        #endregion       
-
-
-
-        #region caller
-
-        [JsonProperty]
-        public JObject caller
-        {
-            get => this.caller_Get();
-            set => this.caller_Set(value);
-        }
-        #endregion
-
-        #region caller_source
-        /// <summary>
-        /// 调用来源
-        /// </summary>    
-        ECallerSource? caller_source
-        {
-            get
-            {                
-                return this.caller_source_GetEnum();
-            }
-            set
-            {
-                this.caller_source_Set(value);
-            }
-        }
-        #endregion
-
-
-        #region http
-
-        [JsonProperty]
-        public JObject http
-        {
-            get => this.http_Get();
-            set=> this.http_Set(value);
-        }
-        #endregion
-
-
-        #region user
-
-        [JsonProperty]
-        public JObject user
-        {
-            get => this.user_Get();
-            set => this.user_Set(value);
-        }
-        #endregion
-
-
-    }
-}

+ 2 - 2
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Message/ApiMessage.cs

@@ -41,9 +41,9 @@ namespace Sers.Core.Module.Message
             }
         }
 
-        public void RpcContextData_OriData_Set(IRpcContextData rpcData)
+        public void RpcContextData_OriData_Set(RpcContextData rpcData)
         {
-            rpcContextData_OriData = rpcData.PackageOriData();
+            rpcContextData_OriData = rpcData.ToBytes().BytesToArraySegmentByte();
         }
 
 

+ 8 - 8
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Message/Extendsions/ApiMessageExtensions.cs

@@ -20,13 +20,13 @@ namespace Vit.Extensions
             if (data == null || error == null) return data;
 
             #region (x.1) set rpcData
-            var rpcData = RpcFactory.CreateRpcContextData();
-            rpcData.error_Set(error);
- 
-            rpcData.http_header_Set("Content-Type", Response_ContentType_Json);
+            var rpcData = new RpcContextData();
+            rpcData.error = error;
 
-            rpcData.http_header_Set("responseState", "fail");
-            rpcData.http_header_Set("responseError_Base64", error?.SerializeToBytes()?.BytesToBase64String());
+            rpcData.http.headers["Content-Type"] = Response_ContentType_Json;
+
+            rpcData.http.headers["responseState"] = "fail";
+            rpcData.http.headers["responseError_Base64"] = error?.SerializeToBytes()?.BytesToBase64String();
 
 
             data.RpcContextData_OriData_Set(rpcData);
@@ -94,10 +94,10 @@ namespace Vit.Extensions
         /// <param name="InitRpc">对Rpc的额外处理,如添加header</param>
         /// <returns></returns>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static ApiMessage InitAsApiRequestMessage(this ApiMessage apiRequestMessage, string url, Object arg=null,string httpMethod=null,Action<IRpcContextData>InitRpc=null)
+        public static ApiMessage InitAsApiRequestMessage(this ApiMessage apiRequestMessage, string url, Object arg=null,string httpMethod=null,Action<RpcContextData>InitRpc=null)
         {   
             //(x.1)初始化rpcData
-            var rpcData = RpcFactory.CreateRpcContextData().InitFromRpcContext().Init(url, httpMethod);
+            var rpcData = new RpcContextData().InitFromRpcContext().Init(url, httpMethod);
             InitRpc?.Invoke(rpcData);
             apiRequestMessage.RpcContextData_OriData_Set(rpcData);
 

+ 1 - 3
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/Rpc/ECallerSource.cs → dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Rpc/ECallerSource.cs

@@ -1,8 +1,6 @@
 using System;
-using System.Collections.Generic;
-using System.Text;
 
-namespace Sers.Core.Module.Api.Rpc
+namespace Sers.Core.Module.Rpc
 {
     /// <summary>
     /// 调用来源

+ 2 - 2
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/Rpc/Extendsions/ECallerSourceExtensions.cs → dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Rpc/Extensions/ECallerSourceExtensions.cs

@@ -1,4 +1,4 @@
-using Sers.Core.Module.Api.Rpc;
+using Sers.Core.Module.Rpc;
 
 namespace Vit.Extensions
 {
@@ -27,7 +27,7 @@ namespace Vit.Extensions
                 case "Internal": return ECallerSource.Internal;
                 case "OutSide": return ECallerSource.OutSide;
             }
-            return default(ECallerSource);
+            return default;
         }
 
     }

+ 204 - 0
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Rpc/Extensions/RpcContextDataExtensions.cs

@@ -0,0 +1,204 @@
+using System;
+using Sers.Core.Module.Rpc;
+using Vit.Core.Util.Common;
+using System.IO;
+
+namespace Vit.Extensions
+{
+    /// <summary>
+    /// Extension methods for RpcContextData
+    /// </summary>
+    public static partial class RpcContextDataExtensions
+    {
+
+
+
+        #region Init
+
+        public static RpcContextData Init(this RpcContextData rpcData, String callerSource=nameof(ECallerSource.Internal))
+        {
+            var rid = CommonHelp.NewGuid();
+             
+            rpcData.caller.rid = rid;
+            rpcData.caller.source = callerSource; 
+
+            return rpcData;
+        }
+
+ 
+
+        public static RpcContextData Init(this RpcContextData data, string url, string httpMethod = null)
+        {
+            data.http.url = "http://sers.internal" + url;
+
+            #region (x.2)设置route
+            //去除query string(url ?后面的字符串)           
+            {
+                //问号的位置
+                var queryIndex = url.IndexOf('?');
+
+                // b2?a=c
+                if (queryIndex >= 0)
+{
+                    data.route = url.Substring(0, queryIndex);
+                }
+                else
+{
+                    data.route = url;
+                }
+            }
+            #endregion              
+
+            //(x.3)设置httpMethod
+            if (httpMethod != null) data.http.method=httpMethod;
+
+            return data;
+        }
+
+        #endregion
+
+        #region InitFromRpcContext
+
+        public static RpcContextData InitFromRpcContext(this RpcContextData rpcData)
+        {
+            rpcData.Init();
+
+            var rpcDataFromContext = RpcContext.RpcData;
+            if (null == rpcDataFromContext) return rpcData;
+
+
+            #region (x.2) caller_callStack
+            String parentRid = rpcDataFromContext.caller.rid;
+
+            rpcData.caller.callStack.AddRange(rpcDataFromContext.caller.callStack);
+            rpcData.caller.callStack.Add(parentRid);
+
+            #endregion
+
+
+            //(x.3) http
+            //rpcData.http=rpcDataFromContext.http;
+
+            //(x.4) user
+            rpcData.user = rpcDataFromContext.user;    
+
+
+            return rpcData;
+        }
+        #endregion
+
+
+
+
+
+
+
+
+
+
+        #region http_url_search_Get
+        /// <summary>
+        /// 获取泛接口 路由 * 实际传递的内容。
+        /// <para>(若 route为"/Station1/fold1/a/*",url为"http://127.0.0.1/Station1/fold1/a/1/2.html?c=9",则search为"1/2.html?c=9")</para>
+        /// </summary>
+        /// <param name="data"></param>
+        /// <returns></returns>
+        public static String http_url_search_Get(this RpcContextData data)
+        {
+            // "http://127.0.0.1/Station1/fold1/a/1/2.html?c=9"
+            var http_url = data.http.url;
+
+            // "/Station1/fold1/a/*"
+            var route = data.route;
+
+            int index = http_url.IndexOf(route.Substring(0, route.Length - 1));
+            if (index < 0) return null;
+
+            return http_url.Substring(index + route.Length - 1);
+        }
+        #endregion
+
+
+        #region http_url_RelativePath_Get
+
+        /// <summary>
+        /// 获取当前url对应的相对文件路径(若不合法,则返回null)。demo:"rpc/2.html"
+        /// <para>(若 route为"/Station1/fold1/a/*",url为"http://127.0.0.1/Station1/fold1/a/1/2.html?c=9",则 relativePath为"1/2.html")</para>
+        /// </summary>
+        /// <returns></returns>
+        public static string http_url_RelativeUrl_Get(this RpcContextData rpcData)
+        {
+            // "1/2.html?c=9"
+            var search = rpcData.http_url_search_Get();
+            if (String.IsNullOrEmpty(search)) return null;
+            var index = search.IndexOf('?');
+
+            String relativePath = search;
+            if (index >= 0)
+            {
+                relativePath = relativePath.Substring(0, index);
+            }
+            return relativePath;
+        }
+        #endregion
+
+
+        #region http_url_RelativePath_Get
+
+        /// <summary>
+        /// 获取当前url对应的相对文件路径(若不合法,则返回null,会自动转换文件夹分隔符)。demo:"rpc\\2.html"
+        /// <para>(若 route为"/Station1/fold1/a/*",url为"http://127.0.0.1/Station1/fold1/a/1/2.html?c=9",则 relativePath为"1\\2.html")</para>
+        /// </summary>
+        /// <returns></returns>
+        public static string http_url_RelativePath_Get(this RpcContextData rpcData)
+        {
+            String relativePath = http_url_RelativeUrl_Get(rpcData);
+
+            return relativePath?.Replace('/', Path.DirectorySeparatorChar).Replace("..", "");
+        }
+        #endregion
+
+
+
+        #region Content-Type
+        public static String http_header_ContentType_Get(this RpcContextData data)
+        {
+            return data.http.GetHeader("Content-Type");
+        }
+
+        public static RpcContextData http_header_ContentType_Set(this RpcContextData data, String value)
+        {
+             data.http.headers["Content-Type"]=value;
+            return data;
+        }
+        #endregion
+
+
+
+        #region apiStationName_Get
+        public static string apiStationName_Get(this RpcContextData data)
+        {
+            var arr = data.route?.Split('/');
+            if (arr == null || arr.Length <= 1) return null;
+            return arr[1];
+        }
+        #endregion
+
+        #region caller_callStack
+       
+
+        public static String caller_parentRid_Get(this RpcContextData data)
+        {
+            var ja = data.caller.callStack ;
+            if (null == ja || ja.Count == 0) return null;
+            return ja[ja.Count - 1];
+        }
+        public static String caller_rootRid_Get(this RpcContextData data)
+        {
+            var ja = data.caller.callStack;
+            if (null == ja || ja.Count == 0) return null;
+            return ja[0];
+        }
+        #endregion
+    }
+}

+ 0 - 45
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Rpc/IRpcContextData.cs

@@ -1,45 +0,0 @@
-using Newtonsoft.Json.Linq;
-using System;
-
-namespace Sers.Core.Module.Rpc
-{
-    public interface IRpcContextData
-    {
-        /*
-    {
-        "route": "/DemoStation/v1/api/5/rpc/2",
-        "caller": {
-            "rid": "8320becee0d945e9ab93de6fdac7627a",
-            "source": "Outside"
-        },
-        "http": {
-            "url": "http://127.0.0.1:6000/DemoStation/v1/api/5/rpc/2",
-            "headers": {
-                "Cache-Control": "no-cache",
-                "Connection": "keep-alive",
-                "Content-Type": "application/javascript",
-                "Accept": "* / *",
-                "Accept-Encoding": "gzip, deflate",
-                "Authorization": "bearer",
-                "Host": "127.0.0.1:6000",
-                "User-Agent": "PostmanRuntime/7.6.0",
-                "Postman-Token": "78c5a1cb-764f-4e04-b2ae-514924a40d5a"
-            }
-        },
-        "user": {}
-    }
-
-             */
-
-
-
-        IRpcContextData UnpackOriData(ArraySegment<byte> oriData);
-        ArraySegment<byte> PackageOriData();
-
-        string route { get; set; }
-
-
-        JObject oriJson { get; }
-
-    }
-}

+ 2 - 2
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Rpc/RpcContext.cs

@@ -13,7 +13,7 @@ namespace Sers.Core.Module.Rpc
 
         public static RpcContext Current => CurrentRpcContext_AsyncCache.Value;
 
-        public static IRpcContextData RpcData => Current?.rpcData;
+        public static RpcContextData RpcData => Current?.rpcData;
 
         #endregion
 
@@ -21,7 +21,7 @@ namespace Sers.Core.Module.Rpc
         public ApiMessage apiRequestMessage;
         public ApiMessage apiReplyMessage;
 
-        public IRpcContextData rpcData;
+        public RpcContextData rpcData;
 
 
 

+ 115 - 0
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Rpc/RpcContextData.cs

@@ -0,0 +1,115 @@
+using System;
+using System.Collections.Generic;
+
+ 
+
+namespace Sers.Core.Module.Rpc
+{
+    public class RpcContextData
+    {
+        public RpcContextData() 
+        {
+        }
+
+
+        public string Serialize()
+        {
+            //return Vit.Core.Module.Serialization.Serialization.Instance.SerializeToString(this);
+
+            return Vit.Core.Module.Serialization.Serialization_Text.Instance.SerializeToString(this);
+        
+        }
+
+        public byte[] ToBytes() 
+        {
+            //return Vit.Core.Module.Serialization.Serialization.Instance.SerializeToBytes(this);
+            return Vit.Core.Module.Serialization.Serialization_Text.Instance.SerializeToBytes(this);
+        }
+
+        public  static RpcContextData FromBytes(ReadOnlySpan<byte>data)
+        {
+            //return Vit.Core.Module.Serialization.Serialization.Instance.DeserializeFromSpan<RpcContextData>(data);
+            return Vit.Core.Module.Serialization.Serialization_Text.Instance.DeserializeFromSpan<RpcContextData>(data);
+        }
+
+
+        /*
+        {
+        "route": "/DemoStation/v1/api/5/rpc/2",
+        "caller": {
+            "rid": "8320becee0d945e9ab93de6fdac7627a",
+            "callStack": ["xxxx","xxxxxx"],    // parentRequestGuid array
+            "source": "Outside"
+        },
+        "http": {
+            "url": "https://127.0.0.1:6000/DemoStation/v1/api/5/rpc/2?a=1",
+            "method":"GET",
+            "statusCode":400,
+            "protocol":"HTTP/2.0",
+            "headers": {
+                "Cache-Control": "no-cache",
+                "Connection": "keep-alive",
+                "Content-Type": "application/javascript",
+                "Accept": "* / *",
+                "Accept-Encoding": "gzip, deflate",
+                "Authorization": "bearer",
+                "Host": "127.0.0.1:6000",
+                "User-Agent": "PostmanRuntime/7.6.0",
+                "Postman-Token": "78c5a1cb-764f-4e04-b2ae-514924a40d5a"
+            }
+        },
+	    "error":{SsError},
+        "user": {"userInfo":{} }
+    }             
+         
+         */
+
+
+
+
+
+        public string route;
+
+        #region caller
+
+        public Caller caller=new Caller();
+
+        public class Caller 
+        {
+            public string rid;
+            public List<string> callStack;
+            public string source;
+
+        }
+        #endregion
+
+
+        #region http
+        public Http http=new Http();
+        public class Http
+        {
+            public string url;
+            public string method;
+            public int? statusCode;
+            public string protocol;
+            public Dictionary<string, string> headers=new Dictionary<string, string>();
+
+            public string GetHeader(string key) 
+            {                
+                if (headers.TryGetValue(key, out var value)) return value;
+                return null;
+            }
+
+        }
+
+        #endregion
+
+
+        public object error;
+
+        public object user;
+
+ 
+
+    }
+}

+ 1 - 4
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Rpc/RpcFactory.cs

@@ -1,5 +1,4 @@
 using System;
-using Sers.Core.Module.Api.Rpc;
 
 namespace Sers.Core.Module.Rpc
 {
@@ -8,8 +7,6 @@ namespace Sers.Core.Module.Rpc
         public static Func<RpcContext> CreateRpcContext  =
             () => new RpcContext();
 
-
-        public static Func<IRpcContextData> CreateRpcContextData =
-            () => new RpcContextData();
+ 
     }
 }

+ 2 - 1
dotnet/Library/Sers/Sers.Core/Sers.Core/SersLoader/ApiDesc/Attribute/Valid/SsCallerSourceAttribute.cs

@@ -1,7 +1,8 @@
 using System;
 using System.Collections.Generic;
-using Sers.Core.Module.Api.Rpc;
+using Sers.Core.Module.Rpc;
 using Sers.SersLoader.ApiDesc.Attribute.RpcVerify;
+
 using Vit.Extensions;
 
 namespace Sers.SersLoader.ApiDesc.Attribute.Valid

+ 6 - 4
dotnet/Library/Sers/Sers.Core/Test/Sers.Core.Module.Rpc.MsTest/UnitTest1.cs

@@ -14,13 +14,15 @@ namespace Sers.Core.Module.Rpc.MsTest
             {
                 using (var rpcContext = RpcFactory.CreateRpcContext())
                 {
-                    var rpcData = RpcFactory.CreateRpcContextData();
+                    var rpcData = new RpcContextData();
                     rpcContext.rpcData = rpcData;
-                    rpcData.http_method_Set("POST");
+                    rpcData.http.method="POST";
 
 
-                    var rpcData2 = RpcFactory.CreateRpcContextData();
-                    rpcData2.UnpackOriData(rpcData.PackageOriData());
+                    var rpcData2 = RpcContextData.FromBytes(rpcData.ToBytes());
+
+
+                    Assert.AreEqual(rpcData.http.method, rpcData2.http.method);
                 }
                  
             }

+ 1 - 1
dotnet/Library/Vit/Vit.Core/Test/Vit.Core.MsTest/Module/SerializationTest.cs

@@ -64,7 +64,7 @@ namespace Vit.Core.MsTest.Module
 
             string str = obj.Serialize();
 
-            Serialization.Instance.SetDateTimeFormat("yyyy-MM-dd");
+            Serialization.Newtonsoft.SetDateTimeFormat("yyyy-MM-dd");
 
             string str2 = obj.Serialize();
             var jtObj = str2.Deserialize<JObject>();

+ 1 - 1
dotnet/Library/Vit/Vit.Core/Vit.Core/Extensions/EnumExtensions.cs

@@ -11,7 +11,7 @@ namespace Vit.Extensions
         #region String --> Enum
 
         /// <summary>
-        /// T 必须为Enum
+        /// T 必须为Enum,且不可为Nullable
         /// </summary>
         /// <typeparam name="T"></typeparam>
         /// <param name="data"></param>

+ 6 - 4
dotnet/Library/Vit/Vit.Core/Vit.Core/Extensions/byte/ArraySegmentByteExtensions.cs

@@ -1,6 +1,7 @@
 using Vit.Core.Module.Serialization;
 using System;
 using System.Runtime.CompilerServices;
+using System.Text;
 
 namespace Vit.Extensions
 {
@@ -23,7 +24,7 @@ namespace Vit.Extensions
         public static ArraySegment<T> Slice<T>(this ArraySegment<T> seg,int Offset,int? count=null)
         {
             return new ArraySegment<T>(seg.Array,seg.Offset+ Offset, count?? (seg.Count-Offset) );
-        } 
+        }
 
 
 
@@ -32,17 +33,18 @@ namespace Vit.Extensions
         #region ArraySegmentByte <--> String
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static string ArraySegmentByteToString(this ArraySegment<byte> data)
+        public static string ArraySegmentByteToString(this ArraySegment<byte> data, Encoding encoding = null)
         {
             if (null == data || data.Array==null) return null;
-            return data.Count==0?"":Serialization.Instance.encoding.GetString(data.Array,data.Offset,data.Count); 
+            ReadOnlySpan<byte> span = data;
+            return span.SpanToString(encoding);
         }
 
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         public static ArraySegment<byte> StringToArraySegmentByte(this string data)
         {
-            return (null == data) ? Null : Serialization.Instance.encoding.GetBytes(data).BytesToArraySegmentByte();
+            return (null == data) ? Null : data.StringToBytes().BytesToArraySegmentByte();
         }
         #endregion
 

+ 30 - 0
dotnet/Library/Vit/Vit.Core/Vit.Core/Extensions/byte/SpanExtensions.cs

@@ -0,0 +1,30 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Text;
+
+using Vit.Core.Module.Serialization;
+
+namespace Vit.Extensions
+{
+    public static partial class SpanExtensions
+    {
+
+
+        #region SpanToString
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public static string SpanToString(this ReadOnlySpan<byte> data, Encoding encoding = null)
+        {
+            return Serialization.Instance.SpanToString(data, encoding);
+        }
+
+        #endregion
+
+
+ 
+
+ 
+
+
+    }
+}

+ 35 - 0
dotnet/Library/Vit/Vit.Core/Vit.Core/Module/Serialization/Extensions/EncodingExtensions.cs

@@ -3,6 +3,8 @@ using System;
 using System.Runtime.CompilerServices;
 using System.Text;
 
+using Vit.Core.Module.Serialization;
+
 namespace Vit.Extensions
 {
     public static partial class EncodingExtensions
@@ -16,5 +18,38 @@ namespace Vit.Extensions
             return value.ToString();
         }
 
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public static Encoding ToEncoding(this EEncoding type)
+        {
+            //if (null == type) return null;
+            switch (type)
+            {
+                case EEncoding.ASCII: return Encoding.ASCII;
+                case EEncoding.UTF32: return Encoding.UTF32;
+                case EEncoding.UTF7: return Encoding.UTF7;
+                case EEncoding.UTF8: return Encoding.UTF8;
+                case EEncoding.Unicode: return Encoding.Unicode;
+            }
+            return null;
+        }
+
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public static Encoding ToEncoding(this EEncoding? type)
+        {
+            if (null == type) return null;
+            switch (type.Value)
+            {
+                case EEncoding.ASCII: return Encoding.ASCII;
+                case EEncoding.UTF32: return Encoding.UTF32;
+                case EEncoding.UTF7: return Encoding.UTF7;
+                case EEncoding.UTF8: return Encoding.UTF8;
+                case EEncoding.Unicode: return Encoding.Unicode;
+            }
+            return null;
+        }
+
+
     }
 }

+ 142 - 179
dotnet/Library/Vit/Vit.Core/Vit.Core/Module/Serialization/Serialization.cs

@@ -1,116 +1,78 @@
-using Newtonsoft.Json;
-using Newtonsoft.Json.Converters;
-using Vit.Extensions;
+using Vit.Extensions;
 using System;
 using System.Text;
-using Vit.Core.Util.ConfigurationManager;
 using System.Runtime.CompilerServices;
+using Vit.Core.Util.ConfigurationManager;
+
 
 namespace Vit.Core.Module.Serialization
 {
-    public class Serialization
+    public  abstract class Serialization
     {
-        
-        public static Serialization Instance { get; } = new Serialization();
 
-        #region 静态初始化器
-        static Serialization()
-        {
-            //初始化序列化配置
-            Instance.InitByAppSettings();
-        }
+        #region defaultEncoding
+        public static Encoding defaultEncoding { get; set; } =
+            ConfigurationManager.Instance.GetByPath<string>("Vit.Serialization.Encoding").StringToEnum<EEncoding>().ToEncoding() ?? Encoding.UTF8;
+
         #endregion
 
 
-        #region 成员对象
 
-        /// <summary>
-        /// 时间序列化格式。例如 "yyyy-MM-dd HH:mm:ss"
-        /// </summary>
-        readonly IsoDateTimeConverter Serialize_DateTimeFormat = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };
+        public static Serialization Instance { get; set; } = Serialization_Newtonsoft.Instance;
 
-        /// <summary>
-        /// 设置时间序列化格式。例如 "yyyy-MM-dd HH:mm:ss"
-        /// </summary>
-        /// <param name="DateTimeFormat"></param>
-        public void SetDateTimeFormat(string DateTimeFormat) {
-            Serialize_DateTimeFormat.DateTimeFormat = DateTimeFormat;
-        }
+        public static readonly Serialization_Newtonsoft Newtonsoft = Serialization_Newtonsoft.Instance;
+        public static readonly Serialization_Text Text = Serialization_Text.Instance;
 
 
-        public Encoding encoding { get; private set; } = System.Text.Encoding.UTF8;
-        public string charset => encoding.GetCharset();
+ 
 
-        public void SetEncoding(EEncoding? type)
-        {
-            if (null == type) return;
 
-            switch (type.Value)
-            {
-                case EEncoding.ASCII: encoding = Encoding.ASCII; return;
-                case EEncoding.UTF32: encoding = Encoding.UTF32; return;
-                case EEncoding.UTF7: encoding = Encoding.UTF7; return;
-                case EEncoding.UTF8: encoding = Encoding.UTF8; return;
-                case EEncoding.Unicode: encoding = Encoding.Unicode; return;
-            }
-        }
+
+        #region 成员对象 
+
+
+        public virtual Encoding encoding { get; set; } = defaultEncoding;
+        public virtual string charset { get => encoding.GetCharset();  }
+ 
         #endregion
 
 
-        #region InitByAppSettings
-        /// <summary>
-        /// 根据配置文件(appsettings.json)初始化序列化配置
-        /// </summary>
-        public void InitByAppSettings()
-        {
-            #region (x.1)初始化序列化字符编码
-            var encoding = ConfigurationManager.Instance.GetByPath<string>("Vit.Serialization.Encoding");
-            if (!string.IsNullOrWhiteSpace(encoding))
-            {
-                try
-                {
-                    SetEncoding(encoding.StringToEnum<EEncoding>());
-                }
-                catch
-                {
-                }
-            }
-            #endregion
 
+        #region SpanToString
 
-            #region (x.2) DateTimeFormat
-            var DateTimeFormat = ConfigurationManager.Instance.GetByPath<string>("Vit.Serialization.DateTimeFormat");
-            if (!string.IsNullOrWhiteSpace(DateTimeFormat))
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public string SpanToString(ReadOnlySpan<byte> data, Encoding encoding = null)
+        {
+            if (data.Length == 0) return default;
+            unsafe
             {
-                try
-                {
-                    SetDateTimeFormat(DateTimeFormat);
-                }
-                catch
+                fixed (byte* bytes = data)
                 {
+                    return (encoding ?? this.encoding).GetString(bytes, data.Length);
                 }
             }
-            #endregion
         }
+
         #endregion
 
 
         #region (x.1)bytes <--> String
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public string BytesToString(byte[] data, Encoding encoding = null)
+        public virtual string BytesToString(byte[] data, Encoding encoding = null)
         {
             return (encoding ?? this.encoding).GetString(data);
         }
 
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public byte[] StringToBytes(string data, Encoding encoding = null)
+        public virtual byte[] StringToBytes(string data, Encoding encoding = null)
         {
             return (encoding ?? this.encoding).GetBytes(data);
         }
         #endregion
 
+       
 
 
         #region (x.2)object <--> String
@@ -118,21 +80,17 @@ namespace Vit.Core.Module.Serialization
         #region SerializeToString
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public string SerializeToString(object value)
-        {
-            if (null == value) return null;
+        public abstract string SerializeToString<T>(T value);
 
-            if (value.GetType().TypeIsValueTypeOrStringType())
-            {
-                return value.Convert<string>();
-            }
 
-            return JsonConvert.SerializeObject(value, Serialize_DateTimeFormat);
-            //return JsonConvert.SerializeObject(value, Newtonsoft.Json.Formatting.Indented,Serialize_DateTimeFormat);
-            //return JsonConvert.SerializeObject(value, timeFormat);    
-        }
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public abstract string SerializeToString(object value, Type type);        
+
         #endregion
 
+
+
+
         #region DeserializeFromString
 
         /// <summary>
@@ -142,16 +100,8 @@ namespace Vit.Core.Module.Serialization
         /// <param name="type"></param>
         /// <returns></returns>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public object DeserializeFromString(string value, Type type)
-        {
-            if (null == value || null == type) return null;
-
-            if (type.TypeIsValueTypeOrStringType())
-            {
-                return DeserializeStruct(value, type);
-            }
-            return DeserializeClass(value, type);
-        }
+        public abstract object DeserializeFromString(string value, Type type);
+         
 
 
         /// <summary>
@@ -161,68 +111,13 @@ namespace Vit.Core.Module.Serialization
         /// <param name="value"></param>
         /// <returns></returns>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public T DeserializeFromString<T>(string value)
+        public virtual T DeserializeFromString<T>(string value)
         {
             return (T)DeserializeFromString(value, typeof(T));
         }
 
 
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="value"></param>
-        /// <param name="type">必须为 where T : struct</param>
-        /// <returns></returns>
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        private object DeserializeStruct(string value, Type type)
-        {
-            try
-            {
-                if (type.IsStringType())
-                    return value;
-                return value.Convert(type);
-            }
-            catch { }
-            return type.DefaultValue();
-        }
-
-        ///// <summary>
-        ///// 
-        ///// </summary>
-        ///// <typeparam name="T">必须为 where T : struct</typeparam>
-        ///// <param name="value"></param>
-        ///// <returns></returns>
-        //private object DeserializeStruct<T>(string value)
-        //{
-        //    return DeserializeStruct(value, typeof(T));
-        //}
-
-
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="value"></param>
-        /// <param name="type"> 必须为 where T : class </param>
-        /// <returns></returns>
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        private object DeserializeClass(string value, Type type)
-        {
-            if (string.IsNullOrWhiteSpace(value)) return type.DefaultValue();
-            return JsonConvert.DeserializeObject(value, type);
-        }
-
-
-        ///// <summary>
-        ///// 
-        ///// </summary>
-        ///// <typeparam name="T">必须为 where T : class</typeparam>
-        ///// <param name="value"></param>
-        //private T DeserializeClass<T>(string value)
-        //{
-        //    return (T)DeserializeClass(value, typeof(T));
-        //}
+           
         #endregion
 
         #endregion
@@ -239,35 +134,47 @@ namespace Vit.Core.Module.Serialization
         /// <param name="obj"></param>
         /// <returns></returns>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public byte[] SerializeToBytes(object obj)
+        public virtual byte[] SerializeToBytes<T>(T obj)
         {
-            if (null == obj) return new byte[0];
-            
-            if (obj is byte[] bytes)
+            string strValue;
+            switch (obj) 
             {
-                return bytes;
-            }
-          
-            if(! (obj is string strValue))
-            {                 
-                strValue = SerializeToString(obj);
-            }
+                case null:
+                    return new byte[0];
+                case byte[] bytes:
+                    return bytes;
+                case ArraySegment<byte> asbs:
+                    return asbs.ArraySegmentByteToBytes();
+                case string str:
+                    strValue = str; break;
+                default: strValue = SerializeToString(obj);break;
+            }    
+      
             return StringToBytes(strValue);
         }
+
+
+
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public virtual byte[] SerializeToBytes(object value, Type type) 
+        {
+            return SerializeToBytes(value);
+        }
         #endregion
 
 
         #region DeserializeFromBytes
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public T DeserializeFromBytes<T>(byte[] bytes)
+        public virtual T DeserializeFromBytes<T>(byte[] bytes)
         {
             return (T)DeserializeFromBytes(bytes, typeof(T));
         }
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public object DeserializeFromBytes(byte[] bytes, Type type)
-        {
+        public virtual object DeserializeFromBytes(byte[] bytes, Type type)
+        {      
             if (type == typeof(byte[]))
             {
                 return bytes;
@@ -285,6 +192,29 @@ namespace Vit.Core.Module.Serialization
         }
         #endregion
 
+
+        #region DeserializeFromBytes
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public virtual T DeserializeFromSpan<T>(ReadOnlySpan<byte> bytes)
+        {
+            return (T)DeserializeFromSpan(bytes, typeof(T));
+        }
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public virtual object DeserializeFromSpan(ReadOnlySpan<byte> bytes, Type type)
+        {
+            if (bytes.Length == 0) return default;
+
+            string strValue = SpanToString(bytes);
+            if (type == typeof(string))
+            {
+                return strValue;
+            }
+            return DeserializeFromString(strValue, type);
+        }
+        #endregion
+
         #endregion
 
 
@@ -297,7 +227,7 @@ namespace Vit.Core.Module.Serialization
         /// <param name="obj"></param>
         /// <returns></returns>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public ArraySegment<byte> SerializeToArraySegmentByte(object obj)
+        public virtual ArraySegment<byte> SerializeToArraySegmentByte<T>(T obj)
         {
             if (null == obj) return ArraySegmentByteExtensions.Null;
 
@@ -305,30 +235,25 @@ namespace Vit.Core.Module.Serialization
             {
                 return asbs;
             }
-            if (obj is byte[] bytes)
-            {
-                return bytes.BytesToArraySegmentByte();
-            }
-
-            if (!(obj is string strValue))
-            {
-                strValue = SerializeToString(obj);
-            }
-            return StringToBytes(strValue).BytesToArraySegmentByte();
+            
+            return SerializeToBytes(obj).BytesToArraySegmentByte();
         }
         #endregion
 
         #region DeserializeFromArraySegmentByte
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public T DeserializeFromArraySegmentByte<T>(ArraySegment<byte> bytes)
+        public virtual T DeserializeFromArraySegmentByte<T>(ArraySegment<byte> bytes)
         {
+            if (bytes.Count == 0) return default;
             return (T)DeserializeFromArraySegmentByte(bytes, typeof(T));
         }
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public object DeserializeFromArraySegmentByte(ArraySegment<byte> bytes, Type type)
+        public virtual object DeserializeFromArraySegmentByte(ArraySegment<byte> bytes, Type type)
         {
+            if (bytes.Count == 0) return default;
+
             if (type == typeof(byte[]))
             {
                 return bytes.ArraySegmentByteToBytes();
@@ -358,7 +283,7 @@ namespace Vit.Core.Module.Serialization
         /// <param name="type"></param>
         /// <returns></returns>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public object ConvertBySerialize(Object value, Type type)
+        public virtual object ConvertBySerialize(Object value, Type type)
         {
             var str = SerializeToString(value);
             return DeserializeFromString(str,type);
@@ -366,17 +291,55 @@ namespace Vit.Core.Module.Serialization
 
         /// <summary>
         /// 通过序列化克隆对象
-        /// </summary>
-        /// <typeparam name="T"></typeparam>
+        /// </summary> 
+        /// <typeparam name="TTarget"></typeparam>
         /// <param name="value"></param>
         /// <returns></returns>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public T ConvertBySerialize<T>(Object value)
+        public virtual TTarget ConvertBySerialize<TTarget>(Object value)
         {
             var str = SerializeToString(value);
-            return DeserializeFromString<T>(str);
+            return DeserializeFromString<TTarget>(str);
         }
         #endregion
 
+
+
+        #region DeserializeStruct
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="value"></param>
+        /// <param name="type">必须为 where T : struct</param>
+        /// <returns></returns>
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public  object DeserializeStruct(string value, Type type)
+        {
+            try
+            {
+                if (type.IsStringType())
+                    return value;
+                return value.Convert(type);
+            }
+            catch { }
+            return type.DefaultValue();
+        }
+
+        ///// <summary>
+        ///// 
+        ///// </summary>
+        ///// <typeparam name="T">必须为 where T : struct</typeparam>
+        ///// <param name="value"></param>
+        ///// <returns></returns>
+        //public object DeserializeStruct<T>(string value)
+        //{
+        //    return DeserializeStruct(value, typeof(T));
+        //}
+
+
+
+        #endregion
+
     }
 }

+ 126 - 0
dotnet/Library/Vit/Vit.Core/Vit.Core/Module/Serialization/Serialization_Newtonsoft.cs

@@ -0,0 +1,126 @@
+using Newtonsoft.Json;
+using Newtonsoft.Json.Converters;
+using Vit.Extensions;
+using System;
+using Vit.Core.Util.ConfigurationManager;
+using System.Runtime.CompilerServices;
+
+namespace Vit.Core.Module.Serialization
+{
+    public class Serialization_Newtonsoft: Serialization
+    {
+        
+        public static readonly Serialization_Newtonsoft Instance = new Serialization_Newtonsoft().InitByAppSettings(); 
+
+
+        #region 成员对象
+
+        /// <summary>
+        /// 时间序列化格式。例如 "yyyy-MM-dd HH:mm:ss"
+        /// </summary>
+        readonly IsoDateTimeConverter Serialize_DateTimeFormat = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };
+
+        /// <summary>
+        /// 设置时间序列化格式。例如 "yyyy-MM-dd HH:mm:ss"
+        /// </summary>
+        /// <param name="DateTimeFormat"></param>
+        public  void SetDateTimeFormat(string DateTimeFormat) {
+            Serialize_DateTimeFormat.DateTimeFormat = DateTimeFormat;
+        }
+
+ 
+
+       
+        #endregion
+
+
+        #region InitByAppSettings
+        /// <summary>
+        /// 根据配置文件(appsettings.json)初始化序列化配置
+        /// </summary>
+        public Serialization_Newtonsoft InitByAppSettings()
+        { 
+
+            #region (x.2) DateTimeFormat
+            var DateTimeFormat = ConfigurationManager.Instance.GetByPath<string>("Vit.Serialization.DateTimeFormat");
+            if (!string.IsNullOrWhiteSpace(DateTimeFormat))
+            {
+                try
+                {
+                    SetDateTimeFormat(DateTimeFormat);
+                }
+                catch
+                {
+                }
+            }
+            #endregion
+
+            return this;
+        }
+        #endregion
+
+
+      
+
+
+        #region (x.2)object <--> String
+
+        #region SerializeToString
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public override string SerializeToString<T>(T value)
+        {
+            if (null == value) return null;
+
+            if (value.GetType().TypeIsValueTypeOrStringType())
+            {
+                return value.Convert<string>();
+            }
+
+            return JsonConvert.SerializeObject(value, Serialize_DateTimeFormat);
+
+        }
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public override string SerializeToString(object value, Type type)
+        {
+            return JsonConvert.SerializeObject(value,  Serialize_DateTimeFormat);
+        }
+
+        #endregion
+
+        #region DeserializeFromString
+
+        /// <summary>
+        /// 使用Newtonsoft反序列化。T也可为值类型(例如 int?、bool) 
+        /// </summary>
+        /// <param name="value"></param>
+        /// <param name="type"></param>
+        /// <returns></returns>
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public override object DeserializeFromString(string value, Type type)
+        {
+            if (null == value || null == type) return null;
+
+            if (type.TypeIsValueTypeOrStringType())
+            {
+                return DeserializeStruct(value, type);
+            }
+
+            if (string.IsNullOrWhiteSpace(value)) return type.DefaultValue();
+
+            return JsonConvert.DeserializeObject(value, type);
+        }
+
+        #endregion
+
+        #endregion
+
+
+
+
+
+
+
+    }
+}

+ 222 - 0
dotnet/Library/Vit/Vit.Core/Vit.Core/Module/Serialization/Serialization_Text.cs

@@ -0,0 +1,222 @@
+
+using Vit.Extensions;
+using System;
+using System.Runtime.CompilerServices;
+using System.Text.Json;
+
+namespace Vit.Core.Module.Serialization
+{
+    public class Serialization_Text : Serialization
+    {
+
+        public static readonly Serialization_Text Instance = new Serialization_Text();
+
+        public JsonSerializerOptions serializeOptions = new JsonSerializerOptions
+        {
+            IncludeFields = true,
+            DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
+        };
+
+        public JsonSerializerOptions deserializeOptions = new JsonSerializerOptions
+        {
+            IncludeFields = true,
+            DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
+        };
+
+
+        #region (x.2)object <--> String
+
+        #region SerializeToString
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public override string SerializeToString<T>(T value)
+        {  
+            return JsonSerializer.Serialize(value, serializeOptions);
+        }
+
+
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public override string SerializeToString(object value,Type type)
+        {
+            return JsonSerializer.Serialize(value, type, serializeOptions);
+        }
+
+        #endregion
+
+        #region DeserializeFromString
+
+   
+
+        /// <summary>
+        /// 使用Newtonsoft反序列化。T也可为值类型(例如 int?、bool) 
+        /// </summary>
+        /// <param name="value"></param>
+        /// <param name="type"></param>
+        /// <returns></returns>
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public override object DeserializeFromString(string value, Type type)
+        {
+            if (null == value || null == type) return null;
+
+            if (type.TypeIsValueTypeOrStringType())
+            {
+                return DeserializeStruct(value, type);
+            }
+            return JsonSerializer.Deserialize(value, type, deserializeOptions);
+        }
+
+        #endregion
+
+        #endregion
+
+
+
+        #region (x.3)object <--> bytes
+
+        #region SerializeToBytes
+
+        /// <summary>
+        /// obj 可以为   byte[]、string、 object       
+        /// </summary>
+        /// <param name="value"></param>
+        /// <returns></returns>
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public override byte[] SerializeToBytes<T>(T value)
+        {
+            if (null == value) return new byte[0];
+            
+            if (value is byte[] bytes)
+            {
+                return bytes;
+            }
+
+            return JsonSerializer.SerializeToUtf8Bytes(value, serializeOptions); 
+        }
+
+
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public override byte[] SerializeToBytes(object value,Type type)
+        {
+            if (null == value) return new byte[0];
+
+            if (value is byte[] bytes)
+            {
+                return bytes;
+            }
+
+            return JsonSerializer.SerializeToUtf8Bytes(value,type, serializeOptions);
+        }
+        #endregion
+
+
+        #region DeserializeFromBytes
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public override T DeserializeFromBytes<T>(byte[] bytes)
+        {
+            if (bytes == null || bytes.Length == 0) return default;
+            return JsonSerializer.Deserialize<T>(bytes, deserializeOptions);
+        }
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public override object DeserializeFromBytes(byte[] bytes, Type type)
+        {
+            if (bytes == null || bytes.Length == 0) return default;
+            //if (type == typeof(byte[]))
+            //{
+            //    return bytes;
+            //}
+            //if (type == typeof(ArraySegment<byte>))
+            //{
+            //    return bytes.BytesToArraySegmentByte();
+            //}
+            return JsonSerializer.Deserialize(bytes,type, deserializeOptions);
+        }
+        #endregion
+
+        #endregion
+
+
+
+
+        #region DeserializeFromSpan
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public override T DeserializeFromSpan<T>(ReadOnlySpan<byte> bytes)
+        {
+            if (bytes.Length == 0) return default;
+            return JsonSerializer.Deserialize<T>(bytes, deserializeOptions);
+        }
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public override object DeserializeFromSpan(ReadOnlySpan<byte> bytes, Type type)
+        {
+            if (bytes.Length == 0) return default;
+
+            return JsonSerializer.Deserialize(bytes, type, deserializeOptions);
+        }
+        #endregion
+
+
+        #region (x.4)object <--> ArraySegmentByte
+
+        #region SerializeToArraySegmentByte
+        /// <summary>
+        /// obj 可以为   byte[]、string、 object       
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <returns></returns>
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public ArraySegment<byte> SerializeToArraySegmentByte(object obj)
+        {
+            if (null == obj) return ArraySegmentByteExtensions.Null;
+
+            if (obj is ArraySegment<byte> asbs)
+            {
+                return asbs;
+            }
+            if (obj is byte[] bytes)
+            {
+                return bytes.BytesToArraySegmentByte();
+            }
+            
+            return SerializeToBytes(obj).BytesToArraySegmentByte();
+        }
+        #endregion
+
+        #region DeserializeFromArraySegmentByte
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public T DeserializeFromArraySegmentByte<T>(ArraySegment<byte> bytes)
+        {
+            if (bytes.Count == 0) return default;
+
+            return JsonSerializer.Deserialize<T>(bytes, deserializeOptions);
+        }
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public object DeserializeFromArraySegmentByte(ArraySegment<byte> bytes, Type type)
+        {
+            if (bytes.Count == 0) return default;
+
+            //if (type == typeof(byte[]))
+            //{
+            //    return bytes.ArraySegmentByteToBytes();
+            //}
+            //if (type == typeof(ArraySegment<byte>))
+            //{
+            //    return bytes;
+            //}
+            return JsonSerializer.Deserialize(bytes, type, deserializeOptions);
+        }
+        #endregion
+
+        #endregion
+
+
+ 
+
+    }
+}

+ 28 - 26
dotnet/Library/Vit/Vit.Core/Vit.Core/Vit.Core.csproj

@@ -1,28 +1,30 @@
-<Project Sdk="Microsoft.NET.Sdk">
-
-  <PropertyGroup>
-    <TargetFramework>netstandard2.0</TargetFramework>
-    <Version>2.1.1.499</Version>
-    <Description>https://github.com/serset/Sers/tree/2.1.1/release</Description>
-  </PropertyGroup>
-
-  <PropertyGroup> 
-    <DocumentationFile>bin\Debug\netstandard2.0\Vit.Core.xml</DocumentationFile>
-  </PropertyGroup>
-
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>netstandard2.0</TargetFramework>
+    <Version>2.1.1.499</Version>
+    <Description>https://github.com/serset/Sers/tree/2.1.1/release</Description>
+    <LangVersion>latest</LangVersion>
+  </PropertyGroup>
+
+  <PropertyGroup> 
+    <DocumentationFile>bin\Debug\netstandard2.0\Vit.Core.xml</DocumentationFile>
+  </PropertyGroup>
+
   <PropertyGroup>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-  </PropertyGroup>
-
-  <ItemGroup>
-    <Compile Remove="Extensions\byte\ReadOnlySpanByteExtensions.cs" />
-    <Compile Remove="Extensions\byte\SpanByteExtensions.cs" />
-  </ItemGroup>
-
-  <ItemGroup>
-    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
-    <PackageReference Include="System.Buffers" Version="4.5.1" /> 
-    <PackageReference Include="Microsoft.Extensions.DependencyModel" Version="2.0.0" />
-  </ItemGroup>
-
-</Project>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <Compile Remove="Extensions\byte\ReadOnlySpanByteExtensions.cs" />
+    <Compile Remove="Extensions\byte\SpanByteExtensions.cs" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
+    <PackageReference Include="System.Buffers" Version="4.5.1" /> 
+    <PackageReference Include="Microsoft.Extensions.DependencyModel" Version="2.0.0" /> 
+    <PackageReference Include="System.Text.Json" Version="5.0.1" />
+  </ItemGroup>
+
+</Project>

+ 21 - 4
dotnet/ServiceCenter/Sers.ServiceCenter/Apm/Sers.Gover.Apm.Zipkin/AppEvent.cs

@@ -19,7 +19,7 @@ namespace Sers.Gover.Apm.Zipkin
     public class AppEvent : IAppEvent
     {        
 
-        Action<Object, Vit.Core.Util.Pipelines.ByteData> ApiScopeEvent(IRpcContextData rpcData, ApiMessage apiRequestMessage)
+        Action<Object, Vit.Core.Util.Pipelines.ByteData> ApiScopeEvent(RpcContextData rpcData, ApiMessage apiRequestMessage)
         {
             //记录请求数据
 
@@ -32,7 +32,7 @@ namespace Sers.Gover.Apm.Zipkin
                 long? parentSpanId = null;
 
                 {
-                    var hexStr = rpcData.caller_rid_Get();
+                    var hexStr = rpcData.caller.rid;
                     spanId = hexStr.Substring(0, 16).HexStringToInt64();
                 }
                 {
@@ -91,6 +91,8 @@ namespace Sers.Gover.Apm.Zipkin
 
                 #region method getTagValue
 
+                string requestRpc_oriString = null;
+                JObject requestRpc_json = null;
 
                 string requestData_oriString = null;
                 JObject requestData_json = null;
@@ -130,7 +132,22 @@ namespace Sers.Gover.Apm.Zipkin
 
                         switch (dataType)
                         {
-                            case "requestRpc": return rpcData?.oriJson.SelectToken(path).ConvertToString();
+                            case "requestRpc":
+                               
+                                if (requestRpc_oriString == null)
+                                {
+                                    requestRpc_oriString = apiRequestMessage.rpcContextData_OriData.ArraySegmentByteToString();
+                                }
+                                if (string.IsNullOrEmpty(path))
+                                {
+                                    return requestRpc_oriString;
+                                }
+                                if (requestRpc_json == null)
+                                {
+                                    requestRpc_json = requestRpc_oriString.Deserialize<JObject>();
+                                }
+                                return requestRpc_json.SelectToken(path).ConvertToString();
+
                             case "requestData":
                                 if (requestData_oriString == null)
                                 {
@@ -240,7 +257,7 @@ namespace Sers.Gover.Apm.Zipkin
             #endregion
 
 
-            GoverManage.Instance.AddApiScopeEvent(ApiScopeEvent);
+            GoverApiCenterService.Instance.AddApiScopeEvent(ApiScopeEvent);
 
             Logger.Info("[zipkin]启动成功");
         }

+ 1 - 1
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Base/ApiLoadBalancingMng.cs

@@ -33,7 +33,7 @@ namespace Sers.Gover.Base
         /// <param name="routeType"></param>
         /// <returns></returns>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public virtual ApiNode GetCurApiNodeByLoadBalancing(IRpcContextData rpcData, out ERouteType routeType)
+        public virtual ApiNode GetCurApiNodeByLoadBalancing(RpcContextData rpcData, out ERouteType routeType)
         {
             return routeMap.Routing(rpcData.route, out routeType)?.GetCurApiNodeBalancing();
         }

+ 2 - 2
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Base/ApiLoadBalancingMng_RESTful.cs

@@ -30,9 +30,9 @@ namespace Sers.Gover.Base
         /// <param name="rpcData"></param>
         /// <param name="routeType"></param>
         /// <returns></returns>
-        public override ApiNode GetCurApiNodeByLoadBalancing(IRpcContextData rpcData, out ERouteType routeType)
+        public override ApiNode GetCurApiNodeByLoadBalancing(RpcContextData rpcData, out ERouteType routeType)
         {
-            var method= rpcData.http_method_Get()?.ToUpper();
+            var method= rpcData.http.method?.ToUpper();
             if (string.IsNullOrEmpty(method)) method = "_";
 
             var oriRoute = rpcData.route;          

+ 2 - 2
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Base/ApiStationMng.cs

@@ -19,12 +19,12 @@ namespace Sers.Gover.Base
     {
         [JsonProperty]
         ConcurrentDictionary<string, ApiStationData> apiStations;
-        GoverManage goverManage;
+        GoverApiCenterService goverManage;
         public ApiStationMng()
         {            
         }
 
-        public ApiStationMng Init(GoverManage goverManage)
+        public ApiStationMng Init(GoverApiCenterService goverManage)
         {
             this.goverManage = goverManage;
             if (null == apiStations)

+ 34 - 17
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Base/GoverManage.cs → dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Base/GoverApiCenterService.cs

@@ -2,6 +2,8 @@
 using System.Collections.Generic;
 using System.Runtime.CompilerServices;
 using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+
 using Sers.Core.CL.MessageOrganize;
 using Sers.Core.Module.Api.ApiDesc;
 using Sers.Core.Module.Api.Data;
@@ -17,19 +19,18 @@ using Sers.ServiceCenter.Entity;
 using Vit.Core.Module.Log;
 using Vit.Core.Util.ComponentModel.SsError;
 using Vit.Core.Util.ConfigurationManager;
-using Vit.Core.Util.Pipelines;
 using Vit.Extensions;
 
 namespace Sers.Gover.Base
 {
     [JsonObject(MemberSerialization.OptIn)]
-    public class GoverManage : ApiCenterService
+    public class GoverApiCenterService : ApiCenterService
     {
         #region static       
-        public static readonly GoverManage Instance = LoadFromFile();
-        static GoverManage LoadFromFile()
+        public static readonly GoverApiCenterService Instance = LoadFromFile();
+        static GoverApiCenterService LoadFromFile()
         {
-            var mng=new GoverManage();
+            var mng=new GoverApiCenterService();
 
             Persistence_ApiDesc.ApiDesc_LoadAllFromJsonFile(mng.apiStationMng);
             Persistence_Counter.LoadCounterFromJsonFile(mng.apiStationMng);
@@ -46,7 +47,7 @@ namespace Sers.Gover.Base
 
 
 
-        public GoverManage()
+        public GoverApiCenterService()
         {
             //init apiLoadBalancingMng
             switch (ConfigurationManager.Instance.GetStringByPath("Sers.ServiceCenter.ApiRouteType"))
@@ -107,10 +108,14 @@ namespace Sers.Gover.Base
         #region CallApi
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public override void CallApiAsync(IRpcContextData rpcData, ApiMessage requestMessage, Object sender, Action<object, Vit.Core.Util.Pipelines.ByteData> callback)
+        public override void CallApiAsync(ApiMessage requestMessage, Object sender, Action<object, Vit.Core.Util.Pipelines.ByteData> callback)
         {
+            RpcContextData rpcData = null;
             try
             {
+                rpcData = RpcContextData.FromBytes(requestMessage.rpcContextData_OriData);
+
+
                 #region (x.0)ApiScopeEvent
                 apiScopeEventList?.ForEach(onScope =>
                 {
@@ -184,19 +189,31 @@ namespace Sers.Gover.Base
                 // 权限校验不通过,调用次数也计数
                 // TODO:应当有其他计数
 
+                JObject oriJson = null;
+
                 //(x.x.1) rpcValidations Sers1校验
-                if (!Sers.Core.Module.Valid.Sers1.RpcVerify1.Verify(rpcData.oriJson, apiNode.apiDesc.rpcValidations, out var validError))
+                if (apiNode.apiDesc.rpcValidations != null && apiNode.apiDesc.rpcValidations.Count > 0)
                 {
-                    SendReply(validError);
-                    return;
+                    if (oriJson == null) oriJson = rpcData.Serialize().Deserialize<JObject>();
+
+                    if (!Sers.Core.Module.Valid.Sers1.RpcVerify1.Verify(oriJson, apiNode.apiDesc.rpcValidations, out var validError))
+                    {
+                        SendReply(validError);
+                        return;
+                    }
                 }
 
                 //(x.x.2) rpcVerify2 Sers2校验
-                if (!Sers.Core.Module.Valid.Sers2.RpcVerify2.Verify(rpcData.oriJson, apiNode.apiDesc.rpcVerify2, out var verifyError))
+                if (apiNode.apiDesc.rpcVerify2 != null && apiNode.apiDesc.rpcVerify2.Count > 0)
                 {
-                    SendReply(verifyError);
-                    return;
-                }                     
+                    if (oriJson == null) oriJson = rpcData.Serialize().Deserialize<JObject>();
+
+                    if (!Sers.Core.Module.Valid.Sers2.RpcVerify2.Verify(oriJson, apiNode.apiDesc.rpcVerify2, out var verifyError))
+                    {
+                        SendReply(verifyError);
+                        return;
+                    }
+                }
                 #endregion
 
 
@@ -342,14 +359,14 @@ namespace Sers.Gover.Base
         /// <summary>
         /// 
         /// </summary>
-        List<Func<IRpcContextData, ApiMessage, Action<Object, Vit.Core.Util.Pipelines.ByteData>>> apiScopeEventList = null;
+        List<Func<RpcContextData, ApiMessage, Action<Object, Vit.Core.Util.Pipelines.ByteData>>> apiScopeEventList = null;
         /// <summary>
         /// 在调用api前调用onScope,若onScope返回的结果(onDispose)不为空,则在api调用结束前调用onDispose
         /// </summary>
         /// <param name="apiScopeEvent"></param>
-        public void AddApiScopeEvent(Func<IRpcContextData, ApiMessage, Action<Object, Vit.Core.Util.Pipelines.ByteData>> apiScopeEvent) 
+        public void AddApiScopeEvent(Func<RpcContextData, ApiMessage, Action<Object, Vit.Core.Util.Pipelines.ByteData>> apiScopeEvent) 
         {
-            if (apiScopeEventList == null) apiScopeEventList=new List<Func<IRpcContextData, ApiMessage, Action<Object, Vit.Core.Util.Pipelines.ByteData>>>();
+            if (apiScopeEventList == null) apiScopeEventList=new List<Func<RpcContextData, ApiMessage, Action<Object, Vit.Core.Util.Pipelines.ByteData>>>();
 
             apiScopeEventList.Add(apiScopeEvent);
         }

+ 2 - 2
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Base/ServiceStationMng.cs

@@ -13,9 +13,9 @@ namespace Sers.Gover.Base
 {
     public class ServiceStationMng
     {
-        GoverManage goverManage;
+        GoverApiCenterService goverManage;
 
-        public ServiceStationMng Init(GoverManage goverManage)
+        public ServiceStationMng Init(GoverApiCenterService goverManage)
         {
             this.goverManage = goverManage;
             return this;

+ 3 - 3
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Controllers/ApiControllers/ApiDescController.cs

@@ -1,7 +1,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using Sers.Core.Module.Api.ApiDesc;
-using Sers.Core.Module.Api.Rpc;
+using Sers.Core.Module.Rpc;
 using Sers.Gover.Base;
 using Sers.SersLoader;
 using Sers.SersLoader.ApiDesc.Attribute.Valid;
@@ -23,7 +23,7 @@ namespace Sers.Gover.Controllers.ApiControllers
         [SsDescription("获取所有可调用api。返回ApiDesc列表")]
         public ApiReturn<List<SsApiDesc>> GetActive([SsDescription("route前缀(不指定则返回所有),例如 \"_gover_\"、\"/demo/a.html\" "),SsExample("_gover_")]string r)
         {
-            var apiDescs = GoverManage.Instance.ApiDesc_GetActive();
+            var apiDescs = GoverApiCenterService.Instance.ApiDesc_GetActive();
             if (!string.IsNullOrWhiteSpace(r))
             {
                 if (!r.StartsWith("/")) r = "/" + r;
@@ -40,7 +40,7 @@ namespace Sers.Gover.Controllers.ApiControllers
         [SsDescription("获取所有api。返回ApiDesc列表")]
         public ApiReturn<List<SsApiDesc>> GetAll([SsDescription("route前缀(不指定则返回所有),例如 \"_gover_\"、\"/demo/a.html\" "), SsExample("_gover_")]string r)
         {
-            var apiDescs = GoverManage.Instance.ApiDesc_GetAll();
+            var apiDescs = GoverApiCenterService.Instance.ApiDesc_GetAll();
             if (!string.IsNullOrWhiteSpace(r))
             {
                 if (!r.StartsWith("/")) r = "/" + r;

+ 4 - 4
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Controllers/ApiControllers/ApiStationController.cs

@@ -1,5 +1,5 @@
 using System.Collections.Generic;
-using Sers.Core.Module.Api.Rpc;
+using Sers.Core.Module.Rpc;
 using Sers.Gover.Base;
 using Sers.Gover.Base.Model;
 using Sers.SersLoader;
@@ -23,7 +23,7 @@ namespace Sers.Gover.Controllers.ApiControllers
         [SsName("获取所有ApiStation")]
         public ApiReturn<List<ApiStationData>> GetAll()
         {
-            return new ApiReturn<List<ApiStationData>> { data = GoverManage.Instance.ApiStation_GetAll() };
+            return new ApiReturn<List<ApiStationData>> { data = GoverApiCenterService.Instance.ApiStation_GetAll() };
         }
 
 
@@ -36,7 +36,7 @@ namespace Sers.Gover.Controllers.ApiControllers
         [SsName("暂停指定的ApiStation")]
         public ApiReturn Pause(string stationName)
         {
-            return new ApiReturn { success = GoverManage.Instance.ApiStation_Pause(stationName) };
+            return new ApiReturn { success = GoverApiCenterService.Instance.ApiStation_Pause(stationName) };
         }
 
         /// <summary>
@@ -48,7 +48,7 @@ namespace Sers.Gover.Controllers.ApiControllers
         [SsName("启用指定的ApiStation")]
         public ApiReturn Start(string stationName)
         {
-            return new ApiReturn { success = GoverManage.Instance.ApiStation_Start(stationName) };
+            return new ApiReturn { success = GoverApiCenterService.Instance.ApiStation_Start(stationName) };
         }
          
 

+ 2 - 2
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Controllers/ApiControllers/RateLimitController.cs

@@ -1,5 +1,5 @@
 using Newtonsoft.Json.Linq;
-using Sers.Core.Module.Api.Rpc;
+using Sers.Core.Module.Rpc;
 using Sers.Gover.Base;
 using Sers.Gover.RateLimit;
 using Sers.SersLoader;
@@ -14,7 +14,7 @@ namespace Sers.Gover.Controllers.ApiControllers
     public class RateLimitController : IApiController
     {
 
-        static RateLimitMng rateLimitMng => GoverManage.Instance.rateLimitMng;
+        static RateLimitMng rateLimitMng => GoverApiCenterService.Instance.rateLimitMng;
 
 
         /// <summary>

+ 1 - 1
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Controllers/ApiControllers/ServiceCenterController.cs

@@ -1,7 +1,7 @@
 using System;
 using System.Diagnostics;
 using Newtonsoft.Json.Linq;
-using Sers.Core.Module.Api.Rpc;
+using Sers.Core.Module.Rpc;
 using Sers.Hardware.Usage;
 using Sers.SersLoader;
 using Sers.SersLoader.ApiDesc.Attribute.Valid;

+ 5 - 5
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Controllers/ApiControllers/ServiceStationController.cs

@@ -1,5 +1,5 @@
 using System.Collections.Generic;
-using Sers.Core.Module.Api.Rpc;
+using Sers.Core.Module.Rpc;
 using Sers.Gover.Base;
 using Sers.Gover.Base.Model;
 using Sers.SersLoader;
@@ -23,7 +23,7 @@ namespace Sers.Gover.Controllers.ApiControllers
         [SsName("获取所有ServiceStation")]
         public ApiReturn<List<ServiceStationData>> GetAll()
         {
-            return new ApiReturn<List<ServiceStationData>> { data = GoverManage.Instance.ServiceStation_GetAll() }; 
+            return new ApiReturn<List<ServiceStationData>> { data = GoverApiCenterService.Instance.ServiceStation_GetAll() }; 
         }
 
 
@@ -37,7 +37,7 @@ namespace Sers.Gover.Controllers.ApiControllers
         [SsName("暂停指定的服务站点")]
         public ApiReturn Pause(string connKey)
         {
-            return new ApiReturn { success = GoverManage.Instance.ServiceStation_Pause(connKey) };
+            return new ApiReturn { success = GoverApiCenterService.Instance.ServiceStation_Pause(connKey) };
         }
 
         /// <summary>
@@ -50,7 +50,7 @@ namespace Sers.Gover.Controllers.ApiControllers
         [SsName("启用指定的服务站点")]
         public ApiReturn Start(string connKey)
         {
-            return new ApiReturn { success = GoverManage.Instance.ServiceStation_Start(connKey) };
+            return new ApiReturn { success = GoverApiCenterService.Instance.ServiceStation_Start(connKey) };
         }
 
 
@@ -65,7 +65,7 @@ namespace Sers.Gover.Controllers.ApiControllers
         [SsName("启用指定的服务站点")]
         public ApiReturn Stop(string connKey)
         {
-            return new ApiReturn { success = GoverManage.Instance.ServiceStation_Stop(connKey) };
+            return new ApiReturn { success = GoverApiCenterService.Instance.ServiceStation_Stop(connKey) };
         }
 
 

+ 1 - 1
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Controllers/Subscribers/UsageSubController.cs

@@ -12,7 +12,7 @@ namespace Sers.Gover.Controllers.Subscribers
 
         public override void Handle(EnvUsageInfo item)
         {
-            GoverManage.Instance.SaveUsageInfo(item);
+            GoverApiCenterService.Instance.SaveUsageInfo(item);
         }
     }
 }

+ 5 - 5
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Extensions/ServiceCenter_GoverExtensions.cs

@@ -15,12 +15,12 @@ namespace Vit.Extensions
         {
             if (null == serviceCenter) return;
 
-            serviceCenter.apiCenterService = GoverManage.Instance;
+            serviceCenter.apiCenterService = GoverApiCenterService.Instance;
 
             serviceCenter.LoadSsApi(typeof(ServiceCenter_GoverExtensions).Assembly);
 
             //注册站点关闭回调
-            SersApplication.onStop += (GoverManage.SaveToFile);
+            SersApplication.onStop += (GoverApiCenterService.SaveToFile);
 
 
             #region ApiStation Qps 定时计算
@@ -38,7 +38,7 @@ namespace Vit.Extensions
             //(x.1)计算ApiStation qps
             try
             {
-                foreach (var item in GoverManage.Instance.ApiStation_GetAll())
+                foreach (var item in GoverApiCenterService.Instance.ApiStation_GetAll())
                 {
                     item.QpsCalc();
                 }
@@ -51,7 +51,7 @@ namespace Vit.Extensions
             //(x.2)计算ServiceStation qps
             try
             {
-                foreach (var item in GoverManage.Instance.serviceStationMng.serviceStationCollection)
+                foreach (var item in GoverApiCenterService.Instance.serviceStationMng.serviceStationCollection)
                 {
                     item.QpsCalc();
                 }
@@ -68,7 +68,7 @@ namespace Vit.Extensions
                 if (SaveToFile_tick > 10)
                 {
                     SaveToFile_tick = 0;
-                    GoverManage.SaveToFile();
+                    GoverApiCenterService.SaveToFile();
                 }
             }
             catch (System.Exception ex)

+ 2 - 2
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/RateLimit/FixedWindow.cs

@@ -49,7 +49,7 @@ namespace Sers.Gover.RateLimit
 
 
 
-        public SsError BeforeLoadBalancing(IRpcContextData rpcData, ApiMessage requestMessage)
+        public SsError BeforeLoadBalancing(RpcContextData rpcData, ApiMessage requestMessage)
         {
             //以_开始的系统节点不限流 
             var route = rpcData.route??"";
@@ -89,7 +89,7 @@ namespace Sers.Gover.RateLimit
             }
         }
 
-        public SsError BeforeCallRemoteApi(IRpcContextData rpcData, ApiMessage requestMessage, ApiNode apiNode)
+        public SsError BeforeCallRemoteApi(RpcContextData rpcData, ApiMessage requestMessage, ApiNode apiNode)
         {
             return null;
         }

+ 2 - 2
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/RateLimit/IRateLimit.cs

@@ -18,7 +18,7 @@ namespace Sers.Gover.RateLimit
         /// <param name="rpcData"></param>
         /// <param name="requestMessage"></param>
         /// <returns></returns>
-        SsError BeforeLoadBalancing(IRpcContextData rpcData, ApiMessage requestMessage);
+        SsError BeforeLoadBalancing(RpcContextData rpcData, ApiMessage requestMessage);
 
 
         /// <summary>
@@ -28,7 +28,7 @@ namespace Sers.Gover.RateLimit
         /// <param name="requestMessage"></param>
         /// <param name="apiNode"></param>
         /// <returns></returns>
-        SsError BeforeCallRemoteApi(IRpcContextData rpcData, ApiMessage requestMessage, ApiNode apiNode);
+        SsError BeforeCallRemoteApi(RpcContextData rpcData, ApiMessage requestMessage, ApiNode apiNode);
 
  
     }

+ 2 - 2
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/RateLimit/RateLimitMng.cs

@@ -96,7 +96,7 @@ namespace Sers.Gover.RateLimit
         /// <param name="rpcData"></param>
         /// <param name="requestMessage"></param>
         /// <returns></returns>
-        public SsError BeforeLoadBalancing(IRpcContextData rpcData, ApiMessage requestMessage)
+        public SsError BeforeLoadBalancing(RpcContextData rpcData, ApiMessage requestMessage)
         {
             foreach (var rateLimit in limits)
             {
@@ -115,7 +115,7 @@ namespace Sers.Gover.RateLimit
         /// <param name="requestMessage"></param>
         /// <param name="apiNode"></param>
         /// <returns></returns>
-        public SsError BeforeCallRemoteApi(IRpcContextData rpcData, ApiMessage requestMessage,ApiNode apiNode)
+        public SsError BeforeCallRemoteApi(RpcContextData rpcData, ApiMessage requestMessage,ApiNode apiNode)
         {
             foreach (var rateLimit in limits)
             {

+ 3 - 6
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.ServiceCenter/ApiCenter/ApiCenterService.cs

@@ -1,6 +1,5 @@
 using System;
 using Sers.Core.Module.Rpc;
-using System.Collections.Generic;
 using Vit.Core.Util.Pool;
 using System.Threading;
 using Sers.Core.CL.CommunicationManage;
@@ -25,9 +24,7 @@ namespace Sers.ServiceCenter.ApiCenter
 
             var requestMessage = new ApiMessage(apiRequest);
 
-            var rpcData = RpcFactory.CreateRpcContextData().UnpackOriData(requestMessage.rpcContextData_OriData);
-
-            CallApiAsync(rpcData, requestMessage, sender, callback);
+            CallApiAsync(requestMessage, sender, callback);
         }
 
 
@@ -79,9 +76,9 @@ namespace Sers.ServiceCenter.ApiCenter
         /// BeforeCallApi(IRpcContextData rpcData, ApiMessage requestMessage)
         /// </summary>
         [JsonIgnore]
-        public Action<IRpcContextData, ApiMessage> BeforeCallApi;
+        public Action<RpcContextData, ApiMessage> BeforeCallApi;
 
-        public abstract void CallApiAsync(IRpcContextData rpcData, ApiMessage requestMessage, Object sender, Action<object, Vit.Core.Util.Pipelines.ByteData> callback);
+        public abstract void CallApiAsync(ApiMessage requestMessage, Object sender, Action<object, Vit.Core.Util.Pipelines.ByteData> callback);
 
 
 

+ 1 - 1
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.ServiceCenter/Controllers/ServiceStationController.cs

@@ -1,4 +1,4 @@
-using Sers.Core.Module.Api.Rpc;
+using Sers.Core.Module.Rpc;
 using Sers.SersLoader;
 using Sers.SersLoader.ApiDesc.Attribute.Valid;
 using Sers.Core.CL.CommunicationManage;

+ 1 - 1
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.ServiceCenter/Entity/ApiNode.cs

@@ -34,7 +34,7 @@ namespace Sers.ServiceCenter.Entity
         #endregion
 
 
-        public void CallApiAsync(IRpcContextData rpcContextData, ApiMessage reqMessage, Object sender,  Action<object, Vit.Core.Util.Pipelines.ByteData> callback)
+        public void CallApiAsync(RpcContextData rpcContextData, ApiMessage reqMessage, Object sender,  Action<object, Vit.Core.Util.Pipelines.ByteData> callback)
         {
             //count
             bool success = true;

+ 10 - 15
dotnet/ServiceStation/ApiLoader/Sers.Serslot/Extensions/SerslotServer_ProcessRequest_Extensions.cs

@@ -19,7 +19,7 @@ namespace Vit.Extensions
 
                 #region (x.1) build requestFeature
                 // "http://127.0.0.1/Station1/fold1/a/1/2.html?c=9"
-                var http_url = rpcData.http_url_Get();
+                var http_url = rpcData.http.url;
                 Uri uri = new Uri(http_url);
                 //var Query = Uri.UnescapeDataString(uri.Query);
                 var Query = uri.Query;
@@ -30,9 +30,9 @@ namespace Vit.Extensions
                 {
                     Body = new MemoryStream(arg_OriData.Array, arg_OriData.Offset, arg_OriData.Count),
                     Headers = new HeaderDictionary(),
-                    Protocol = rpcData.http_protocol_Get(),
+                    Protocol = rpcData.http.protocol,
                     Scheme = uri.Scheme,
-                    Method = rpcData.http_method_Get(),
+                    Method = rpcData.http.method,
                     PathBase = "",
                     QueryString = uri.Query,
 
@@ -42,15 +42,10 @@ namespace Vit.Extensions
                 };
 
                 #region http header
-                var headers = rpcData.http_headers_Get();
-                if (headers != null)
+                foreach (var t in rpcData.http.headers)
                 {
-                    foreach (var t in headers)
-                    {
-                        //requestFeature.Headers.Add(t.Key, t.Value.ConvertToString());
-                        requestFeature.Headers[t.Key] = t.Value.ConvertToString();                 
-                    }
-                }                 
+                    requestFeature.Headers[t.Key] = t.Value;
+                }
                 #endregion
 
                 //var requestFeature = new HttpRequestFeature
@@ -73,10 +68,10 @@ namespace Vit.Extensions
 
 
                 #region (x.3)build reply info
-                var rpcReply = RpcFactory.CreateRpcContextData();
+                var rpcReply = new RpcContextData();
 
                 //(x.x.1)StatusCode
-                rpcReply.http_statusCode_Set(responseFeature.StatusCode);
+                rpcReply.http.statusCode=responseFeature.StatusCode;
 
                 #region (x.x.2)http_header
                 var replyHeader = responseFeature.Headers;
@@ -84,13 +79,13 @@ namespace Vit.Extensions
                 {
                     foreach (var item in replyHeader)
                     {
-                        rpcReply.http_header_Set(item.Key, item.Value.ToString());
+                        rpcReply.http.headers[item.Key]=item.Value.ToString();
                     }
                 }
                 #endregion
 
                 //(x.x.3)
-                RpcContext.Current.apiReplyMessage.rpcContextData_OriData = rpcReply.PackageOriData();
+                RpcContext.Current.apiReplyMessage.rpcContextData_OriData = rpcReply.ToBytes().BytesToArraySegmentByte();
                 #endregion
 
                 #region (x.4) return reply data

+ 13 - 23
dotnet/ServiceStation/Demo/SersLoader/Did.SersLoader.Demo/Controllers/Demo/SampleController.cs

@@ -5,7 +5,7 @@ using System.Threading.Tasks;
 using Newtonsoft.Json;
 using Sers.Core.Module.Api;
 using Sers.Core.Module.Api.LocalApi.StaticFileTransmit;
-using Sers.Core.Module.Api.Rpc;
+using Sers.Core.Module.Rpc;
 using Sers.Core.Module.Message;
 using Sers.Core.Module.Rpc;
 using Sers.SersLoader;
@@ -42,7 +42,7 @@ namespace Did.SersLoader.Demo.Controllers.Demo
         [SsRoute("/demo/v1/api/103/route")] //使用绝对路径路由  
         public ApiReturn<object> Route()
         {
-            return new { url = RpcContext.RpcData.http_url_Get() };
+            return new { url = RpcContext.RpcData.http.url };
         }
 
 
@@ -57,10 +57,10 @@ namespace Did.SersLoader.Demo.Controllers.Demo
         {
             var rpcData = RpcContext.RpcData;
             var route = rpcData.route;
-            var http_url = rpcData.http_url_Get();
+            var http_url = rpcData.http.url;
             var http_url_search = rpcData.http_url_search_Get();
             var http_url_RelativePath = rpcData.http_url_RelativePath_Get();
-            var http_method = rpcData.http_method_Get() ;
+            var http_method = rpcData.http.method ;
 
             var data = new
             {
@@ -400,8 +400,8 @@ namespace Did.SersLoader.Demo.Controllers.Demo
             var data = new
             {
                 rpcData.route,
-                http_url = rpcData.http_url_Get(),
-                userInfo = rpcData.user_userInfo_Get(),
+                http_url = rpcData.http.url,
+                user = rpcData.user,
                 serviceId= DateTime.Now.ToString("sss")
             };
 
@@ -419,25 +419,15 @@ namespace Did.SersLoader.Demo.Controllers.Demo
         {
             #region reply header
 
-            RpcContext.Current.apiReplyMessage.rpcContextData_OriData =
-                    RpcFactory.CreateRpcContextData()
-                    .http_statusCode_Set(201)
-                    //.http_header_Set("Content-Type", "application/json")
-                    .http_header_ContentType_Set("application/json")
-                    .http_header_Set("testHeader", "abc")
-                    .PackageOriData();
-
-
-            //var replyRpcData = RpcFactory.Instance.CreateRpcContextData();
-
-            //var header = new JObject();
-
-            //header["testHeader"] = "abc";
-            //header["Content-Type"] = "application/json";s
+            var replyRpcData = new RpcContextData();
+            replyRpcData.http.statusCode = 201;
+            replyRpcData.http.headers["Content-Type"] = "application/json";
+            replyRpcData.http.headers["testHeader"] = "abc";
+     
 
-            //replyRpcData.http_headers_Set(header);
+            RpcContext.Current.apiReplyMessage.rpcContextData_OriData = replyRpcData.ToBytes().BytesToArraySegmentByte();
 
-            //RpcContext.Current.apiReplyMessage.rpcContextData_OriData = replyRpcData.PackageOriData();
+ 
             #endregion
 
             var data = new

+ 1 - 1
dotnet/ServiceStation/Demo/StressTest/App.Robot.Station/Controllers/TaskController.cs

@@ -3,7 +3,7 @@ using App.Robot.Station.Logical;
 using App.Robot.Station.Logical.Model;
 using Sers.SersLoader;
 using Sers.SersLoader.ApiDesc.Attribute.Valid;
-using Sers.Core.Module.Api.Rpc;
+using Sers.Core.Module.Rpc;
 using Sers.Core.Module.App;
 using Vit.Core.Util.ComponentModel.Api;
 using Vit.Core.Util.ComponentModel.Data;

+ 1 - 1
dotnet/todo.txt

@@ -1,5 +1,5 @@
 CUR£º
-
+   
 -----------------------------------------
 °ÙÍòÓÅ»¯¼Æ»®