private string BulidArgXml(FileIdentify file) { try { InputArg arg = _argMode.Copy(); arg.InputFilename = file.FileName; if (file.Identify.OrbitDateTime == DateTime.MinValue)//没解析出来时间。 { PrintInfo("获取轨道时间失败:" + file.FileName); } else if (_orbitDataTime == null || (Math.Abs((_orbitDataTime.Value - file.Identify.OrbitDateTime).TotalMinutes) >= 20)) { _orbitDataTime = file.Identify.OrbitDateTime; arg.PervObservationDate = _orbitDataTime.Value.ToString("yyyyMMdd"); arg.PervObservationTime = _orbitDataTime.Value.ToString("HHmm"); arg.OrbitIdentify = _orbitDataTime.Value.ToString("HHmm"); } else { arg.PervObservationDate = _orbitDataTime.Value.ToString("yyyyMMdd"); arg.PervObservationTime = _orbitDataTime.Value.ToString("HHmm"); arg.OrbitIdentify = _orbitDataTime.Value.ToString("HHmm"); } string xml = Path.Combine(arg.OutputDir, "batchArgs\\" + Path.GetFileName(file.FileName) + ".xml"); arg.ToXml(xml); return(xml); } catch (Exception ex) { PrintInfo("创建执行程序参数失败 " + ex.Message); return(null); } }
private void timer_Elapsed(object sender, ElapsedEventArgs e) { string[] fs = null; if (_isFileList) { fs = _fileList; } else { if (string.IsNullOrWhiteSpace(_searchOption)) { fs = Directory.GetFiles(_path); } else { fs = Directory.GetFiles(_path, _searchOption); } } if (fs == null || fs.Length == 0) { return; } //初步筛选扫描到的文件。 List <FileIdentify> newFiles = new List <FileIdentify>(); foreach (string f in fs) { if (_processedFiles.Contains(f))//过滤已经处理过的数据 { continue; } FileIdentify fileIdentify = new FileIdentify(f); if (fileIdentify.Identify == null) { PrintInfo("获取文件标识失败:" + Path.GetFileName(f)); continue; } newFiles.Add(fileIdentify); } if (newFiles.Count == 0) { return; } PrintInfo("扫描新的文件加入待处理队列:"); StringBuilder bat = new StringBuilder(); FileIdentify[] files = newFiles.OrderBy((identify) => { return(identify.Identify.OrbitDateTime); }).ToArray();//按轨道市时间排序 foreach (FileIdentify file in files) { string xml = BulidArgXml(file); if (!string.IsNullOrWhiteSpace(xml) && File.Exists(xml)) { TaskQueueEnqueue(xml); _processedFiles.Add(file.FileName); bat.AppendLine(); PrintInfo(file.FileName); } } }