版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

131 lines
4.4 KiB

  1. using AssistClient.Utils;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace AssistClient
  10. {
  11. public static class WebApi
  12. {
  13. private static bool debug=false;
  14. /// <summary>
  15. /// date,sn
  16. /// </summary>
  17. /// <param name="req"></param>
  18. /// <returns></returns>
  19. /// <exception cref="Exception"></exception>
  20. public static JObject getDefectFromSN(JObject req)
  21. {
  22. if (debug)
  23. {
  24. //JObject data = new JObject()
  25. //{
  26. // {$"Defect_{sn}_1_X111_Y222",JArray.Parse(File.ReadAllText(@"d:\\test.json")) },
  27. //};
  28. //return new JObject()
  29. //{
  30. // {"code",200},
  31. // {"data",data},
  32. //};
  33. }
  34. JObject resp = HttpUtil.postSync($"http://{Config.ServerIP}:{Config.ServerPort}" + "/api/get_defect_from_sn", req.ToString());
  35. if (!resp.Value<bool>("success"))//框架库内
  36. throw new Exception(resp.Value<string>("data"));//框架库内
  37. //成功接收返回
  38. JObject obj = JObject.Parse(resp.Value<string>("data"));
  39. //if (obj.Value<int>("code") != 200)
  40. // throw new Exception(resp.Value<string>("data"));
  41. return obj;
  42. }
  43. public static JObject getDefectSmallFromSN(JObject req)
  44. {
  45. if (debug)
  46. {
  47. //JObject data = new JObject()
  48. //{
  49. // {$"Defect_{sn}_1_X111_Y222",JArray.Parse(File.ReadAllText(@"d:\\test.json")) },
  50. //};
  51. //return new JObject()
  52. //{
  53. // {"code",200},
  54. // {"data",data},
  55. //};
  56. }
  57. JObject resp = HttpUtil.postSync($"http://{Config.ServerIP}:{Config.ServerPort}" + "/api/get_smalldir_from_sn", req.ToString());
  58. if (!resp.Value<bool>("success"))//框架库内
  59. throw new Exception(resp.Value<string>("data"));//框架库内
  60. //成功接收返回
  61. JObject obj = JObject.Parse(resp.Value<string>("data"));
  62. //if (obj.Value<int>("code") != 200)
  63. // throw new Exception(resp.Value<string>("data"));
  64. return obj;
  65. }
  66. /// <summary>
  67. /// date,sn,file_name
  68. /// </summary>
  69. /// <param name="file_name"></param>
  70. /// <returns></returns>
  71. /// <exception cref="Exception"></exception>
  72. public static JObject getDefectBmpBase64(JObject req)
  73. {
  74. if (debug)
  75. {
  76. //return new JObject()
  77. //{
  78. // {"code",200},
  79. // {"data",Convert.ToBase64String(File.ReadAllBytes(Config.Defect_SavePath+"\\"+ file_name))},
  80. //};
  81. }
  82. JObject resp = HttpUtil.postSync($"http://{Config.ServerIP}:{Config.ServerPort}" + "/api/get_defect_pic", req.ToString());
  83. if (!resp.Value<bool>("success"))//框架库内
  84. throw new Exception(resp.Value<string>("data"));//框架库内
  85. //成功接收返回
  86. JObject obj = JObject.Parse(resp.Value<string>("data"));
  87. //if (obj.Value<int>("code") != 200)
  88. // throw new Exception(resp.Value<string>("data"));
  89. return obj;
  90. }
  91. public static JObject getDefectSmallBmpBase64(JObject req)
  92. {
  93. if (debug)
  94. {
  95. //return new JObject()
  96. //{
  97. // {"code",200},
  98. // {"data",Convert.ToBase64String(File.ReadAllBytes(Config.Defect_SavePath+"\\"+ file_name))},
  99. //};
  100. }
  101. JObject resp = HttpUtil.postSync($"http://{Config.ServerIP}:{Config.ServerPort}" + "/api/get_defect_smallpic", req.ToString());
  102. if (!resp.Value<bool>("success"))//框架库内
  103. throw new Exception(resp.Value<string>("data"));//框架库内
  104. //成功接收返回
  105. JObject obj = JObject.Parse(resp.Value<string>("data"));
  106. //if (obj.Value<int>("code") != 200)
  107. // throw new Exception(resp.Value<string>("data"));
  108. return obj;
  109. }
  110. }
  111. }