CommonMethod.cs 155 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using SufeiUtil;
  4. using SXLibrary;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.Configuration;
  9. using System.Data.SQLite;
  10. using System.Globalization;
  11. using System.IO;
  12. using System.Management;
  13. using System.Net;
  14. using System.Text;
  15. using System.Text.RegularExpressions;
  16. using System.Windows.Forms;
  17. using System.Xml;
  18. using WHC.OrderWater.Commons;
  19. using HttpHelper = SufeiUtil.HttpHelper;
  20. using System.Web;
  21. using System.Security.Cryptography.X509Certificates;
  22. using System.Net.Security;
  23. using System.Runtime.InteropServices;
  24. using System.Diagnostics;
  25. using System.Linq;
  26. namespace MOKA_Factory_Tools
  27. {
  28. class CommonMethod
  29. {
  30. [DllImport("kernel32")]
  31. public static extern bool GetProfileString(string lpApplicationName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize);
  32. [DllImport("kernel32")]
  33. public static extern bool WriteProfileString(string lpApplicationName, string lpKeyName, string lpString);
  34. public static string FactoryName = "Unknown";
  35. private static string lastOrder = "";
  36. private static List<string> ListACASSN = new List<string>();
  37. private static LoginInput loginInput = new LoginInput();
  38. private static Dictionary<string,string> LastKaylaOrderInfo = new Dictionary<string,string>();
  39. /// <summary>
  40. /// 保存登录信息;
  41. /// </summary>
  42. /// <param name="strAccount"></param>
  43. /// <param name="strPssword"></param>
  44. public static void SaveLoginInfo(string strAccount, string strPssword)
  45. {
  46. loginInput.account = strAccount;
  47. loginInput.password = strPssword;
  48. }
  49. /// <summary>
  50. /// 获取登录账号;
  51. /// </summary>
  52. /// <returns></returns>
  53. public static string GetLoginAccout()
  54. {
  55. return loginInput.account;
  56. }
  57. public static string ReadProfileString(string lpApplicationName, string lpKeyName, string lpDefault)
  58. {
  59. StringBuilder MyString = new StringBuilder(256);
  60. GetProfileString(lpApplicationName, lpKeyName, lpDefault, MyString, 256);
  61. if ( MyString.Length > 0)
  62. return MyString.ToString();
  63. return lpDefault;
  64. }
  65. /// <summary>
  66. /// 更新G客户抄写状态;
  67. /// </summary>
  68. /// <param name="SN">当前SN</param>
  69. /// <param name="bResult">当前SN的抄写结果,true=pass, false=fail</param>
  70. public static void UpdateGSNProfile( string SN, bool bResult = false )
  71. {
  72. string strLastSN = ReadProfileString("MOKAFactoryTools", "LastGSN", "");
  73. if (!strLastSN.Equals(SN, StringComparison.OrdinalIgnoreCase))
  74. {
  75. WriteProfileString("MOKAFactoryTools", "LastGSN", SN);
  76. // 清空连续次数值;
  77. WriteProfileString("MOKAFactoryTools", "GFailCount", "0");
  78. // 清空上次测试状态;
  79. WriteProfileString("MOKAFactoryTools", "LastGResult", "0");
  80. }
  81. else
  82. {
  83. if (bResult == false)
  84. {
  85. int nGSNCount = Convert.ToInt32(ReadProfileString("MOKAFactoryTools", "GFailCount", "0")) + 1;
  86. // 更新连续测试中累计失败的次数;
  87. WriteProfileString("MOKAFactoryTools", "GFailCount", nGSNCount.ToString());
  88. }
  89. // 更新抄写状态;
  90. WriteProfileString("MOKAFactoryTools", "LastGResult", bResult ? "1" : "0");
  91. }
  92. }
  93. //public static string LocalMacAddress = GetMacAddress();
  94. /// <summary>
  95. /// 获取活动网卡硬件地址
  96. /// </summary>
  97. /// <returns></returns>
  98. public static string GetMacAddress()
  99. {
  100. string mac = "";
  101. using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"))
  102. {
  103. ManagementObjectCollection moc = mc.GetInstances();
  104. int i = 0;
  105. int j = 0;
  106. foreach (ManagementObject mo in moc)
  107. {
  108. if (mo["MacAddress"] != null)
  109. {
  110. if (Convert.ToBoolean(mo["IPEnabled"]))
  111. {
  112. if (j < 2)
  113. {
  114. mac = mo["MacAddress"].ToString() + "&" + mac;
  115. j++;
  116. }
  117. }
  118. else
  119. {
  120. if (i < 1)
  121. {
  122. mac += mo["MacAddress"].ToString() + "&";
  123. i++;
  124. }
  125. }
  126. }
  127. }
  128. }
  129. return mac.Replace(":", "-");
  130. //return "C0-B6-F9-44-D7-BB";
  131. }
  132. /// <summary>
  133. ///
  134. /// </summary>
  135. /// <param name="runFilePath"></param>
  136. /// <param name="args"></param>
  137. /// <returns></returns>
  138. public static bool StartProcess(string runFilePath, string args)
  139. {
  140. try
  141. {
  142. Process process = new Process();//创建进程对象
  143. ProcessStartInfo startInfo = new ProcessStartInfo(runFilePath, args);
  144. startInfo.UseShellExecute = false;
  145. startInfo.CreateNoWindow = true;
  146. process.StartInfo = startInfo;
  147. return process.Start();
  148. //process.WaitForExit();
  149. }
  150. catch (Exception ex)
  151. {
  152. Log.WriteErrorLog(string.Format("打开进程{0}失败:{1}", runFilePath, ex.Message));
  153. }
  154. return false;
  155. }
  156. public static bool StartProcess(string runFilePath, string args, out string outPutMsg)
  157. {
  158. try
  159. {
  160. outPutMsg = null;
  161. Process process = new Process();
  162. ProcessStartInfo startInfo = new ProcessStartInfo(runFilePath, args);
  163. startInfo.UseShellExecute = false;
  164. process.StartInfo = startInfo;
  165. process.StartInfo.RedirectStandardError = true;
  166. process.StartInfo.RedirectStandardInput = true;
  167. process.StartInfo.RedirectStandardOutput = true;
  168. process.StartInfo.CreateNoWindow= true;
  169. process.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "replace_tv_projects";
  170. process.Start();
  171. outPutMsg = process.StandardOutput.ReadToEnd();
  172. process.WaitForExit();
  173. process.Close();
  174. }
  175. catch(Exception ex)
  176. {
  177. outPutMsg = null;
  178. Log.WriteErrorLog(string.Format("打开进程{0}失败:{1}", runFilePath, ex.Message));
  179. return false;
  180. }
  181. Log.WriteInfoLog(string.Format("adb push结果={0}",outPutMsg));
  182. return true;
  183. }
  184. /// <summary>
  185. /// 获取订单信息
  186. /// </summary>
  187. /// <param name="url"></param>
  188. /// <param name="order"></param>
  189. /// <param name="pcmac"></param>
  190. /// <param name="iptvip"></param>
  191. /// <param name="version"></param>
  192. /// <param name="sqliteConn"></param>
  193. /// <param name="mid"></param>
  194. /// <returns></returns>
  195. public static bool GetMidInfo(string url, string order, string pcmac, string iptvip, string version, SQLiteConnection sqliteConn, out MidList mid)
  196. {
  197. mid = new MidList();
  198. OrderInput orderInput1 = new OrderInput { bid = order, mac = pcmac, version = "", clientType = "" };//"74-27-EA-6E-DA-9F"
  199. string jsonorder = JsonConvert.SerializeObject(orderInput1, Newtonsoft.Json.Formatting.Indented);
  200. HttpHelper http = new HttpHelper();
  201. HttpItem item = new HttpItem()
  202. {
  203. URL = url,//URL这里都是测试URl   必需项
  204. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  205. //Encoding = Encoding.Default,
  206. Method = "post",//URL     可选项 默认为Get
  207. Postdata = jsonorder,
  208. PostEncoding = Encoding.UTF8,
  209. KeepAlive = false
  210. };
  211. item.ContentType = "application/json;charset=utf-8";
  212. System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
  213. stopwatch.Start();
  214. HttpResult result = http.GetHtml(item);
  215. stopwatch.Stop();
  216. string usingtime = stopwatch.ElapsedMilliseconds.ToString();
  217. stopwatch.Reset();
  218. string ParseText = result.Html;
  219. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  220. {
  221. Log.WriteGetKeyLog("\r\nGet MID info\r\nUsing time:" + usingtime + "ms\r\n" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  222. }
  223. else
  224. {
  225. Log.WriteErrorLog("\r\nFail to GetMidInfo:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  226. ReportErrormsg("Fail to GetMidInfo", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  227. return false;
  228. }
  229. try
  230. {
  231. JObject jObject = JObject.Parse(ParseText);
  232. mid.message = jObject["message"].Value<string>();
  233. mid.code = jObject["code"].Value<string>();
  234. mid.factoryname = jObject["factoryName"].Value<string>();
  235. mid.factoryNum = jObject["factoryNum"].Value<string>();
  236. mid.version = jObject["version"].Value<string>();
  237. mid.quantity = jObject["quantity"].Value<string>();
  238. mid.projectid = jObject["projectId"].Value<string>();
  239. mid.clienttype = jObject["clientType"].Value<string>();
  240. mid.host = jObject["host"].Value<string>();
  241. mid.whiteType = jObject["whiteType"].Value<string>();
  242. object a = jObject["rokuCustomer"];
  243. if (jObject["rokuCustomer"].ToString().Length > 0)
  244. mid.rokuCustomer = new RokuCustomer()
  245. {
  246. id = JSON_SeleteNode(jObject["rokuCustomer"], "id").Trim(),
  247. ordernum = JSON_SeleteNode(jObject["rokuCustomer"], "ordernum").Trim(),
  248. brand = JSON_SeleteNode(jObject["rokuCustomer"], "brand").Trim(),
  249. region = JSON_SeleteNode(jObject["rokuCustomer"], "region").Trim(),
  250. oemmodel = JSON_SeleteNode(jObject["rokuCustomer"], "oemmodel").Trim(),
  251. supporturl = JSON_SeleteNode(jObject["rokuCustomer"], "supporturl").Trim(),
  252. supportphone = JSON_SeleteNode(jObject["rokuCustomer"], "supportphone").Trim(),
  253. productiondate = JSON_SeleteNode(jObject["rokuCustomer"], "productiondate").Trim(),
  254. remotetype = JSON_SeleteNode(jObject["rokuCustomer"], "remotetype").Trim(),
  255. updatetime = JSON_SeleteNode(jObject["rokuCustomer"], "updatetime").Trim(),
  256. createtime = JSON_SeleteNode(jObject["rokuCustomer"], "createtime").Trim(),
  257. isdelete = JSON_SeleteNode(jObject["rokuCustomer"], "isdelete").Trim()
  258. };
  259. mid.keytype = new Dictionary<string, string>();
  260. foreach (var ss in jObject["obj"]) //查找某个字段与值
  261. {
  262. mid.keytype.Add(ss["name"].Value<string>(), ss["type"].Value<string>());
  263. }
  264. if (url == Serverurl.Testurl)
  265. mid.host = "http://test.idmanage.qhmoka.com/IDManage";
  266. if (mid.code == "1000")
  267. return true;
  268. else
  269. return false;
  270. }
  271. catch (Exception ex)
  272. {
  273. Log.WriteErrorLog("\r\nFail to parse MID info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  274. ReportErrormsg("Fail to parse MID info", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  275. MessageBox.Show("Fail to parse MID info\r\n " + ex.Message);
  276. return false;
  277. }
  278. }
  279. /// <summary>
  280. /// 获取预绑定模式下的key包地址
  281. /// </summary>
  282. /// <param name="midInfo"></param>
  283. /// <param name="order"></param>
  284. /// <param name="sqliteConn"></param>
  285. /// <param name="midAddress"></param>
  286. /// <returns></returns>
  287. public static bool GetMidAddress(MidList midInfo, string order, SQLiteConnection sqliteConn, out MidAddress midAddress)
  288. {
  289. midAddress = new MidAddress();
  290. HttpHelper http = new HttpHelper();
  291. HttpItem item = new HttpItem()
  292. {
  293. URL = midInfo.host + "/getofflinelist.do?",//URL这里都是测试URl   必需项
  294. Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  295. //Encoding = Encoding.Default,
  296. Method = "post",//URL     可选项 默认为Get
  297. Postdata = ("orderNumber=" + order + "&mac=" + HttpUtility.UrlEncode(TestMode.MAC)),
  298. KeepAlive = false
  299. };
  300. item.ContentType = "application/x-www-form-urlencoded";
  301. HttpResult result = http.GetHtml(item);
  302. string ParseText = result.Html;
  303. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  304. {
  305. }
  306. else
  307. {
  308. Log.WriteErrorLog("\r\nFail to get Mid address:" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  309. CommonMethod.ReportErrormsg("Fail to get Mid address", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
  310. return false;
  311. }
  312. try
  313. {
  314. JObject jObject = JObject.Parse(ParseText);
  315. midAddress.des = JSON_SeleteNode(jObject, "des");
  316. midAddress.code = JSON_SeleteNode(jObject, "code");
  317. midAddress.order = JSON_SeleteNode(jObject, "order_number");
  318. midAddress.number = JSON_SeleteNode(jObject, "order_quantity");
  319. midAddress.pid = JSON_SeleteNode(jObject, "project_id");
  320. midAddress.ctype = JSON_SeleteNode(jObject, "client_type");
  321. midAddress.purl = JSON_SeleteNode(jObject, "packet_url");
  322. midAddress.psize = JSON_SeleteNode(jObject, "packet_size");
  323. midAddress.pmd5 = JSON_SeleteNode(jObject, "packet_md5");
  324. midAddress.version = JSON_SeleteNode(jObject, "soft_version");
  325. midAddress.host = midInfo.host;
  326. Log.WriteGetKeyLog("\r\nGet Mid address success:" + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  327. return true;
  328. }
  329. catch (Exception ex)
  330. {
  331. Log.WriteErrorLog("\r\nFail to parse MID address," + ex.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  332. CommonMethod.ReportErrormsg("Fail to parse MID address", ex.Message + "\r\n" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
  333. MessageBox.Show("Fail to parse MIDAddress info\r\n " + ex.Message);
  334. return false;
  335. }
  336. }
  337. /// <summary>
  338. /// 获取预绑定模式下的key包地址
  339. /// </summary>
  340. /// <param name="midInfo"></param>
  341. /// <param name="order"></param>
  342. /// <param name="sqliteConn"></param>
  343. /// <param name="midAddress"></param>
  344. /// <returns></returns>
  345. public static bool GetMidAddress2(MidList midInfo, string order, SQLiteConnection sqliteConn, out List<MidAddress> midAddressList)
  346. {
  347. midAddressList = new List<MidAddress>();
  348. HttpHelper http = new HttpHelper();
  349. HttpItem item = new HttpItem()
  350. {
  351. URL = midInfo.host + "/getofflinelist.do?",//URL这里都是测试URl   必需项
  352. Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  353. //Encoding = Encoding.Default,
  354. Method = "post",//URL     可选项 默认为Get
  355. Postdata = ("orderNumber=" + order + "&mac=" + HttpUtility.UrlEncode(TestMode.MAC)),
  356. KeepAlive = false
  357. };
  358. item.ContentType = "application/x-www-form-urlencoded";
  359. HttpResult result = http.GetHtml(item);
  360. string ParseText = result.Html;
  361. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  362. {
  363. }
  364. else
  365. {
  366. Log.WriteErrorLog("\r\nFail to get Mid address:" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  367. CommonMethod.ReportErrormsg("Fail to get Mid address", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
  368. return false;
  369. }
  370. try
  371. {
  372. JObject jObject = JObject.Parse(ParseText);
  373. if (jObject["data"] != null)
  374. {
  375. foreach (var data in jObject["data"])
  376. {
  377. midAddressList.Add(new MidAddress()
  378. {
  379. des = JSON_SeleteNode(jObject, "des"),
  380. code = JSON_SeleteNode(jObject, "code"),
  381. order = data["order_number"].ToObject<string>(),
  382. number = data["order_quantity"].ToObject<string>(),
  383. pid = data["project_id"].ToObject<string>(),
  384. ctype = data["client_type"].ToObject<string>(),
  385. purl = data["packet_url"].ToObject<string>(),
  386. psize = data["packet_size"].ToObject<string>(),
  387. pmd5 = data["packet_md5"].ToObject<string>(),
  388. version = data["soft_version"].ToObject<string>(),
  389. host = midInfo.host
  390. });
  391. }
  392. }
  393. Log.WriteGetKeyLog("\r\nGet Mid address success:" + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  394. return true;
  395. }
  396. catch (Exception ex)
  397. {
  398. Log.WriteErrorLog("\r\nFail to parse MID address," + ex.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  399. CommonMethod.ReportErrormsg("Fail to parse MID address", ex.Message + "\r\n" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
  400. MessageBox.Show("Fail to parse MIDAddress info\r\n " + ex.Message);
  401. return false;
  402. }
  403. }
  404. /// <summary>
  405. /// 解析XML格式的DID
  406. /// </summary>
  407. /// <param name="str"></param>
  408. /// <param name="node"></param>
  409. /// <param name="node2"></param>
  410. /// <param name="code"></param>
  411. /// <param name="desc"></param>
  412. /// <param name="value"></param>
  413. /// <returns></returns>
  414. public static bool GetDIDKeyXml(string str, string node, string node2, out string code, out string desc, out string value)
  415. {
  416. code = "";
  417. value = "";
  418. try
  419. {
  420. XmlDocument xml = new XmlDocument();
  421. //xml.Load(path);
  422. xml.LoadXml(str);
  423. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  424. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  425. if (code == "200")
  426. {
  427. value = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("deviceid").InnerText;
  428. string CRC32 = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("crc32").InnerText;
  429. if (CrcUtils.CRC32(value) == Convert.ToUInt32(CRC32))
  430. {
  431. return true;
  432. }
  433. else
  434. {
  435. desc = "CRC32 error";
  436. return false;
  437. }
  438. }
  439. return false;
  440. }
  441. catch (Exception ex)
  442. {
  443. desc = ex.Message;
  444. return false;
  445. }
  446. }
  447. /// <summary>
  448. /// 解析其他keys
  449. /// </summary>
  450. /// <param name="url"></param>
  451. /// <param name="keymessage"></param>
  452. /// <param name="keytype"></param>
  453. /// <param name="sqliteConn"></param>
  454. /// <param name="key"></param>
  455. /// <param name="error"></param>
  456. /// <returns></returns>
  457. public static bool GetKeys(string url, string keymessage, string sn, string keytype, SQLiteConnection sqliteConn, out string key, out string error, string order, out string md5)
  458. {
  459. string code;
  460. string desc;
  461. error = "";
  462. key = "";
  463. md5 = "";
  464. HttpHelper http = new HttpHelper();
  465. HttpItem item = new HttpItem()
  466. {
  467. Encoding = Encoding.Default,
  468. Method = "post",
  469. ContentType = "application/x-www-form-urlencoded",
  470. KeepAlive = false
  471. };
  472. // 计算函数耗时;
  473. Stopwatch watch = new Stopwatch();
  474. watch.Start();
  475. switch (keymessage)
  476. {
  477. case "DeviceID":
  478. {
  479. item.URL = url + "/getid.do?";
  480. item.Postdata = "devicetype=tcl_unknown_model" + "&sn=" + sn;
  481. if (sn.Trim().Length > 0)
  482. item.Postdata += "&order=" + order;
  483. HttpResult result = http.GetHtml(item);
  484. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  485. {
  486. Log.WriteGetKeyLog("\r\nGetDeviceID:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  487. if (Xmlconfig.GetDIDKeyXml(result.Html, "response", "id", out code, out desc, out key))
  488. {
  489. //
  490. }
  491. else
  492. {
  493. error = desc;
  494. ReportErrormsg("Fail to parse DID", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  495. return false;
  496. }
  497. }
  498. else
  499. {
  500. error = result.StatusDescription;
  501. ReportErrormsg("Fail to get DID", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  502. return false;
  503. }
  504. break;
  505. }
  506. case "MAC":
  507. {
  508. item.URL = url + "/getmac.do?";
  509. item.Postdata = "typeString=" + keytype + "&sn=" + sn;
  510. if (sn.Trim().Length > 0)
  511. item.Postdata += "&order=" + order;
  512. HttpResult result = http.GetHtml(item);
  513. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  514. {
  515. Log.WriteGetKeyLog("\r\nGetMac:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  516. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "mac", out code, out desc, out key, out md5))
  517. {
  518. }
  519. else
  520. {
  521. error = desc;
  522. ReportErrormsg("Fail to parse Mac", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  523. return false;
  524. }
  525. }
  526. else
  527. {
  528. error = result.StatusDescription;
  529. ReportErrormsg("Fail to get Mac", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  530. return false;
  531. }
  532. break;
  533. }
  534. case "HDCP_KEY":
  535. {
  536. item.URL = url + "/gethdcpkey.do?";
  537. item.Postdata = "type=" + keytype + "&sn=" + sn;
  538. if (sn.Trim().Length > 0)
  539. item.Postdata += "&order=" + order;
  540. HttpResult result = http.GetHtml(item);
  541. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  542. {
  543. Log.WriteGetKeyLog("\r\nGetHDCP_KEY:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  544. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
  545. {
  546. }
  547. else
  548. {
  549. error = desc;
  550. ReportErrormsg("Fail to parse hdcp", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  551. return false;
  552. }
  553. }
  554. else
  555. {
  556. error = result.StatusDescription;
  557. ReportErrormsg("Fail to get hdcp", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  558. return false;
  559. }
  560. break;
  561. }
  562. case "CI_PLUS_KEY":
  563. {
  564. item.URL = url + "/getcikey.do?";
  565. item.Postdata = "type=" + keytype + "&sn=" + sn;
  566. if (sn.Trim().Length > 0)
  567. item.Postdata += "&order=" + order;
  568. HttpResult result = http.GetHtml(item);
  569. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  570. {
  571. Log.WriteGetKeyLog("\r\nGetCI_PLUS_KEY:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  572. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
  573. {
  574. }
  575. else
  576. {
  577. error = desc;
  578. ReportErrormsg("Fail to parse ciplus", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  579. return false;
  580. }
  581. }
  582. else
  583. {
  584. error = result.StatusDescription;
  585. ReportErrormsg("Fail to get ciplus", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  586. return false;
  587. }
  588. break;
  589. }
  590. case "WiDi":
  591. {
  592. item.URL = url + "/getwidi.do?";
  593. item.Postdata = "type=" + keytype + "&sn=" + sn;
  594. if (sn.Trim().Length > 0)
  595. item.Postdata += "&order=" + order;
  596. HttpResult result = http.GetHtml(item);
  597. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  598. {
  599. Log.WriteGetKeyLog("\r\nGetWiDi:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  600. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
  601. {
  602. }
  603. else
  604. {
  605. error = desc;
  606. ReportErrormsg("Fail to parse widi", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  607. return false;
  608. }
  609. }
  610. else
  611. {
  612. error = result.StatusDescription;
  613. ReportErrormsg("Fail to get widi", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  614. return false;
  615. }
  616. break;
  617. }
  618. case "HDCP2.2_KEY":
  619. {
  620. item.URL = url + "/gethdcpkey2.do?";
  621. item.Postdata = "type=" + keytype + "&sn=" + sn;
  622. if (sn.Trim().Length > 0)
  623. item.Postdata += "&order=" + order;
  624. HttpResult result = http.GetHtml(item);
  625. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  626. {
  627. Log.WriteGetKeyLog("\r\nGetHDCP2.2_KEY:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  628. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
  629. {
  630. }
  631. else
  632. {
  633. error = desc;
  634. ReportErrormsg("Fail to parse hdcp22", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  635. return false;
  636. }
  637. }
  638. else
  639. {
  640. error = result.StatusDescription;
  641. ReportErrormsg("Fail to get hdcp22", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  642. return false;
  643. }
  644. break;
  645. }
  646. case "NETFILX_ESN":
  647. {
  648. item.URL = url + "/getnetfilxesn.do?";
  649. item.Postdata = "type=" + keytype + "&sn=" + sn;
  650. if (sn.Trim().Length > 0)
  651. item.Postdata += "&order=" + order;
  652. HttpResult result = http.GetHtml(item);
  653. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  654. {
  655. Log.WriteGetKeyLog("\r\nGetNETFILX_ESN:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  656. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "esn", out code, out desc, out key, out md5))
  657. {
  658. }
  659. else
  660. {
  661. error = desc;
  662. ReportErrormsg("Fail to parse esn", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  663. return false;
  664. }
  665. }
  666. else
  667. {
  668. error = result.StatusDescription;
  669. ReportErrormsg("Fail to get esn", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  670. return false;
  671. }
  672. break;
  673. }
  674. case "MGK_KEY":
  675. {
  676. item.URL = url + "/getmgk.do?";
  677. item.Postdata = "type=" + keytype + "&sn=" + sn;
  678. if (sn.Trim().Length > 0)
  679. item.Postdata += "&order=" + order;
  680. HttpResult result = http.GetHtml(item);
  681. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  682. {
  683. Log.WriteGetKeyLog("\r\nGetMGK:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  684. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
  685. {
  686. }
  687. else
  688. {
  689. error = desc;
  690. ReportErrormsg("Fail to parse MGK", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  691. return false;
  692. }
  693. }
  694. else
  695. {
  696. error = result.StatusDescription;
  697. ReportErrormsg("Fail to get MGK", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  698. return false;
  699. }
  700. break;
  701. }
  702. case "Fairplay_KEY":
  703. {
  704. item.URL = url + "/getfairplay.do?";
  705. item.Postdata = "type=" + keytype + "&sn=" + sn;
  706. if (sn.Trim().Length > 0)
  707. item.Postdata += "&order=" + order;
  708. HttpResult result = http.GetHtml(item);
  709. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  710. {
  711. Log.WriteGetKeyLog("\r\nGetFairplay:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  712. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "fairplay", out code, out desc, out key, out md5))
  713. {
  714. }
  715. else
  716. {
  717. error = desc;
  718. ReportErrormsg("Fail to parse Fairplay", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  719. return false;
  720. }
  721. }
  722. else
  723. {
  724. error = result.StatusDescription;
  725. ReportErrormsg("Fail to get Fairplay", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  726. return false;
  727. }
  728. break;
  729. }
  730. case "ECP_KEY":
  731. {
  732. item.URL = url + "/getecp.do?";
  733. item.Postdata = "type=" + keytype + "&sn=" + sn;
  734. if (sn.Trim().Length > 0)
  735. item.Postdata += "&order=" + order;
  736. HttpResult result = http.GetHtml(item);
  737. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  738. {
  739. Log.WriteGetKeyLog("\r\nGetecp:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  740. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "ecp", out code, out desc, out key, out md5))
  741. {
  742. }
  743. else
  744. {
  745. error = desc;
  746. ReportErrormsg("Fail to parse ecp", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  747. return false;
  748. }
  749. }
  750. else
  751. {
  752. error = result.StatusDescription;
  753. ReportErrormsg("Fail to get ecp", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  754. return false;
  755. }
  756. break;
  757. }
  758. case "LEK":
  759. {
  760. item.URL = url + "/getlek.do?";
  761. item.Postdata = "type=" + keytype + "&sn=" + sn;
  762. if (sn.Trim().Length > 0)
  763. item.Postdata += "&order=" + order;
  764. HttpResult result = http.GetHtml(item);
  765. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  766. {
  767. Log.WriteGetKeyLog("\r\nGetlek:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  768. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "lek", out code, out desc, out key, out md5))
  769. {
  770. }
  771. else
  772. {
  773. error = desc;
  774. ReportErrormsg("Fail to parse lek", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  775. return false;
  776. }
  777. }
  778. else
  779. {
  780. error = result.StatusDescription;
  781. ReportErrormsg("Fail to get lek", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  782. return false;
  783. }
  784. break;
  785. }
  786. case "PEK":
  787. {
  788. item.URL = url + "/getpek.do?";
  789. item.Postdata = "type=" + keytype + "&sn=" + sn;
  790. if (sn.Trim().Length > 0)
  791. item.Postdata += "&order=" + order;
  792. HttpResult result = http.GetHtml(item);
  793. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  794. {
  795. Log.WriteGetKeyLog("\r\nGetpek:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  796. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "pek", out code, out desc, out key, out md5))
  797. {
  798. }
  799. else
  800. {
  801. error = desc;
  802. ReportErrormsg("Fail to parse pek", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  803. return false;
  804. }
  805. }
  806. else
  807. {
  808. error = result.StatusDescription;
  809. ReportErrormsg("Fail to get pek", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  810. return false;
  811. }
  812. break;
  813. }
  814. case "PlayReady_key":
  815. {
  816. item.URL = url + "/getplayready.do?";
  817. item.Postdata = "type=" + keytype + "&sn=" + sn;
  818. if (sn.Trim().Length > 0)
  819. item.Postdata += "&order=" + order;
  820. HttpResult result = http.GetHtml(item);
  821. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  822. {
  823. Log.WriteGetKeyLog("\r\nGetplayready:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  824. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "playReady", out code, out desc, out key, out md5))
  825. {
  826. }
  827. else
  828. {
  829. error = desc;
  830. ReportErrormsg("Fail to parse playready", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  831. return false;
  832. }
  833. }
  834. else
  835. {
  836. error = result.StatusDescription;
  837. ReportErrormsg("Fail to get playready", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  838. return false;
  839. }
  840. break;
  841. }
  842. case "Hashkey":
  843. {
  844. item.URL = url + "/gethash.do?";
  845. item.Postdata = "type=" + keytype + "&sn=" + sn;
  846. if (sn.Trim().Length > 0)
  847. item.Postdata += "&order=" + order;
  848. HttpResult result = http.GetHtml(item);
  849. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  850. {
  851. Log.WriteGetKeyLog("\r\nGethash:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  852. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "hash", out code, out desc, out key, out md5))
  853. {
  854. }
  855. else
  856. {
  857. error = desc;
  858. ReportErrormsg("Fail to parse hash", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  859. return false;
  860. }
  861. }
  862. else
  863. {
  864. error = result.StatusDescription;
  865. ReportErrormsg("Fail to get hash", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  866. return false;
  867. }
  868. break;
  869. }
  870. case "YouTube_KEY":
  871. {
  872. item.URL = url + "/getYoutubeKey.do?";
  873. item.Postdata = "type=" + keytype + "&sn=" + sn;
  874. if (sn.Trim().Length > 0)
  875. item.Postdata += "&order=" + order;
  876. HttpResult result = http.GetHtml(item);
  877. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  878. {
  879. Log.WriteGetKeyLog("\r\nGet youtube key:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  880. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "youtubeKey", out code, out desc, out key, out md5))
  881. {
  882. }
  883. else
  884. {
  885. error = desc;
  886. ReportErrormsg("Fail to parse youtube key", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  887. return false;
  888. }
  889. }
  890. else
  891. {
  892. error = result.StatusDescription;
  893. ReportErrormsg("Fail to get youtube key", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  894. return false;
  895. }
  896. break;
  897. }
  898. case "DAK":
  899. {
  900. item.URL = url + "/getdak.do?";
  901. item.Postdata = "type=" + keytype + "&sn=" + sn;
  902. if (sn.Trim().Length > 0)
  903. item.Postdata += "&order=" + order;
  904. HttpResult result = http.GetHtml(item);
  905. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  906. {
  907. Log.WriteGetKeyLog("\r\nGetDAK:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  908. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "dak", out code, out desc, out key, out md5))
  909. {
  910. }
  911. else
  912. {
  913. error = desc;
  914. ReportErrormsg("Fail to parse dak", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  915. return false;
  916. }
  917. }
  918. else
  919. {
  920. error = result.StatusDescription;
  921. ReportErrormsg("Fail to get dak", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  922. return false;
  923. }
  924. break;
  925. }
  926. }
  927. watch.Stop();
  928. Log.WriteInfoLog(string.Format("[GetKeys] order={0},sn={1},keytype={2},keymessage={3}, Elapsed={4}", order,sn,keytype,keymessage,watch.Elapsed.TotalMilliseconds));
  929. return true;
  930. }
  931. public static bool GetWidevineAnAttestationKey(
  932. string url,
  933. string sn,
  934. string keytype,
  935. SQLiteConnection sqliteConn,
  936. out bool isAndroidTV,
  937. out string Widevinekey,
  938. out string Attestationkey,
  939. out string error,
  940. string order,
  941. out string AttestationMd5)
  942. {
  943. string code;
  944. string desc;
  945. isAndroidTV = false;
  946. error = "";
  947. Widevinekey = "";
  948. Attestationkey = "";
  949. AttestationMd5 = "";
  950. HttpHelper http = new HttpHelper();
  951. HttpItem item = new HttpItem()
  952. {
  953. Encoding = Encoding.Default,
  954. Method = "post",
  955. ContentType = "application/x-www-form-urlencoded",
  956. KeepAlive = false
  957. };
  958. // 计算函数耗时;
  959. Stopwatch watch = new Stopwatch();
  960. watch.Start();
  961. item.URL = url + "/getWidevineAndAttestation.do?";
  962. item.Postdata = "type=" + keytype + "&order=" + order + "&sn=" + sn;
  963. HttpResult result = http.GetHtml(item);
  964. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  965. {
  966. Log.WriteGetKeyLog("\r\nGetWidevine_KEY:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  967. if (!Xmlconfig.GetWidevineAndAttestationKeyXml(result.Html, "response", out code, out desc, out isAndroidTV, out Widevinekey, out Attestationkey, out AttestationMd5))
  968. {
  969. error = desc;
  970. ReportErrormsg("Fail to parse widevineAndAttestation", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  971. return false;
  972. }
  973. }
  974. else
  975. {
  976. error = result.StatusDescription;
  977. ReportErrormsg("Fail to get widevineAndAttestation", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  978. return false;
  979. }
  980. watch.Stop();
  981. Log.WriteInfoLog(string.Format("[getWidevineAndAttestation] order={0},sn={1},keytype={2},Elapsed={3}", order, sn, keytype, watch.Elapsed.TotalMilliseconds));
  982. return true;
  983. }
  984. public static bool GetAcasKey(string url, string keymessage, string sn, string keytype, SQLiteConnection sqliteConn, string order, out string acaskey_data, out string acaskey_datamd5, out string acaskey_tool, out string acaskey_toolmd5, out string error)
  985. {
  986. string code;
  987. string desc;
  988. error = "";
  989. acaskey_data = "";
  990. acaskey_datamd5 = "";
  991. acaskey_tool = "";
  992. acaskey_toolmd5 = "";
  993. HttpHelper http = new HttpHelper();
  994. HttpItem item = new HttpItem()
  995. {
  996. Encoding = Encoding.Default,
  997. Method = "post",
  998. ContentType = "application/x-www-form-urlencoded",
  999. KeepAlive = false
  1000. };
  1001. // 计算函数耗时;
  1002. Stopwatch watch = new Stopwatch();
  1003. watch.Start();
  1004. item.URL = url + "/getAcasKey.do?";
  1005. item.Postdata = "type=" + keytype + "&sn=" + sn;
  1006. if (sn.Trim().Length > 0)
  1007. item.Postdata += "&order=" + order;
  1008. HttpResult result = http.GetHtml(item);
  1009. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1010. {
  1011. Log.WriteGetKeyLog("\r\nGet ACAS key:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  1012. if (Xmlconfig.Get2KeyInfoFromXml(result.Html, "acasKey_data", "acasKey_tool", out code, out desc, out acaskey_data, out acaskey_datamd5, out acaskey_tool, out acaskey_toolmd5))
  1013. {
  1014. }
  1015. else
  1016. {
  1017. error = desc;
  1018. ReportErrormsg("Fail to parse ACAS key", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  1019. return false;
  1020. }
  1021. }
  1022. else
  1023. {
  1024. error = result.StatusDescription;
  1025. ReportErrormsg("Fail to get ACAS key", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  1026. return false;
  1027. }
  1028. watch.Stop();
  1029. Log.WriteInfoLog(string.Format("[getAcasKey] order={0},sn={1},keytype={2},Elapsed={3}", order, sn, keytype, watch.Elapsed.TotalMilliseconds));
  1030. return true;
  1031. }
  1032. /// <summary>
  1033. /// 异常上报
  1034. /// </summary>
  1035. /// <param name="reportType"></param>
  1036. /// <param name="reportData"></param>
  1037. /// <param name="sqliteConn"></param>
  1038. /// <returns></returns>
  1039. public static bool ReportErrormsg(string reportType, string reportData, SQLiteConnection sqliteConn)
  1040. {
  1041. // 计算函数耗时;
  1042. Stopwatch watch = new Stopwatch();
  1043. watch.Start();
  1044. ErrorInfo ErrorInfo1 = new ErrorInfo { reportType = reportType, reportData = reportData.Replace("'", ""), version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(), factory = FactoryName, mac = TestMode.MAC, reportTime = System.DateTime.Now.ToString(("yyyy-MM-dd HH:mm:ss")) };
  1045. string jsonError = Newtonsoft.Json.JsonConvert.SerializeObject(ErrorInfo1, Newtonsoft.Json.Formatting.Indented);
  1046. HttpHelper http = new HttpHelper();
  1047. HttpItem item = new HttpItem()
  1048. {
  1049. URL = TestMode.errorreportServerurl,//URL这里都是测试URl   必需项
  1050. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  1051. //Encoding = Encoding.Default,
  1052. Method = "post",//URL     可选项 默认为Get
  1053. Postdata = jsonError,
  1054. PostEncoding = Encoding.UTF8,
  1055. KeepAlive = false
  1056. };
  1057. item.ContentType = "application/json;charset=utf-8";
  1058. HttpResult result = http.GetHtml(item);
  1059. string ParseText = result.Html;
  1060. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1061. {
  1062. Log.WriteGetKeyLog("\r\nReportErrormsg:\r\n" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + jsonError);
  1063. }
  1064. else
  1065. {
  1066. if (HTTPChecker(item.URL))
  1067. SQLiteHelper.InsertDelayErrorReport(sqliteConn, new object[] { item.URL, item.Postdata });
  1068. Log.WriteErrorLog("\r\nFail to ReportErrormsg:\r\n" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + jsonError);
  1069. return false;
  1070. }
  1071. try
  1072. {
  1073. JObject jObject = JObject.Parse(ParseText);
  1074. string message = jObject["message"].Value<string>();
  1075. string code = jObject["code"].Value<string>();
  1076. if (code != "1000")
  1077. {
  1078. Log.WriteErrorLog("\r\nError report return error:\r\n" + ParseText + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + jsonError);
  1079. return false;
  1080. }
  1081. watch.Stop();
  1082. Log.WriteInfoLog(string.Format("[ReportErrormsg] Elapsed={0}", watch.Elapsed.TotalMilliseconds));
  1083. return true;
  1084. }
  1085. catch (Exception ex)
  1086. {
  1087. Log.WriteErrorLog("\r\nFail to parse Error report return info," + ex.Message + ":" + ParseText + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + jsonError);
  1088. return false;
  1089. }
  1090. }
  1091. /// <summary>
  1092. /// 上报预绑定包下载结果
  1093. /// </summary>
  1094. /// <param name="url"></param>
  1095. /// <param name="order"></param>
  1096. /// <param name="sqliteConn"></param>
  1097. /// <returns></returns>
  1098. public static bool ReportDownloadStatus(string url, string order, SQLiteConnection sqliteConn)
  1099. {
  1100. HttpHelper http = new HttpHelper();
  1101. HttpItem item = new HttpItem()
  1102. {
  1103. URL = url + "/getreportofflinesn.do?",//URL这里都是测试URl   必需项
  1104. Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  1105. //Encoding = Encoding.Default,
  1106. Method = "post",//URL     可选项 默认为Get
  1107. Postdata = ("orderNumber =" + order),
  1108. KeepAlive = false
  1109. };
  1110. item.ContentType = "application/x-www-form-urlencoded";
  1111. HttpResult result = http.GetHtml(item);
  1112. string ParseText = result.Html;
  1113. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1114. {
  1115. //
  1116. }
  1117. else
  1118. {
  1119. Log.WriteErrorLog("\r\nFail to report download status:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order));
  1120. CommonMethod.ReportErrormsg("Fail to report download status", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order), sqliteConn);
  1121. return false;
  1122. }
  1123. try
  1124. {
  1125. JObject jObject = JObject.Parse(ParseText);
  1126. string des = JSON_SeleteNode(jObject, "des");
  1127. string code = JSON_SeleteNode(jObject, "code");
  1128. string data = JSON_SeleteNode(jObject, "data");
  1129. if (code == "1000")
  1130. return true;
  1131. else
  1132. {
  1133. Log.WriteErrorLog("\r\nError report download status,should be 1000:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order));
  1134. CommonMethod.ReportErrormsg("Error download status code return", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order), sqliteConn);
  1135. return false;
  1136. }
  1137. }
  1138. catch (Exception ex)
  1139. {
  1140. MessageBox.Show(ex.Message);
  1141. Log.WriteErrorLog("\r\n" + ex.Message + ":" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order));
  1142. CommonMethod.ReportErrormsg("Error parse download status return", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order), sqliteConn);
  1143. return false;
  1144. }
  1145. }
  1146. /// <summary>
  1147. /// 生成DB格式key json字符串
  1148. /// </summary>
  1149. /// <param name="keyInfo"></param>
  1150. /// <param name="keydata"></param>
  1151. /// <param name="error"></param>
  1152. /// <returns></returns>
  1153. public static bool CreateDBkeyString(KeyInfo keyInfo, out string keydata, out string error)
  1154. {
  1155. keydata = "";
  1156. error = "";
  1157. try
  1158. {
  1159. DBKeysStringFormat DBKeysStringFormat1 = new DBKeysStringFormat { cikey = keyInfo.CI_plus == null ? "" : keyInfo.CI_plus, esn = keyInfo.ESN == null ? "" : keyInfo.ESN, hdcp = keyInfo.HDCP == null ? "" : keyInfo.HDCP, widevine = keyInfo.Widevine == null ? "" : keyInfo.Widevine, hdcp22 = keyInfo.HDCP22 == null ? "" : keyInfo.HDCP22, did = keyInfo.DID == null ? "" : keyInfo.DID, mac = keyInfo.Mac == null ? "" : keyInfo.Mac, widi = keyInfo.WiDi == null ? "" : keyInfo.WiDi, attestation = keyInfo.Attestation == null ? "" : keyInfo.Attestation, mgk = keyInfo.MGK == null ? "" : keyInfo.MGK };
  1160. keydata = Newtonsoft.Json.JsonConvert.SerializeObject(DBKeysStringFormat1, Newtonsoft.Json.Formatting.Indented);
  1161. return true;
  1162. }
  1163. catch (Exception ex)
  1164. {
  1165. error = ex.Message;
  1166. return false;
  1167. }
  1168. }
  1169. /// <summary>
  1170. /// 获取相应json子节点的值
  1171. /// </summary>
  1172. /// <param name="childnodelist"></param>
  1173. public static string JSON_SeleteNode(JToken json, string ReName)
  1174. {
  1175. try
  1176. {
  1177. string result = "";
  1178. //这里6.0版块可以用正则匹配
  1179. var node = json.SelectToken("$.." + ReName);
  1180. if (node != null)
  1181. {
  1182. //判断节点类型
  1183. if (node.Type == JTokenType.String || node.Type == JTokenType.Integer || node.Type == JTokenType.Float)
  1184. {
  1185. //返回string值
  1186. result = node.Value<object>().ToString();
  1187. }
  1188. }
  1189. return result;
  1190. }
  1191. catch (Exception ex)
  1192. {
  1193. return "";
  1194. }
  1195. }
  1196. /// <summary>
  1197. /// 确认是否为有效的url(检测开头是否为http://或者https://)
  1198. /// </summary>
  1199. /// <param name="Value"></param>
  1200. /// <returns></returns>
  1201. public static bool HTTPChecker(string Value)
  1202. {
  1203. try
  1204. {
  1205. if ((Value.Substring(0, 7) == "http://") || (Value.Substring(0, 8) == "https://"))
  1206. {
  1207. return true;
  1208. }
  1209. else
  1210. return false;
  1211. }
  1212. catch (Exception ex)
  1213. {
  1214. return false;
  1215. }
  1216. }
  1217. /// <summary>
  1218. /// 检查是否能正常访问网络
  1219. /// </summary>
  1220. /// <param name="url"></param>
  1221. /// <returns></returns>
  1222. public static bool CheckUrlConnection(string url)
  1223. {
  1224. try
  1225. {
  1226. HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
  1227. myRequest.Method = "HEAD"; //设置提交方式可以为"get","head"等
  1228. myRequest.Timeout = 10000; //设置网页响应时间长度
  1229. myRequest.AllowAutoRedirect = false;//是否允许自动重定向
  1230. myRequest.UseDefaultCredentials = true;
  1231. HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
  1232. myRequest.UseDefaultCredentials = true;//权限设置
  1233. return (myResponse.StatusCode == HttpStatusCode.OK);//返回响应的状态
  1234. }
  1235. catch (Exception ex)
  1236. {
  1237. return false;
  1238. }
  1239. }
  1240. /// <summary>
  1241. /// 指定目录创建文件夹
  1242. /// </summary>
  1243. /// <param name="path"></param>
  1244. public static void CreateDirectory(string path)
  1245. {
  1246. if (!Directory.Exists(path))//如果不存在就创建file文件夹
  1247. {
  1248. Directory.CreateDirectory(path);
  1249. }
  1250. }
  1251. /// <summary>
  1252. /// 在线下载抄写模式抄写的上报
  1253. /// </summary>
  1254. /// <param name="content"></param>
  1255. /// <returns></returns>
  1256. public static bool UploadCopyResult(string content, string url, SQLiteConnection sqliteConn, string order, bool repeatupload, string id, int timeout)
  1257. {
  1258. if (timeout < 5000)
  1259. timeout = 5000;
  1260. HttpHelper http = new HttpHelper();
  1261. HttpItem item = new HttpItem()
  1262. {
  1263. Encoding = Encoding.UTF8,
  1264. Method = "post",
  1265. ContentType = "application/x-www-form-urlencoded",
  1266. Timeout = timeout,
  1267. KeepAlive = false
  1268. };
  1269. item.PostEncoding = Encoding.UTF8;
  1270. item.URL = url;
  1271. item.Postdata = content;
  1272. System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
  1273. stopwatch.Start();
  1274. HttpResult result = http.GetHtml(item);
  1275. stopwatch.Stop();
  1276. string usingtime = stopwatch.ElapsedMilliseconds.ToString();
  1277. stopwatch.Reset();
  1278. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1279. {
  1280. if (Xmlconfig.ReportXml(result.Html, "response", out string code, out string desc))
  1281. {
  1282. Log.WriteGetKeyLog("\r\nUpload copy status success:\r\nUsing time:" + usingtime + "ms\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  1283. return true;
  1284. }
  1285. else
  1286. {
  1287. CommonMethod.ReportErrormsg("Fail to parse copy result return", desc + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, sqliteConn);
  1288. Log.WriteErrorLog(code + "Error");
  1289. if (repeatupload)
  1290. {
  1291. SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
  1292. }
  1293. return false;
  1294. }
  1295. }
  1296. else
  1297. {
  1298. if (repeatupload)
  1299. return false;
  1300. if (CommonMethod.HTTPChecker(item.URL))
  1301. SQLiteHelper.InsertDelayCopyReport(sqliteConn, new object[] { order, item.URL, item.Postdata });
  1302. CommonMethod.ReportErrormsg("Fail to upload copy result", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, sqliteConn);
  1303. return true;
  1304. }
  1305. }
  1306. /// <summary>
  1307. /// 本地DB存储的异常重新上报
  1308. /// </summary>
  1309. /// <param name="reportType"></param>
  1310. /// <param name="reportData"></param>
  1311. /// <param name="sqliteConn"></param>
  1312. /// <returns></returns>
  1313. public static bool ReportErrormsg2(string url, string content, out bool mark)
  1314. {
  1315. mark = false;
  1316. HttpHelper http = new HttpHelper();
  1317. HttpItem item = new HttpItem()
  1318. {
  1319. URL = url,//URL这里都是测试URl   必需项
  1320. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  1321. //Encoding = Encoding.Default,
  1322. Method = "post",//URL     可选项 默认为Get
  1323. Postdata = content,
  1324. PostEncoding = Encoding.UTF8,
  1325. KeepAlive = false
  1326. };
  1327. item.ContentType = "application/json;charset=utf-8";
  1328. HttpResult result = http.GetHtml(item);
  1329. string ParseText = result.Html;
  1330. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1331. {
  1332. mark = true;
  1333. Log.WriteGetKeyLog("\r\nReportErrormsg:\r\n" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + content);
  1334. }
  1335. else
  1336. {
  1337. Log.WriteErrorLog("\r\nFail to ReportErrormsg:\r\n" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + content);
  1338. return false;
  1339. }
  1340. try
  1341. {
  1342. JObject jObject = JObject.Parse(ParseText);
  1343. string message = jObject["message"].Value<string>();
  1344. string code = jObject["code"].Value<string>();
  1345. if (code == "1000")
  1346. return true;
  1347. else
  1348. {
  1349. Log.WriteErrorLog("\r\nError report return error:\r\n" + ParseText + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + content);
  1350. return false;
  1351. }
  1352. }
  1353. catch (Exception ex)
  1354. {
  1355. Log.WriteErrorLog("\r\nFail to parse Error report return info," + ex.Message + ":" + ParseText + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + content);
  1356. return false;
  1357. }
  1358. }
  1359. /// <summary>
  1360. /// 判断目标字符串是否只有数字和字母
  1361. /// </summary>
  1362. /// <param name="value">目标字符串</param>
  1363. /// <returns></returns>
  1364. public static bool IsNumberAndWord(string value)
  1365. {
  1366. if (value is null)
  1367. return false;
  1368. Regex r = new Regex(@"^[a-zA-Z0-9]+$");
  1369. return r.Match(value).Success;
  1370. }
  1371. public static bool InsertJsonConfig(string node, string key)
  1372. {
  1373. JObject jObject;
  1374. using (StreamReader file = new StreamReader(LocalPath.localpath + "\\Config.json"))
  1375. {
  1376. using (JsonTextReader reader = new JsonTextReader(file))
  1377. {
  1378. jObject = (JObject)JToken.ReadFrom(reader);
  1379. jObject[node][key] = true;
  1380. }
  1381. }
  1382. using (StreamWriter writer = new StreamWriter(LocalPath.localpath + "\\Config.json"))
  1383. {
  1384. writer.Write(jObject.ToString());
  1385. }
  1386. return true;
  1387. }
  1388. public static bool AddJsonConfig(string key, object value)
  1389. {
  1390. JObject jObject;
  1391. using (StreamReader file = new StreamReader(LocalPath.localpath + "\\Config.json"))
  1392. {
  1393. using (JsonTextReader reader = new JsonTextReader(file))
  1394. {
  1395. jObject = (JObject)JToken.ReadFrom(reader);
  1396. jObject.Add(key, (JToken)value);
  1397. }
  1398. }
  1399. using (StreamWriter writer = new StreamWriter(LocalPath.localpath + "\\Config.json"))
  1400. {
  1401. writer.Write(jObject.ToString());
  1402. }
  1403. return false;
  1404. }
  1405. /// <summary>
  1406. /// 预下载模式抄写的上报
  1407. /// </summary>
  1408. /// <param name="copydate">烧录时间</param>
  1409. /// <returns></returns>
  1410. public static bool UploadPreloadCopyResult(string host, string copydate, string SN, SQLiteConnection localDBNow, SQLiteConnection sqliteConn, bool repeatupload, string id, int timeout)
  1411. {
  1412. string ParseText = "";
  1413. bool status;
  1414. try
  1415. {
  1416. List<PostDateClass> postList = new List<PostDateClass>();
  1417. postList.Add(new PostDateClass("sn", SN));
  1418. postList.Add(new PostDateClass("date", copydate));
  1419. ParseText = FormPost.postFileMessage(host + "/reportlist.do?", postList, out status, timeout);
  1420. if (status)
  1421. {
  1422. JObject jObject = JObject.Parse(ParseText);
  1423. string des = CommonMethod.JSON_SeleteNode(jObject, "des");
  1424. string code = CommonMethod.JSON_SeleteNode(jObject, "code");
  1425. string data = JSON_SeleteNode(jObject, "data");
  1426. if (code == "1000")
  1427. {
  1428. //更新上报内容
  1429. if (SQLiteHelper.UpdateReportStatus(localDBNow, SN))
  1430. {
  1431. //更新成功
  1432. Log.WriteGetKeyLog("\r\nUpdateReportStatus success:\r\n" + host + "/reportlist.do?\r\n" + "sn=" + SN + "\r\ndate=" + copydate + "\r\n" + ParseText);
  1433. return true;
  1434. }
  1435. else
  1436. {
  1437. Log.WriteErrorLog("\r\nFail to UpdateReportStatus: " + SN);
  1438. return false;
  1439. }
  1440. }
  1441. else
  1442. {
  1443. CommonMethod.ReportErrormsg("Fail to UploadPreloadCopyResult", "Address: " + host + "/reportlist.do?" + "\r\nPostdata: " + "sn=" + SN + "\r\ndate=" + copydate + "\r\n" + ParseText, sqliteConn);
  1444. Log.WriteErrorLog("\r\nUpdateReportStatus code return error,should be 1000 " + "\r\n" + SN + ":" + ParseText + "\r\nAddress:" + host + "/reportlist.do?" + "\r\nPostdata: " + "sn=" + SN + "\r\ndate=" + copydate);
  1445. if (repeatupload)
  1446. {
  1447. SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
  1448. }
  1449. return false;
  1450. }
  1451. }
  1452. else
  1453. {
  1454. if (repeatupload)
  1455. return false;
  1456. if (CommonMethod.HTTPChecker(host))
  1457. SQLiteHelper.InsertDelayCopyReport(sqliteConn, new object[] { "preload_mode", host, SN + "@" + copydate });
  1458. return false;
  1459. }
  1460. }
  1461. catch (Exception ex)
  1462. {
  1463. Log.WriteErrorLog("\r\nFail to parse UpdateReportStatus return: " + ex.Message + "\r\n" + SN + ":" + ParseText);
  1464. return false;
  1465. }
  1466. }
  1467. /// <summary>
  1468. /// 预下载模式抄写的批量上报
  1469. /// </summary>
  1470. /// <param name="host"></param>
  1471. /// <param name="postList"></param>
  1472. /// <param name="localDBNow"></param>
  1473. /// <param name="sqliteConn"></param>
  1474. /// <param name="repeatupload"></param>
  1475. /// <param name="id"></param>
  1476. /// <returns></returns>
  1477. public static bool UploadPreloadCopyResultList(string host, List<PostDateClass> postList, SQLiteConnection localDBNow, SQLiteConnection sqliteConn, bool repeatupload, string id)
  1478. {
  1479. string ParseText = "";
  1480. bool status;
  1481. try
  1482. {
  1483. ParseText = FormPost.postFileMessage(host + "/reportlist.do?", postList, out status, 30000);
  1484. if (status)
  1485. {
  1486. JObject jObject = JObject.Parse(ParseText);
  1487. string des = CommonMethod.JSON_SeleteNode(jObject, "des");
  1488. string code = CommonMethod.JSON_SeleteNode(jObject, "code");
  1489. string data = JSON_SeleteNode(jObject, "data");
  1490. if (code == "1000")
  1491. {
  1492. Log.WriteGetKeyLog("UploadPreloadCopyResult successful\r\nAddress: " + host + "/reportlist.do?" + ParseText);
  1493. return true;
  1494. }
  1495. else
  1496. {
  1497. CommonMethod.ReportErrormsg("Fail to UploadPreloadCopyResult", "Address: " + host + "/reportlist.do?" + ParseText, sqliteConn);
  1498. Log.WriteErrorLog("\r\nUpdateReportStatus code return error,should be 1000 " + "\r\n" + ParseText + "\r\nAddress:" + host + "/reportlist.do?");
  1499. if (repeatupload)
  1500. {
  1501. SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
  1502. }
  1503. return false;
  1504. }
  1505. }
  1506. else
  1507. {
  1508. Log.WriteErrorLog("Fail to UploadPreloadCopyResult\r\nAddress: " + host + "/reportlist.do?" + ParseText);
  1509. return false;
  1510. }
  1511. }
  1512. catch (Exception ex)
  1513. {
  1514. Log.WriteErrorLog("\r\nFail to parse UpdateReportStatus return: " + ex.Message + "\r\n" + ParseText);
  1515. return false;
  1516. }
  1517. }
  1518. /// <summary>
  1519. /// byte[]数组到int转换
  1520. /// </summary>
  1521. /// <param name="value"></param>
  1522. /// <returns></returns>
  1523. public static int BytelisttoInt(byte[] value)
  1524. {
  1525. Array.Reverse(value);
  1526. int result = 0;
  1527. for (int i = 0; i < value.Length; i++)
  1528. {
  1529. result += value[i] << i * 8;
  1530. }
  1531. return result;
  1532. }
  1533. /// <summary>
  1534. /// int类型到byte[]数组转换
  1535. /// </summary>
  1536. /// <param name="value"></param>
  1537. /// <returns></returns>
  1538. public static byte[] InttoBytelist(int value)
  1539. {
  1540. byte[] bytes = BitConverter.GetBytes(value);
  1541. Array.Reverse(bytes);
  1542. if (value == 0)
  1543. return bytes;
  1544. List<byte> list = new List<byte>();
  1545. list.AddRange(bytes);
  1546. while (true)
  1547. {
  1548. if (list[0] != 0)
  1549. break;
  1550. else
  1551. list.RemoveAt(0);
  1552. }
  1553. bytes = list.ToArray();
  1554. return bytes;
  1555. }
  1556. /// <summary>
  1557. /// 升级检查
  1558. /// </summary>
  1559. /// <param name="url"></param>
  1560. /// <param name="FactoryNum"></param>
  1561. /// <param name="sqliteConn"></param>
  1562. /// <param name="upmid"></param>
  1563. /// <returns></returns>
  1564. public static bool UpgradeCheck(string url, string FactoryNum, SQLiteConnection sqliteConn, out UpgradeMsgList upmid)
  1565. {
  1566. upmid = new UpgradeMsgList();
  1567. UpgradeCheckInput UpgradeCheckInput1 = new UpgradeCheckInput { appid = "SCBC_Factory_Tools", devicemodel = "SCBC_Factory_Tools", dnum = FactoryNum, ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(), type = "pc" };//System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
  1568. string jsonorder = Newtonsoft.Json.JsonConvert.SerializeObject(UpgradeCheckInput1, Newtonsoft.Json.Formatting.Indented);
  1569. HttpHelper http = new HttpHelper();
  1570. HttpItem item = new HttpItem()
  1571. {
  1572. URL = url,//URL这里都是测试URl   必需项
  1573. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  1574. //Encoding = Encoding.Default,
  1575. Method = "post",//URL     可选项 默认为Get
  1576. Postdata = jsonorder,
  1577. PostEncoding = Encoding.UTF8,
  1578. KeepAlive = false
  1579. };
  1580. item.ContentType = "application/json;charset=utf-8";
  1581. ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
  1582. | SecurityProtocolType.Tls
  1583. | SecurityProtocolType.Tls11//(SecurityProtocolType)0x300 //Tls11
  1584. | SecurityProtocolType.Tls12;//(SecurityProtocolType)0xC00; //Tls12
  1585. HttpResult result = http.GetHtml(item);
  1586. string ParseText = result.Html;
  1587. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1588. {
  1589. Log.WriteGetKeyLog("\r\nUpgrade check," + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1590. }
  1591. else
  1592. {
  1593. Log.WriteErrorLog("\r\nFail to upgrade check:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1594. ReportErrormsg("Fail to upgrade check", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1595. return false;
  1596. }
  1597. try
  1598. {
  1599. JObject jObject = JObject.Parse(ParseText);
  1600. upmid.servertime = jObject["servertime"].Value<string>();
  1601. upmid.callid = jObject["callid"].Value<string>();
  1602. upmid.state = jObject["state"].Value<string>();
  1603. upmid.note = jObject["note"].Value<string>();
  1604. upmid.language = jObject["language"].Value<string>();
  1605. upmid.apiversion = jObject["apiversion"].Value<string>();
  1606. upmid.upgrade = new UpgradeMsgList2()
  1607. {
  1608. type = JSON_SeleteNode(jObject, "type"),
  1609. appid = JSON_SeleteNode(jObject, "appid"),
  1610. apptype = JSON_SeleteNode(jObject, "apptype"),
  1611. version = JSON_SeleteNode(jObject, "version"),
  1612. verid = JSON_SeleteNode(jObject, "verid"),
  1613. md5 = JSON_SeleteNode(jObject, "md5"),
  1614. size = JSON_SeleteNode(jObject, "size"),
  1615. minicon = JSON_SeleteNode(jObject, "minicon"),
  1616. midicon = JSON_SeleteNode(jObject, "midicon"),
  1617. fileurl = JSON_SeleteNode(jObject, "fileurl"),
  1618. increment = JSON_SeleteNode(jObject, "increment"),
  1619. appendver = JSON_SeleteNode(jObject, "appendver"),
  1620. updatetime = JSON_SeleteNode(jObject, "updatetime")
  1621. };
  1622. if (upmid.state == "0000")
  1623. return true;
  1624. else
  1625. {
  1626. return false;
  1627. }
  1628. }
  1629. catch (Exception ex)
  1630. {
  1631. Log.WriteErrorLog("\r\nFail to parse upgrade check info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1632. ReportErrormsg("Fail to parse upgrade check info", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1633. MessageBox.Show("Fail to parse upgrade check info\r\n " + ex.Message);
  1634. return false;
  1635. }
  1636. }
  1637. /// <summary>
  1638. /// 升级上报
  1639. /// </summary>
  1640. /// <param name="url"></param>
  1641. /// <param name="FactoryNum"></param>
  1642. /// <param name="Result"></param>
  1643. /// <param name="sqliteConn"></param>
  1644. /// <returns></returns>
  1645. public static bool UpgradeReport(string url, string FactoryNum, string Result, SQLiteConnection sqliteConn)
  1646. {
  1647. UpgradeReportInput UpgradeCheckInput1 = new UpgradeReportInput { appid = "SCBC_Factory_Tools", devmodel = "SCBC_Factory_Tools", dnum = FactoryNum, ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(), type = "pc", result = Result };
  1648. string jsonorder = Newtonsoft.Json.JsonConvert.SerializeObject(UpgradeCheckInput1, Newtonsoft.Json.Formatting.Indented);
  1649. HttpHelper http = new HttpHelper();
  1650. HttpItem item = new HttpItem()
  1651. {
  1652. URL = url,//URL这里都是测试URl   必需项
  1653. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  1654. //Encoding = Encoding.Default,
  1655. Method = "post",//URL     可选项 默认为Get
  1656. Postdata = jsonorder,
  1657. PostEncoding = Encoding.UTF8,
  1658. KeepAlive = false
  1659. };
  1660. item.ContentType = "application/json;charset=utf-8";
  1661. ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
  1662. | SecurityProtocolType.Tls
  1663. | (SecurityProtocolType)0x300 //Tls11
  1664. | (SecurityProtocolType)0xC00; //Tls12
  1665. HttpResult result = http.GetHtml(item);
  1666. string ParseText = result.Html;
  1667. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1668. {
  1669. Log.WriteGetKeyLog("\r\nUpgrade report," + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1670. }
  1671. else
  1672. {
  1673. Log.WriteErrorLog("\r\nFail to upgrade report:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1674. ReportErrormsg("Fail to upgrade report", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1675. return false;
  1676. }
  1677. try
  1678. {
  1679. JObject jObject = JObject.Parse(ParseText);
  1680. return true;
  1681. }
  1682. catch (Exception ex)
  1683. {
  1684. Log.WriteErrorLog("\r\nFail to parse upgrade report info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1685. ReportErrormsg("Fail to parse upgrade report info", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1686. MessageBox.Show("Fail to parse upgrade report info\r\n " + ex.Message);
  1687. return false;
  1688. }
  1689. }
  1690. /// <summary>
  1691. /// 比较本地文件的MD5值
  1692. /// </summary>
  1693. /// <param name="filename"></param>
  1694. /// <param name="filetype"></param>
  1695. /// <param name="filemd5"></param>
  1696. /// <param name="error"></param>
  1697. /// <returns></returns>
  1698. public static bool CompareLocalkey(string filename, string filetype, string filemd5, out string error, out string filefullname)
  1699. {
  1700. error = "";
  1701. filefullname = "";
  1702. try
  1703. {
  1704. string filepath = AppDomain.CurrentDomain.BaseDirectory + "\\Keys\\" + filename + "\\" + filetype;
  1705. if (!Directory.Exists(filepath))
  1706. {
  1707. Directory.CreateDirectory(filepath);
  1708. }
  1709. DirectoryInfo Getkeyfile = new DirectoryInfo(filepath);
  1710. foreach (FileInfo keyfile in Getkeyfile.GetFiles())
  1711. {
  1712. string FileMD5 = GetMD5.GetMD5HashFromFile(keyfile.Name);
  1713. if (FileMD5 == filemd5)
  1714. {
  1715. Log.WriteGetKeyLog("Check md5file success,file md5:" + FileMD5 + "\r\nfile:" + keyfile.FullName);
  1716. filefullname = keyfile.FullName;
  1717. return true;
  1718. }
  1719. else
  1720. {
  1721. Log.WriteErrorLog("Check md5file error,delete file:" + keyfile.FullName + "\r\nfile md5" + FileMD5);
  1722. File.Delete(keyfile.FullName);
  1723. }
  1724. }
  1725. return false;
  1726. }
  1727. catch (Exception ex)
  1728. {
  1729. error = ex.Message;
  1730. return false;
  1731. }
  1732. }
  1733. /// <summary>
  1734. /// 数据MD5核对。当数据头为"MD5="时,key内容比对改为key内容MD5比对
  1735. /// </summary>
  1736. /// <param name="key"></param>
  1737. /// <param name="data"></param>
  1738. /// <param name="md5"></param>
  1739. /// <returns></returns>
  1740. public static bool CompareMD5(byte[] key, byte[] data)
  1741. {
  1742. string strdata = Encoding.ASCII.GetString(data);
  1743. Console.WriteLine(strdata);
  1744. if (strdata.StartsWith("MD5="))
  1745. {
  1746. string md5 = GetMD5.GetMD5Hash(key);
  1747. Console.WriteLine(md5);
  1748. return strdata.Remove(0, 4).Equals(md5);
  1749. }
  1750. return false;
  1751. }
  1752. /// <summary>
  1753. /// 将16进制字符串转为对应字节流写入生成key文件
  1754. /// </summary>
  1755. /// <param name="path"></param>
  1756. /// <param name="data"></param>
  1757. /// <param name="error"></param>
  1758. /// <returns></returns>
  1759. public static bool GetCreateHexkey(string path, string data, out string error)
  1760. {
  1761. error = "";
  1762. try
  1763. {
  1764. string filepath = path + ".bin";
  1765. byte[] bytedata = SerialInit.HexToByte(data);
  1766. //创建一个文件流
  1767. FileStream fs = new FileStream(filepath, FileMode.Create);
  1768. fs.Write(bytedata, 0, bytedata.Length);
  1769. fs.Close();
  1770. Log.WriteGetKeyLog("save key:" + filepath);
  1771. return true;
  1772. }
  1773. catch (Exception ex)
  1774. {
  1775. error = ex.Message;
  1776. Log.WriteErrorLog("save key error:" + error);
  1777. return false;
  1778. }
  1779. }
  1780. /// <summary>
  1781. /// 读取key文件内容转换为16进制字符串
  1782. /// </summary>
  1783. /// <param name="filepath"></param>
  1784. /// <param name="data"></param>
  1785. /// <param name="error"></param>
  1786. /// <returns></returns>
  1787. public static bool ReadHexFile(string filepath, out string data, out string error)
  1788. {
  1789. data = "";
  1790. error = "";
  1791. try
  1792. {
  1793. using FileStream fskey = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.None);
  1794. {
  1795. using BinaryReader brkey = new BinaryReader(fskey);
  1796. {
  1797. data = SerialInit.ByteToHex(brkey.ReadBytes((int)fskey.Length));
  1798. data = data.Replace(" ", "");
  1799. return true;
  1800. }
  1801. }
  1802. }
  1803. catch (Exception ex)
  1804. {
  1805. error = ex.Message;
  1806. return false;
  1807. }
  1808. }
  1809. /// <summary>
  1810. /// 账号登录
  1811. /// </summary>
  1812. /// <param name="url"></param>
  1813. /// <param name="account"></param>
  1814. /// <param name="password"></param>
  1815. /// <param name="pcmac"></param>
  1816. /// <param name="sqliteConn"></param>
  1817. /// <param name="loginOutput1"></param>
  1818. /// <returns></returns>
  1819. public static bool UserLogin(string url, string account, string password, string pcmac, SQLiteConnection sqliteConn, out LoginOutput loginOutput1)
  1820. {
  1821. loginOutput1 = new LoginOutput();
  1822. LoginInput LoginInput1 = new LoginInput { account = account, password = password, mac = pcmac };
  1823. string jsonorder = Newtonsoft.Json.JsonConvert.SerializeObject(LoginInput1, Newtonsoft.Json.Formatting.Indented);
  1824. HttpHelper http = new HttpHelper();
  1825. HttpItem item = new HttpItem()
  1826. {
  1827. URL = url,//URL这里都是测试URl   必需项
  1828. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  1829. //Encoding = Encoding.Default,
  1830. Method = "post",//URL     可选项 默认为Get
  1831. Postdata = jsonorder,
  1832. PostEncoding = Encoding.UTF8,
  1833. KeepAlive = false
  1834. };
  1835. item.ContentType = "application/json;charset=utf-8";
  1836. ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;//
  1837. HttpResult result = http.GetHtml(item);
  1838. string ParseText = result.Html;
  1839. if (result.StatusCode == HttpStatusCode.OK)
  1840. {
  1841. Log.WriteGetKeyLog("\r\nLogin," + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1842. }
  1843. else
  1844. {
  1845. Log.WriteErrorLog("\r\nFail to login:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1846. ReportErrormsg("Fail to login", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1847. return false;
  1848. }
  1849. try
  1850. {
  1851. JObject jObject = JObject.Parse(ParseText);
  1852. loginOutput1.msg = jObject["msg"].Value<string>();
  1853. loginOutput1.code = jObject["code"].Value<string>();
  1854. loginOutput1.factoryname = JSON_SeleteNode(jObject, "factoryName");
  1855. loginOutput1.factorynum = JSON_SeleteNode(jObject, "factoryNum");
  1856. if (loginOutput1.code == "1000")
  1857. return true;
  1858. else
  1859. return false;
  1860. }
  1861. catch (Exception ex)
  1862. {
  1863. Log.WriteErrorLog("\r\nFail to login," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1864. ReportErrormsg("Fail to login", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1865. MessageBox.Show("Fail to parse login return\r\n " + ex.Message);
  1866. return false;
  1867. }
  1868. }
  1869. /// <summary>
  1870. /// 获取指定日期,在为一年中为第几周
  1871. /// </summary>
  1872. /// <param name="dt">指定时间</param>
  1873. /// <reutrn>返回第几周</reutrn>
  1874. public static int GetWeekOfYear(DateTime dt)
  1875. {
  1876. GregorianCalendar gc = new GregorianCalendar();
  1877. int weekOfYear = gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
  1878. return weekOfYear;
  1879. }
  1880. /// <summary>
  1881. /// 版本号比较:new_version>=old_version
  1882. /// </summary>
  1883. /// <param name="new_version">8.4.0</param>
  1884. /// <param name="old_version">8.3.10</param>
  1885. /// <returns></returns>
  1886. public static bool CompareVersion(string new_version, string old_version)
  1887. {
  1888. try
  1889. {
  1890. if (string.IsNullOrEmpty(new_version) || string.IsNullOrEmpty(old_version))
  1891. return false;
  1892. Version v_new = new Version(new_version);
  1893. Version v_old = new Version(old_version);
  1894. if (v_new >= v_old)
  1895. return true;
  1896. return false;
  1897. }
  1898. catch (Exception ex)
  1899. {
  1900. throw ex;
  1901. }
  1902. }
  1903. /// <summary>
  1904. /// 获取白平衡信息
  1905. /// </summary>
  1906. /// <param name="url"></param>
  1907. /// <param name="order"></param>
  1908. /// <param name="pcmac"></param>
  1909. /// <param name="sqliteConn"></param>
  1910. /// <param name="WBList"></param>
  1911. /// <returns></returns>
  1912. public static bool GetWhiteBalanceInfo(string url, string order, string pcmac, SQLiteConnection sqliteConn, out WhiteBalanceList WBList)
  1913. {
  1914. WBList = new WhiteBalanceList();
  1915. WhiteBalanceInput WBInput1 = new WhiteBalanceInput { bid = order, mac = pcmac };//"74-27-EA-6E-DA-9F"
  1916. string jsonorder = Newtonsoft.Json.JsonConvert.SerializeObject(WBInput1, Newtonsoft.Json.Formatting.Indented);
  1917. HttpHelper http = new HttpHelper();
  1918. HttpItem item = new HttpItem()
  1919. {
  1920. URL = url,//URL这里都是测试URl   必需项
  1921. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  1922. //Encoding = Encoding.Default,
  1923. Method = "post",//URL     可选项 默认为Get
  1924. Postdata = jsonorder,
  1925. PostEncoding = Encoding.UTF8,
  1926. KeepAlive = false
  1927. };
  1928. item.ContentType = "application/json;charset=utf-8";
  1929. System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
  1930. stopwatch.Start();
  1931. HttpResult result = http.GetHtml(item);
  1932. stopwatch.Stop();
  1933. string usingtime = stopwatch.ElapsedMilliseconds.ToString();
  1934. stopwatch.Reset();
  1935. string ParseText = result.Html;
  1936. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1937. {
  1938. Log.WriteGetKeyLog("\r\nGet WB info\r\nUsing time:" + usingtime + "ms\r\n" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1939. }
  1940. else
  1941. {
  1942. Log.WriteErrorLog("\r\nFail to WBinfo:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1943. ReportErrormsg("Fail to WBinfo", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1944. return false;
  1945. }
  1946. try
  1947. {
  1948. JObject jObject = JObject.Parse(ParseText);
  1949. WBList.message = jObject["message"].Value<string>();
  1950. WBList.code = jObject["code"].Value<string>();
  1951. object a = jObject["obj"];
  1952. if (jObject["obj"].ToString().Length > 0)
  1953. WBList.whiteBalanceInfo = new WhiteBalanceInfo()
  1954. {
  1955. id = JSON_SeleteNode(jObject["obj"], "id"),
  1956. ordernum = JSON_SeleteNode(jObject["obj"], "ordernum"),
  1957. hdmirgain = JSON_SeleteNode(jObject["obj"], "hdmirgain"),
  1958. hdmiggain = JSON_SeleteNode(jObject["obj"], "hdmiggain"),
  1959. hdmibgain = JSON_SeleteNode(jObject["obj"], "hdmibgain"),
  1960. nrgain = JSON_SeleteNode(jObject["obj"], "nrgain"),
  1961. nggain = JSON_SeleteNode(jObject["obj"], "nggain"),
  1962. nbgain = JSON_SeleteNode(jObject["obj"], "nbgain"),
  1963. lrgain = JSON_SeleteNode(jObject["obj"], "lrgain"),
  1964. lggain = JSON_SeleteNode(jObject["obj"], "lggain"),
  1965. lbgain = JSON_SeleteNode(jObject["obj"], "lbgain"),
  1966. updatetime = JSON_SeleteNode(jObject["obj"], "updatetime"),
  1967. createtime = JSON_SeleteNode(jObject["obj"], "createtime"),
  1968. isdelete = JSON_SeleteNode(jObject["obj"], "isdelete"),
  1969. isExemption = JSON_SeleteNode(jObject["obj"], "isExemption")
  1970. };
  1971. if (WBList.code == "1000")
  1972. return true;
  1973. else
  1974. return false;
  1975. }
  1976. catch (Exception ex)
  1977. {
  1978. Log.WriteErrorLog("\r\nFail to parse WB info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1979. ReportErrormsg("Fail to parse WB info", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1980. MessageBox.Show("Fail to parse WB info\r\n " + ex.Message);
  1981. return false;
  1982. }
  1983. }
  1984. private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
  1985. {
  1986. return true;
  1987. }
  1988. public static bool AutoGetKey(string url, string order, string key, string keytype, SQLiteConnection errorDBNow)
  1989. {
  1990. string code;
  1991. string desc;
  1992. HttpHelper http = new HttpHelper();
  1993. HttpItem item = new HttpItem()
  1994. {
  1995. Encoding = Encoding.Default,
  1996. Method = "post",
  1997. ContentType = "application/x-www-form-urlencoded",
  1998. KeepAlive = false
  1999. };
  2000. url += "/autogetkey.do?";
  2001. item.URL = url;
  2002. item.Postdata = string.Format("order={0}&key={1}&keytype={2}&mac={3}", order, key, keytype, HttpUtility.UrlEncode(TestMode.MAC));
  2003. HttpResult result = http.GetHtml(item);
  2004. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  2005. {
  2006. Log.WriteGetKeyLog("\r\nAutoquestKey :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  2007. if (Xmlconfig.AutoKeyStatusXml(result.Html, "response", out code, out desc))
  2008. {
  2009. return true;
  2010. }
  2011. else
  2012. {
  2013. CommonMethod.ReportErrormsg("Auto get key error", desc + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, errorDBNow);
  2014. return false;
  2015. }
  2016. }
  2017. else
  2018. {
  2019. CommonMethod.ReportErrormsg("Auto get key error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, errorDBNow);
  2020. return false;
  2021. }
  2022. }
  2023. public static bool AutoGetKeyStatus(string url, string key, string keytype, SQLiteConnection errorDBNow)
  2024. {
  2025. string code;
  2026. string desc;
  2027. HttpHelper http = new HttpHelper();
  2028. HttpItem item = new HttpItem()
  2029. {
  2030. Encoding = Encoding.Default,
  2031. Method = "post",
  2032. ContentType = "application/x-www-form-urlencoded",
  2033. KeepAlive = false
  2034. };
  2035. url += "/autogetkeystatus.do?";
  2036. item.URL = url;
  2037. item.Postdata = string.Format("key={0}&keytype={1}", key, keytype);
  2038. HttpResult result = http.GetHtml(item);
  2039. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  2040. {
  2041. Log.WriteGetKeyLog("\r\nAutoGetKeyStatus :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  2042. if (Xmlconfig.AutoKeyStatusXml(result.Html, "response", out code, out desc))
  2043. {
  2044. return true;
  2045. }
  2046. else
  2047. {
  2048. return false;
  2049. }
  2050. }
  2051. else
  2052. {
  2053. CommonMethod.ReportErrormsg("Auto get key status error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, errorDBNow);
  2054. return false;
  2055. }
  2056. }
  2057. public static bool GetFireTVDsn(string url, string ordernum, string deviceCode, string FSN, string PSN, out string dsn, out string error, SQLiteConnection errorDBNow)
  2058. {
  2059. // 计算函数耗时;
  2060. Stopwatch watch = new Stopwatch();
  2061. watch.Start();
  2062. dsn = "";
  2063. error = "";
  2064. HttpHelper http = new HttpHelper();
  2065. HttpItem item = new HttpItem()
  2066. {
  2067. Encoding = null, // 编码格式(utf-8,gb2312,gbk)可选项 默认类会自动识别Encoding = Encoding.Default,
  2068. Method = "GET", // URL 可选项 默认为Get
  2069. KeepAlive = false
  2070. };
  2071. item.URL = string.Format("{0}/getFiretvDsn.do?ordernum={1}&fsn={2}&psn={3}&deviceCode={4}&mac={5}", url, ordernum, FSN, PSN, deviceCode, HttpUtility.UrlEncode(TestMode.MAC));
  2072. HttpResult result = http.GetHtml(item);
  2073. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  2074. {
  2075. string code;
  2076. string desc;
  2077. Log.WriteGetKeyLog("\r\nGetFireTVDsn :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  2078. if (Xmlconfig.GetDSNXml(result.Html, "response", out code, out desc, out dsn))
  2079. {
  2080. Log.WriteGetKeyLog(string.Format("\r\nDSN= {0}\r\nHttp Get Dsn Elapsed = {1}", dsn, watch.Elapsed.TotalMilliseconds));
  2081. return true;
  2082. }
  2083. else
  2084. {
  2085. error = desc;
  2086. CommonMethod.ReportErrormsg("GetFireTVDsn error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL, errorDBNow);
  2087. return false;
  2088. }
  2089. }
  2090. else
  2091. {
  2092. error = "Communication with server failed";
  2093. CommonMethod.ReportErrormsg("GetFireTVDsn error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL, errorDBNow);
  2094. return false;
  2095. }
  2096. }
  2097. /// <summary>
  2098. /// 导出日本的SN与ACASID到文本中;
  2099. /// </summary>
  2100. /// <param name="ordernum"></param>
  2101. /// <param name="sn"></param>
  2102. /// <param name="acasid"></param>
  2103. public static void ExportSNACASID(string ordernum, string sn, string acasid)
  2104. {
  2105. string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\SN-ACAS";
  2106. if (!Directory.Exists(path))
  2107. {
  2108. Directory.CreateDirectory(path);
  2109. }
  2110. if (!lastOrder.Equals(ordernum))
  2111. {
  2112. lastOrder = ordernum;
  2113. ListACASSN.Clear();
  2114. }
  2115. string msg = string.Format("{0};{1}", sn, acasid);
  2116. if (ListACASSN.Contains(msg))
  2117. {
  2118. return;
  2119. }
  2120. ListACASSN.Add(msg);
  2121. string fileName = path + "\\" + ordernum + ".txt";
  2122. var stream = new StreamWriter(fileName, true);
  2123. stream.WriteLine(msg);
  2124. stream.Close();
  2125. stream.Dispose();
  2126. }
  2127. /// <summary>
  2128. /// 是否抄写EDID;
  2129. /// </summary>
  2130. /// <param name="midInfo"></param>
  2131. /// <returns></returns>
  2132. public static bool IsEDIDCopy(MidList midInfo)
  2133. {
  2134. if (midInfo == null || midInfo.keytype == null)
  2135. return false;
  2136. if (!midInfo.keytype.ContainsKey("edid_pid") && !midInfo.keytype.ContainsKey("edid_model_name"))
  2137. return false;
  2138. return true;
  2139. }
  2140. #region G客户相关功能接口
  2141. public static bool GetMaInfo(string sn, out MaInfo maInfo, SQLiteConnection errorDBNow)
  2142. {
  2143. string desc;
  2144. maInfo = null;
  2145. string strPost = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
  2146. "<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/\">"+
  2147. "<soap:Body>"+
  2148. "<GetMaInfo xmlns=\"http://tempuri.org/\">"+
  2149. "<sn>"+sn+"</sn>"+
  2150. "</GetMaInfo>"+
  2151. "</soap:Body>"+
  2152. "</soap:Envelope>";
  2153. HttpHelper http = new HttpHelper();
  2154. HttpItem item = new HttpItem()
  2155. {
  2156. Encoding = Encoding.UTF8,
  2157. Method = "post",
  2158. ContentType = "text/xml",
  2159. KeepAlive = false
  2160. };
  2161. item.URL = "http://smes-prd-app01.tclking.com:9002/SAPService.asmx";
  2162. item.Postdata = strPost;
  2163. HttpResult result = http.GetHtml(item);
  2164. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  2165. {
  2166. Log.WriteGetKeyLog("\r\nGetMaInfo :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  2167. if (!Xmlconfig.GetMaInfoXml(result.Html, out maInfo, out desc))
  2168. {
  2169. Log.WriteGetKeyLog("GetMaInfo error:" + desc + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2170. return false;
  2171. }
  2172. }
  2173. else
  2174. {
  2175. Log.WriteGetKeyLog("GetMaInfo error:" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2176. return false;
  2177. }
  2178. return true;
  2179. }
  2180. /// <summary>
  2181. /// 上报数据抄写结果到MES系统中;
  2182. /// </summary>
  2183. /// <param name="fsn"></param>
  2184. /// <param name="dsn"></param>
  2185. /// <param name="dateTime">抄写时间</param>
  2186. /// <param name="result">抄写结果</param>
  2187. /// <param name="msg">如果上报失败,此参数为失败的描述信息</param>
  2188. /// <returns></returns>
  2189. public static bool ReportDataBurningResultToMES(string fsn, string dsn, string result, string dateTime, SQLiteConnection errorDBNow, out string msg, out string returnObject)
  2190. {
  2191. msg = "";
  2192. returnObject = "";
  2193. string strPost = string.Format("{{\"FSN\":\"{0}\",\"DSN\":\"{1}\",\"DataCopy\":\"{2}\",\"UPDATETIME\":\"{3}\"}}", fsn, dsn, result, dateTime);
  2194. HttpHelper http = new HttpHelper();
  2195. HttpItem item = new HttpItem()
  2196. {
  2197. Encoding = Encoding.UTF8,
  2198. Method = "post",
  2199. ContentType = "application/json",
  2200. KeepAlive = false
  2201. };
  2202. // 测试地址;
  2203. item.URL = "http://smes-app-prod.tclking.com/FireTVApi/api/SMES/RecordKey";
  2204. item.Postdata = strPost;
  2205. HttpResult hResult = http.GetHtml(item);
  2206. if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
  2207. {
  2208. try
  2209. {
  2210. using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
  2211. {
  2212. JObject jObject = (JObject)JToken.ReadFrom(reader);
  2213. reader.Close();
  2214. bool bResult = jObject["Result"].Value<bool>();
  2215. msg = jObject["EroMsg"].Value<string>();
  2216. if ( jObject["returnObject"] != null )
  2217. returnObject = jObject["returnObject"].ToString();
  2218. Log.WriteInfoLog("nReportDataBurningResultToMES:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2219. return bResult;
  2220. }
  2221. }
  2222. catch (Exception e)
  2223. {
  2224. msg = e.Message;
  2225. Log.WriteErrorLog("ReportDataBurningResultToMES Json-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2226. }
  2227. }
  2228. else
  2229. {
  2230. msg = hResult.StatusDescription;
  2231. Log.WriteInfoLog("ReportDataBurningResultToMES Http-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2232. }
  2233. // 没有进行数据库查重:惹数据已添加过,同一次FSN抄写多次失败后导致多条记录。
  2234. SQLiteHelper.InsertDelayErrorReport(errorDBNow, new object[] { item.URL, item.Postdata });
  2235. return false;
  2236. }
  2237. /// <summary>
  2238. /// 上传本地数据库失败的日志,重新上传;
  2239. /// </summary>
  2240. /// <param name="url"></param>
  2241. /// <param name="strPost"></param>
  2242. /// <param name="mark"></param>
  2243. /// <returns></returns>
  2244. public static bool ReportDataBurningResultToMES(string url, string strPost, out bool mark)
  2245. {
  2246. // 表示是否上传成功;
  2247. mark = false;
  2248. HttpHelper http = new HttpHelper();
  2249. HttpItem item = new HttpItem()
  2250. {
  2251. Encoding = Encoding.UTF8,
  2252. Method = "post",
  2253. ContentType = "application/json",
  2254. KeepAlive = false
  2255. };
  2256. item.URL = url;
  2257. item.Postdata = strPost;
  2258. HttpResult hResult = http.GetHtml(item);
  2259. if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
  2260. {
  2261. try
  2262. {
  2263. using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
  2264. {
  2265. JObject jObject = (JObject)JToken.ReadFrom(reader);
  2266. reader.Close();
  2267. mark = jObject["Result"].Value<bool>();
  2268. Log.WriteInfoLog("nReportDataBurningResultToMES:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2269. return true;
  2270. }
  2271. }
  2272. catch (Exception)
  2273. {
  2274. Log.WriteErrorLog("ReportDataBurningResultToMES error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2275. throw;
  2276. }
  2277. }
  2278. else
  2279. {
  2280. Log.WriteInfoLog("ReportDataBurningResultToMES error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2281. }
  2282. return false;
  2283. }
  2284. /// <summary>
  2285. /// 通过SN获取订单类型
  2286. /// </summary>
  2287. /// <param name="sn"></param>
  2288. /// <returns></returns>
  2289. public static bool GetOrderTypeFromSN(string sn, out string result, out string msg)
  2290. {
  2291. msg = "";
  2292. result = "";
  2293. HttpHelper http = new HttpHelper();
  2294. HttpItem item = new HttpItem()
  2295. {
  2296. Encoding = Encoding.UTF8,
  2297. Method = "post",
  2298. ContentType = "application/x-www-form-urlencoded",
  2299. KeepAlive = false
  2300. };
  2301. // 测试地址;
  2302. item.URL = "http://smes-app-prod.tclking.com/FireTVApi/api/SMES/IsCuringBOM?sn=" + sn;
  2303. HttpResult hResult = http.GetHtml(item);
  2304. if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
  2305. {
  2306. try
  2307. {
  2308. using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
  2309. {
  2310. JObject jObject = (JObject)JToken.ReadFrom(reader);
  2311. reader.Close();
  2312. bool bResult = jObject["Result"].Value<bool>();
  2313. msg = jObject["EroMsg"].Value<string>();
  2314. string returnObject = jObject["returnObject"].ToString();
  2315. if (bResult)
  2316. {
  2317. if (returnObject.Contains("量产"))
  2318. result = "量产";
  2319. else if (returnObject.Contains("试产"))
  2320. result = "试产";
  2321. else
  2322. result = "错误返回";
  2323. Log.WriteInfoLog("\r\nIsCuringBOM :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + hResult.Html);
  2324. return true;
  2325. }
  2326. Log.WriteInfoLog("IsCuringBOM error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2327. }
  2328. }
  2329. catch (Exception e)
  2330. {
  2331. msg = e.Message;
  2332. Log.WriteErrorLog("IsCuringBOM Json-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2333. }
  2334. }
  2335. else
  2336. {
  2337. msg = hResult.StatusDescription;
  2338. Log.WriteInfoLog("IsCuringBOM Http-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2339. }
  2340. return false;
  2341. }
  2342. /// <summary>
  2343. // Section1:本机信息;
  2344. // Section2:SMES信息;
  2345. // Section3:实际抄写Key信息;
  2346. /// </summary>
  2347. /// <param name="Line"></param>
  2348. /// <param name="Station"></param>
  2349. /// <param name="order"></param>
  2350. /// <param name="sn"></param>
  2351. /// <param name="StartTime"></param>
  2352. /// <param name="EndOfTime"></param>
  2353. /// <param name="returnObject"></param>
  2354. /// <param name="key"></param>
  2355. /// <param name="result"></param>
  2356. /// <returns></returns>
  2357. public static bool GeneratKaylaData(string Line, string Station, string order, string sn, DateTime StartTime, DateTime EndOfTime, string returnObject, KeyInfo key, bool result)
  2358. {
  2359. Dictionary<string, string> localInfo = new Dictionary<string,string>();
  2360. // 本机信息;
  2361. localInfo.Add("Item", "Value");
  2362. localInfo.Add("factory_id_I", "TCL");
  2363. localInfo.Add("operator_I", Line);
  2364. localInfo.Add("station_I", Station);
  2365. localInfo.Add("fixture_id_I", "1_1");
  2366. localInfo.Add("gui_ver_I", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
  2367. localInfo.Add("route_check_I", "1");
  2368. // SMES信息;
  2369. string strLastOrder = ReadProfileString("MOKAFactoryTools", "LastOrder", "");
  2370. if ( !strLastOrder.Equals(order,StringComparison.OrdinalIgnoreCase) )
  2371. {
  2372. // 请求新的订单信息;
  2373. MaInfo maInfo;
  2374. if ( !GetMaInfo(sn, out maInfo, null) )
  2375. {
  2376. Log.WriteErrorLog("Kayla GetMaInfo失败");
  2377. return false;
  2378. }
  2379. LastKaylaOrderInfo = new Dictionary<string,string>();
  2380. if ( maInfo != null )
  2381. {
  2382. LastKaylaOrderInfo.Add("project_name_I", maInfo.project_name_I);
  2383. LastKaylaOrderInfo.Add("build_I", maInfo.build_I);
  2384. LastKaylaOrderInfo.Add("build_config_I", maInfo.build_config_I);
  2385. LastKaylaOrderInfo.Add("diag_ver_I", maInfo.diag_ver_I);
  2386. LastKaylaOrderInfo.Add("image_name_ver_I", maInfo.image_name_ver_I);
  2387. LastKaylaOrderInfo.Add("soc_type", maInfo.soc_type);
  2388. LastKaylaOrderInfo.Add("speaker_vender", maInfo.speaker_vender);
  2389. LastKaylaOrderInfo.Add("mic_vender", maInfo.mic_vender);
  2390. }
  2391. }
  2392. Dictionary<string, string> dic = localInfo.Union(LastKaylaOrderInfo).ToDictionary(k=>k.Key, v=>v.Value);
  2393. dic.Add("start_time_I", StartTime.ToString());
  2394. dic.Add("serial_id_I", key != null ? key.DSN : ""); // DSN;
  2395. dic.Add("FSN", sn);
  2396. // 耐压值;
  2397. if (returnObject != null && returnObject.Length > 0 && returnObject.Contains("Hightpot"))
  2398. {
  2399. Log.WriteInfoLog(String.Format("returnObjec={0}", returnObject));
  2400. // 删除头尾[];
  2401. returnObject = returnObject.Remove(0, 1);
  2402. returnObject = returnObject.Remove(returnObject.Length - 1, 1);
  2403. JObject jObject = JObject.Parse(returnObject);
  2404. string hightpot = JSON_SeleteNode(jObject, "Hightpot");
  2405. int pos = hightpot.LastIndexOf('/');
  2406. if (pos != -1)
  2407. {
  2408. hightpot = hightpot.Substring(pos+1);
  2409. pos = hightpot.IndexOf("mA");
  2410. // 使用正规去除数字+小数点以外的字符;
  2411. string AC = hightpot.Substring(0, pos + 2);
  2412. string DC = hightpot.Substring(pos + 2);
  2413. AC = System.Text.RegularExpressions.Regex.Replace(AC, @"[^\d.]*", "");
  2414. DC = System.Text.RegularExpressions.Regex.Replace(DC, @"[^\d.]*", "");
  2415. dic.Add("AC_I", AC);
  2416. dic.Add("DC_R", DC);
  2417. }
  2418. else
  2419. {
  2420. dic.Add("AC_I", "");
  2421. dic.Add("DC_R", "");
  2422. }
  2423. }
  2424. else
  2425. {
  2426. dic.Add("AC_I", "");
  2427. dic.Add("DC_R", "");
  2428. Log.WriteErrorLog("获取耐压值结果为空");
  2429. }
  2430. if ( key != null )
  2431. {
  2432. if (key.DID.enable)
  2433. {
  2434. dic.Add("DID", key.DID); // 本身就是字符串;
  2435. dic.Add("DID_check", key.DID.result ? "PASS" : "FAIL");
  2436. }
  2437. if (key.Mac.enable)
  2438. {
  2439. dic.Add("Mac", key.Mac);//keyInfo.Mac.data.Replace("-", ":");
  2440. dic.Add("Mac_check", key.Mac.result ? "PASS" : "FAIL");
  2441. }
  2442. if (key.HDCP.enable)
  2443. {
  2444. dic.Add("HDCP", key.HDCP);
  2445. dic.Add("HDCP_check", key.HDCP.result ? "PASS" : "FAIL");
  2446. }
  2447. if (key.HDCP22.enable)
  2448. {
  2449. dic.Add("HDCP22", key.HDCP22);
  2450. dic.Add("HDCP22_check", key.HDCP22.result ? "PASS" : "FAIL");
  2451. }
  2452. if (key.ESN.enable)
  2453. {
  2454. dic.Add("ESN", key.ESN);
  2455. dic.Add("ESN_check", key.ESN.result ? "PASS" : "FAIL");
  2456. }
  2457. if (key.WiDi.enable)
  2458. {
  2459. dic.Add("WiDi", key.WiDi);
  2460. dic.Add("WiDi_check", key.WiDi.result ? "PASS" : "FAIL");
  2461. }
  2462. if (key.Widevine.enable)
  2463. {
  2464. dic.Add("Widevine", key.Widevine);
  2465. dic.Add("Widevine_check", key.Widevine.result ? "PASS" : "FAIL");
  2466. }
  2467. if (key.CI_plus.enable)
  2468. {
  2469. dic.Add("CI_plus", key.CI_plus);
  2470. dic.Add("CI_plus_check", key.CI_plus.result ? "PASS" : "FAIL");
  2471. }
  2472. if (key.Attestation.enable)
  2473. {
  2474. dic.Add("Attestation", key.Attestation);
  2475. dic.Add("Attestation_check", key.Attestation.result ? "PASS" : "FAIL");
  2476. }
  2477. if (key.MGK.enable)
  2478. {
  2479. dic.Add("MGK", key.MGK);
  2480. dic.Add("MGK_check", key.MGK.result ? "PASS" : "FAIL");
  2481. }
  2482. if (key.Fairplay.enable)
  2483. {
  2484. dic.Add("Fairplay", key.Fairplay);
  2485. dic.Add("Fairplay_check", key.Fairplay.result ? "PASS" : "FAIL");
  2486. }
  2487. if (key.DSN.enable)
  2488. {
  2489. dic.Add("DSN", key.DSN);
  2490. dic.Add("DSN_check", key.DSN.result ? "PASS" : "FAIL");
  2491. }
  2492. if (key.WiFi_MAC.enable)
  2493. {
  2494. dic.Add("WiFi_MAC", key.WiFi_MAC);
  2495. dic.Add("WiFi_MAC_check", key.WiFi_MAC.result ? "PASS" : "FAIL");
  2496. }
  2497. if (key.BT_MAC.enable)
  2498. {
  2499. dic.Add("BT_MAC", key.BT_MAC);
  2500. dic.Add("BT_MAC_check", key.BT_MAC.result ? "PASS" : "FAIL");
  2501. }
  2502. if (key.LEK.enable)
  2503. {
  2504. dic.Add("LEK", key.LEK);
  2505. dic.Add("LEK_check", key.LEK.result ? "PASS" : "FAIL");
  2506. }
  2507. if (key.PEK.enable)
  2508. {
  2509. dic.Add("PEK", key.PEK);
  2510. dic.Add("PEK_check", key.PEK.result ? "PASS" : "FAIL");
  2511. }
  2512. if (key.Playready.enable)
  2513. {
  2514. dic.Add("Playready", key.Playready);
  2515. dic.Add("Playready_check", key.Playready.result ? "PASS" : "FAIL");
  2516. }
  2517. if (key.Hashkey.enable)
  2518. {
  2519. dic.Add("Hashkey", key.Hashkey);
  2520. dic.Add("Hashkey_check", key.Hashkey.result ? "PASS" : "FAIL");
  2521. }
  2522. if (key.ECP.enable)
  2523. {
  2524. dic.Add("ECP", key.ECP);
  2525. dic.Add("ECP_check", key.ECP.result ? "PASS" : "FAIL");
  2526. }
  2527. if (key.YouTube_KEY.enable)
  2528. {
  2529. dic.Add("YouTube_KEY", key.YouTube_KEY);
  2530. dic.Add("YouTube_KEY_check", key.YouTube_KEY.result ? "PASS" : "FAIL");
  2531. }
  2532. }
  2533. dic.Add("cycle_time_I", EndOfTime.Subtract(StartTime).Seconds.ToString());
  2534. dic.Add("test_result_I", result ? "PASS" : "FAIL");
  2535. try
  2536. {
  2537. // 以DSN命名文件;
  2538. if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory+ "Kayla"))
  2539. {
  2540. Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "Kayla");
  2541. }
  2542. string savefile = string.Format("{0}Kayla\\{1}.csv", AppDomain.CurrentDomain.BaseDirectory, sn);
  2543. using (System.IO.StreamWriter file = new System.IO.StreamWriter(savefile, false))
  2544. {
  2545. foreach (KeyValuePair<string, string> kvp in dic)
  2546. {
  2547. file.WriteLine(string.Format("{0},{1}", kvp.Key, kvp.Value));
  2548. }
  2549. }
  2550. }
  2551. catch (Exception ex)
  2552. {
  2553. Log.WriteErrorLog(string.Format("保存csv文件失败:{0}", ex.ToString()));
  2554. return false;
  2555. }
  2556. StartProcess(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "tcp_send.exe", sn);
  2557. return true;
  2558. }
  2559. #endregion
  2560. #region 小米FireTV功能模块相关接口;
  2561. public static bool GetMIKey(string sn, out MIKey mikey, out string msg)
  2562. {
  2563. msg = "";
  2564. mikey = new MIKey();
  2565. string strPost = String.Format("{{\"TVSN\":\"{0}\"}}", sn);
  2566. HttpHelper http = new HttpHelper();
  2567. HttpItem item = new HttpItem()
  2568. {
  2569. Encoding = Encoding.UTF8,
  2570. Method = "post",
  2571. ContentType = "application/json",
  2572. KeepAlive = false
  2573. };
  2574. #if DEBUG
  2575. item.URL = "http://10.126.124.85:9306/api/SMESCustomer/GetXMCard";
  2576. #else
  2577. item.URL = "http://smes-app-prod.tclking.com:9006/api/SMESCustomer/GetXMCard";
  2578. #endif
  2579. item.Postdata = strPost;
  2580. HttpResult hResult = http.GetHtml(item);
  2581. if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
  2582. {
  2583. try
  2584. {
  2585. using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
  2586. {
  2587. JObject jObject = (JObject)JToken.ReadFrom(reader);
  2588. reader.Close();
  2589. bool bResult = jObject["Result"].Value<bool>();
  2590. msg = jObject["Error"].Value<string>();
  2591. JArray jAry = (JArray)JsonConvert.DeserializeObject(jObject["Data"].ToString());
  2592. if (jAry == null)
  2593. {
  2594. Log.WriteErrorLog("GetMIKey Json-null:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2595. return false;
  2596. }
  2597. if ( jAry.Count > 0 )
  2598. {
  2599. mikey = JsonConvert.DeserializeObject<MIKey>(jAry[0].ToString());
  2600. }
  2601. if (bResult)
  2602. {
  2603. return true;
  2604. }
  2605. Log.WriteInfoLog("GetMIKey error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2606. }
  2607. }
  2608. catch (Exception e)
  2609. {
  2610. msg = e.Message;
  2611. Log.WriteErrorLog("GetMIKey Json-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2612. }
  2613. }
  2614. else
  2615. {
  2616. msg = hResult.StatusDescription;
  2617. Log.WriteInfoLog("GetMIKey Http-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2618. }
  2619. return false;
  2620. }
  2621. public static bool ReportMIKey(ReportMIKey mikey, out string msg)
  2622. {
  2623. msg = "";
  2624. HttpHelper http = new HttpHelper();
  2625. HttpItem item = new HttpItem()
  2626. {
  2627. Encoding = Encoding.UTF8,
  2628. Method = "post",
  2629. ContentType = "application/json",
  2630. KeepAlive = false
  2631. };
  2632. #if DEBUG
  2633. item.URL = "http://10.126.124.85:9306/api/SMESCustomer/UploadXMDataControl";
  2634. #else
  2635. item.URL = "http://smes-app-prod.tclking.com:9006/api/SMESCustomer/UploadXMDataControl";
  2636. #endif
  2637. item.Postdata = JsonConvert.SerializeObject(mikey); ;
  2638. HttpResult hResult = http.GetHtml(item);
  2639. if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
  2640. {
  2641. try
  2642. {
  2643. using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
  2644. {
  2645. JObject jObject = (JObject)JToken.ReadFrom(reader);
  2646. reader.Close();
  2647. bool bResult = jObject["Result"].Value<bool>();
  2648. msg = jObject["Error"].Value<string>();
  2649. string data = jObject["Data"].ToString();
  2650. if (bResult && data.StartsWith("成功"))
  2651. {
  2652. return true;
  2653. }
  2654. Log.WriteInfoLog("ReportMIKey error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2655. }
  2656. }
  2657. catch (Exception e)
  2658. {
  2659. msg = e.Message;
  2660. Log.WriteErrorLog("ReportMIKey Json-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2661. }
  2662. }
  2663. else
  2664. {
  2665. msg = hResult.StatusDescription;
  2666. Log.WriteInfoLog("ReportMIKey Http-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  2667. }
  2668. return false;
  2669. }
  2670. #endregion
  2671. }
  2672. /// <summary>
  2673. /// CRC32
  2674. /// </summary>
  2675. class CRC32
  2676. {
  2677. //生成CRC32码表
  2678. static uint[] Crc32Table;
  2679. public static void GetCRC32Table()
  2680. {
  2681. uint Crc;
  2682. Crc32Table = new uint[256];
  2683. int i, j;
  2684. for (i = 0; i < 256; i++)
  2685. {
  2686. Crc = (uint)i;
  2687. for (j = 8; j > 0; j--)
  2688. {
  2689. if ((Crc & 1) == 1)
  2690. Crc = (Crc >> 1) ^ 0xEDB88320;
  2691. else
  2692. Crc >>= 1;
  2693. }
  2694. Crc32Table[i] = Crc;
  2695. }
  2696. }
  2697. public static uint GetCRC32(byte[] bytes)
  2698. {
  2699. GetCRC32Table();
  2700. uint value = 0xffffffff;
  2701. int len = bytes.Length;
  2702. for (int i = 0; i < len; i++)
  2703. {
  2704. value = (value >> 8) ^ Crc32Table[(value & 0xFF) ^ bytes[i]];
  2705. }
  2706. return value ^ 0xffffffff;
  2707. }
  2708. }
  2709. /// <summary>
  2710. /// 本地抄写模式方法
  2711. /// </summary>
  2712. public class GetLocalKeyCount
  2713. {
  2714. static string LocalKeyPath = AppDomain.CurrentDomain.BaseDirectory + "\\Keys\\";
  2715. public static bool GetLocalDidCount(string order, out int num, ref MidList localmidList, SQLiteConnection errorDBNow)
  2716. {
  2717. num = 0;
  2718. try
  2719. {
  2720. string DIDpath = LocalKeyPath + order + "\\DeviceID";
  2721. if (Directory.Exists(DIDpath) == false)
  2722. return false;
  2723. else
  2724. {
  2725. DirectoryInfo GetDIDfile = new DirectoryInfo(DIDpath);
  2726. foreach (FileInfo keyfile in GetDIDfile.GetFiles())
  2727. {
  2728. string filename = keyfile.FullName;
  2729. if (keyfile.Name.Contains("Online"))
  2730. {
  2731. if (localmidList.host == null)
  2732. {
  2733. if (CommonMethod.GetMidInfo(TestMode.serverurl, order, TestMode.MAC, "", "", errorDBNow, out localmidList))
  2734. {
  2735. ;
  2736. }
  2737. else
  2738. {
  2739. num = -1;
  2740. return true;
  2741. }
  2742. }
  2743. HttpHelper http = new HttpHelper();
  2744. HttpItem item = new HttpItem()
  2745. {
  2746. Encoding = Encoding.Default,
  2747. Method = "post",
  2748. ContentType = "application/x-www-form-urlencoded"
  2749. };
  2750. string url1 = localmidList.host + "/statdeviceid.do?";
  2751. item.URL = url1;
  2752. item.Postdata = "devicetype=tcl_unknown_model";
  2753. HttpResult result = http.GetHtml(item);
  2754. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  2755. {
  2756. Log.WriteGetKeyLog("\r\nGetDeviceID count:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  2757. if (Xmlconfig.KeyCountXml(result.Html, "response", "count", out string code, out string desc, out string count))
  2758. {
  2759. num = Convert.ToInt32(count.Replace(",", ""));
  2760. return true;
  2761. }
  2762. else
  2763. {
  2764. num = -1;
  2765. return true;
  2766. }
  2767. }
  2768. else
  2769. {
  2770. num = -1;
  2771. return true;
  2772. }
  2773. }
  2774. else
  2775. {
  2776. num = GetDIDfile.GetFiles().Length;
  2777. return true;
  2778. }
  2779. }
  2780. return true;
  2781. }
  2782. }
  2783. catch (Exception ex)
  2784. {
  2785. num = -1;
  2786. return true;
  2787. }
  2788. }
  2789. public static bool GetLocalMacCount(string order, out int num, ref MidList localmidList, SQLiteConnection errorDBNow)
  2790. {
  2791. num = 0;
  2792. try
  2793. {
  2794. string MACpath = LocalKeyPath + order + "\\MAC";
  2795. if (Directory.Exists(MACpath) == false)
  2796. return false;
  2797. else
  2798. {
  2799. DirectoryInfo GetMACfile = new DirectoryInfo(MACpath);
  2800. foreach (FileInfo keyfile in GetMACfile.GetFiles())
  2801. {
  2802. string filename = keyfile.FullName;
  2803. if (keyfile.Name.Contains("Online"))
  2804. {
  2805. if (localmidList.host == null)
  2806. {
  2807. if (CommonMethod.GetMidInfo(TestMode.serverurl, order, TestMode.MAC, "", "", errorDBNow, out localmidList))
  2808. {
  2809. ;
  2810. }
  2811. else
  2812. {
  2813. num = -1;
  2814. return true;
  2815. }
  2816. }
  2817. HttpHelper http = new HttpHelper();
  2818. HttpItem item = new HttpItem()
  2819. {
  2820. Encoding = Encoding.Default,
  2821. Method = "post",
  2822. ContentType = "application/x-www-form-urlencoded"
  2823. };
  2824. string url1 = localmidList.host + "/statmac.do?";
  2825. item.URL = url1;
  2826. item.Postdata = "typeString=" + localmidList.keytype["MAC"];
  2827. HttpResult result = http.GetHtml(item);
  2828. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  2829. {
  2830. Log.WriteGetKeyLog("\r\nGetMac count:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  2831. if (Xmlconfig.KeyCountXml(result.Html, "response", "count", out string code, out string desc, out string count))
  2832. {
  2833. num = Convert.ToInt32(count.Replace(",", ""));
  2834. return true;
  2835. }
  2836. else
  2837. {
  2838. num = -1;
  2839. return true;
  2840. }
  2841. }
  2842. else
  2843. {
  2844. num = -1;
  2845. return true;
  2846. }
  2847. }
  2848. else
  2849. {
  2850. num = GetMACfile.GetFiles().Length;
  2851. return true;
  2852. }
  2853. }
  2854. return true;
  2855. }
  2856. }
  2857. catch (Exception ex)
  2858. {
  2859. num = -1;
  2860. return true;
  2861. }
  2862. }
  2863. public static bool GetLocalHDCPKEYCount(string order, out int num)
  2864. {
  2865. num = 0;
  2866. try
  2867. {
  2868. string HDCPKEYpath = LocalKeyPath + order + "\\HDCPKEY";
  2869. if (Directory.Exists(HDCPKEYpath) == false)
  2870. return false;
  2871. else
  2872. {
  2873. DirectoryInfo GetHDCPKEYfile = new DirectoryInfo(HDCPKEYpath);
  2874. num = GetHDCPKEYfile.GetFiles().Length;
  2875. return true;
  2876. }
  2877. }
  2878. catch (Exception ex)
  2879. {
  2880. num = -1;
  2881. return true;
  2882. }
  2883. }
  2884. public static bool GetLocalHDCPKEY22Count(string order, out int num)
  2885. {
  2886. num = 0;
  2887. try
  2888. {
  2889. string HDCPKEY22path = LocalKeyPath + order + "\\HDCPKEY22";
  2890. if (Directory.Exists(HDCPKEY22path) == false)
  2891. return false;
  2892. else
  2893. {
  2894. DirectoryInfo GetHDCPKEY22file = new DirectoryInfo(HDCPKEY22path);
  2895. num = GetHDCPKEY22file.GetFiles().Length;
  2896. return true;
  2897. }
  2898. }
  2899. catch (Exception ex)
  2900. {
  2901. num = -1;
  2902. return true;
  2903. }
  2904. }
  2905. public static bool GetLocalWiDiCount(string order, out int num)
  2906. {
  2907. num = 0;
  2908. try
  2909. {
  2910. string WiDipath = LocalKeyPath + order + "\\WiDi";
  2911. if (Directory.Exists(WiDipath) == false)
  2912. return false;
  2913. else
  2914. {
  2915. DirectoryInfo GetWiDifile = new DirectoryInfo(WiDipath);
  2916. num = GetWiDifile.GetFiles().Length;
  2917. return true;
  2918. }
  2919. }
  2920. catch (Exception ex)
  2921. {
  2922. num = -1;
  2923. return true;
  2924. }
  2925. }
  2926. public static bool GetLocalWidevineCount(string order, out int num)
  2927. {
  2928. num = 0;
  2929. try
  2930. {
  2931. string Widevinepath = LocalKeyPath + order + "\\Widevine";
  2932. if (Directory.Exists(Widevinepath) == false)
  2933. return false;
  2934. else
  2935. {
  2936. DirectoryInfo GetWidevinefile = new DirectoryInfo(Widevinepath);
  2937. num = GetWidevinefile.GetFiles().Length;
  2938. return true;
  2939. }
  2940. }
  2941. catch (Exception ex)
  2942. {
  2943. num = -1;
  2944. return true;
  2945. }
  2946. }
  2947. public static bool GetLocalESNCount(string order, out int num)
  2948. {
  2949. num = 0;
  2950. try
  2951. {
  2952. string ESNpath = LocalKeyPath + order + "\\ESN";
  2953. if (Directory.Exists(ESNpath) == false)
  2954. return false;
  2955. else
  2956. {
  2957. DirectoryInfo GetESNfile = new DirectoryInfo(ESNpath);
  2958. num = GetESNfile.GetFiles().Length;
  2959. return true;
  2960. }
  2961. }
  2962. catch (Exception ex)
  2963. {
  2964. num = -1;
  2965. return true;
  2966. }
  2967. }
  2968. public static bool GetLocalMGKCount(string order, out int num)
  2969. {
  2970. num = 0;
  2971. try
  2972. {
  2973. string MGKpath = LocalKeyPath + order + "\\MGK";
  2974. if (Directory.Exists(MGKpath) == false)
  2975. return false;
  2976. else
  2977. {
  2978. DirectoryInfo GetMGKfile = new DirectoryInfo(MGKpath);
  2979. num = GetMGKfile.GetFiles().Length;
  2980. return true;
  2981. }
  2982. }
  2983. catch (Exception ex)
  2984. {
  2985. num = -1;
  2986. return true;
  2987. }
  2988. }
  2989. public static bool GetLocalFairplayCount(string order, out int num)
  2990. {
  2991. num = 0;
  2992. try
  2993. {
  2994. string Fairplaypath = LocalKeyPath + order + "\\Fairplay";
  2995. if (Directory.Exists(Fairplaypath) == false)
  2996. return false;
  2997. else
  2998. {
  2999. DirectoryInfo GetFairplayfile = new DirectoryInfo(Fairplaypath);
  3000. num = GetFairplayfile.GetFiles().Length;
  3001. return true;
  3002. }
  3003. }
  3004. catch (Exception ex)
  3005. {
  3006. num = -1;
  3007. return true;
  3008. }
  3009. }
  3010. public static bool GetLocalFolderKeyCount(string order, string keyname, out int num)
  3011. {
  3012. num = 0;
  3013. try
  3014. {
  3015. string Fairplaypath = LocalKeyPath + order + "\\" + keyname;
  3016. if (Directory.Exists(Fairplaypath) == false)
  3017. return false;
  3018. else
  3019. {
  3020. DirectoryInfo GetFairplayfile = new DirectoryInfo(Fairplaypath);
  3021. num = GetFairplayfile.GetFiles().Length;
  3022. return true;
  3023. }
  3024. }
  3025. catch (Exception ex)
  3026. {
  3027. num = -1;
  3028. return true;
  3029. }
  3030. }
  3031. public static bool GetLocalAttestationCount(string order, out int num)
  3032. {
  3033. num = 0;
  3034. try
  3035. {
  3036. string Attestationpath = LocalKeyPath + order + "\\Attestation";
  3037. if (Directory.Exists(Attestationpath) == false)
  3038. return false;
  3039. else
  3040. {
  3041. DirectoryInfo GetAttestationfile = new DirectoryInfo(Attestationpath);
  3042. num = GetAttestationfile.GetFiles().Length;
  3043. return true;
  3044. }
  3045. }
  3046. catch (Exception ex)
  3047. {
  3048. num = -1;
  3049. return true;
  3050. }
  3051. }
  3052. public static bool GetLocalCIKEYCount(string order, out int num)
  3053. {
  3054. num = 0;
  3055. try
  3056. {
  3057. string CIKEYpath = LocalKeyPath + order + "\\CIKEY";
  3058. if (Directory.Exists(CIKEYpath) == false)
  3059. return false;
  3060. else
  3061. {
  3062. DirectoryInfo GetCIKEYfile = new DirectoryInfo(CIKEYpath);
  3063. num = GetCIKEYfile.GetFiles().Length;
  3064. return true;
  3065. }
  3066. }
  3067. catch (Exception ex)
  3068. {
  3069. num = -1;
  3070. return true;
  3071. }
  3072. }
  3073. public static bool GetLocalStringKeys(string order, string keytype, int filesize, out FileStream fskey, out StreamReader brkey, out string data, out string filename, out string error, SQLiteConnection errorDBNow, ref MidList localmidList, string SN)
  3074. {
  3075. data = "";
  3076. filename = "";
  3077. error = "";
  3078. brkey = null;
  3079. fskey = null;
  3080. try
  3081. {
  3082. string keypath = LocalKeyPath + order + "\\" + keytype;
  3083. if (Directory.Exists(keypath) == false)
  3084. {
  3085. error = "File not exist";
  3086. return false;
  3087. }
  3088. else
  3089. {
  3090. DirectoryInfo Getkeyfile = new DirectoryInfo(keypath);
  3091. foreach (FileInfo keyfile in Getkeyfile.GetFiles())
  3092. {
  3093. filename = keyfile.FullName;
  3094. if (keyfile.Name.Contains("Online"))
  3095. {
  3096. try
  3097. {
  3098. if (localmidList.host == null)
  3099. {
  3100. if (CommonMethod.GetMidInfo(TestMode.serverurl, order, TestMode.MAC, "", "", errorDBNow, out localmidList))
  3101. {
  3102. ;
  3103. }
  3104. else
  3105. {
  3106. return false;
  3107. }
  3108. }
  3109. if (keytype == "DeviceID")
  3110. localmidList.keytype["DeviceID"] = "devicetype=tcl_unknown_model";
  3111. else if (keytype == "MAC")
  3112. keytype = "MAC";
  3113. else if (keytype == "HDCPKEY")
  3114. keytype = "HDCP_KEY";
  3115. else if (keytype == "HDCPKEY22")
  3116. keytype = "HDCP2.2_KEY";
  3117. else if (keytype == "ESN")
  3118. keytype = "NETFILX_ESN";
  3119. else if (keytype == "Widevine")
  3120. keytype = "Widevine_KEY";
  3121. else if (keytype == "WiDi")
  3122. keytype = "WiDi";
  3123. else if (keytype == "CIKEY")
  3124. keytype = "CI_PLUS_KEY";
  3125. if (CommonMethod.GetKeys(localmidList.host, keytype, SN, localmidList.keytype[keytype], errorDBNow, out string did, out error, order, out string md5))
  3126. {
  3127. data = did;
  3128. Log.WriteGetKeyLog("\r\n" + keytype + "= " + data);
  3129. return true;
  3130. }
  3131. else
  3132. {
  3133. return false;
  3134. }
  3135. }
  3136. catch (Exception ex)
  3137. {
  3138. error = ex.Message;
  3139. return false;
  3140. }
  3141. }
  3142. else
  3143. {
  3144. try
  3145. {
  3146. fskey = new FileStream(keyfile.FullName.ToString(), FileMode.Open, FileAccess.ReadWrite, FileShare.None);
  3147. {
  3148. brkey = new StreamReader(fskey);
  3149. {
  3150. if (fskey.Length == filesize || filesize == -1)
  3151. {
  3152. data = brkey.ReadToEnd();
  3153. return true;
  3154. }
  3155. else
  3156. {
  3157. error = "File size error.\r\nFilename:" + keyfile.Name + "\r\nFilesize:" + fskey.Length.ToString();
  3158. return false;
  3159. }
  3160. }
  3161. }
  3162. }
  3163. catch
  3164. {
  3165. ;
  3166. }
  3167. }
  3168. }
  3169. return false;
  3170. }
  3171. }
  3172. catch (Exception ex)
  3173. {
  3174. error = ex.Message;
  3175. return false;
  3176. }
  3177. }
  3178. public static bool GetLocalHexKeys(string order, string keytype, int filesize, out FileStream fskey, out BinaryReader brkey, out string data, out string filename, out string error, SQLiteConnection errorDBNow, ref MidList localmidList, string SN)
  3179. {
  3180. data = "";
  3181. filename = "";
  3182. error = "";
  3183. brkey = null;
  3184. fskey = null;
  3185. try
  3186. {
  3187. string keypath = LocalKeyPath + order + "\\" + keytype;
  3188. if (Directory.Exists(keypath) == false)
  3189. {
  3190. error = "File not exist";
  3191. return false;
  3192. }
  3193. else
  3194. {
  3195. DirectoryInfo Getkeyfile = new DirectoryInfo(keypath);
  3196. foreach (FileInfo keyfile in Getkeyfile.GetFiles())
  3197. {
  3198. filename = keyfile.FullName;
  3199. if (keyfile.Name.Contains("Online"))
  3200. {
  3201. try
  3202. {
  3203. if (localmidList.host == null)
  3204. {
  3205. if (CommonMethod.GetMidInfo(TestMode.serverurl, order, TestMode.MAC, "", "", errorDBNow, out localmidList))
  3206. {
  3207. ;
  3208. }
  3209. else
  3210. {
  3211. return false;
  3212. }
  3213. }
  3214. if (keytype == "DeviceID")
  3215. localmidList.keytype["DeviceID"] = "devicetype=tcl_unknown_model";
  3216. else if (keytype == "MAC")
  3217. keytype = "MAC";
  3218. else if (keytype == "HDCPKEY")
  3219. keytype = "HDCP_KEY";
  3220. else if (keytype == "HDCPKEY22")
  3221. keytype = "HDCP2.2_KEY";
  3222. else if (keytype == "ESN")
  3223. keytype = "NETFILX_ESN";
  3224. else if (keytype == "Widevine")
  3225. keytype = "Widevine_KEY";
  3226. else if (keytype == "WiDi")
  3227. keytype = "WiDi";
  3228. else if (keytype == "CIKEY")
  3229. keytype = "CI_PLUS_KEY";
  3230. else if (keytype == "MGK")
  3231. keytype = "MGK_KEY";
  3232. else if (keytype == "Attestation")
  3233. keytype = "Attestation";
  3234. else if (keytype == "Fairplay")
  3235. keytype = "Fairplay_KEY";
  3236. if (CommonMethod.GetKeys(localmidList.host, keytype, SN, localmidList.keytype[keytype], errorDBNow, out string did, out error, order, out string md5))
  3237. {
  3238. data = did;
  3239. Log.WriteGetKeyLog("\r\n" + keytype + "= " + data);
  3240. return true;
  3241. }
  3242. else
  3243. {
  3244. return false;
  3245. }
  3246. }
  3247. catch (Exception ex)
  3248. {
  3249. error = ex.Message;
  3250. return false;
  3251. }
  3252. }
  3253. else
  3254. {
  3255. try
  3256. {
  3257. fskey = new FileStream(keyfile.FullName.ToString(), FileMode.Open, FileAccess.Read, FileShare.None);
  3258. {
  3259. brkey = new BinaryReader(fskey);
  3260. {
  3261. if (fskey.Length == filesize || filesize == -1)
  3262. {
  3263. data = SerialInit.ByteToHex(brkey.ReadBytes((int)fskey.Length));
  3264. data = data.Replace(" ", "");
  3265. return true;
  3266. }
  3267. else
  3268. {
  3269. error = "File size error.\r\nFilename: " + keyfile.Name + "\r\nFilesize: " + fskey.Length.ToString();
  3270. return false;
  3271. }
  3272. }
  3273. }
  3274. }
  3275. catch
  3276. {
  3277. ;
  3278. }
  3279. }
  3280. }
  3281. return false;
  3282. }
  3283. }
  3284. catch (Exception ex)
  3285. {
  3286. error = ex.Message;
  3287. return false;
  3288. }
  3289. }
  3290. public static bool DeleteLocalKeys(ArrayList filelist, ArrayList Stream, ArrayList Reader)
  3291. {
  3292. try
  3293. {
  3294. if (filelist.Count == Reader.Count)
  3295. {
  3296. for (int i = 0; i < filelist.Count; i++)
  3297. {
  3298. if (filelist[i].ToString().Contains("DeviceID"))
  3299. ((StreamReader)Reader[i]).Dispose();
  3300. else
  3301. ((BinaryReader)Reader[i]).Dispose();
  3302. ((FileStream)Stream[i]).Dispose();
  3303. File.Delete(filelist[i].ToString());
  3304. }
  3305. return true;
  3306. }
  3307. else
  3308. return false;
  3309. }
  3310. catch (Exception ex)
  3311. {
  3312. for (int i = 0; i < Reader.Count; i++)
  3313. {
  3314. if (filelist[i].ToString().Contains("DeviceID"))
  3315. ((StreamReader)Reader[i]).Dispose();
  3316. else
  3317. ((BinaryReader)Reader[i]).Dispose();
  3318. ((FileStream)Stream[i]).Dispose();
  3319. }
  3320. return false;
  3321. }
  3322. }
  3323. public static bool UnlockLocalKeys(ArrayList filelist, ArrayList Stream, ArrayList Reader)
  3324. {
  3325. for (int i = 0; i < Reader.Count; i++)
  3326. {
  3327. if (filelist[i].ToString().Contains("DeviceID"))
  3328. ((StreamReader)Reader[i]).Dispose();
  3329. else
  3330. ((BinaryReader)Reader[i]).Dispose();
  3331. ((FileStream)Stream[i]).Dispose();
  3332. }
  3333. return true;
  3334. }
  3335. }
  3336. /// <summary>
  3337. /// 本地缓存记录
  3338. /// </summary>
  3339. public class LocalTxtRecord
  3340. {
  3341. public static bool LocalRecord(string record, string name)
  3342. {
  3343. try
  3344. {
  3345. string order = name + ".txt";
  3346. if (File.Exists(@order))
  3347. {
  3348. FileStream fs = new FileStream(@order, FileMode.Append);
  3349. byte[] data = System.Text.Encoding.Default.GetBytes("\r\n" + record);
  3350. fs.Write(data, 0, data.Length);
  3351. fs.Flush();
  3352. fs.Close();
  3353. }
  3354. else
  3355. {
  3356. FileStream fs = new FileStream(@order, FileMode.Create);
  3357. byte[] data = System.Text.Encoding.Default.GetBytes(record);
  3358. fs.Write(data, 0, data.Length);
  3359. fs.Flush();
  3360. fs.Close();
  3361. }
  3362. return true;
  3363. }
  3364. catch (Exception ex)
  3365. {
  3366. return false;
  3367. }
  3368. }
  3369. }
  3370. }