GMethod.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using SufeiUtil;
  4. using SXLibrary;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data.SQLite;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Runtime.CompilerServices;
  11. using System.Security.Policy;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. namespace MOKA_Factory_Tools
  16. {
  17. internal class GMethod
  18. {
  19. private static MaInfo s_maInfo = null;
  20. private static string strLastOrder = "";
  21. private static string strOrderKind = ""; // 试产 or 量产;
  22. private static Dictionary<string, string> LastKaylaOrderInfo = new Dictionary<string, string>();
  23. private static string url_MaInfo = "http://smes-prd-app01.tclking.com:9002/SAPService.asmx";
  24. private static string url_ReportKey = "http://smes-app-prod.tclking.com/FireTVApi/api/SMES/RecordKey";
  25. private static string url_getOrderProductStatus = "http://smes-app-prod.tclking.com/FireTVApi/api/SMES/getOrderProductStatus?sn=";
  26. private static string url_getMainBoardPSNWithSN = "http://smes-app-prod.tclking.com:9006/api/xm/GetXMTVParts?TVSN=";
  27. private static string url_getTVInfo = "http://smes-app-prod.tclking.com:9006/api/PE/GetTVInfo?sn=";
  28. public static void SetPolandConfig(bool bPoland = false)
  29. {
  30. if(bPoland)
  31. {
  32. url_MaInfo = "http://10.146.0.56:8084/?wsdl?op=GetMaInfo";
  33. url_ReportKey = "http://10.146.0.56/FireTV/RecordKey";
  34. url_getOrderProductStatus = "http://10.146.0.56/FireTV/GetOrderProductStatus?SN=";
  35. url_getTVInfo = "http://10.146.0.56/FireTV/GetTVinfo?SN=";
  36. }
  37. }
  38. public static void SetMexicanConfig(bool bMexican=false)
  39. {
  40. if (bMexican)
  41. {
  42. url_MaInfo = "http://SMES.TMSA.MX:9002/SAPService.asmx";
  43. url_ReportKey = "http://SMES.TMSA.MX/FireTVApi/api/SMESMX/RecordKey";
  44. url_getOrderProductStatus = "http://SMES.TMSA.MX/FireTVApi/api/SMESMX/getOrderProductStatus?sn=";
  45. url_getTVInfo = "http://SMES.TMSA.MX:9006/api/PE/GetTVInfo?sn=";
  46. }
  47. }
  48. public static bool GetMaInfo(string sn, string order, out MaInfo maInfo, SQLiteConnection errorDBNow)
  49. {
  50. if (GetMaInfoBySAP(sn, order, out maInfo, errorDBNow))
  51. {
  52. return true;
  53. }
  54. return GetMaInfoByMES(sn, order, out maInfo, errorDBNow);
  55. }
  56. public static bool GetMaInfoByMES(string sn, string order, out MaInfo maInfo, SQLiteConnection errorDBNow)
  57. {
  58. maInfo = null;
  59. if (s_maInfo != null && s_maInfo.ODF.Equals(order, StringComparison.InvariantCultureIgnoreCase))
  60. {
  61. maInfo = s_maInfo;
  62. return true;
  63. }
  64. HttpHelper http = new HttpHelper();
  65. HttpItem item = new HttpItem()
  66. {
  67. URL = url_getTVInfo + sn,
  68. Encoding = Encoding.UTF8,
  69. Method = "get",
  70. PostEncoding = Encoding.UTF8,
  71. KeepAlive = false
  72. };
  73. item.ContentType = "application/x-www-form-urlencoded";
  74. HttpResult hResult = http.GetHtml(item);
  75. if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
  76. {
  77. try
  78. {
  79. using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
  80. {
  81. JObject jObject = (JObject)JToken.ReadFrom(reader);
  82. reader.Close();
  83. maInfo.ODF = jObject["ODF"].Value<string>();
  84. maInfo.BOM = jObject["ProductCode"].Value<string>();
  85. maInfo.Model = jObject["ProductName"].Value<string>().Split('/')[1];
  86. maInfo.SIZE = maInfo.Model.Substring(0, 3);
  87. Log.WriteInfoLog("GetMaInfoByMES:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  88. s_maInfo = maInfo;
  89. return true;
  90. }
  91. }
  92. catch (Exception)
  93. {
  94. Log.WriteErrorLog("GetMaInfoByMES error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  95. }
  96. }
  97. else
  98. {
  99. Log.WriteInfoLog("GetMaInfoByMES error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  100. }
  101. return false;
  102. }
  103. public static bool GetMaInfoBySAP(string sn, string order, out MaInfo maInfo, SQLiteConnection errorDBNow)
  104. {
  105. string desc;
  106. maInfo = null;
  107. if (s_maInfo != null && s_maInfo.ODF.Equals(order, StringComparison.InvariantCultureIgnoreCase) )
  108. {
  109. maInfo = s_maInfo;
  110. return true;
  111. }
  112. string strPost = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
  113. "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
  114. "<soap:Body>" +
  115. "<GetMaInfo xmlns=\"http://tempuri.org/\">" +
  116. "<sn>" + sn + "</sn>" +
  117. "</GetMaInfo>" +
  118. "</soap:Body>" +
  119. "</soap:Envelope>";
  120. HttpHelper http = new HttpHelper();
  121. HttpItem item = new HttpItem()
  122. {
  123. Encoding = Encoding.UTF8,
  124. Method = "post",
  125. ContentType = "text/xml",
  126. KeepAlive = false
  127. };
  128. item.URL = url_MaInfo;
  129. item.Postdata = strPost;
  130. HttpResult result = http.GetHtml(item);
  131. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  132. {
  133. Log.WriteGetKeyLog("\r\nGetMaInfo :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  134. if (!Xmlconfig.GetMaInfoXml(result.Html, out maInfo, out desc))
  135. {
  136. Log.WriteGetKeyLog("GetMaInfo error:" + desc + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  137. return false;
  138. }
  139. }
  140. else
  141. {
  142. Log.WriteGetKeyLog("GetMaInfo error:" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  143. return false;
  144. }
  145. s_maInfo = maInfo;
  146. return true;
  147. }
  148. /// <summary>
  149. /// 上报数据抄写结果到MES系统中;
  150. /// </summary>
  151. /// <param name="fsn"></param>
  152. /// <param name="dsn"></param>
  153. /// <param name="dateTime">抄写时间</param>
  154. /// <param name="result">抄写结果</param>
  155. /// <param name="msg">如果上报失败,此参数为失败的描述信息</param>
  156. /// <returns></returns>
  157. public static bool ReportDataBurningResultToMES(string fsn, string dsn, string result, string dateTime, SQLiteConnection errorDBNow, out string msg, out string returnObject)
  158. {
  159. msg = "";
  160. returnObject = "";
  161. string strPost = string.Format("{{\"FSN\":\"{0}\",\"DSN\":\"{1}\",\"DataCopy\":\"{2}\",\"UPDATETIME\":\"{3}\"}}", fsn, dsn, result, dateTime);
  162. HttpHelper http = new HttpHelper();
  163. HttpItem item = new HttpItem()
  164. {
  165. Encoding = Encoding.UTF8,
  166. Method = "post",
  167. ContentType = "application/json",
  168. KeepAlive = false
  169. };
  170. // 测试地址;
  171. item.URL = url_ReportKey;
  172. item.Postdata = strPost;
  173. HttpResult hResult = http.GetHtml(item);
  174. if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
  175. {
  176. try
  177. {
  178. using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
  179. {
  180. JObject jObject = (JObject)JToken.ReadFrom(reader);
  181. reader.Close();
  182. bool bResult = jObject["Result"].Value<bool>();
  183. msg = jObject["EroMsg"].Value<string>();
  184. if (jObject["returnObject"] != null)
  185. returnObject = jObject["returnObject"].ToString();
  186. Log.WriteInfoLog("nReportDataBurningResultToMES:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  187. return bResult;
  188. }
  189. }
  190. catch (Exception e)
  191. {
  192. msg = e.Message;
  193. Log.WriteErrorLog("ReportDataBurningResultToMES Json-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  194. }
  195. }
  196. else
  197. {
  198. msg = hResult.StatusDescription;
  199. Log.WriteInfoLog("ReportDataBurningResultToMES Http-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  200. }
  201. // 没有进行数据库查重:惹数据已添加过,同一次FSN抄写多次失败后导致多条记录。
  202. SQLiteHelper.InsertDelayErrorReport(errorDBNow, new object[] { item.URL, item.Postdata });
  203. return false;
  204. }
  205. /// <summary>
  206. /// 上传本地数据库失败的日志,重新上传;
  207. /// </summary>
  208. /// <param name="url"></param>
  209. /// <param name="strPost"></param>
  210. /// <param name="mark"></param>
  211. /// <returns></returns>
  212. public static bool ReportDataBurningResultToMES(string url, string strPost, out bool mark)
  213. {
  214. // 表示是否上传成功;
  215. mark = false;
  216. HttpHelper http = new HttpHelper();
  217. HttpItem item = new HttpItem()
  218. {
  219. Encoding = Encoding.UTF8,
  220. Method = "post",
  221. ContentType = "application/json",
  222. KeepAlive = false
  223. };
  224. item.URL = url;
  225. item.Postdata = strPost;
  226. HttpResult hResult = http.GetHtml(item);
  227. if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
  228. {
  229. try
  230. {
  231. using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
  232. {
  233. JObject jObject = (JObject)JToken.ReadFrom(reader);
  234. reader.Close();
  235. mark = jObject["Result"].Value<bool>();
  236. Log.WriteInfoLog("nReportDataBurningResultToMES:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  237. return true;
  238. }
  239. }
  240. catch (Exception)
  241. {
  242. Log.WriteErrorLog("ReportDataBurningResultToMES error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  243. return false;
  244. }
  245. }
  246. else
  247. {
  248. Log.WriteInfoLog("ReportDataBurningResultToMES error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  249. }
  250. return false;
  251. }
  252. /// <summary>
  253. /// 通过SN获取订单类型
  254. /// </summary>
  255. /// <param name="sn"></param>
  256. /// <returns></returns>
  257. public static bool GetOrderTypeFromSN(string sn, string order, out string result, out string msg)
  258. {
  259. msg = "";
  260. result = "";
  261. if (order.Equals(strLastOrder, StringComparison.OrdinalIgnoreCase))
  262. {
  263. if (strOrderKind.Equals("量产") || strOrderKind.Equals("试产"))
  264. {
  265. result = strOrderKind;
  266. return true;
  267. }
  268. }
  269. HttpHelper http = new HttpHelper();
  270. HttpItem item = new HttpItem()
  271. {
  272. Encoding = Encoding.UTF8,
  273. Method = "post",
  274. ContentType = "application/x-www-form-urlencoded",
  275. KeepAlive = false
  276. };
  277. // 测试地址;
  278. item.URL = url_getOrderProductStatus + sn;
  279. HttpResult hResult = http.GetHtml(item);
  280. if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
  281. {
  282. try
  283. {
  284. using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
  285. {
  286. JObject jObject = (JObject)JToken.ReadFrom(reader);
  287. reader.Close();
  288. bool bResult = jObject["Result"].Value<bool>();
  289. msg = jObject["EroMsg"].Value<string>();
  290. string returnObject = jObject["returnObject"].ToString();
  291. if (bResult)
  292. {
  293. if (returnObject.Contains("量产"))
  294. result = "量产";
  295. else if (returnObject.Contains("试产"))
  296. result = "试产";
  297. else
  298. result = "错误返回";
  299. strOrderKind = result;
  300. Log.WriteInfoLog("\r\nIsCuringBOM :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + hResult.Html);
  301. return true;
  302. }
  303. Log.WriteInfoLog("IsCuringBOM error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  304. }
  305. }
  306. catch (Exception e)
  307. {
  308. msg = e.Message;
  309. Log.WriteErrorLog("IsCuringBOM Json-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  310. }
  311. }
  312. else
  313. {
  314. msg = hResult.StatusDescription;
  315. Log.WriteInfoLog("IsCuringBOM Http-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  316. }
  317. strOrderKind = "";
  318. return false;
  319. }
  320. /// <summary>
  321. // Section1:本机信息;
  322. // Section2:SMES信息;
  323. // Section3:实际抄写Key信息;
  324. /// </summary>
  325. /// <param name="Line"></param>
  326. /// <param name="Station"></param>
  327. /// <param name="order"></param>
  328. /// <param name="sn"></param>
  329. /// <param name="StartTime"></param>
  330. /// <param name="EndOfTime"></param>
  331. /// <param name="returnObject"></param>
  332. /// <param name="key"></param>
  333. /// <param name="result"></param>
  334. /// <returns></returns>
  335. public static bool GeneratKaylaData(string Line, string Station, string order, string sn, DateTime StartTime, DateTime EndOfTime, string returnObject, KeyInfo key, bool result)
  336. {
  337. Dictionary<string, string> localInfo = new Dictionary<string, string>();
  338. // 本机信息;
  339. localInfo.Add("Item", "Value");
  340. localInfo.Add("factory_id_I", "TCL");
  341. localInfo.Add("operator_I", Line);
  342. localInfo.Add("station_I", Station);
  343. localInfo.Add("fixture_id_I", "1_1");
  344. localInfo.Add("gui_ver_I", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
  345. localInfo.Add("route_check_I", "1");
  346. // SMES信息;
  347. string strLastOrder = CommonMethod.ReadProfileString("MOKAFactoryTools", "LastOrder", "");
  348. if (!strLastOrder.Equals(order, StringComparison.OrdinalIgnoreCase))
  349. {
  350. // 请求新的订单信息;
  351. MaInfo maInfo;
  352. if (!GetMaInfo(sn, order, out maInfo, null))
  353. {
  354. Log.WriteErrorLog("Kayla GetMaInfo失败");
  355. return false;
  356. }
  357. LastKaylaOrderInfo = new Dictionary<string, string>();
  358. if (maInfo != null)
  359. {
  360. LastKaylaOrderInfo.Add("project_name_I", maInfo.project_name_I);
  361. LastKaylaOrderInfo.Add("build_I", maInfo.build_I);
  362. LastKaylaOrderInfo.Add("build_config_I", maInfo.build_config_I);
  363. LastKaylaOrderInfo.Add("diag_ver_I", maInfo.diag_ver_I);
  364. LastKaylaOrderInfo.Add("image_name_ver_I", maInfo.image_name_ver_I);
  365. LastKaylaOrderInfo.Add("soc_type", maInfo.soc_type);
  366. LastKaylaOrderInfo.Add("speaker_vender", maInfo.speaker_vender);
  367. LastKaylaOrderInfo.Add("mic_vender", maInfo.mic_vender);
  368. }
  369. }
  370. Dictionary<string, string> dic = localInfo.Union(LastKaylaOrderInfo).ToDictionary(k => k.Key, v => v.Value);
  371. dic.Add("start_time_I", StartTime.ToString());
  372. dic.Add("serial_id_I", key != null ? key.DSN : ""); // DSN;
  373. dic.Add("FSN", sn);
  374. // 耐压值;
  375. if (returnObject != null && returnObject.Length > 0 && returnObject.Contains("Hightpot"))
  376. {
  377. Log.WriteInfoLog(String.Format("returnObjec={0}", returnObject));
  378. // 删除头尾[];
  379. returnObject = returnObject.Remove(0, 1);
  380. returnObject = returnObject.Remove(returnObject.Length - 1, 1);
  381. JObject jObject = JObject.Parse(returnObject);
  382. string hightpot = CommonMethod.JSON_SeleteNode(jObject, "Hightpot");
  383. int pos = hightpot.LastIndexOf('/');
  384. if (pos != -1)
  385. {
  386. hightpot = hightpot.Substring(pos + 1);
  387. pos = hightpot.IndexOf("mA");
  388. // 使用正规去除数字+小数点以外的字符;
  389. string AC = hightpot.Substring(0, pos + 2);
  390. string DC = hightpot.Substring(pos + 2);
  391. AC = System.Text.RegularExpressions.Regex.Replace(AC, @"[^\d.]*", "");
  392. DC = System.Text.RegularExpressions.Regex.Replace(DC, @"[^\d.]*", "");
  393. dic.Add("AC_I", AC);
  394. dic.Add("DC_R", DC);
  395. }
  396. else
  397. {
  398. dic.Add("AC_I", "");
  399. dic.Add("DC_R", "");
  400. }
  401. }
  402. else
  403. {
  404. dic.Add("AC_I", "");
  405. dic.Add("DC_R", "");
  406. Log.WriteErrorLog("获取耐压值结果为空");
  407. }
  408. if (key != null)
  409. {
  410. if (key.DID.enable)
  411. {
  412. dic.Add("DID", key.DID); // 本身就是字符串;
  413. dic.Add("DID_check", key.DID.result ? "PASS" : "FAIL");
  414. }
  415. if (key.Mac.enable)
  416. {
  417. dic.Add("Mac", key.Mac);//keyInfo.Mac.data.Replace("-", ":");
  418. dic.Add("Mac_check", key.Mac.result ? "PASS" : "FAIL");
  419. }
  420. if (key.HDCP.enable)
  421. {
  422. dic.Add("HDCP", key.HDCP);
  423. dic.Add("HDCP_check", key.HDCP.result ? "PASS" : "FAIL");
  424. }
  425. if (key.HDCP22.enable)
  426. {
  427. dic.Add("HDCP22", key.HDCP22);
  428. dic.Add("HDCP22_check", key.HDCP22.result ? "PASS" : "FAIL");
  429. }
  430. if (key.ESN.enable)
  431. {
  432. dic.Add("ESN", key.ESN);
  433. dic.Add("ESN_check", key.ESN.result ? "PASS" : "FAIL");
  434. }
  435. if (key.Widevine.enable)
  436. {
  437. dic.Add("Widevine", key.Widevine);
  438. dic.Add("Widevine_check", key.Widevine.result ? "PASS" : "FAIL");
  439. }
  440. if (key.CI_plus.enable)
  441. {
  442. dic.Add("CI_plus", key.CI_plus);
  443. dic.Add("CI_plus_check", key.CI_plus.result ? "PASS" : "FAIL");
  444. }
  445. if (key.Attestation.enable)
  446. {
  447. dic.Add("Attestation", key.Attestation);
  448. dic.Add("Attestation_check", key.Attestation.result ? "PASS" : "FAIL");
  449. }
  450. if (key.MGK.enable)
  451. {
  452. dic.Add("MGK", key.MGK);
  453. dic.Add("MGK_check", key.MGK.result ? "PASS" : "FAIL");
  454. }
  455. if (key.Fairplay.enable)
  456. {
  457. dic.Add("Fairplay", key.Fairplay);
  458. dic.Add("Fairplay_check", key.Fairplay.result ? "PASS" : "FAIL");
  459. }
  460. if (key.DSN.enable)
  461. {
  462. dic.Add("DSN", key.DSN);
  463. dic.Add("DSN_check", key.DSN.result ? "PASS" : "FAIL");
  464. }
  465. if (key.WiFi_MAC.enable)
  466. {
  467. dic.Add("WiFi_MAC", key.WiFi_MAC);
  468. dic.Add("WiFi_MAC_check", key.WiFi_MAC.result ? "PASS" : "FAIL");
  469. }
  470. if (key.BT_MAC.enable)
  471. {
  472. dic.Add("BT_MAC", key.BT_MAC);
  473. dic.Add("BT_MAC_check", key.BT_MAC.result ? "PASS" : "FAIL");
  474. }
  475. if (key.LEK.enable)
  476. {
  477. dic.Add("LEK", key.LEK);
  478. dic.Add("LEK_check", key.LEK.result ? "PASS" : "FAIL");
  479. }
  480. if (key.PEK.enable)
  481. {
  482. dic.Add("PEK", key.PEK);
  483. dic.Add("PEK_check", key.PEK.result ? "PASS" : "FAIL");
  484. }
  485. if (key.Playready.enable)
  486. {
  487. dic.Add("Playready", key.Playready);
  488. dic.Add("Playready_check", key.Playready.result ? "PASS" : "FAIL");
  489. }
  490. if (key.Hashkey.enable)
  491. {
  492. dic.Add("Hashkey", key.Hashkey);
  493. dic.Add("Hashkey_check", key.Hashkey.result ? "PASS" : "FAIL");
  494. }
  495. if (key.ECP.enable)
  496. {
  497. dic.Add("ECP", key.ECP);
  498. dic.Add("ECP_check", key.ECP.result ? "PASS" : "FAIL");
  499. }
  500. if (key.YouTube_KEY.enable)
  501. {
  502. dic.Add("YouTube_KEY", key.YouTube_KEY);
  503. dic.Add("YouTube_KEY_check", key.YouTube_KEY.result ? "PASS" : "FAIL");
  504. }
  505. if ( key.FVP.enable )
  506. {
  507. dic.Add("FVP_set", key.FVP.data);
  508. dic.Add("FVP_check", key.FVP.result ? "PASS" : "FAIL");
  509. }
  510. }
  511. dic.Add("cycle_time_I", EndOfTime.Subtract(StartTime).Seconds.ToString());
  512. dic.Add("test_result_I", result ? "PASS" : "FAIL");
  513. try
  514. {
  515. // 以DSN命名文件;
  516. if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "Kayla"))
  517. {
  518. Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "Kayla");
  519. }
  520. string savefile = string.Format("{0}Kayla\\{1}.csv", AppDomain.CurrentDomain.BaseDirectory, sn);
  521. Log.WriteInfoLog(string.Format("Kayla: sn={0}, savefile={1}", sn, savefile));
  522. using (System.IO.StreamWriter file = new System.IO.StreamWriter(savefile, false))
  523. {
  524. foreach (KeyValuePair<string, string> kvp in dic)
  525. {
  526. file.WriteLine(string.Format("{0},{1}", kvp.Key, kvp.Value));
  527. }
  528. }
  529. }
  530. catch (Exception ex)
  531. {
  532. Log.WriteErrorLog(string.Format("保存csv文件失败:{0}", ex.ToString()));
  533. return false;
  534. }
  535. CommonMethod.StartProcess(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "tcp_send.exe", sn);
  536. return true;
  537. }
  538. // 根据FSN获取服务器上与之绑定的PSN值;
  539. // 这个函数在哪里调用,被谁调用;
  540. // 成功怎么处理;失败怎么处理;
  541. public static bool GetMainBoardPSNWithSN(string FSN, out string PSN)
  542. {
  543. string msg;
  544. PSN = "";
  545. HttpHelper http = new HttpHelper();
  546. HttpItem item = new HttpItem()
  547. {
  548. Encoding = Encoding.UTF8,
  549. Method = "post",
  550. ContentType = "application/x-www-form-urlencoded",
  551. KeepAlive = false
  552. };
  553. item.URL = url_getMainBoardPSNWithSN + FSN;
  554. HttpResult hResult = http.GetHtml(item);
  555. if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
  556. {
  557. try
  558. {
  559. using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
  560. {
  561. JObject jObject = (JObject)JToken.ReadFrom(reader);
  562. reader.Close();
  563. foreach (var ss in jObject["Tvparts"]) //查找某个字段与值
  564. {
  565. //如果里面的TypeCode为MA(主板),读出他的PSN
  566. if (ss["PartTypeCode"].Value<string>().Equals("MA", StringComparison.OrdinalIgnoreCase))
  567. {
  568. PSN = ss["PartSN"].Value<string>();
  569. }
  570. }
  571. if (PSN == "" || PSN == null)
  572. {
  573. MessageBox.Show(LResource.FindPSNError);
  574. return false;
  575. }
  576. Log.WriteInfoLog("PartSN" + PSN);
  577. return true;
  578. }
  579. }
  580. catch (Exception e)
  581. {
  582. msg = e.Message;
  583. Log.WriteErrorLog("IsCuringBOM Json-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  584. }
  585. }
  586. else
  587. {
  588. msg = hResult.StatusDescription;
  589. Log.WriteInfoLog("IsCuringBOM Http-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  590. }
  591. return false;
  592. }
  593. }
  594. }