| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- using DevExpress.Pdf;
- using Ips.Library.Basic;
- using Ips.Library.Entity;
- using Ips.Library.Signals;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace Ips.Service.GpuServer
- {
- /// <summary>
- /// 同频对消处理服务(未完成,参数模型都是拷贝的参估的)
- /// </summary>
- public class TpdxService
- {
- private bool isBusy = false;
- private string exeName = "DefruiterGpu";
- /// <summary>
- /// 开始
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<CorResult[]> StartAsync(CorParams dto)
- {
- if (isBusy)
- {
- throw new Exception("上次GPU调用未结束");
- }
- //直接从采集上下载文件到本地
- string[] files = new string[] { dto.File1, dto.File2 };
- for (int i = 0; i < 2; i++)
- {
- string localFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Download", files[i]);
- if (!File.Exists(localFile))
- {
- var res = await HttpHelper.DownloadFileAsync(dto.AdFileDownloadUrl, files[i], localFile);
- if (!res)
- {
- throw new Exception($"文件下载失败,url=[{dto.AdFileDownloadUrl}?filename={files[i]}]");
- }
- }
- if (i == 0)
- dto.File1 = localFile;
- else
- dto.File2 = localFile;
- }
- string ifile = null;
- string ofile = null;
- long fs = 0;
- double fc = 0;
- double bw = 0;
- double ps = 0;
- int mod = 0;
- int order = 0;
- return await Task.Run(() =>
- {
- try
- {
- isBusy = true;
- Process pro = new Process();
- pro.StartInfo.FileName = $"同频对消\\{exeName}.exe";
- pro.StartInfo.CreateNoWindow = true;
- pro.StartInfo.RedirectStandardError = true;
- pro.StartInfo.RedirectStandardOutput = true;
- pro.StartInfo.UseShellExecute = false;
- pro.StartInfo.Arguments = $"\"{ifile}\" \"{ofile}\" {fs} {fc} {bw} {mod} {order}";
- Console.WriteLine(pro.StartInfo.Arguments);
- pro.Start();
- Stopwatch sw = new Stopwatch();
- IpsLogger.Info($"开始同频对消.可打开Logs目录查看{exeName}.exe命令行参数详细");
- IpsLogger.Info($"开始同频对消.{exeName}.exe参数={pro.StartInfo.Arguments}", false);
- sw.Start();
- var succeed = pro.WaitForExit(30 * 1000);//timeout
- if (!succeed)
- {
- Stop();
- throw new Exception($"同频对消超时");
- }
- var res = pro.StandardError.ReadToEnd();
- sw.Stop();
- if (sw.ElapsedMilliseconds < 800)
- {
- throw new Exception("没有GPU");
- }
- if (!string.IsNullOrWhiteSpace(res))
- {
- throw new Exception(res);
- }
- if (!File.Exists(ofile))
- {
- throw new Exception("没有输出文件");
- }
- else
- {
- FileInfo f = new FileInfo(ofile);
- if (f.Length == 0)
- {
- try
- {
- File.Delete(ofile);
- }
- catch
- { }
- throw new Exception("没有输出文件");
- }
- }
- return new CorResult[0];
- }
- finally
- {
- isBusy = false;
- }
- });
- }
- /// <summary>
- /// 停止
- /// </summary>
- public void Stop()
- {
- var pros = Process.GetProcessesByName(exeName);
- foreach (var item in pros)
- {
- try
- {
- item.Kill();
- }
- catch
- { }
- }
- }
- }
- }
|