zoule 9 months ago
parent
commit
12fb17fe61
48 changed files with 670 additions and 522 deletions
  1. 5 0
      .editorconfig
  2. BIN
      AddIns/DevExpress.Data.Desktop.v24.1.dll
  3. BIN
      AddIns/DevExpress.Data.v24.1.dll
  4. BIN
      AddIns/DevExpress.Drawing.v24.1.dll
  5. BIN
      AddIns/DevExpress.Images.v24.1.dll
  6. BIN
      AddIns/DevExpress.Map.v24.1.Core.dll
  7. BIN
      AddIns/DevExpress.Mvvm.v24.1.dll
  8. BIN
      AddIns/DevExpress.Printing.v24.1.Core.dll
  9. BIN
      AddIns/DevExpress.Utils.v24.1.dll
  10. BIN
      AddIns/DevExpress.Xpo.v24.1.dll
  11. BIN
      AddIns/DevExpress.XtraBars.v24.1.dll
  12. BIN
      AddIns/DevExpress.XtraEditors.v24.1.dll
  13. BIN
      AddIns/DevExpress.XtraGrid.v24.1.dll
  14. BIN
      AddIns/DevExpress.XtraLayout.v24.1.dll
  15. BIN
      AddIns/DevExpress.XtraMap.v24.1.dll
  16. BIN
      AddIns/DevExpress.XtraPrinting.v24.1.dll
  17. BIN
      AddIns/DevExpress.XtraTreeList.v24.1.dll
  18. 1 1
      ipslib/Ips.Library.Basic/AppDomainExtents.cs
  19. 14 0
      ipslib/Ips.Library.Basic/String/StringExtensions.cs
  20. 70 0
      ipslib/Ips.Library.DxpLib/Extensions/PanelExtensions.cs
  21. 3 2
      ipslib/Ips.Library.DxpLib/Ips.Library.DxpLib.csproj
  22. 2 2
      ipslib/Ips.Library.DxpLib/Logging/LogCtrl.cs
  23. 39 54
      ipslib/Ips.Library.WebApi/BaseClearServicce.cs
  24. 1 0
      ipslib/Ips.Library.WebApi/BaseController.cs
  25. 53 12
      ipslib/Ips.Library.WebApi/WebApiHelper.cs
  26. 1 1
      ipsmodule/adc/Ips.Adc.WadTool/Ips.Adc.WadTool.csproj
  27. 1 1
      ipsmodule/adc/Ips.AdcTool.Win/Ips.AdcTool.Win.csproj
  28. 1 1
      ipsmodule/cor/Ips.CorTool.Win/Ips.CorTool.Win.csproj
  29. 8 2
      ipsservice/Ips.Service.CapServer/App.config
  30. 13 2
      ipsservice/Ips.Service.CapServer/AppConst.cs
  31. 175 0
      ipsservice/Ips.Service.CapServer/BackgroundServices/CearDirService.cs
  32. 0 18
      ipsservice/Ips.Service.CapServer/BackgroundServices/InitService.cs
  33. 149 150
      ipsservice/Ips.Service.CapServer/DirectXForm1.Designer.cs
  34. 80 110
      ipsservice/Ips.Service.CapServer/DirectXForm1.cs
  35. 31 31
      ipsservice/Ips.Service.CapServer/DirectXForm1.resx
  36. 0 109
      ipsservice/Ips.Service.CapServer/FileMonitor.cs
  37. 1 1
      ipsservice/Ips.Service.CapServer/Ips.Service.CapServer.csproj
  38. 2 1
      ipsservice/Ips.Service.CapServer/Program.cs
  39. 1 1
      ipsservice/Ips.Service.CapServer/Service/AdcService.cs
  40. 1 1
      ipsservice/Ips.Service.CpuServe/Ips.Service.CpuServe.csproj
  41. 1 4
      ipsservice/Ips.Service.GpuServer/DirectXForm1.cs
  42. 1 1
      ipsservice/Ips.Service.GpuServer/Ips.Service.GpuServer.csproj
  43. 2 2
      ipstool/ipssps2/Ips.Sps.Core/Ips.Sps.Core.csproj
  44. 1 1
      ipstool/ipssps2/Ips.Sps.Data/Ips.Sps.Data.csproj
  45. 6 6
      ipstool/ipssps2/Ips.Sps.Host.Win/Ips.Sps.Host.Win.csproj
  46. 2 3
      ipstool/ipssps2/Ips.Sps.Host.Win/MainWin.cs
  47. 4 4
      ipstool/ipssps2/Ips.Sps.Host.Win/MainWin.resx
  48. 1 1
      ipstool/ipssps2/Ips.Sps.Scheduling/Ips.Sps.Scheduling.csproj

+ 5 - 0
.editorconfig

@@ -20,6 +20,9 @@ dotnet_style_qualification_for_field = false:silent
 dotnet_style_qualification_for_property = false:silent
 dotnet_style_qualification_for_method = false:silent
 dotnet_style_qualification_for_event = false:silent
+tab_width = 4
+indent_size = 4
+dotnet_style_operator_placement_when_wrapping = beginning_of_line
 [*.cs]
 #### 命名样式 ####
 
@@ -67,6 +70,8 @@ dotnet_naming_style.pascal_case.required_prefix =
 dotnet_naming_style.pascal_case.required_suffix = 
 dotnet_naming_style.pascal_case.word_separator = 
 dotnet_naming_style.pascal_case.capitalization = pascal_case
+csharp_space_around_binary_operators = before_and_after
+csharp_indent_labels = one_less_than_current
 
 [*.vb]
 #### 命名样式 ####

BIN
AddIns/DevExpress.Data.Desktop.v24.1.dll


BIN
AddIns/DevExpress.Data.v24.1.dll


BIN
AddIns/DevExpress.Drawing.v24.1.dll


BIN
AddIns/DevExpress.Images.v24.1.dll


BIN
AddIns/DevExpress.Map.v24.1.Core.dll


BIN
AddIns/DevExpress.Mvvm.v24.1.dll


BIN
AddIns/DevExpress.Printing.v24.1.Core.dll


BIN
AddIns/DevExpress.Utils.v24.1.dll


BIN
AddIns/DevExpress.Xpo.v24.1.dll


BIN
AddIns/DevExpress.XtraBars.v24.1.dll


BIN
AddIns/DevExpress.XtraEditors.v24.1.dll


BIN
AddIns/DevExpress.XtraGrid.v24.1.dll


BIN
AddIns/DevExpress.XtraLayout.v24.1.dll


BIN
AddIns/DevExpress.XtraMap.v24.1.dll


BIN
AddIns/DevExpress.XtraPrinting.v24.1.dll


BIN
AddIns/DevExpress.XtraTreeList.v24.1.dll


+ 1 - 1
ipslib/Ips.Library.Basic/AppDomainExtents.cs

@@ -28,7 +28,7 @@ public static class AppDomainExtents
                 dic[i.FullName] = i;
             GetReferanceAssemblies(i, dic, prefix);
         });
-        var res= dic.Values.OrderBy(p => p.FullName).ToArray();
+        var res = dic.Values.OrderBy(p => p.FullName).ToArray();
         return res;
     }
     static void GetReferanceAssemblies(Assembly assembly, Dictionary<string, Assembly> dic, string prefix)

+ 14 - 0
ipslib/Ips.Library.Basic/String/StringExtensions.cs

@@ -16,6 +16,20 @@ using System.Net;
 //{
 public static class StringExtensions
 {
+    public static string[] ToStrArray(this string @this)
+    {
+        return new string[1]
+        {
+            @this
+        };
+    }
+    public static List<string> ToStrList(this string @this)
+    {
+        return  new List<string>
+        {
+            @this
+        };
+    }
     /// <summary>
     /// ʹÓÃNewtonsoft Json½«stringת»»Îª¶ÔÏó
     /// </summary>

+ 70 - 0
ipslib/Ips.Library.DxpLib/Extensions/PanelExtensions.cs

@@ -0,0 +1,70 @@
+using DevExpress.CodeParser;
+using DevExpress.Utils;
+using DevExpress.XtraEditors;
+using DevExpress.XtraEditors.Controls;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Ips.Library.Basic;
+using DevExpress.Utils.Url;
+
+namespace Ips.Library.DxpLib
+{
+    public static class PanelExtensions
+    {
+        /// <summary>
+        /// 禁用容器中的子控件
+        /// </summary>
+        /// <param name="panel"></param>
+        /// <param name="ctrls">不禁用的子控件</param>
+        /// <returns></returns>
+        public static PanelControl DisabledChildWithout(this PanelControl panel, params Control[] ctrls)
+        {
+            var ctrl = panel.GetChildControls();
+            foreach (var item in ctrl)
+            {
+                if (ctrls == null || !ctrls.Contains(item))
+                    item.Enabled = false;
+            }
+            return panel;
+        }
+        /// <summary>
+        /// 启用容器中的子控件
+        /// </summary>
+        /// <param name="panel"></param>
+        /// <returns></returns>
+        public static PanelControl EnableChild(this PanelControl panel)
+        {
+            var ctrl = panel.GetChildControls();
+            foreach (var item in ctrl)
+            {
+                item.Enabled = true;
+            }
+            return panel;
+        }
+        public static List<Control> GetChildControls(this PanelControl panel)
+        {
+            List<Control> list = new List<Control>();
+            foreach (Control item in panel.Controls)
+            {
+                list.Add(item);
+                list.AddRange(GetChildControls(item));
+            }
+            return list;
+        }
+        private static List<Control> GetChildControls(Control ctrl)
+        {
+            List<Control> list = new List<Control>();
+            if (ctrl.Controls == null || ctrl.Controls.Count == 0) return list;
+            foreach (Control item in ctrl.Controls)
+            {
+                list.Add(item);
+                list.AddRange(GetChildControls(item));
+            }
+            return list;
+        }
+
+    }
+}

+ 3 - 2
ipslib/Ips.Library.DxpLib/Ips.Library.DxpLib.csproj

@@ -21,13 +21,14 @@
 	</PropertyGroup>
 
 	<ItemGroup>
-		<PackageReference Include="DevExpress.Document.Processor" Version="23.2.3" PrivateAssets="all" />
-		<PackageReference Include="DevExpress.Win.Design" Version="23.2.3" PrivateAssets="all" />
+		<PackageReference Include="DevExpress.Document.Processor" Version="24.1.6" PrivateAssets="all" />
+		<PackageReference Include="DevExpress.Win.Design" Version="24.1.6" PrivateAssets="all" />
 		<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
 	</ItemGroup>
 
 	<ItemGroup>
 		<ProjectReference Include="..\Ips.Library.Basic\Ips.Library.Basic.csproj" />
+		<ProjectReference Include="..\Ips.Library.CliLib\Ips.Library.CliLib.csproj" />
 		<ProjectReference Include="..\Ips.Library.Entity\Ips.Library.Entity.csproj" />
 	</ItemGroup>
 

+ 2 - 2
ipslib/Ips.Library.DxpLib/Logging/LogCtrl.cs

@@ -35,12 +35,12 @@ namespace Ips.Library.DxpLib
                 }
                 if (e.WriteToUI)
                 {
-                    if (e.Exception != null && !string.IsNullOrWhiteSpace(e.Exception.Message))
+                    if (e.Exception != null && !string.IsNullOrWhiteSpace(e.Exception.Message) && e.Content != e.Exception.Message)
                         e.Content = $"{e.Content},{e.Exception.Message}";
                     this.AddLog(e.LogType, e.Content);
                 }
             };
-            this.Dock = DockStyle.Fill; 
+            this.Dock = DockStyle.Fill;
         }
 
         public bool AutoMoveToLastLine { get; set; } = true;

+ 39 - 54
ipslib/Ips.Library.WebApi/BaseClearServicce.cs

@@ -9,29 +9,21 @@ using System.Threading.Tasks;
 namespace Ips.Library.WebApi
 {
     /// <summary>
-    /// 基础清理服务(负责Upload目录的清理)
+    /// 基础清理服务(负责upload目录的清理)
     /// </summary>
     public class BaseClearService : BackgroundService
     {
-        private string[] _dirs;
-
-        /// <summary>
-        /// 构造函数
-        /// </summary>
-        /// <param name="dirs">默认清理Upload目录</param>
-        public BaseClearService(string[] dirs = null)
-        {
-            if (dirs == null) dirs = new string[1] { "Upload" };
-            this._dirs = dirs;
-        }
+        private readonly string dir = "upload";
         /// <summary>
         /// 
         /// </summary>
         /// <param name="stoppingToken"></param>
         /// <returns></returns>
-        protected override Task ExecuteAsync(CancellationToken stoppingToken)
+        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
         {
-            return Task.Run(async () =>
+            await Task.Delay(5000, stoppingToken);//延迟一会儿让webbapi先启动
+            IpsLogger.Info($"启动通用目录{dir}数据清理功能...");
+            await Task.Run(async () =>
             {
                 while (!stoppingToken.IsCancellationRequested)
                 {
@@ -41,65 +33,58 @@ namespace Ips.Library.WebApi
                 }
                 //程序退出时强制删除所有
 
-                foreach (var dir in _dirs)
+                try
                 {
-                    try
-                    {
-                        Directory.Delete(dir, true);
-                    }
-                    catch
-                    { }
+                    Directory.Delete(dir, true);
                 }
+                catch
+                { }
             }, stoppingToken);
 
         }
 
         private void Clear()
         {
-            foreach (var name in _dirs)
+            #region 清理空目录
+            string clearDir = Path.Combine(AppContext.BaseDirectory, dir);
+            try
             {
-                #region 清理空目录
-                string clearDir = Path.Combine(AppContext.BaseDirectory, name);
-                try
+                var dirs = Directory.EnumerateDirectories(clearDir, "*", SearchOption.AllDirectories);
+                foreach (var item in dirs)
                 {
-                    var dirs = Directory.EnumerateDirectories(clearDir, "*", SearchOption.TopDirectoryOnly);
-                    foreach (var item in dirs)
+                    DirectoryInfo dir = new DirectoryInfo(item);
+                    if (dir.EnumerateFiles().Any()) continue;
+                    //删除5分钟以前创建的空目录
+                    if ((DateTime.Now - dir.CreationTime).TotalMinutes > 5)
                     {
-                        DirectoryInfo dir = new DirectoryInfo(item);
-                        if (dir.EnumerateFiles().Any()) continue;
-                        //删除5分钟以前创建的空目录
-                        if ((DateTime.Now - dir.CreationTime).TotalMinutes > 5)
-                        {
-                            dir.Delete();
-                        }
+                        dir.Delete();
                     }
                 }
-                catch (Exception ex)
-                {
-                    IpsLogger.Error($"删除{name}目录中的空目录出错", ex);
-                }
-                #endregion
+            }
+            catch (Exception ex)
+            {
+                IpsLogger.Error($"删除{dir}目录中的空目录出错", ex);
+            }
+            #endregion
 
-                #region 清理30分钟以前上传的文件
-                var files = Directory.EnumerateFiles(clearDir, "*", SearchOption.AllDirectories);
-                foreach (var item in files)
+            #region 清理30分钟以前上传的文件
+            var files = Directory.EnumerateFiles(clearDir, "*", SearchOption.AllDirectories);
+            foreach (var item in files)
+            {
+                FileInfo f = new FileInfo(item);
+                if ((DateTime.Now - f.LastWriteTime).TotalMinutes > 30)
                 {
-                    FileInfo f = new FileInfo(item);
-                    if ((DateTime.Now - f.LastWriteTime).TotalMinutes > 30)
+                    try
                     {
-                        try
-                        {
-                            f.Delete();
-                        }
-                        catch (Exception ex)
-                        {
-                            IpsLogger.Error($"$删除{name}目录中文件[{f.Name}]失败", ex);
-                        }
+                        f.Delete();
+                    }
+                    catch (Exception ex)
+                    {
+                        IpsLogger.Error($"$删除{dir}目录中文件[{f.Name}]失败", ex);
                     }
                 }
-                #endregion
             }
-
+            #endregion
         }
     }
 }

+ 1 - 0
ipslib/Ips.Library.WebApi/BaseController.cs

@@ -28,6 +28,7 @@ namespace Ips.Library.WebApi
         {
             this.uploadFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot");
         }
+
         /// <summary>
         /// 返回本地文件
         /// </summary>

+ 53 - 12
ipslib/Ips.Library.WebApi/WebApiHelper.cs

@@ -29,32 +29,73 @@ namespace Ips.Library.WebApi
     public static class WebApiHelper
     {
         private static CancellationTokenSource _cts;
+
+
+        public static WebApplicationBuilder CreateDefault()
+        {
+
+        }
+
+        /// <summary>
+        /// 启用Swagger
+        /// </summary>
+        /// <param name="builder"></param>
+        /// <param name="xmlName"></param>
+        public static void LoadController()
+        {
+        }
+
+        public static void UseStaticDir()
+        {
+            
+        }
+
         /// <summary>
         /// 启动AspNetCore WebAPI
         /// </summary>
         /// <param name="_localPort">本地端口</param>
-        /// <param name="controllerXmlName">Controller所在程序集XML描述文档名称</param>
-        /// <param name="dtoXmlName">DTO所在程序集XML描述文档</param>
-        /// <param name="staticDir">要启用的静态目录预览及文件下载(默认为Upload目录)</param>
-        /// <param name="diAssemblyPrefix">使用DI注入时程序集的前缀</param>
+        /// <param name="controllerXmlName">Controller所在程序集XML描述文档名称,默认使用入口程序生成的xml</param>
+        /// <param name="dtoXmlName">DTO所在程序集XML描述文档,默认使用入口程序生成的xml</param>
+        /// <param name="staticDir">要启用的静态目录预览及文件下载的目录(已经包含upload、download、logs三个目录)</param>
+        /// <param name="prefix">使用DI注入时程序集的前缀</param>
         /// <exception cref="Exception"></exception>
-        public static void Start(int _localPort, string controllerXmlName, string dtoXmlName, string[] staticDir = null,string diAssemblyPrefix="ips")
+        public static void Start(int _localPort, string dtoXmlName = null, string[] staticDir = null, string controllerXmlName = null, string prefix = "ips")
         {
             _cts = new CancellationTokenSource();
-            if (staticDir == null)
-                staticDir = new string[] { "Upload" };
-            var assemblies = AppDomain.CurrentDomain.GetAllAssemblies(diAssemblyPrefix);
+            if (controllerXmlName == null)
+                controllerXmlName = $"{AppDomain.CurrentDomain.FriendlyName}.xml";
+            if (dtoXmlName == null)
+                dtoXmlName = $"{AppDomain.CurrentDomain.FriendlyName}.xml";
+            List<string> listDir = new List<string>();
+            if (staticDir != null)
+            {
+                listDir.AddRange(staticDir.Select(p => p.ToLower()).Distinct());
+            }
+            if (!listDir.Contains("upload"))
+            {
+                listDir.Add("upload");
+            }
+            if (!listDir.Contains("download"))
+            {
+                listDir.Add("download");
+            }
+            if (!listDir.Contains("logs"))
+            {
+                listDir.Add("logs");
+            }
+            staticDir = listDir.ToArray();
+            var assemblies = AppDomain.CurrentDomain.GetAllAssemblies(prefix);
             if (assemblies == null)
             {
-                throw new Exception($"未扫描到{diAssemblyPrefix}前缀的程序集");
+                throw new Exception($"未扫描到{prefix}前缀的程序集");
             }
             foreach (var item in assemblies)
             {
-                IpsLogger.Info($"已加载DI注入程序集[{item.FullName}]",false);
+                IpsLogger.Info($"已加载DI注入程序集[{item.FullName}]", false);
             }
             var controllerAssemblies = assemblies.Where(p => p.GetTypes().Any(q =>
             {
-                if (q.Name.EndsWith("Controller") && q.IsPublic && q.IsSubclassOf(typeof(BaseController)))
+                if (q.Name.EndsWith("Controller") && q.IsSubclassOf(typeof(BaseController)))
                     return true;
                 return false;
             })).ToList();
@@ -265,7 +306,7 @@ namespace Ips.Library.WebApi
         /// </summary>
         public static void Stop()
         {
-            _cts.Cancel();
+            _cts?.Cancel();
         }
     }
 }

+ 1 - 1
ipsmodule/adc/Ips.Adc.WadTool/Ips.Adc.WadTool.csproj

@@ -26,7 +26,7 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="DevExpress.Win.Design" Version="23.2.3" />
+    <PackageReference Include="DevExpress.Win.Design" Version="24.1.6" />
   </ItemGroup>
 
   <ItemGroup>

+ 1 - 1
ipsmodule/adc/Ips.AdcTool.Win/Ips.AdcTool.Win.csproj

@@ -31,7 +31,7 @@
 	</ItemGroup>
 
 	<ItemGroup>
-		<PackageReference Include="DevExpress.Win.Design" Version="23.2.3" />
+		<PackageReference Include="DevExpress.Win.Design" Version="24.1.6" />
 		<PackageReference Include="PropertyChanged.Fody" Version="4.1.0">
 			<PrivateAssets>all</PrivateAssets>
 		</PackageReference>

+ 1 - 1
ipsmodule/cor/Ips.CorTool.Win/Ips.CorTool.Win.csproj

@@ -19,7 +19,7 @@
 	</ItemGroup>
 
 	<ItemGroup>
-		<PackageReference Include="DevExpress.Win.Design" Version="23.2.3" />
+		<PackageReference Include="DevExpress.Win.Design" Version="24.1.6" />
 		<PackageReference Include="PropertyChanged.Fody" Version="4.1.0">
 			<PrivateAssets>all</PrivateAssets>
 		</PackageReference>

+ 8 - 2
ipsservice/Ips.Service.CapServer/App.config

@@ -4,12 +4,18 @@
 		<!--数据存储目录(会自动选择一个容量大的目录存储),当外部未指定目录时使用此目录-->
 		<add key="DataDir" value="D:\data;E:data"/>
 
-		<!--数据清理目录(多个目录用分号隔开)-->
-		<add key="ClearDir" value="D:\data;E:\data" />
+		<!--数据清理目录(多个目录用分号隔开,数据存储目录会自动加入清理计划,不用配置)-->
+		<add key="ClearDir" value="D:\data1;c:\dataC" />
 
 		<!--磁盘可用空间百分比不足此数时开始清理-->
 		<add key="ClearCondition" value="0.2"/>
 
+		<!--每次达到清理条件时最多删除{ClearHours}小时的数据,为0时每次删除所有文件-->
+		<add key="ClearHours" value="12"/>
+
+		<!--子目录format格式(暂未实现此功能)-->
+		<add key="ClearDirFormat" value="yyyyMMdd_HH"/>
+
 		<!--数据备份地址(暂未实现此功能)-->
 		<add key="DataBackupDir" value=""/>
 	</appSettings>

+ 13 - 2
ipsservice/Ips.Service.CapServer/AppConst.cs

@@ -59,11 +59,22 @@ namespace Ips.Service.CapServer
         /// <summary>
         /// 采集服务使用的Http通信端口
         /// </summary>
-        public static string LocalPort { get; set; }
+        public static int LocalPort { get; set; }
+
+        /// <summary>
+        /// 服务编号
+        /// </summary>
+        public static string SvrNo { get; set; }
+
+        /// <summary>
+        /// 注册的容器http地址
+        /// </summary>
+        public static string RegistryUri { get; set; }
 
         /// <summary>
         /// 采集卡类型
         /// </summary>
-        public static AdCardType CardType { get; set; }
+        public static EnumCapDevType CardType { get; set; }
+
     }
 }

+ 175 - 0
ipsservice/Ips.Service.CapServer/BackgroundServices/CearDirService.cs

@@ -0,0 +1,175 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Channels;
+using System.Threading.Tasks;
+using Ips.Library.Basic;
+using Ips.Library.DxpLib;
+using Microsoft.Extensions.Hosting;
+
+namespace Ips.Service.CapServer
+{
+    /// <summary>
+    /// 数据清理服务(每隔5分钟扫描一次)
+    /// </summary>
+    public class CearDirService : BackgroundService
+    {
+        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
+        {
+            await Task.Delay(5000, stoppingToken);//延迟一会儿让webbapi先启动
+            IpsLogger.Info($"启动采集专用目录数据清理功能...");
+            await Task.Run(async () =>
+            {
+                #region 读取清理目录配置信息
+                string dataClearStr = ToolConfig.GetAppSetting("ClearDir");
+                var dataClears = dataClearStr.Split(new string[] { ";", ";" }, StringSplitOptions.RemoveEmptyEntries)
+                .Select(p => p.ToLower()).ToList();
+                if (!dataClears.Contains(AppConst.DataDir))
+                    dataClears.Add(AppConst.DataDir);
+                #endregion
+
+                #region 检测有效的清理目录并读取清理条件
+                List<string> list = new List<string>();
+                foreach (var item in dataClears)
+                {
+                    var root = Path.GetPathRoot(item);
+                    DriveInfo drive = new DriveInfo(root);
+                    if (!drive.IsReady)
+                    {
+                        continue;
+                    }
+                    if (Directory.Exists(item))
+                    {
+                        list.Add(item);
+                    }
+                }
+                if (!list.Any())
+                {
+                    IpsLogger.Warn($"配置文件中的数据清理目录无效");
+                    return;
+                }
+                float maxPercent = ToolConfig.GetAppSetting("ClearCondition", 0.2f);
+                var clearHours = (int)ToolConfig.GetAppSetting("ClearHours", 12d);
+                if (clearHours < 1)
+                {
+                    clearHours = 1;
+                }
+                IpsLogger.Info($"已启动目录[{string.Join(";", list)}]自动清理,清理条件=可用空间不足{(int)(maxPercent * 100)}%");
+                #endregion
+
+
+                //缓存每个目录上次清理的文件最大的一个写入时间
+                var prevClearTime = new Dictionary<string, DateTime>();
+                foreach (var item in list)
+                {
+                    prevClearTime[item] = DateTime.MinValue;
+
+                }
+
+                while (!stoppingToken.IsCancellationRequested)
+                {
+                    IpsLogger.Info($"开始数据清理...");
+
+                    #region 从上次开始每个目录清理一定的数据(ClearHours)
+                    int delFileCount = 0;
+                    try
+                    {
+                        var driveFolders = list.GroupBy(m => Path.GetPathRoot(m).ToUpper());
+                        foreach (var driveFolder in driveFolders)//like D:\ E:\
+                        {
+                            if (stoppingToken.IsCancellationRequested) break;
+                            DriveInfo drive = new DriveInfo(driveFolder.Key);
+
+                            while (drive.TotalFreeSpace / (drive.TotalSize * 1.0f) <= maxPercent)
+                            {
+                                foreach (var item in driveFolder)//like D:\data E:\data
+                                {
+                                    IpsLogger.Info($"正在清理[{item}]中的数据...");
+                                    var fsList = Directory.EnumerateFiles(item, "*", SearchOption.AllDirectories).Select(p => new FileInfo(p));
+                                    if (!fsList.Any())
+                                    {
+                                        IpsLogger.Warn($"{drive.ToString().Substring(0, 1)}盘空间不足,但目录{item}没有数据,跳过此目录");
+                                    }
+                                    else
+                                    {
+                                        if (prevClearTime[item] == DateTime.MinValue)
+                                            prevClearTime[item] = fsList.Min(p => p.LastWriteTime);
+                                        var maxTime = prevClearTime[item].AddHours(clearHours);
+                                        if (maxTime <= prevClearTime[item])
+                                        {
+                                            //clearHours配置为0或负数时一次删所有文件
+                                            maxTime = DateTime.MaxValue;
+                                        }
+                                        //每次清理从上次清理结束时间开始,防止有些删不掉的文件阻止删除文件
+                                        var clearFiles = fsList.Where(m => m.LastWriteTime >= prevClearTime[item] && m.LastWriteTime <= maxTime).OrderBy(m => m.LastWriteTime);
+                                        foreach (var fsItem in clearFiles)
+                                        {
+                                            try
+                                            {
+                                                if (stoppingToken.IsCancellationRequested) break;
+                                                fsItem.Delete();
+                                                delFileCount++;
+                                            }
+                                            catch (Exception ex)
+                                            {
+                                                IpsLogger.Error($"删除文件{fsItem.Name}出错", ex);
+                                            }
+                                        }
+                                        prevClearTime[item] = maxTime;
+
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        IpsLogger.Error($"清理数据异常", ex);
+                    }
+                    #endregion
+
+                    #region 清理空目录
+                    int delDirCount = 0;
+                    foreach (var name in list)
+                    {
+                        string clearDir = Path.Combine(AppContext.BaseDirectory, name);
+                        try
+                        {
+                            var dirs = Directory.EnumerateDirectories(clearDir, "*", SearchOption.AllDirectories);
+                            foreach (var item in dirs)
+                            {
+                                DirectoryInfo dir = new DirectoryInfo(item);
+                                if (dir.EnumerateFiles().Any()) continue;
+                                //删除5分钟以前创建的空目录
+                                if ((DateTime.Now - dir.CreationTime).TotalMinutes > 5)
+                                {
+
+                                    try
+                                    {
+                                        dir.Delete();
+                                        delDirCount++;
+                                    }
+                                    catch (Exception ex)
+                                    {
+                                        IpsLogger.Error($"删除空目录{dir.Name}异常", ex);
+                                    }
+                                }
+                            }
+                        }
+                        catch (Exception ex)
+                        {
+                            IpsLogger.Error($"删除{name}目录中的空目录出错", ex);
+                        }
+                    }
+                    #endregion
+
+                    IpsLogger.Info($"本次清理数据结束,删除{delFileCount}个文件,删除{delDirCount}个空目录");
+
+                    await Task.Delay(5 * 60 * 1000, stoppingToken);
+                }
+            }, stoppingToken);
+        }
+    }
+}

+ 0 - 18
ipsservice/Ips.Service.CapServer/BackgroundServices/InitService.cs

@@ -1,18 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Channels;
-using System.Threading.Tasks;
-using Microsoft.Extensions.Hosting;
-
-namespace Ips.Service.CapServer
-{
-    public class InitService : BackgroundService
-    {
-        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
-        {
-            await Task.FromResult(true);
-        }
-    }
-}

+ 149 - 150
ipsservice/Ips.Service.CapServer/DirectXForm1.Designer.cs

@@ -29,193 +29,191 @@
         private void InitializeComponent()
         {
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DirectXForm1));
-            DevExpress.Utils.SuperToolTip superToolTip1 = new DevExpress.Utils.SuperToolTip();
-            DevExpress.Utils.ToolTipItem toolTipItem1 = new DevExpress.Utils.ToolTipItem();
-            this.directXFormContainerControl1 = new DevExpress.XtraEditors.DirectXFormContainerControl();
-            this.groupControl1 = new DevExpress.XtraEditors.GroupControl();
-            this.stackPanel1 = new DevExpress.Utils.Layout.StackPanel();
-            this.labelControl1 = new DevExpress.XtraEditors.LabelControl();
-            this.txtLocalPort = new DevExpress.XtraEditors.TextEdit();
-            this.labelControl2 = new DevExpress.XtraEditors.LabelControl();
-            this.txtCardType = new DevExpress.XtraEditors.ComboBoxEdit();
-            this.labelControl3 = new DevExpress.XtraEditors.LabelControl();
-            this.txtCardNo = new DevExpress.XtraEditors.TextEdit();
-            this.labelControl4 = new DevExpress.XtraEditors.LabelControl();
-            this.txtRptAddr = new DevExpress.XtraEditors.TextEdit();
-            this.btnShowApi = new DevExpress.XtraBars.BarButtonItem();
-            this.directXFormContainerControl1.SuspendLayout();
-            ((System.ComponentModel.ISupportInitialize)(this.groupControl1)).BeginInit();
-            ((System.ComponentModel.ISupportInitialize)(this.stackPanel1)).BeginInit();
-            this.stackPanel1.SuspendLayout();
-            ((System.ComponentModel.ISupportInitialize)(this.txtLocalPort.Properties)).BeginInit();
-            ((System.ComponentModel.ISupportInitialize)(this.txtCardType.Properties)).BeginInit();
-            ((System.ComponentModel.ISupportInitialize)(this.txtCardNo.Properties)).BeginInit();
-            ((System.ComponentModel.ISupportInitialize)(this.txtRptAddr.Properties)).BeginInit();
-            this.SuspendLayout();
+            DevExpress.Utils.SuperToolTip superToolTip2 = new DevExpress.Utils.SuperToolTip();
+            DevExpress.Utils.ToolTipItem toolTipItem2 = new DevExpress.Utils.ToolTipItem();
+            directXFormContainerControl1 = new DevExpress.XtraEditors.DirectXFormContainerControl();
+            groupControl1 = new DevExpress.XtraEditors.GroupControl();
+            stackPanel1 = new DevExpress.Utils.Layout.StackPanel();
+            labelControl1 = new DevExpress.XtraEditors.LabelControl();
+            txtLocalPort = new DevExpress.XtraEditors.TextEdit();
+            labelControl2 = new DevExpress.XtraEditors.LabelControl();
+            txtCardType = new DevExpress.XtraEditors.ComboBoxEdit();
+            labelControl3 = new DevExpress.XtraEditors.LabelControl();
+            txtSvrNo = new DevExpress.XtraEditors.TextEdit();
+            labelControl4 = new DevExpress.XtraEditors.LabelControl();
+            txtRptAddr = new DevExpress.XtraEditors.TextEdit();
+            btnStart = new DevExpress.XtraEditors.SimpleButton();
+            btnShowApi = new DevExpress.XtraBars.BarButtonItem();
+            directXFormContainerControl1.SuspendLayout();
+            ((System.ComponentModel.ISupportInitialize)groupControl1).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)stackPanel1).BeginInit();
+            stackPanel1.SuspendLayout();
+            ((System.ComponentModel.ISupportInitialize)txtLocalPort.Properties).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)txtCardType.Properties).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)txtSvrNo.Properties).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)txtRptAddr.Properties).BeginInit();
+            SuspendLayout();
             // 
             // directXFormContainerControl1
             // 
-            this.directXFormContainerControl1.Controls.Add(this.groupControl1);
-            this.directXFormContainerControl1.Controls.Add(this.stackPanel1);
-            this.directXFormContainerControl1.Location = new System.Drawing.Point(1, 31);
-            this.directXFormContainerControl1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
-            this.directXFormContainerControl1.Name = "directXFormContainerControl1";
-            this.directXFormContainerControl1.Size = new System.Drawing.Size(845, 545);
-            this.directXFormContainerControl1.TabIndex = 0;
+            directXFormContainerControl1.Controls.Add(groupControl1);
+            directXFormContainerControl1.Controls.Add(stackPanel1);
+            directXFormContainerControl1.Location = new Point(1, 31);
+            directXFormContainerControl1.Margin = new Padding(3, 4, 3, 4);
+            directXFormContainerControl1.Name = "directXFormContainerControl1";
+            directXFormContainerControl1.Size = new Size(957, 545);
+            directXFormContainerControl1.TabIndex = 0;
             // 
             // groupControl1
             // 
-            this.groupControl1.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.groupControl1.Location = new System.Drawing.Point(0, 39);
-            this.groupControl1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
-            this.groupControl1.Name = "groupControl1";
-            this.groupControl1.Size = new System.Drawing.Size(845, 506);
-            this.groupControl1.TabIndex = 1;
-            this.groupControl1.Text = "日志信息";
+            groupControl1.Dock = DockStyle.Fill;
+            groupControl1.Location = new Point(0, 39);
+            groupControl1.Margin = new Padding(3, 4, 3, 4);
+            groupControl1.Name = "groupControl1";
+            groupControl1.Size = new Size(957, 506);
+            groupControl1.TabIndex = 1;
+            groupControl1.Text = "日志信息";
             // 
             // stackPanel1
             // 
-            this.stackPanel1.Controls.Add(this.labelControl1);
-            this.stackPanel1.Controls.Add(this.txtLocalPort);
-            this.stackPanel1.Controls.Add(this.labelControl2);
-            this.stackPanel1.Controls.Add(this.txtCardType);
-            this.stackPanel1.Controls.Add(this.labelControl3);
-            this.stackPanel1.Controls.Add(this.txtCardNo);
-            this.stackPanel1.Controls.Add(this.labelControl4);
-            this.stackPanel1.Controls.Add(this.txtRptAddr);
-            this.stackPanel1.Dock = System.Windows.Forms.DockStyle.Top;
-            this.stackPanel1.Location = new System.Drawing.Point(0, 0);
-            this.stackPanel1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
-            this.stackPanel1.Name = "stackPanel1";
-            this.stackPanel1.Size = new System.Drawing.Size(845, 39);
-            this.stackPanel1.TabIndex = 0;
+            stackPanel1.Controls.Add(labelControl1);
+            stackPanel1.Controls.Add(txtLocalPort);
+            stackPanel1.Controls.Add(labelControl2);
+            stackPanel1.Controls.Add(txtCardType);
+            stackPanel1.Controls.Add(labelControl3);
+            stackPanel1.Controls.Add(txtSvrNo);
+            stackPanel1.Controls.Add(labelControl4);
+            stackPanel1.Controls.Add(txtRptAddr);
+            stackPanel1.Controls.Add(btnStart);
+            stackPanel1.Dock = DockStyle.Top;
+            stackPanel1.Location = new Point(0, 0);
+            stackPanel1.Margin = new Padding(3, 4, 3, 4);
+            stackPanel1.Name = "stackPanel1";
+            stackPanel1.Size = new Size(957, 39);
+            stackPanel1.TabIndex = 0;
             // 
             // labelControl1
             // 
-            this.labelControl1.Location = new System.Drawing.Point(3, 12);
-            this.labelControl1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
-            this.labelControl1.Name = "labelControl1";
-            this.labelControl1.Padding = new System.Windows.Forms.Padding(10, 0, 0, 0);
-            this.labelControl1.Size = new System.Drawing.Size(58, 14);
-            this.labelControl1.TabIndex = 0;
-            this.labelControl1.Text = "本地端口";
+            labelControl1.Location = new Point(3, 12);
+            labelControl1.Margin = new Padding(3, 4, 3, 4);
+            labelControl1.Name = "labelControl1";
+            labelControl1.Padding = new Padding(10, 0, 0, 0);
+            labelControl1.Size = new Size(58, 14);
+            labelControl1.TabIndex = 0;
+            labelControl1.Text = "本地端口";
             // 
             // txtLocalPort
             // 
-            this.txtLocalPort.Location = new System.Drawing.Point(67, 7);
-            this.txtLocalPort.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
-            this.txtLocalPort.Name = "txtLocalPort";
-            this.txtLocalPort.Properties.AutoHeight = false;
-            this.txtLocalPort.Size = new System.Drawing.Size(70, 24);
-            this.txtLocalPort.TabIndex = 2;
-            this.txtLocalPort.ToolTip = "创建Http服务使用的本地端口,修改后需要重启软件";
-            this.txtLocalPort.EditValueChanged += new System.EventHandler(this.Parms_TextChanged);
+            txtLocalPort.Location = new Point(67, 7);
+            txtLocalPort.Name = "txtLocalPort";
+            txtLocalPort.Properties.AutoHeight = false;
+            txtLocalPort.Size = new Size(70, 24);
+            txtLocalPort.TabIndex = 2;
+            txtLocalPort.ToolTip = "创建Http服务使用的本地端口,修改后需要重启软件";
             // 
             // labelControl2
             // 
-            this.labelControl2.Location = new System.Drawing.Point(143, 12);
-            this.labelControl2.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
-            this.labelControl2.Name = "labelControl2";
-            this.labelControl2.Padding = new System.Windows.Forms.Padding(10, 0, 0, 0);
-            this.labelControl2.Size = new System.Drawing.Size(70, 14);
-            this.labelControl2.TabIndex = 0;
-            this.labelControl2.Text = "采集卡类型";
+            labelControl2.Location = new Point(143, 12);
+            labelControl2.Margin = new Padding(3, 4, 3, 4);
+            labelControl2.Name = "labelControl2";
+            labelControl2.Padding = new Padding(10, 0, 0, 0);
+            labelControl2.Size = new Size(70, 14);
+            labelControl2.TabIndex = 0;
+            labelControl2.Text = "采集卡类型";
             // 
             // txtCardType
             // 
-            this.txtCardType.EditValue = "华力采集";
-            this.txtCardType.Location = new System.Drawing.Point(219, 7);
-            this.txtCardType.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
-            this.txtCardType.Name = "txtCardType";
-            this.txtCardType.Properties.AutoHeight = false;
-            this.txtCardType.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
-            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
-            this.txtCardType.Properties.Items.AddRange(new object[] {
-            "华力采集",
-            "前锋采集"});
-            this.txtCardType.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
-            this.txtCardType.Size = new System.Drawing.Size(80, 24);
-            this.txtCardType.TabIndex = 3;
-            this.txtCardType.EditValueChanged += new System.EventHandler(this.Parms_TextChanged);
+            txtCardType.EditValue = "华力采集";
+            txtCardType.Location = new Point(219, 7);
+            txtCardType.Name = "txtCardType";
+            txtCardType.Properties.AutoHeight = false;
+            txtCardType.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo) });
+            txtCardType.Properties.Items.AddRange(new object[] { "华力采集", "前锋采集" });
+            txtCardType.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
+            txtCardType.Size = new Size(80, 24);
+            txtCardType.TabIndex = 3;
             // 
             // labelControl3
             // 
-            this.labelControl3.Location = new System.Drawing.Point(305, 12);
-            this.labelControl3.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
-            this.labelControl3.Name = "labelControl3";
-            this.labelControl3.Padding = new System.Windows.Forms.Padding(10, 0, 0, 0);
-            this.labelControl3.Size = new System.Drawing.Size(70, 14);
-            this.labelControl3.TabIndex = 0;
-            this.labelControl3.Text = "采集卡编号";
+            labelControl3.Location = new Point(305, 12);
+            labelControl3.Margin = new Padding(3, 4, 3, 4);
+            labelControl3.Name = "labelControl3";
+            labelControl3.Padding = new Padding(10, 0, 0, 0);
+            labelControl3.Size = new Size(58, 14);
+            labelControl3.TabIndex = 0;
+            labelControl3.Text = "服务编号";
             // 
-            // txtCardNo
+            // txtSvrNo
             // 
-            this.txtCardNo.Location = new System.Drawing.Point(381, 7);
-            this.txtCardNo.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
-            this.txtCardNo.Name = "txtCardNo";
-            this.txtCardNo.Properties.AutoHeight = false;
-            this.txtCardNo.Size = new System.Drawing.Size(100, 24);
-            this.txtCardNo.TabIndex = 1;
-            this.txtCardNo.EditValueChanged += new System.EventHandler(this.Parms_TextChanged);
+            txtSvrNo.Location = new Point(369, 7);
+            txtSvrNo.Name = "txtSvrNo";
+            txtSvrNo.Properties.AutoHeight = false;
+            txtSvrNo.Size = new Size(100, 24);
+            txtSvrNo.TabIndex = 1;
             // 
             // labelControl4
             // 
-            this.labelControl4.Location = new System.Drawing.Point(487, 12);
-            this.labelControl4.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
-            this.labelControl4.Name = "labelControl4";
-            this.labelControl4.Padding = new System.Windows.Forms.Padding(10, 0, 0, 0);
-            this.labelControl4.Size = new System.Drawing.Size(82, 14);
-            this.labelControl4.TabIndex = 0;
-            this.labelControl4.Text = "服务注册地址";
+            labelControl4.Location = new Point(475, 12);
+            labelControl4.Margin = new Padding(3, 4, 3, 4);
+            labelControl4.Name = "labelControl4";
+            labelControl4.Padding = new Padding(10, 0, 0, 0);
+            labelControl4.Size = new Size(82, 14);
+            labelControl4.TabIndex = 0;
+            labelControl4.Text = "服务注册地址";
             // 
             // txtRptAddr
             // 
-            this.txtRptAddr.EditValue = "";
-            this.txtRptAddr.Location = new System.Drawing.Point(575, 7);
-            this.txtRptAddr.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
-            this.txtRptAddr.Name = "txtRptAddr";
-            this.txtRptAddr.Properties.AutoHeight = false;
-            this.txtRptAddr.Size = new System.Drawing.Size(234, 24);
-            this.txtRptAddr.TabIndex = 2;
-            this.txtRptAddr.ToolTip = "多个地址用空格隔开";
-            this.txtRptAddr.EditValueChanged += new System.EventHandler(this.Parms_TextChanged);
+            txtRptAddr.EditValue = "";
+            txtRptAddr.Location = new Point(563, 7);
+            txtRptAddr.Name = "txtRptAddr";
+            txtRptAddr.Properties.AutoHeight = false;
+            txtRptAddr.Size = new Size(234, 24);
+            txtRptAddr.TabIndex = 2;
+            // 
+            // btnStart
+            // 
+            btnStart.Location = new Point(803, 7);
+            btnStart.Name = "btnStart";
+            btnStart.Size = new Size(75, 24);
+            btnStart.TabIndex = 4;
+            btnStart.Text = "启动服务";
+            btnStart.Click += btnStart_Click;
             // 
             // btnShowApi
             // 
-            this.btnShowApi.Alignment = DevExpress.XtraBars.BarItemLinkAlignment.Right;
-            this.btnShowApi.Caption = "barButtonItem1";
-            this.btnShowApi.Id = 0;
-            this.btnShowApi.ImageOptions.SvgImage = ((DevExpress.Utils.Svg.SvgImage)(resources.GetObject("btnShowApi.ImageOptions.SvgImage")));
-            this.btnShowApi.Name = "btnShowApi";
-            toolTipItem1.Text = "查看Http接口";
-            superToolTip1.Items.Add(toolTipItem1);
-            this.btnShowApi.SuperTip = superToolTip1;
-            this.btnShowApi.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.barbtnShowApi_ItemClick);
+            btnShowApi.Alignment = DevExpress.XtraBars.BarItemLinkAlignment.Right;
+            btnShowApi.Caption = "barButtonItem1";
+            btnShowApi.Id = 0;
+            btnShowApi.ImageOptions.SvgImage = (DevExpress.Utils.Svg.SvgImage)resources.GetObject("btnShowApi.ImageOptions.SvgImage");
+            btnShowApi.Name = "btnShowApi";
+            toolTipItem2.Text = "查看Http接口";
+            superToolTip2.Items.Add(toolTipItem2);
+            btnShowApi.SuperTip = superToolTip2;
+            btnShowApi.ItemClick += barbtnShowApi_ItemClick;
             // 
             // DirectXForm1
             // 
-            this.Appearance.Options.UseFont = true;
-            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
-            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ChildControls.Add(this.directXFormContainerControl1);
-            this.ClientSize = new System.Drawing.Size(847, 577);
-            this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
-            this.IconOptions.SvgImage = ((DevExpress.Utils.Svg.SvgImage)(resources.GetObject("DirectXForm1.IconOptions.SvgImage")));
-            this.Links.Add(this.btnShowApi);
-            this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
-            this.Name = "DirectXForm1";
-            this.Text = "DirectXForm1";
-            this.directXFormContainerControl1.ResumeLayout(false);
-            ((System.ComponentModel.ISupportInitialize)(this.groupControl1)).EndInit();
-            ((System.ComponentModel.ISupportInitialize)(this.stackPanel1)).EndInit();
-            this.stackPanel1.ResumeLayout(false);
-            this.stackPanel1.PerformLayout();
-            ((System.ComponentModel.ISupportInitialize)(this.txtLocalPort.Properties)).EndInit();
-            ((System.ComponentModel.ISupportInitialize)(this.txtCardType.Properties)).EndInit();
-            ((System.ComponentModel.ISupportInitialize)(this.txtCardNo.Properties)).EndInit();
-            ((System.ComponentModel.ISupportInitialize)(this.txtRptAddr.Properties)).EndInit();
-            this.ResumeLayout(false);
-
+            Appearance.Options.UseFont = true;
+            AutoScaleDimensions = new SizeF(7F, 17F);
+            AutoScaleMode = AutoScaleMode.Font;
+            ChildControls.Add(directXFormContainerControl1);
+            ClientSize = new Size(959, 577);
+            Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point);
+            IconOptions.SvgImage = (DevExpress.Utils.Svg.SvgImage)resources.GetObject("DirectXForm1.IconOptions.SvgImage");
+            Links.Add(btnShowApi);
+            Margin = new Padding(3, 4, 3, 4);
+            Name = "DirectXForm1";
+            Text = "DirectXForm1";
+            directXFormContainerControl1.ResumeLayout(false);
+            ((System.ComponentModel.ISupportInitialize)groupControl1).EndInit();
+            ((System.ComponentModel.ISupportInitialize)stackPanel1).EndInit();
+            stackPanel1.ResumeLayout(false);
+            stackPanel1.PerformLayout();
+            ((System.ComponentModel.ISupportInitialize)txtLocalPort.Properties).EndInit();
+            ((System.ComponentModel.ISupportInitialize)txtCardType.Properties).EndInit();
+            ((System.ComponentModel.ISupportInitialize)txtSvrNo.Properties).EndInit();
+            ((System.ComponentModel.ISupportInitialize)txtRptAddr.Properties).EndInit();
+            ResumeLayout(false);
         }
 
         #endregion
@@ -225,12 +223,13 @@
         private DevExpress.Utils.Layout.StackPanel stackPanel1;
         private DevExpress.XtraEditors.LabelControl labelControl1;
         private DevExpress.XtraEditors.TextEdit txtLocalPort;
-        private DevExpress.XtraEditors.TextEdit txtCardNo;
+        private DevExpress.XtraEditors.TextEdit txtSvrNo;
         private DevExpress.XtraEditors.LabelControl labelControl2;
         private DevExpress.XtraEditors.ComboBoxEdit txtCardType;
         private DevExpress.XtraEditors.LabelControl labelControl3;
         private DevExpress.XtraEditors.LabelControl labelControl4;
         private DevExpress.XtraEditors.TextEdit txtRptAddr;
         private DevExpress.XtraEditors.GroupControl groupControl1;
+        private DevExpress.XtraEditors.SimpleButton btnStart;
     }
 }

+ 80 - 110
ipsservice/Ips.Service.CapServer/DirectXForm1.cs

@@ -12,6 +12,7 @@ using System.Drawing;
 using System.IO;
 using System.Linq;
 using System.Reflection;
+using System.Security.Policy;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
@@ -20,89 +21,28 @@ namespace Ips.Service.CapServer
 {
     public partial class DirectXForm1 : DevExpress.XtraEditors.DirectXForm
     {
-        private bool _inited = false;
-        private string _localPort;//本地端口
-        private string _cardType;//华力采集 前锋采集
-        private string _cardNo;//采集卡编号
-        private string _rptAddr;//服务注册上报http地址
+        private bool apiRuning = false;
+        private CancellationTokenSource cts;
         public DirectXForm1()
         {
             InitializeComponent();
             this.Size = new Size(1024, 768);
             this.Text = "采集服务";
         }
-        protected async override void OnLoad(EventArgs e)
+        protected override void OnLoad(EventArgs e)
         {
             base.OnLoad(e);
             new Library.DxpLib.LogCtrl() { Parent = groupControl1 };
             LoadParams();
-            if (int.TryParse(_localPort, out int intPort))
-            {
-                var controllerXml = $"{AppDomain.CurrentDomain.FriendlyName}.xml";
-                var dtoXml = "Ips.Library.Entity.xml";
-                var staticDir = new string[] { AppConst.DataDir, "Logs", AppConst.UploadDir };
-                WebApiHelper.Start(intPort, controllerXml, dtoXml, staticDir);
-                this.FormClosing += (_, _) => WebApiHelper.Stop();
-                _inited = true;
-                ClearCapData();
-                await StateRpt();
-            }
-            _inited = true;
         }
-        private void ClearCapData()
+        private async void RegistrySvr(CancellationToken token)
         {
-            string dataClearStr = ToolConfig.GetAppSetting("ClearDir");
-            if (string.IsNullOrWhiteSpace(dataClearStr)) return;
-            var dataClears = dataClearStr.Split(new string[] { ";", ";" }, StringSplitOptions.RemoveEmptyEntries);
-            if (dataClears.Length > 0)
-            {
-                List<string> list = new List<string>();
-                foreach (var item in dataClears)
-                {
-                    var root = Path.GetPathRoot(item);
-                    DriveInfo drive = new DriveInfo(root);
-                    if (!drive.IsReady)
-                    {
-                        continue;
-                    }
-                    if (Directory.Exists(item))
-                    {
-                        list.Add(item);
-                    }
-                }
-                if (!list.Any())
-                {
-                    IpsLogger.Warn($"配置文件中的数据清理目录无效");
-                }
-                float maxPercent = ToolConfig.GetAppSetting("ClearCondition", 0.2f);
-                FileMonitor monitor = new FileMonitor(list.ToArray(), maxPercent);
-                monitor.Start();
-                IpsLogger.Info($"已启动目录[{string.Join(";", list)}]自动清理,清理条件=可用空间不足{(int)(maxPercent * 100)}%");
-                this.FormClosing += (_, arg) => monitor.Stop();
-            }
-        }
-
-        private async Task StateRpt()
-        {
-            string localIp;
-
-            while (true)
+            while (!this.Disposing && apiRuning)
             {
                 string getIpUrl = null;
                 try
                 {
-                    if (_rptAddr == null)
-                    {
-                        await Task.Delay(5000);
-                        continue;
-                    }
-                    if (!_rptAddr.ToLower().StartsWith("http://"))
-                    {
-                        IpsLogger.Error($"注册地址必须以http://开头");
-                        await Task.Delay(5000);
-                        continue;
-                    }
-                    getIpUrl = _rptAddr.AppendUrlSuffix("api/getclientip");
+                    getIpUrl = AppConst.RegistryUri.AppendUrlSuffix("api/getclientip");
                     var rsp = await HttpHelper.GetRequestAsync<string>(getIpUrl, 5);
                     if (rsp.code == 0)
                     {
@@ -111,58 +51,55 @@ namespace Ips.Service.CapServer
                     }
                     else
                     {
-                        localIp = rsp.data;
+                        AppConst.LocalIp = rsp.data;
                     }
                     break;
                 }
                 catch (Exception ex)
                 {
-                    IpsLogger.Error($"无法连接到{getIpUrl},请检测地址是否正确并确保远程设备设备防火墙入栈规则允许TCP端口{getIpUrl.GetUrlPort()}通过", ex);
-                    await Task.Delay(5000);
+                    IpsLogger.Error($"无法注册到{getIpUrl},请检测地址是否正确并确保远程设备设备防火墙入栈规则允许TCP端口{getIpUrl.GetUrlPort()}通过", ex);
+                    await Task.Delay(10000, token);
                 }
             }
-            AppConst.LocalIp = localIp;
-            IpsLogger.Info($"服务启动成功.接口地址http://{localIp}:{_localPort}/swagger");
-
             bool preSucceed = false;
-            while (!this.Disposing)
+            while (!this.Disposing && apiRuning)
             {
-                string url = _rptAddr.AppendUrlSuffix("api/SvrStateRpt/Report");
+                string url = AppConst.RegistryUri.AppendUrlSuffix("api/SvrStateRpt/Report");
                 try
                 {
                     var res = await HttpHelper.PostRequestAsync<object>(url, new ModelSvrRpt()
                     {
                         SvrType = EnumSvrType.CapSvr,
-                        SvrNo = _cardNo,
+                        SvrNo = AppConst.SvrNo,
                         Features = "数据采集 DDC",
-                        CapDevType = GetCapDevType(_cardType),
+                        CapDevType = AppConst.CardType,
                         SvrRptType = EnumSvrRptType.Online,
-                        BaseHttpAddr = $"http://{localIp}:{_localPort}",
-                        SwaggerAddr = $"http://{localIp}:{_localPort}/Swagger",
+                        BaseHttpAddr = $"http://{AppConst.LocalIp}:{AppConst.LocalPort}",
+                        SwaggerAddr = $"http://{AppConst.LocalIp}:{AppConst.LocalPort}/Swagger",
                     });
                     if (res.code != 200)
                     {
-                        IpsLogger.Error($"状态上报异常[url={url}].{res.msg}");
+                        IpsLogger.Error($"服务注册异常[url={url}].{res.msg}");
                         preSucceed = false;
                     }
                     else
                     {
                         if (!preSucceed)
-                            IpsLogger.Info($"状态上报成功![url={url}]");
+                            IpsLogger.Info($"服务注册成功![url={url}]");
                         preSucceed = true;
                     }
                 }
                 catch (Exception ex)
                 {
-                    IpsLogger.Error($"状态上报异常[url={url}]", ex);
+                    IpsLogger.Error($"服务注册异常[url={url}]", ex);
                     preSucceed = false;
                 }
-                await Task.Delay(10000);
+                await Task.Delay(10000, token);
             }
         }
         private void barbtnShowApi_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
         {
-            string addr = $"http://127.0.0.1:{_localPort}/swagger";
+            string addr = $"http://127.0.0.1:{AppConst.LocalPort}/swagger";
             try
             {
                 //System.Diagnostics.Process.Start(addr);//NetFramework可用,NetCore使用CMD启动
@@ -178,11 +115,59 @@ namespace Ips.Service.CapServer
                 IpsLogger.Error($"无法打开默认浏览器,请手动打开浏览器查看接口文档.地址{addr}", ex);
             }
         }
-
-        private void Parms_TextChanged(object sender, EventArgs e)
+        private void btnStart_Click(object sender, EventArgs e)
         {
-            if (!_inited) return;
-            SaveParams();
+            try
+            {
+                if (btnStart.Text == "启动服务")
+                {
+                    if (!int.TryParse(txtLocalPort.Text.Trim(), out int localPort))
+                    {
+                        throw new Exception("本地端口输入错误");
+                    }
+                    if (localPort < 1024 || localPort > 49151)
+                    {
+                        //1024以下给vip程序预留的,49152-65535用于客户端随机分配的
+                        throw new Exception("本地端口范围[1024,49151]");
+                    }
+                    if (txtSvrNo.Text.Trim().Length < 3 || txtSvrNo.Text.Trim().Length > 15)
+                    {
+                        throw new Exception("服务编号长度范围[3,15]");
+                    }
+                    try
+                    {
+                        var u = new Uri(txtRptAddr.Text.Trim());
+                    }
+                    catch
+                    {
+                        throw new Exception("服务注册地址不是有效的URI");
+                    }
+                    AppConst.LocalPort = localPort;
+                    AppConst.SvrNo = txtSvrNo.Text.Trim();
+                    AppConst.CardType = txtCardType.Text.GetEnumByDisplayName<EnumCapDevType>();
+                    AppConst.RegistryUri = txtRptAddr.Text.Trim();
+                    WebApiHelper.Start(AppConst.LocalPort, "Ips.Library.Entity.xml", AppConst.DataDir.ToStrArray());
+                    btnStart.Text = "停止服务";
+                    stackPanel1.DisabledChildWithout(btnStart);
+                    IpsLogger.Info($"服务启动成功.接口地址http://+:{localPort}/swagger");
+                    apiRuning = true;
+                    cts = new CancellationTokenSource();
+                    RegistrySvr(cts.Token);
+                }
+                else
+                {
+                    apiRuning = false;
+                    btnStart.Text = "启动服务";
+                    WebApiHelper.Stop();
+                    cts?.Cancel();
+                    stackPanel1.EnableChild();
+                }
+                SaveParams();
+            }
+            catch (Exception ex)
+            {
+                IpsLogger.Error(ex.Message, ex);
+            }
         }
         void SaveParams()
         {
@@ -192,20 +177,15 @@ namespace Ips.Service.CapServer
                 StringBuilder sb = new StringBuilder();
                 sb.AppendLine(txtLocalPort.Text);
                 sb.AppendLine(txtCardType.SelectedIndex.ToString());
-                sb.AppendLine(txtCardNo.Text);
+                sb.AppendLine(txtSvrNo.Text);
                 sb.AppendLine(txtRptAddr.Text);
+                sb.AppendLine(btnStart.Text);
                 File.WriteAllText("Params\\Params.txt", sb.ToString());
             }
             catch (Exception ex)
             {
                 IpsLogger.Error("保存Params.txt文件异常", ex);
             }
-            _localPort = txtLocalPort.Text.Trim();
-            _cardType = txtCardType.Text.Trim();
-            _cardNo = txtCardNo.Text.Trim();
-            _rptAddr = txtRptAddr.Text.Trim();
-            AppConst.CardType = _cardType.GetEnumByDisplayName<AdCardType>();
-            AppConst.LocalPort = _localPort;
         }
         void LoadParams()
         {
@@ -216,28 +196,18 @@ namespace Ips.Service.CapServer
                     var lines = File.ReadAllLines("Params\\Params.txt");
                     txtLocalPort.Text = lines[0];
                     txtCardType.SelectedIndex = Convert.ToInt32(lines[1]);
-                    txtCardNo.Text = lines[2];
+                    txtSvrNo.Text = lines[2];
                     txtRptAddr.Text = lines[3];
+                    if (lines[4] == "停止服务")//上次状态是启动状态,加载后直接启动
+                    {
+                        btnStart_Click(null, null);
+                    }
                 }
                 catch (Exception ex)
                 {
                     IpsLogger.Error("加载Params.txt文件异常", ex);
                 }
             }
-            _localPort = txtLocalPort.Text.Trim();
-            _cardType = txtCardType.Text.Trim();
-            _cardNo = txtCardNo.Text.Trim();
-            _rptAddr = txtRptAddr.Text.Trim();
-            AppConst.CardType = _cardType.GetEnumByDisplayName<AdCardType>();
-            AppConst.LocalPort = _localPort;
-        }
-        private EnumCapDevType? GetCapDevType(string capDevType)
-        {
-            if (capDevType == "前锋采集")
-                return EnumCapDevType.QF;
-            else if (capDevType == "华力采集")
-                return EnumCapDevType.HL;
-            return null;
         }
     }
 }

+ 31 - 31
ipsservice/Ips.Service.CapServer/DirectXForm1.resx

@@ -1,24 +1,24 @@
 <?xml version="1.0" encoding="utf-8"?>
 <root>
-  <!-- 
+  <!--
     Microsoft ResX Schema 
-    
+
     Version 2.0
-    
-    The primary goals of this format is to allow a simple XML format 
-    that is mostly human readable. The generation and parsing of the 
-    various data types are done through the TypeConverter classes 
+
+    The primary goals of this format is to allow a simple XML format
+    that is mostly human readable. The generation and parsing of the
+    various data types are done through the TypeConverter classes
     associated with the data types.
-    
+
     Example:
-    
+
     ... ado.net/XML headers & schema ...
     <resheader name="resmimetype">text/microsoft-resx</resheader>
     <resheader name="version">2.0</resheader>
     <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
     <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
     <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
-    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
     <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
         <value>[base64 mime encoded serialized .NET Framework object]</value>
     </data>
@@ -26,36 +26,36 @@
         <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
         <comment>This is a comment</comment>
     </data>
-                
-    There are any number of "resheader" rows that contain simple 
+
+    There are any number of "resheader" rows that contain simple
     name/value pairs.
-    
-    Each data row contains a name, and value. The row also contains a 
-    type or mimetype. Type corresponds to a .NET class that support 
-    text/value conversion through the TypeConverter architecture. 
-    Classes that don't support this are serialized and stored with the 
+
+    Each data row contains a name, and value. The row also contains a
+    type or mimetype. Type corresponds to a .NET class that support
+    text/value conversion through the TypeConverter architecture.
+    Classes that don't support this are serialized and stored with the
     mimetype set.
-    
-    The mimetype is used for serialized objects, and tells the 
-    ResXResourceReader how to depersist the object. This is currently not 
+
+    The mimetype is used for serialized objects, and tells the
+    ResXResourceReader how to depersist the object. This is currently not
     extensible. For a given mimetype the value must be set accordingly:
-    
-    Note - application/x-microsoft.net.object.binary.base64 is the format 
-    that the ResXResourceWriter will generate, however the reader can 
+
+    Note - application/x-microsoft.net.object.binary.base64 is the format
+    that the ResXResourceWriter will generate, however the reader can
     read any of the formats listed below.
-    
+
     mimetype: application/x-microsoft.net.object.binary.base64
-    value   : The object must be serialized with 
+    value   : The object must be serialized with
             : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
             : and then encoded with base64 encoding.
     
     mimetype: application/x-microsoft.net.object.soap.base64
-    value   : The object must be serialized with 
+    value   : The object must be serialized with
             : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
             : and then encoded with base64 encoding.
 
     mimetype: application/x-microsoft.net.object.bytearray.base64
-    value   : The object must be serialized into a byte array 
+    value   : The object must be serialized into a byte array
             : using a System.ComponentModel.TypeConverter
             : and then encoded with base64 encoding.
     -->
@@ -117,10 +117,10 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
-  <assembly alias="DevExpress.Data.v23.2" name="DevExpress.Data.v23.2, Version=23.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
-  <data name="btnShowApi.ImageOptions.SvgImage" type="DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v23.2" mimetype="application/x-microsoft.net.object.bytearray.base64">
+  <assembly alias="DevExpress.Data.v24.1" name="DevExpress.Data.v24.1, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
+  <data name="btnShowApi.ImageOptions.SvgImage" type="DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v24.1" mimetype="application/x-microsoft.net.object.bytearray.base64">
     <value>
-        AAEAAAD/////AQAAAAAAAAAMAgAAAFlEZXZFeHByZXNzLkRhdGEudjIzLjIsIFZlcnNpb249MjMuMi4z
+        AAEAAAD/////AQAAAAAAAAAMAgAAAFlEZXZFeHByZXNzLkRhdGEudjI0LjEsIFZlcnNpb249MjQuMS42
         LjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49Yjg4ZDE3NTRkNzAwZTQ5YQUBAAAAHURl
         dkV4cHJlc3MuVXRpbHMuU3ZnLlN2Z0ltYWdlAQAAAAREYXRhBwICAAAACQMAAAAPAwAAANYEAAAC77u/
         PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0nVVRGLTgnPz4NCjxzdmcgeD0iMHB4IiB5PSIwcHgi
@@ -146,9 +146,9 @@
         MTEuNiwxNC40eiIgY2xhc3M9IkJsdWUiIC8+DQo8L3N2Zz4L
 </value>
   </data>
-  <data name="DirectXForm1.IconOptions.SvgImage" type="DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v23.2" mimetype="application/x-microsoft.net.object.bytearray.base64">
+  <data name="DirectXForm1.IconOptions.SvgImage" type="DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v24.1" mimetype="application/x-microsoft.net.object.bytearray.base64">
     <value>
-        AAEAAAD/////AQAAAAAAAAAMAgAAAFlEZXZFeHByZXNzLkRhdGEudjIzLjIsIFZlcnNpb249MjMuMi4z
+        AAEAAAD/////AQAAAAAAAAAMAgAAAFlEZXZFeHByZXNzLkRhdGEudjI0LjEsIFZlcnNpb249MjQuMS42
         LjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49Yjg4ZDE3NTRkNzAwZTQ5YQUBAAAAHURl
         dkV4cHJlc3MuVXRpbHMuU3ZnLlN2Z0ltYWdlAQAAAAREYXRhBwICAAAACQMAAAAPAwAAAOkEAAAC77u/
         PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0nVVRGLTgnPz4NCjxzdmcgd2lkdGg9Ijk2cHgiIGhl

+ 0 - 109
ipsservice/Ips.Service.CapServer/FileMonitor.cs

@@ -1,109 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.IO;
-using System.Threading;
-using Ips.Library.Basic;
-using DevExpress.PerformanceTests.PerfomanceMonitor;
-
-namespace Ips.Service.CapServer
-{
-    class FileMonitor
-    {
-        /// <summary>
-        /// 磁盘可用空间百分比不足此数时开始清理数据
-        /// </summary>
-        float maxPercent = 0.2f;//
-        /// <summary>
-        /// 被监控目录
-        /// </summary>
-        string[] monitorPaths;
-        /// <summary>
-        /// 是否监控
-        /// </summary>
-        volatile bool isMonitor = false;
-
-        public FileMonitor(string[] p, float maxPercent = 0.2f)
-        {
-            this.monitorPaths = p.Select(p => p.ToUpper()).Distinct().ToArray();
-            this.maxPercent = maxPercent;
-        }
-
-        public void Stop()
-        {
-            isMonitor = false;
-        }
-
-        public void Start()
-        {
-            isMonitor = true;
-            _ = DoMonitor();
-        }
-
-        private async Task DoMonitor()
-        {
-            while (isMonitor)
-            {
-                CheckAndClearDisk();
-                await Task.Delay(1000 * 300);
-            }
-        }
-
-        private void CheckAndClearDisk()
-        {
-            try
-            {
-                var driveFolders = monitorPaths.GroupBy(m => Path.GetPathRoot(m));
-                foreach (var driveFolder in driveFolders)
-                {
-                    DriveInfo drive = new DriveInfo(driveFolder.Key);
-                    DateTime prevClearTime = DateTime.MinValue;
-                    while (drive.TotalFreeSpace / (drive.TotalSize * 1.0f) <= maxPercent)
-                    {
-                        IpsLogger.Info($"正在清理[{string.Join(";",driveFolder.ToList())}]中的数据...");
-                        var fsList = driveFolder.Where(m => Directory.Exists(m))
-                            .Select(m => new DirectoryInfo(m))
-                            .SelectMany(m => m.EnumerateFiles("*", SearchOption.AllDirectories));
-                        if (!fsList.Any())
-                        {
-                            IpsLogger.Warn($"{drive.ToString().Substring(0, 1)}盘空间不足,但要清理数据的目录为空,清理数据结束!");
-                            Thread.Sleep(100);
-                        }
-                        else
-                        {
-                            //每次清理从上次清理结束时间开始,防止有些删不掉的文件阻止删除文件
-                            var firstFs = fsList.Where(m => m.LastWriteTime > prevClearTime).OrderBy(m => m.LastWriteTime).FirstOrDefault();
-                            var clearTime = firstFs.LastWriteTime.AddHours(1);
-                            foreach (var fsItem in fsList.Where(m => m.LastWriteTime <= clearTime))
-                            {
-                                try
-                                {
-                                    fsItem.Delete();
-                                    if (!fsItem.Directory.EnumerateFiles("*", SearchOption.AllDirectories).Any())
-                                    {
-                                        bool isAny = driveFolder.Any(s => s.Contains(fsItem.DirectoryName));
-                                        if (isAny) continue;
-                                        fsItem.Directory.Delete(true);
-                                    }
-                                }
-                                catch (Exception ex)
-                                {
-                                    IpsLogger.Error($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 删除文件或目录出错", ex);
-                                }
-                            }
-                            prevClearTime = clearTime;
-                            IpsLogger.Info($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 清理数据结束!");
-                        }
-                    }
-                }
-            }
-            catch (Exception ex)
-            {
-                IpsLogger.Error($"清理数据异常", ex);
-            }
-
-        }
-    }
-}

+ 1 - 1
ipsservice/Ips.Service.CapServer/Ips.Service.CapServer.csproj

@@ -25,7 +25,7 @@
 		<FrameworkReference Include="Microsoft.AspNetCore.App" />
 	</ItemGroup>
 	<ItemGroup>
-		<PackageReference Include="DevExpress.Win.Design" Version="23.2.3" PrivateAssets="all" />
+		<PackageReference Include="DevExpress.Win.Design" Version="24.1.6" PrivateAssets="all" />
 		<PackageReference Include="Grpc.AspNetCore" Version="2.66.0" />
 	</ItemGroup>
 	<ItemGroup>

+ 2 - 1
ipsservice/Ips.Service.CapServer/Program.cs

@@ -47,7 +47,8 @@ namespace Ips.Service.CapServer
             };
             Application.ThreadException += (sender, e) =>
             {
-                IpsLogger.Error("出现未处理的线程异常!", e.Exception);
+                if (e.Exception.GetType() != typeof(TaskCanceledException))
+                    IpsLogger.Error("出现未处理的线程异常!", e.Exception);
             };
         }
         /// <summary>

+ 1 - 1
ipsservice/Ips.Service.CapServer/Service/AdcService.cs

@@ -30,7 +30,7 @@ namespace Ips.Service.CapServer
             }
             try
             {
-                if (dto.CardType != AppConst.CardType)
+                if (dto.CardType.GetEnumDisplayName() != AppConst.CardType.GetEnumDisplayName())
                 {
                     throw new Exception($"采集卡类型不匹配,采集服务配置={AppConst.CardType.GetEnumDisplayName()},任务设置={dto.CardType.GetEnumDisplayName()}");
                 }

+ 1 - 1
ipsservice/Ips.Service.CpuServe/Ips.Service.CpuServe.csproj

@@ -25,7 +25,7 @@
 		<FrameworkReference Include="Microsoft.AspNetCore.App" />
 	</ItemGroup>
 	<ItemGroup>
-		<PackageReference Include="DevExpress.Win.Design" Version="23.2.3" PrivateAssets="all" />
+		<PackageReference Include="DevExpress.Win.Design" Version="24.1.6" PrivateAssets="all" />
 		<PackageReference Include="Grpc.AspNetCore" Version="2.66.0" />
 	</ItemGroup>
 	<ItemGroup>

+ 1 - 4
ipsservice/Ips.Service.GpuServer/DirectXForm1.cs

@@ -36,10 +36,7 @@ namespace Ips.Service.GpuServer
             LoadParams();
             if (int.TryParse(_localPort, out int intPort))
             {
-                var controllerXml = $"{AppDomain.CurrentDomain.FriendlyName}.xml";
-                var dtoXml = "Ips.Library.Entity.xml";
-                var staticDir = new string[] { "Download","Upload", "Logs"};
-                WebApiHelper.Start(intPort, controllerXml, dtoXml, staticDir);
+                WebApiHelper.Start(intPort, "Ips.Library.Entity.xml");
                 this.FormClosing += (_, _) => WebApiHelper.Stop();
                 _inited = true;
                 await StateRpt();

+ 1 - 1
ipsservice/Ips.Service.GpuServer/Ips.Service.GpuServer.csproj

@@ -25,7 +25,7 @@
 		<FrameworkReference Include="Microsoft.AspNetCore.App" />
 	</ItemGroup>
 	<ItemGroup>
-		<PackageReference Include="DevExpress.Win.Design" Version="23.2.3" PrivateAssets="all" />
+		<PackageReference Include="DevExpress.Win.Design" Version="24.1.6" PrivateAssets="all" />
 		<PackageReference Include="Grpc.AspNetCore" Version="2.66.0" />
 	</ItemGroup>
 	<ItemGroup>

+ 2 - 2
ipstool/ipssps2/Ips.Sps.Core/Ips.Sps.Core.csproj

@@ -11,8 +11,8 @@
 		<DebugSymbols>false</DebugSymbols>
 	</PropertyGroup>
 	<ItemGroup>
-		<PackageReference Include="DevExpress.Mvvm" Version="23.2.3" PrivateAssets="all" />
-		<PackageReference Include="DevExpress.Xpo" Version="23.2.3" PrivateAssets="all" />
+		<PackageReference Include="DevExpress.Mvvm" Version="24.1.6" PrivateAssets="all" />
+		<PackageReference Include="DevExpress.Xpo" Version="24.1.6" PrivateAssets="all" />
 		<PackageReference Include="PropertyChanged.Fody" Version="4.1.0">
 			<PrivateAssets>all</PrivateAssets>
 		</PackageReference>

+ 1 - 1
ipstool/ipssps2/Ips.Sps.Data/Ips.Sps.Data.csproj

@@ -19,7 +19,7 @@
 	</PropertyGroup>
 
 	<ItemGroup>
-		<PackageReference Include="DevExpress.Xpo" Version="23.2.3" PrivateAssets="all" />
+		<PackageReference Include="DevExpress.Xpo" Version="24.1.6" PrivateAssets="all" />
 	</ItemGroup>
 
 	<ItemGroup>

+ 6 - 6
ipstool/ipssps2/Ips.Sps.Host.Win/Ips.Sps.Host.Win.csproj

@@ -25,7 +25,7 @@
 		<FrameworkReference Include="Microsoft.AspNetCore.App" />
 	</ItemGroup>
 	<ItemGroup>
-		<PackageReference Include="DevExpress.Win.Design" Version="23.2.3" PrivateAssets="all" />
+		<PackageReference Include="DevExpress.Win.Design" Version="24.1.6" PrivateAssets="all" />
 	</ItemGroup>
 	<ItemGroup>
 		<ProjectReference Include="..\..\..\ipslib\Ips.Library.Entity\Ips.Library.Entity.csproj" />
@@ -126,13 +126,13 @@
 	</ItemGroup>
 	<!--将解决方案目录中的文件复制输出目录(xcopy命令是文件较新才会复制)-->
 	<Target Name="PostBuild" AfterTargets="PostBuildEvent">
-		<Exec Command="xcopy $(SolutionDir)AddIns $(PublishDir)AddIns\ /d /ey" Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"/>
+		<Exec Command="xcopy $(SolutionDir)AddIns $(PublishDir)AddIns\ /d /ey" Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'" />
 		<Exec Command="xcopy $(SolutionDir)AppData $(PublishDir)AppData\ /d /ey" Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'" />
-		<Exec Command="xcopy $(SolutionDir)ipscli $(PublishDir)ipscli\ /d /ey" Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"/>
+		<Exec Command="xcopy $(SolutionDir)ipscli $(PublishDir)ipscli\ /d /ey" Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'" />
 
-		<Exec Command="xcopy $(SolutionDir)AddIns $(TargetDir)AddIns\ /d /ey" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"/>
-		<Exec Command="xcopy $(SolutionDir)AppData $(TargetDir)AppData\ /d /ey" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"/>
-		<Exec Command="xcopy $(SolutionDir)ipscli $(TargetDir)ipscli\ /d /ey" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"/>
+		<Exec Command="xcopy $(SolutionDir)AddIns $(TargetDir)AddIns\ /d /ey" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'" />
+		<Exec Command="xcopy $(SolutionDir)AppData $(TargetDir)AppData\ /d /ey" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'" />
+		<Exec Command="xcopy $(SolutionDir)ipscli $(TargetDir)ipscli\ /d /ey" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'" />
 	</Target>
 
 	<!--发布时删除pdb文件-->

+ 2 - 3
ipstool/ipssps2/Ips.Sps.Host.Win/MainWin.cs

@@ -61,7 +61,7 @@ namespace Ips.Sps
         private void MainWin_Load(object sender, EventArgs e)
         {
             //Ips.Sps.Controllers.dll被反射加载,不调用一下运行单文件发布的程序会找不到此程序集
-            var t = new HomeController();
+            //var t = new HomeController();
             ServerContext.Instance.Init();
             string autoClearPath = ToolConfig.GetAppSetting("FileClearPath");
             if (autoClearPath.IsNotNullOrWhitespace())
@@ -69,8 +69,7 @@ namespace Ips.Sps
                 _driveMonitor = new DriveMonitor(autoClearPath);
                 _driveMonitor.Start();
             }
-            var staticDir = new string[] { "Download", "Upload", "Logs" };
-            WebApiHelper.Start(Convert.ToInt32(SpsConst.HttpPort), $"Ips.Sps.Controllers.xml", "Ips.Library.Entity.xml", staticDir);
+            WebApiHelper.Start(Convert.ToInt32(SpsConst.HttpPort),  "Ips.Library.Entity.xml",null, $"Ips.Sps.Controllers.xml");
             IpsLogger.Info("系统启动完成");
             SplashScreenManager.CloseForm();
         }

+ 4 - 4
ipstool/ipssps2/Ips.Sps.Host.Win/MainWin.resx

@@ -117,8 +117,8 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
-  <assembly alias="DevExpress.Data.v23.2" name="DevExpress.Data.v23.2, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
-  <data name="btnOpenApi.ImageOptions.SvgImage" type="DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v23.2" mimetype="application/x-microsoft.net.object.bytearray.base64">
+  <assembly alias="DevExpress.Data.v24.1" name="DevExpress.Data.v24.1, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
+  <data name="btnOpenApi.ImageOptions.SvgImage" type="DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v24.1" mimetype="application/x-microsoft.net.object.bytearray.base64">
     <value>
         AAEAAAD/////AQAAAAAAAAAMAgAAAFlEZXZFeHByZXNzLkRhdGEudjIzLjIsIFZlcnNpb249MjMuMi4z
         LjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49Yjg4ZDE3NTRkNzAwZTQ5YQUBAAAAHURl
@@ -146,7 +146,7 @@
         MTEuNiwxNC40eiIgY2xhc3M9IkJsdWUiIC8+DQo8L3N2Zz4L
 </value>
   </data>
-  <data name="btnSvrs.ImageOptions.SvgImage" type="DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v23.2" mimetype="application/x-microsoft.net.object.bytearray.base64">
+  <data name="btnSvrs.ImageOptions.SvgImage" type="DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v24.1" mimetype="application/x-microsoft.net.object.bytearray.base64">
     <value>
         AAEAAAD/////AQAAAAAAAAAMAgAAAFlEZXZFeHByZXNzLkRhdGEudjIzLjIsIFZlcnNpb249MjMuMi4z
         LjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49Yjg4ZDE3NTRkNzAwZTQ5YQUBAAAAHURl
@@ -166,7 +166,7 @@
         Pgs=
 </value>
   </data>
-  <data name="btnSysLog.ImageOptions.SvgImage" type="DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v23.2" mimetype="application/x-microsoft.net.object.bytearray.base64">
+  <data name="btnSysLog.ImageOptions.SvgImage" type="DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v24.1" mimetype="application/x-microsoft.net.object.bytearray.base64">
     <value>
         AAEAAAD/////AQAAAAAAAAAMAgAAAFlEZXZFeHByZXNzLkRhdGEudjIzLjIsIFZlcnNpb249MjMuMi4z
         LjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49Yjg4ZDE3NTRkNzAwZTQ5YQUBAAAAHURl

+ 1 - 1
ipstool/ipssps2/Ips.Sps.Scheduling/Ips.Sps.Scheduling.csproj

@@ -14,7 +14,7 @@
 	</ItemGroup>
 
 	<ItemGroup>
-		<PackageReference Include="DevExpress.Xpo" Version="23.2.3" PrivateAssets="all" />
+		<PackageReference Include="DevExpress.Xpo" Version="24.1.6" PrivateAssets="all" />
 	</ItemGroup>
 
 </Project>