gongqiuhong 1 year ago
parent
commit
22a0014984
1 changed files with 63 additions and 20 deletions
  1. 63 20
      Service/X2D1NoRefTaskServer/Service/TaskService.cs

+ 63 - 20
Service/X2D1NoRefTaskServer/Service/TaskService.cs

@@ -393,18 +393,25 @@ namespace X2D1NoRefTaskServer.Service
 
                         IOrderedEnumerable<IGrouping<DateTime, HistoryFile>> groups = null;
                         groups = files.Select(f => FileToHistoryFile(dto, f, canConnected)).GroupBy(m => m.CapTime).OrderBy(m => m.Key);
-                        foreach (var item in groups)
+                        TimeSpan span = abs(groups.First().Key - preTime);
+                        var closesData = groups.First();
+                        foreach (var item in groups.Skip(1))
                         {
-                            if (cts.IsCancellationRequested) break;
-
-                            var xdgbInfos = item.GroupBy(m => m.XdIndex);
-                            foreach (var xdInfos in xdgbInfos)
+                            if (abs(preTime - item.Key) < span)
                             {
-                                var finfos = xdInfos.ToList();
-                                var capTime = finfos.First().CapTime;
-                                if (capTime < dto.StartTime) continue;
-                                if (capTime > dto.EndTime) break;
-                                if (finfos.Count < 3)
+                                span = abs(preTime - item.Key);
+                                closesData = item;
+                            }
+                        }
+                        //if (cts.IsCancellationRequested) break;
+                        var xdgbInfos = closesData.GroupBy(m => m.XdIndex);
+                        foreach (var xdInfos in xdgbInfos)
+                        {
+                            var finfos = xdInfos.ToList();
+                            var capTime = finfos.First().CapTime;
+                            //if (capTime < dto.StartTime) continue;
+                            //if (capTime > dto.EndTime) break;
+                            if (finfos.Count < 3)
                                 {
                                     LogHelper.Warning($"【任务{dto.ID}】{capTime:yyyyMMddHHmmss}时刻文件数量只有{finfos.Count}个,跳过此组数据");
                                     continue;
@@ -441,14 +448,30 @@ namespace X2D1NoRefTaskServer.Service
                                     var delay2 = taskSig.SigDelay.FirstOrDefault(p => p.SatInfoSatCode == ninfo.SatId)?.Delay;
                                     if (delay1 == null) delay1 = 0;
                                     if (delay2 == null) delay2 = 0;
-                                    LogHelper.Info($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6}],主星[{minfo.SatId}],转发时延{delay1}us");
-                                    LogHelper.Info($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6}],邻星[{ninfo.SatId}],转发时延{delay2}us");
-                                    string mainFile = await HttpHelper.UploadFileAsync(minfo.FilePath, baseUrl + "File/UploadFileAsync", token: cts.Token);//主星文件
-                                    string adjaFile = await HttpHelper.UploadFileAsync(ninfo.FilePath, baseUrl + "File/UploadFileAsync", token: cts.Token);//邻星文件
-                                    string cdbFile = await HttpHelper.UploadFileAsync(dinfo.FilePath, baseUrl + "File/UploadFileAsync", token: cts.Token);//超短文件
+                                LogHelper.Info($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6}],主星[{minfo.SatId}],转发时延{delay1}us");
+                                LogHelper.Info($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6}],邻星[{ninfo.SatId}],转发时延{delay2}us");
 
-                                    DetectDto detectDto = new DetectDto()
-                                    {
+                                while (true)
+                                {
+                                    if (!IsFileInUse(minfo.FilePath))
+                                        break;
+                                }
+                                string mainFile = await HttpHelper.UploadFileAsync(minfo.FilePath, baseUrl + "File/UploadFileAsync", token: cts.Token);//主星文件
+                                while (true)
+                                {
+                                    if (!IsFileInUse(ninfo.FilePath))
+                                        break;
+                                }
+                                string adjaFile = await HttpHelper.UploadFileAsync(ninfo.FilePath, baseUrl + "File/UploadFileAsync", token: cts.Token);//邻星文件
+                                while (true)
+                                {
+                                    if (!IsFileInUse(dinfo.FilePath))
+                                        break;
+                                }
+                                string cdbFile = await HttpHelper.UploadFileAsync(dinfo.FilePath, baseUrl + "File/UploadFileAsync", token: cts.Token);//超短文件
+
+                                DetectDto detectDto = new DetectDto()
+                                {
                                         file1 = cdbFile,//11局使用上行泄露信号进行检测
                                         dmcType = taskSig.SigType,//上行信号检测目前的算法只能使用基于能量的KY或IBS检测
                                         fsHz = minfo.FsHz,
@@ -567,9 +590,6 @@ namespace X2D1NoRefTaskServer.Service
                                 }
 
                             }
-
-
-                        }
                         ResetTime(formatFlag, ref preTime);
                         LogHelper.Info($"【任务{dto.ID}】目录[{filesDir}]中的数据处理完成");
                     }
@@ -582,6 +602,29 @@ namespace X2D1NoRefTaskServer.Service
                 StopTask(dto.ID, EnumTaskStopType.Properly, "数据处理完成,任务结束");
             }, cts.Token);
         }
+        TimeSpan abs(TimeSpan t)
+        {
+            return (t.TotalSeconds >= 0) ? t : -t;
+        }
+        private bool IsFileInUse(string fileName)
+        {
+            bool inUse = true;
+            FileStream fs = null;
+            try
+            {
+                fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None);
+                inUse = false;
+            }
+            catch
+            {
+            }
+            finally
+            {
+                if (fs != null)
+                    fs.Close();
+            }
+            return inUse;//true表示正在使用,false没有使用  
+        }
         private void ResetTime(int formatFlag, ref DateTime time)
         {
             if (formatFlag == 0)