lith 1 năm trước cách đây
mục cha
commit
64254bac87

+ 12 - 6
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Env/SersEnvironment.cs

@@ -13,8 +13,8 @@ namespace Sers.Core.Module.Env
         /// <summary>
         /// 每个服务站点的serviceStationKey在任何时候都唯一
         /// </summary>
-        public static string serviceStationKey => EnvHelp.AppUnqueKey; 
-     
+        public static string serviceStationKey => EnvHelp.AppUnqueKey;
+
 
 
         /// <summary>
@@ -23,10 +23,16 @@ namespace Sers.Core.Module.Env
         /// <returns></returns>
         public static string GetEntryAssemblyVersion()
         {
-            //System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
-            System.Reflection.Assembly assembly = Assembly.GetEntryAssembly();
-            var fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
-            string version = fvi.FileVersion;
+            string version = null;
+            try
+            {
+                //System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
+                System.Reflection.Assembly assembly = Assembly.GetEntryAssembly();
+                var fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
+                //version = fvi.FileVersion;  // 2.1.20.0
+                version = fvi.ProductVersion;  // 2.1.20-preview12
+            }
+            catch { }
             return version;
         }
 

+ 9 - 8
dotnet/Library/Sers/Sers.Hardware/Sers.Hardware/Env/EnvHelp.cs

@@ -12,12 +12,13 @@ namespace Sers.Hardware.Env
     {
         #region GetDeviceInfo
 
-       
+
         public static DeviceInfo GetDeviceInfo()
         {
             var osPlatform = GetOSPlatform();
 
-            var osInfo= new DeviceInfo {
+            var osInfo = new DeviceInfo
+            {
                 OSPlatform = "" + osPlatform,
                 OSArchitecture = "" + RuntimeInformation.OSArchitecture,
                 OSDescription = "" + RuntimeInformation.OSDescription,
@@ -26,8 +27,8 @@ namespace Sers.Hardware.Env
                 ProcessorCount = Environment.ProcessorCount,
                 MachineName = "" + Environment.MachineName,
                 OSVersion = "" + Environment.OSVersion,
-                WorkingSet =   Environment.WorkingSet
-            }; 
+                WorkingSet = Environment.WorkingSet
+            };
 
             if (osPlatform == OSPlatform.Linux)
             {
@@ -123,7 +124,7 @@ namespace Sers.Hardware.Env
                 AddItem("OSVersion", "" + Environment.OSVersion);
                 #endregion
 
-                return string.IsNullOrWhiteSpace(oriData)?null: oriData;
+                return string.IsNullOrWhiteSpace(oriData) ? null : oriData;
             }
             #endregion
         }
@@ -160,7 +161,7 @@ namespace Sers.Hardware.Env
 
         #region GetAppUnqueInfo
         public static string GetAppUnqueInfo()
-        {         
+        {
             if (MachineUnqueKey == null) return null;
 
 
@@ -172,7 +173,7 @@ namespace Sers.Hardware.Env
 
 
             //(x.1)MachineUnqueKey
-            AddItem("MachineUnqueKey", MachineUnqueKey);          
+            AddItem("MachineUnqueKey", MachineUnqueKey);
 
 
             #region (x.2) app directory
@@ -221,7 +222,7 @@ namespace Sers.Hardware.Env
         /// <returns>加密后的字符串</returns>
         internal static string MD5(string source)
         {
-            return Vit.Core.Util.Common.CommonHelp.MD5(source); 
+            return Vit.Core.Util.Common.CommonHelp.MD5(source);
         }
 
 

+ 32 - 36
dotnet/Library/Sers/Sers.ServiceStation/Sers.ServiceStation/ServiceStation.cs

@@ -31,7 +31,7 @@ namespace Sers.ServiceStation
     {
 
         #region static
- 
+
         public static readonly ServiceStation Instance = new ServiceStation();
 
         /// <summary>
@@ -57,7 +57,7 @@ namespace Sers.ServiceStation
 
             //(x.4) RunAwait
             ServiceStation.RunAwait();
- 
+
         }
 
 
@@ -72,11 +72,11 @@ namespace Sers.ServiceStation
             Instance.InitStation();
         }
         #endregion
-       
 
 
-   
-        #region (x.2) Start        
+
+
+        #region (x.2) Start
         /// <summary>
         /// 是否成功启动站点
         /// </summary>
@@ -128,20 +128,14 @@ namespace Sers.ServiceStation
 
         public void InitStation()
         {
-            string FileVersion = null;
-            try
-            {
-                FileVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetEntryAssembly().Location).FileVersion;
-            }
-            catch { }
-            Logger.Info("[ServiceStation] initializing", new { FileVersion });
+            Logger.Info("[ServiceStation] initializing", new { AssemblyVersion = SersEnvironment.GetEntryAssemblyVersion() });
 
             //(x.0) appEvent BeforeStart
             appEventList?.ForEach(ev => ev.BeforeStart());
 
 
-            #region (x.1)CL add builder for IocpThreadWait
-            communicationManage.BeforeBuildOrganize = (configs,  organizeList) => 
+            #region (x.1)CL add builder for Iocp/ThreadWait
+            communicationManage.BeforeBuildOrganize = (configs, organizeList) =>
             {
                 var builderTypeList = new[] {
                     typeof(Sers.CL.Socket.Iocp.OrganizeClientBuilder),
@@ -150,7 +144,7 @@ namespace Sers.ServiceStation
 
                 foreach (var config in configs)
                 {
-                    var className = config["className"].ConvertToString();                    
+                    var className = config["className"].ConvertToString();
 
                     var type = builderTypeList.FirstOrDefault(t => t.FullName == className);
                     if (type != null)
@@ -158,8 +152,8 @@ namespace Sers.ServiceStation
                         var builder = Activator.CreateInstance(type) as IOrganizeClientBuilder;
                         builder.Build(organizeList, config);
                         config["className"] = null;
-                    } 
-                }                
+                    }
+                }
             };
             #endregion
 
@@ -237,11 +231,11 @@ namespace Sers.ServiceStation
 
             communicationManage.conn_OnGetMessage = MessageClient.Instance.OnGetMessage;
 
-            communicationManage.conn_OnGetRequest = (IOrganizeConnection conn,Object sender, ArraySegment<byte> requestData, Action<object, Vit.Core.Util.Pipelines.ByteData> callback) => 
+            communicationManage.conn_OnGetRequest = (IOrganizeConnection conn, Object sender, ArraySegment<byte> requestData, Action<object, Vit.Core.Util.Pipelines.ByteData> callback) =>
             {
                 localApiService.InvokeApiAsync(sender, new ApiMessage(requestData), (object sender1, ApiMessage apiReplyMessage) =>
                 {
-                     callback(sender1, apiReplyMessage.Package());
+                    callback(sender1, apiReplyMessage.Package());
                 });
             };
 
@@ -255,7 +249,7 @@ namespace Sers.ServiceStation
             #region (x.3) CL 连接服务器
 
             Logger.Info("[CL] Connect - trying...");
-            
+
             if (!communicationManage.Start())
             {
                 Logger.Error("[CL] Connect - failed");
@@ -269,15 +263,16 @@ namespace Sers.ServiceStation
 
             #region (x.4) 初始化ApiClient
             ApiClient.SetOnSendRequest(
-                communicationManage.organizeList.Select(organize=> organize.conn)
+                communicationManage.organizeList.Select(organize => organize.conn)
                 .Select<IOrganizeConnection, Action<ApiMessage, Action<ArraySegment<byte>>>>(
                 conn =>
                 {
-                    return (apiRequestMessage,callback) => {
-                        conn.SendRequestAsync(null, apiRequestMessage.Package(), (sender,replyData)=> 
+                    return (apiRequestMessage, callback) =>
+                    {
+                        conn.SendRequestAsync(null, apiRequestMessage.Package(), (sender, replyData) =>
                         {
                             callback(replyData.ToArraySegment());
-                        });                         
+                        });
                     };
                 }
                 ).ToArray(), communicationManage.requestTimeoutMs);
@@ -293,7 +288,7 @@ namespace Sers.ServiceStation
                 Logger.Info("[ServiceStation] regist serviceStation to ServiceCenter...");
 
                 var serviceStationData = new
-                {                
+                {
                     serviceStationInfo = SersApplication.serviceStationInfo,
                     deviceInfo = SersApplication.deviceInfo,
                     localApiService.apiNodes
@@ -305,7 +300,7 @@ namespace Sers.ServiceStation
                 }
 
 
-               
+
                 try
                 {
                     foreach (var apiClient in ApiClient.Instances)
@@ -321,17 +316,18 @@ namespace Sers.ServiceStation
 
 
                     #region (x.x.2)后台获取机器码,并向服务中心提交(获取机器码比较耗时,故后台获取)
-                    Task.Run(()=> {
+                    Task.Run(() =>
+                    {
                         try
                         {
                             //(x.x.x.1)计算  DeviceUnqueKey 和 ServiceStationUnqueKey
                             SersApplication.CalculateUniquekey();
 
-                           //(x.x.x.2)构建api参数
+                            //(x.x.x.2)构建api参数
                             var strServiceStationData = new
                             {
                                 serviceStationInfo = SersApplication.serviceStationInfo,
-                                deviceInfo = SersApplication.deviceInfo                           
+                                deviceInfo = SersApplication.deviceInfo
                             }.Serialize();
 
                             //(x.x.x.3)调用api
@@ -348,8 +344,8 @@ namespace Sers.ServiceStation
                         catch (Exception ex)
                         {
                             Logger.Error(ex);
-                        }                    
-                    
+                        }
+
                     });
                     #endregion
                 }
@@ -357,7 +353,7 @@ namespace Sers.ServiceStation
                 {
                     Logger.Error("[ServiceStation] regist - failed", ex);
                     return false;
-                }               
+                }
 
                 Logger.Info("[ServiceStation] regist - succeed");
 
@@ -368,13 +364,13 @@ namespace Sers.ServiceStation
             #region (x.7)PubSub 初始化消息订阅 PubSubClient          
             MessageClient.Instance.OnSendMessage = communicationManage.SendMessageAsync;
             #endregion
-                            
+
 
             //(x.8) 调用SersApp事件
             SersApplication.ResistConsoleCancelKey(Stop);
             SersApplication.OnStart();
 
-            Logger.Info("[ServiceStation] started",SersApplication.serviceStationInfo.serviceStationName);
+            Logger.Info("[ServiceStation] started", SersApplication.serviceStationInfo.serviceStationName);
 
             //(x.9) appEvent AfterStart
             appEventList?.ForEach(ev => ev.AfterStart());
@@ -389,7 +385,7 @@ namespace Sers.ServiceStation
 
 
         public void StopStation()
-        {       
+        {
             Logger.Info("[ServiceStation] stoping...");
 
             //(x.1) appEvent BeforeStop
@@ -435,7 +431,7 @@ namespace Sers.ServiceStation
 
 
 
-       
+
 
 
     }

+ 3 - 1
dotnet/Library/Vit/Vit.Core/Vit.Core/Util/Reflection/ObjectLoader.cs

@@ -12,11 +12,13 @@
 
 
 using Microsoft.Extensions.DependencyModel;
+
 using System;
 using System.IO;
 using System.Linq;
 using System.Reflection;
 using System.Runtime.CompilerServices;
+
 using Vit.Core.Module.Log;
 using Vit.Core.Util.Common;
 
@@ -93,7 +95,7 @@ namespace Vit.Core.Util.Reflection
             }
             #endregion
 
-            #region (x.3)Get from ReferencedAssemblies               
+            #region (x.3)Get from ReferencedAssemblies
             if (assembly == null)
             {
                 assembly = Assembly.GetEntryAssembly().GetReferencedAssemblies()

+ 14 - 19
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.ServiceCenter/ServiceCenter.cs

@@ -78,7 +78,7 @@ namespace Sers.ServiceCenter
 
         List<IAppEvent> appEventList { get; set; }
 
-        public   ApiCenterService apiCenterService { get; set; }  
+        public ApiCenterService apiCenterService { get; set; }
 
 
         private readonly CommunicationManageServer communicationManage = new CommunicationManageServer();
@@ -104,9 +104,9 @@ namespace Sers.ServiceCenter
             {
                 localApiService.InvokeApiAsync(sender, new ApiMessage(requestData.ToArraySegment()), (sender_, apiReplyMessage) =>
                 {
-                    callback(sender_,apiReplyMessage.Package());
+                    callback(sender_, apiReplyMessage.Package());
                 });
-            }            
+            }
 
 
             [MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -116,7 +116,7 @@ namespace Sers.ServiceCenter
             }
 
 
-            public void Close() 
+            public void Close()
             {
                 ServiceCenter.Instance.StopCenter();
             }
@@ -134,16 +134,10 @@ namespace Sers.ServiceCenter
 
         public void InitCenter()
         {
-            string FileVersion = null;
-            try
-            {
-                FileVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetEntryAssembly().Location).FileVersion;
-            }
-            catch { }
-            Logger.Info("[ServiceCenter] initializing", new { FileVersion });
+            Logger.Info("[ServiceCenter] initializing", new { AssemblyVersion = SersEnvironment.GetEntryAssemblyVersion() });
 
             //(x.0) appEvent BeforeStart
-            appEventList?.ForEach(ev=>ev.BeforeStart());
+            appEventList?.ForEach(ev => ev.BeforeStart());
 
 
             #region (x.1)CL add builder for Iocp、ThreadWait            
@@ -277,7 +271,8 @@ namespace Sers.ServiceCenter
 
 
                 #region (x.x.2)后台获取机器码,并向服务中心提交(获取机器码比较耗时,故后台获取)
-                Task.Run(() => {
+                Task.Run(() =>
+                {
                     try
                     {
                         //(x.x.x.1)计算  DeviceUnqueKey 和 ServiceStationUnqueKey
@@ -294,7 +289,7 @@ namespace Sers.ServiceCenter
                         serviceStation.connection = connForLocalStationService;
 
                         //(x.x.x.3)调用api
-                        apiCenterService.ServiceStation_UpdateStationInfo(serviceStation);                        
+                        apiCenterService.ServiceStation_UpdateStationInfo(serviceStation);
                     }
                     catch (Exception ex)
                     {
@@ -325,17 +320,17 @@ namespace Sers.ServiceCenter
 
 
             #region (x.6) 初始化ApiClient
-            Action<ApiMessage, Action<ArraySegment<byte>>> OnSendRequest = ((apiRequestMessage,callback) =>
+            Action<ApiMessage, Action<ArraySegment<byte>>> OnSendRequest = ((apiRequestMessage, callback) =>
             {
                 apiCenterService.CallApiAsync(connForLocalStationService, null, apiRequestMessage,
                     (sender, replyData) =>
                     {
                         callback(replyData.ToArraySegment());
                     }
-                 );                
+                 );
             });
 
-            ApiClient.SetOnSendRequest(new[] { OnSendRequest },communicationManage.requestTimeoutMs);
+            ApiClient.SetOnSendRequest(new[] { OnSendRequest }, communicationManage.requestTimeoutMs);
             #endregion
 
 
@@ -365,7 +360,7 @@ namespace Sers.ServiceCenter
 
         #region (x.5) StopCenter
         public void StopCenter()
-        { 
+        {
             Logger.Info("[ServiceCenter] stoping");
 
             //(x.1) appEvent BeforeStop
@@ -407,7 +402,7 @@ namespace Sers.ServiceCenter
             //(x.4)调用SersApp 事件
             SersApplication.OnStop();
 
-           
+
         }
         #endregion