12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace XdCxRhDW.Core.Api
- {
- /// <summary>
- /// 星历推算帮助类.该类调用了Tle2XYZ.exe进程
- /// </summary>
- public static class ReSampleHelper
- {
- private static readonly DateTime dtZero = new DateTime(1970, 1, 1, 0, 0, 0, 0);
- private static string exePath = "xcorr";
- private const string exeName = "ReSample.exe";
- /// <summary>
- /// 设置【ReSample.exe】文件所在路径,支持相对路径
- /// </summary>
- public static void SetExePath(string path)
- {
- if (string.IsNullOrWhiteSpace(path)) return;
- if (path.StartsWith("\\"))//相对路径要么开头不带\,要么是 .\
- path = path.Remove(0, 1);
- exePath = path;
- }
- /// <summary>
- /// 变采样
- /// </summary>
- /// <param name="inFile">输入文件</param>
- /// <param name="outFile">输出文件</param>
- /// <param name="insertFactor">插入因子</param>
- /// <param name="extFactor">抽取因子</param>
- /// <returns>成功后返回文件,失败后返回null</returns>
- public static string Resample(string inFile,string outFile,int insertFactor,int extFactor)
- {
- if (string.IsNullOrWhiteSpace(exePath))
- throw new Exception($"请先调用SetExePath指定{exeName}进程所在路径,支持相对路径");
- if (!Directory.Exists(exePath))
- throw new Exception($"路径[{exePath}]不存在");
- var exeFile = Path.Combine(exePath, exeName);
- if (!File.Exists(exeFile))
- throw new Exception($"文件[{exeFile}]不存在");
- Process p = new Process();
- p.StartInfo.WorkingDirectory = exePath;
- p.StartInfo.FileName = exeFile;
- p.StartInfo.Arguments = $"'{inFile}' '{outFile}' {insertFactor} {extFactor}";
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.UseShellExecute = false;
- p.Start();
- var succeed = p.WaitForExit(10000);
- if (!succeed)
- {
- throw new Exception($"进程[{exeName}]超时未完成!");
- }
- var res=p.StandardOutput.ReadToEnd();
- if (res.StartsWith("1:"))
- {
- return outFile;
- }
- else
- {
- return null;
- }
- }
- }
- }
|