zoulei hace 1 año
padre
commit
2676b4e335

+ 1 - 1
XdCxRhDW.App/CorTools/DetectToolForm.cs

@@ -431,7 +431,7 @@ namespace XdCxRhDW.App.CorTools
                 content.Add(fileContent, "file", Path.GetFileName(filePath));
 
                 // 发送上传请求
-               var filedto = HttpHelper.PostRequest<FileDto>(uploadUri, content);
+               var filedto = HttpHelper.PostRequest<FileUploadResDto>(uploadUri, content);
                 if (filedto != null)
                 {
                     file = filedto.FileName;

+ 13 - 2
XdCxRhDW.App/ExtensionsDev/SearchLookUpEditExtension.cs

@@ -34,6 +34,7 @@ namespace ExtensionsDev
             ctrl.Properties.ShowClearButton = showClearBtn;
             ctrl.Properties.ShowFooter = false;
             ctrl.Properties.ShowPopupShadow = true;
+            
             return ctrl;
         }
 
@@ -57,13 +58,23 @@ namespace ExtensionsDev
         /// </summary>
         /// <param name="ctrl"></param>
         /// <param name="data">数据源</param>
-        public static SearchLookUpEdit SetData<T>(this SearchLookUpEdit ctrl, IEnumerable<T> data)
+        public static SearchLookUpEdit SetData<T>(this SearchLookUpEdit ctrl, IEnumerable<T> data, string displayField = "")
         {
             ctrl.QueryPopUp += Ctrl_QueryPopUp;
             ctrl.Properties.DataSource = data;
             GridView view = ctrl.Properties.View;
             view.OptionsView.ShowColumnHeaders = true;
             view.GridControl.Init();
+            ctrl.CustomDisplayText += (sender, e) =>
+            {
+                if (e.Value == null) return;
+                if (string.IsNullOrWhiteSpace(displayField))
+                    e.DisplayText = e.Value.ToString();
+                else
+                {
+                    e.DisplayText = typeof(T).GetProperty(displayField).GetValue(e.Value).ToString();
+                }
+            };
             return ctrl;
         }
 
@@ -80,7 +91,7 @@ namespace ExtensionsDev
                 var attrDisplayName = prop.GetCustomAttribute<DisplayNameAttribute>();
                 if (attrDisplay == null && attrDisplayName == null)
                     column.Visible = false;
-                else if (attrDisplay != null && attrDisplay.AutoGenerateField == false)
+                else if (attrDisplay != null && attrDisplay.GetAutoGenerateFilter() != null && !attrDisplay.AutoGenerateFilter)
                     column.Visible = false;
                 else
                     column.Visible = true;

+ 0 - 9
XdCxRhDW.App/XdCxRhDW.App.csproj

@@ -516,12 +516,6 @@
     </ProjectReference>
   </ItemGroup>
   <ItemGroup>
-    <None Include="DLL_DTO_DOA_DW.dll">
-      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-    </None>
-    <None Include="DLL_SC_2X1D_DW.dll">
-      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-    </None>
     <None Include="Core\coc.exe">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
@@ -549,9 +543,6 @@
     <EmbeddedResource Include="UserControl\X3DFGDOPParam .resx">
       <DependentUpon>X3DFGDOPParam .cs</DependentUpon>
     </EmbeddedResource>
-    <None Include="DLL_11J.dll">
-      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-    </None>
     <Content Include="Image\DfoLine.svg">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>

+ 2 - 2
XdCxRhDW.Core/Api/PosApi.cs

@@ -21,8 +21,8 @@ namespace XdCxRhDW.Core.Api
         //两星一地带参定位
         private const string X2D1 = @"AddIns\DLL_SC_2X1D_DW.dll";
 
-        //三星双时差带参、三星双时差无参、三星双频差带参、双星时频差带参、两星一地无参
-        private const string OtherPos = @"AddIns\DLL_11J.dll";
+        //三星双时差带参、三星双时差无参、三星双频差带参、双星时频差带参、两星一地无参定位及时差线
+        private const string OtherPos = @"AddIns\DLL_11J_DW.dll";
 
         [DllImport(XDCX, EntryPoint = "XD_CX_DW", CallingConvention = CallingConvention.Cdecl)]//一星一地测向带参
         private extern static void X1D1_Pos20240305_Core(double[] mainSat, double[] satStation, double[] cdbStation, double[] cxStation, double[] refStation, double[] zone, double theta, double tarDto, double refDto, double[] res);

BIN
XdCxRhDW.App/DLL_11J.dll → XdCxRhDW.Core/DLL_11J_DW.dll


+ 0 - 0
XdCxRhDW.App/DLL_DTO_DOA_DW.dll → XdCxRhDW.Core/DLL_DTO_DOA_DW.dll


+ 0 - 0
XdCxRhDW.App/DLL_SC_2X1D_DW.dll → XdCxRhDW.Core/DLL_SC_2X1D_DW.dll


+ 15 - 0
XdCxRhDW.Core/XdCxRhDW.Core.csproj

@@ -137,5 +137,20 @@
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
   </ItemGroup>
+  <ItemGroup>
+    <None Include="DLL_11J_DW.dll">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="DLL_DTO_DOA_DW.dll">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="DLL_SC_2X1D_DW.dll">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

+ 6 - 31
XdCxRhDW.WebApi/Controllers/DetectCgController.cs

@@ -19,6 +19,7 @@ namespace XdCxRhDW.WebApi.Controllers
     /// </summary>
     public class DetectCgController : BaseController
     {
+        private readonly string uploadFolder;
         private readonly TestService service;
 
         /// <summary>
@@ -27,12 +28,12 @@ namespace XdCxRhDW.WebApi.Controllers
         /// <param name="service"></param>
         public DetectCgController(TestService service)
         {
+            this.uploadFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot");
             this.service = service;
         }
         private static readonly object thisLock = new object();
         Dictionary<string, XcorrUtils> keyValues = new Dictionary<string, XcorrUtils>();
 
-        private string UploadFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot");
         private (bool, string) ValidateCalcParam(CalcDto dto)
         {
             if (dto == null)
@@ -78,8 +79,8 @@ namespace XdCxRhDW.WebApi.Controllers
         public async Task<AjaxResult<EstimationResDto>> EstimationCalc(CalcDto dto)
         {
             var token = Request.GetCorrelationId().ToString();
-            dto.file1 = Path.Combine(UploadFolder, dto.file1);
-            dto.file2 = Path.Combine(UploadFolder, dto.file2);
+            dto.file1 = Path.Combine(uploadFolder, dto.file1);
+            dto.file2 = Path.Combine(uploadFolder, dto.file2);
             var vpres = ValidateCalcParam(dto);
             if (!vpres.Item1)
             {
@@ -227,7 +228,7 @@ namespace XdCxRhDW.WebApi.Controllers
         public async Task<AjaxResult<IEnumerable<DetectResDto>>> DetectCalc(DetectDto dto)
         {
             var token = Request.GetCorrelationId().ToString();
-            dto.file1 = Path.Combine(UploadFolder, dto.file1);
+            dto.file1 = Path.Combine(uploadFolder, dto.file1);
             var vpres = ValidateDetectParam(dto);
             if (!vpres.Item1)
             {
@@ -303,32 +304,6 @@ namespace XdCxRhDW.WebApi.Controllers
 
         //}
 
-        /// <summary>
-        /// 上传文件
-        /// </summary>
-        /// <returns></returns>
-        [HttpPost, SwaggerForm]
-        public async Task<AjaxResult<FileDto>> UploadFile()
-        {
-            if (!Request.Content.IsMimeMultipartContent("form-data"))
-            {
-                return Error<FileDto>("请求数据不是multipart/form-data类型");
-            }
-            var provider = new MultipartMemoryStreamProvider();
-            await Request.Content.ReadAsMultipartAsync(provider);
-            Directory.CreateDirectory(UploadFolder);
-            var content = provider.Contents.First();
-            var fileName = Guid.NewGuid().ToString() + ".dat";
-            var fileData = await content.ReadAsByteArrayAsync();
-            FileDto fileDto = new FileDto();
-            fileDto.FileName = fileName;
-            // 将文件保存到本地文件夹中
-            var filePath = Path.Combine(UploadFolder, fileName);
-            using (var fileStream = new FileStream(filePath, FileMode.Create))
-            {
-                await fileStream.WriteAsync(fileData, 0, fileData.Length);
-            }
-            return Success(fileDto);
-        }
+       
     }
 }

+ 91 - 0
XdCxRhDW.WebApi/Controllers/FileController.cs

@@ -0,0 +1,91 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net.Http;
+using System.Text;
+using System.Threading.Tasks;
+using System.Web;
+using System.Web.Http;
+using XdCxRhDw.Dto;
+
+namespace XdCxRhDW.WebApi.Controllers
+{
+    /// <summary>
+    /// 检测参估功能相关接口
+    /// </summary>
+    public class FileController : BaseController
+    {
+        private readonly string uploadFolder;
+        
+        /// <summary>
+        /// 
+        /// </summary>
+        public FileController()
+        {
+            this.uploadFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot");
+        }
+
+        /// <summary>
+        /// 上传文件
+        /// </summary>
+        /// <param name="file">文件</param>
+        /// <returns></returns>
+        [HttpPost, SwaggerForm]
+        public async Task<AjaxResult<FileUploadResDto>> UploadFileAsync(HttpPostedFileBase httpFile)
+        {
+            //if (!Request.Content.IsMimeMultipartContent("form-data"))
+            //{
+            //    return Error<FileDto>("请求数据不是multipart/form-data类型");
+            //}
+            var provider = new MultipartMemoryStreamProvider();
+            await Request.Content.ReadAsMultipartAsync(provider);
+            Directory.CreateDirectory(uploadFolder);
+            var content = provider.Contents.First();
+            var fileName = Guid.NewGuid().ToString() + ".dat";
+            var fileData = await content.ReadAsByteArrayAsync();
+            FileUploadResDto fileDto = new FileUploadResDto();
+            fileDto.FileName = fileName;
+            // 将文件保存到本地文件夹中
+            var filePath = Path.Combine(uploadFolder, fileName);
+            using (var fileStream = new FileStream(filePath, FileMode.Create))
+            {
+                await fileStream.WriteAsync(fileData, 0, fileData.Length);
+            }
+
+            //清除1个小时之前的文件
+            _ = Task.Run(() => {
+
+                var files=Directory.EnumerateFiles(uploadFolder);
+                foreach (var file in files)
+                {
+                    FileInfo info=new FileInfo(file);
+                    if (info.CreationTime<DateTime.Now.AddHours(-1))
+                    {
+                        try
+                        {
+                            info.Delete();
+                        }
+                        catch
+                        {
+                        }
+                    }
+                }
+            });
+            return Success(fileDto);
+        }
+
+        /// <summary>
+        /// 文件下载
+        /// </summary>
+        /// <param name="dto">文件下载参数,值来自文件上传返回的结果</param>
+        /// <returns></returns>
+        [HttpPost]
+        public async Task<AjaxResult<byte[]>> DownloadFileAsync(FileDownloadDto dto)
+        {
+            string file=Path.Combine(uploadFolder, dto.FileName);
+            var data=File.ReadAllBytes(file);
+            return Success(data);
+        }
+    }
+}

+ 24 - 20
XdCxRhDW.WebApi/Startup.cs

@@ -34,6 +34,7 @@ using XdCxRhDw.Dto;
 using Autofac.Core;
 using Microsoft.Owin.FileSystems;
 using Microsoft.Owin.StaticFiles;
+using System.Threading.Tasks;
 
 [assembly: OwinStartup(typeof(XdCxRhDW.WebApi.Startup))]
 
@@ -50,21 +51,18 @@ namespace XdCxRhDW.WebApi
         /// <param name="app"></param>
         public void Configuration(IAppBuilder app)
         {
-            app.UseStaticFiles("/wwwroot");
-            Directory.CreateDirectory("wwwroot");
-            //启用静态目录浏览
-            //string root = AppDomain.CurrentDomain.BaseDirectory;
-            //var physicalFileSystem = new PhysicalFileSystem(Path.Combine(root, "wwwroot"));
-            //var options = new FileServerOptions
-            //{
-            //    RequestPath = PathString.Empty,
-            //    EnableDefaultFiles = true,
-            //    FileSystem = physicalFileSystem
-            //};
-            //options.StaticFileOptions.FileSystem = physicalFileSystem;
-            //options.StaticFileOptions.ServeUnknownFileTypes = false;
-            //app.UseFileServer(options);
-
+            //启用目录浏览和静态文件
+            var physicalFileSystem = new PhysicalFileSystem(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot"));//目录浏览物理地址
+            var options = new FileServerOptions
+            {
+                RequestPath = new PathString("/wwwroot"),//目录浏览地址
+                EnableDefaultFiles = true,
+                EnableDirectoryBrowsing = true,//启用目录浏览
+                FileSystem = physicalFileSystem
+            };
+            options.StaticFileOptions.FileSystem = physicalFileSystem;
+            options.StaticFileOptions.ServeUnknownFileTypes = true;//允许下载wwwroot中的所有类型文件
+            app.UseFileServer(options);
 
             HttpConfiguration config = new HttpConfiguration();
             IEnumerable<ModelValidatorProvider> modelValidatorProviders = config.Services.GetModelValidatorProviders();
@@ -115,7 +113,7 @@ namespace XdCxRhDW.WebApi
                 //单例模式注入Service
                 builder.RegisterTypes(serviceType).SingleInstance();
             }
-            
+
             var container = builder.Build();
             config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
 
@@ -191,15 +189,21 @@ namespace XdCxRhDW.WebApi
                 base.OnException(context);
                 Serilog.Log.Error(context.Exception, context.Exception.Message);
                 //LogFile.WriteError(context.Exception.Message);
+                string msg = context.Exception.Message;
+                if (context.Exception.GetType() == typeof(FileNotFoundException))
+                {
+                    //防止程序路径泄露到前端
+                    msg = "未能找到文件" + context.Exception.Message.Substring(context.Exception.Message.LastIndexOf("\\") + 1);
+                }
                 throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.OK)
                 {
                     Content = new StringContent(
                    JsonConvert.SerializeObject(
-                    new
+                    new AjaxResult
                     {
-                        code = -1,
-                        data = "",
-                        msg = context.Exception.Message
+                        code = 0,
+                        data = null,
+                        msg = msg
                     }), Encoding.UTF8, "text/json")
                 });
             }

+ 1 - 0
XdCxRhDW.WebApi/XdCxRhDW.WebApi.csproj

@@ -186,6 +186,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="App_Start\SwaggerConfig.cs" />
+    <Compile Include="Controllers\FileController.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Controllers\BaseController.cs" />
     <Compile Include="Controllers\DetectCgController.cs" />

+ 0 - 0
XdCxRhDw.Dto/Class1.cs → XdCxRhDw.Dto/EnumPosResTypeDto.cs


+ 19 - 0
XdCxRhDw.Dto/FileDownloadDto.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace XdCxRhDw.Dto
+{
+    /// <summary>
+    /// 文件下载参数DTO
+    /// </summary>
+    public class FileDownloadDto
+    {
+        /// <summary>
+        /// 上传文件成功后返回的名称
+        /// </summary>
+        public string FileName { get; set; }
+    }
+}

+ 2 - 2
XdCxRhDw.Dto/FileDto.cs → XdCxRhDw.Dto/FileUploadResDto.cs

@@ -7,9 +7,9 @@ using System.Threading.Tasks;
 namespace XdCxRhDw.Dto
 {
     /// <summary>
-    /// 文件DTO
+    /// 文件上传结果DTO
     /// </summary>
-    public class FileDto
+    public class FileUploadResDto
     {
         /// <summary>
         /// 上传文件后返回的名称

+ 7 - 0
XdCxRhDw.Dto/PosResQueryDto.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -20,5 +21,11 @@ namespace XdCxRhDw.Dto
         /// 结束时间
         /// </summary>
         public DateTime EndTime { get; set; }
+
+        /// <summary>
+        /// Test
+        /// </summary>
+        [Range(5, 10, ErrorMessage = "5-10")]
+        public int Test { get; set; }
     }
 }

+ 3 - 2
XdCxRhDw.Dto/XdCxRhDw.Dto.csproj

@@ -48,11 +48,12 @@
   <ItemGroup>
     <Compile Include="CalcDto.cs" />
     <Compile Include="AjaxResult.cs" />
-    <Compile Include="Class1.cs" />
+    <Compile Include="FileDownloadDto.cs" />
+    <Compile Include="EnumPosResTypeDto.cs" />
     <Compile Include="DetectDto.cs" />
     <Compile Include="DetectResDto.cs" />
     <Compile Include="EstimationResDto.cs" />
-    <Compile Include="FileDto.cs" />
+    <Compile Include="FileUploadResDto.cs" />
     <Compile Include="PosDto\RHNoXlPosDto.cs" />
     <Compile Include="PosDto\RHNoXlNoParPosDto.cs" />
     <Compile Include="PosDto\RHNoParPosDto.cs" />