TpdxService.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using DevExpress.Pdf;
  2. using Ips.Library.Basic;
  3. using Ips.Library.Entity;
  4. using Ips.Library.Signals;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. namespace Ips.Service.GpuServer
  14. {
  15. /// <summary>
  16. /// 同频对消处理服务(未完成,参数模型都是拷贝的参估的)
  17. /// </summary>
  18. public class TpdxService
  19. {
  20. private bool isBusy = false;
  21. private string exeName = "DefruiterGpu";
  22. /// <summary>
  23. /// 开始
  24. /// </summary>
  25. /// <param name="dto"></param>
  26. /// <returns></returns>
  27. public async Task<CorResult[]> StartAsync(CorParams dto)
  28. {
  29. if (isBusy)
  30. {
  31. throw new Exception("上次GPU调用未结束");
  32. }
  33. //直接从采集上下载文件到本地
  34. string[] files = new string[] { dto.File1, dto.File2 };
  35. for (int i = 0; i < 2; i++)
  36. {
  37. string localFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Download", files[i]);
  38. if (!File.Exists(localFile))
  39. {
  40. var res = await HttpHelper.DownloadFileAsync(dto.AdFileDownloadUrl, files[i], localFile);
  41. if (!res)
  42. {
  43. throw new Exception($"文件下载失败,url=[{dto.AdFileDownloadUrl}?filename={files[i]}]");
  44. }
  45. }
  46. if (i == 0)
  47. dto.File1 = localFile;
  48. else
  49. dto.File2 = localFile;
  50. }
  51. string ifile = null;
  52. string ofile = null;
  53. long fs = 0;
  54. double fc = 0;
  55. double bw = 0;
  56. double ps = 0;
  57. int mod = 0;
  58. int order = 0;
  59. return await Task.Run(() =>
  60. {
  61. try
  62. {
  63. isBusy = true;
  64. Process pro = new Process();
  65. pro.StartInfo.FileName = $"同频对消\\{exeName}.exe";
  66. pro.StartInfo.CreateNoWindow = true;
  67. pro.StartInfo.RedirectStandardError = true;
  68. pro.StartInfo.RedirectStandardOutput = true;
  69. pro.StartInfo.UseShellExecute = false;
  70. pro.StartInfo.Arguments = $"\"{ifile}\" \"{ofile}\" {fs} {fc} {bw} {mod} {order}";
  71. Console.WriteLine(pro.StartInfo.Arguments);
  72. pro.Start();
  73. Stopwatch sw = new Stopwatch();
  74. IpsLogger.Info($"开始同频对消.可打开Logs目录查看{exeName}.exe命令行参数详细");
  75. IpsLogger.Info($"开始同频对消.{exeName}.exe参数={pro.StartInfo.Arguments}", false);
  76. sw.Start();
  77. var succeed = pro.WaitForExit(30 * 1000);//timeout
  78. if (!succeed)
  79. {
  80. Stop();
  81. throw new Exception($"同频对消超时");
  82. }
  83. var res = pro.StandardError.ReadToEnd();
  84. sw.Stop();
  85. if (sw.ElapsedMilliseconds < 800)
  86. {
  87. throw new Exception("没有GPU");
  88. }
  89. if (!string.IsNullOrWhiteSpace(res))
  90. {
  91. throw new Exception(res);
  92. }
  93. if (!File.Exists(ofile))
  94. {
  95. throw new Exception("没有输出文件");
  96. }
  97. else
  98. {
  99. FileInfo f = new FileInfo(ofile);
  100. if (f.Length == 0)
  101. {
  102. try
  103. {
  104. File.Delete(ofile);
  105. }
  106. catch
  107. { }
  108. throw new Exception("没有输出文件");
  109. }
  110. }
  111. return new CorResult[0];
  112. }
  113. finally
  114. {
  115. isBusy = false;
  116. }
  117. });
  118. }
  119. /// <summary>
  120. /// 停止
  121. /// </summary>
  122. public void Stop()
  123. {
  124. var pros = Process.GetProcessesByName(exeName);
  125. foreach (var item in pros)
  126. {
  127. try
  128. {
  129. item.Kill();
  130. }
  131. catch
  132. { }
  133. }
  134. }
  135. }
  136. }