CommonMethod.cs 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758
  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. namespace MOKA_Factory_Tools
  25. {
  26. class CommonMethod
  27. {
  28. [DllImport("kernel32")]
  29. public static extern bool GetProfileString(string lpApplicationName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize);
  30. [DllImport("kernel32")]
  31. public static extern bool WriteProfileString(string lpApplicationName, string lpKeyName, string lpString);
  32. public static string FactoryName = "Unknown";
  33. private static string lastOrder = "";
  34. private static List<string> ListACASSN = new List<string>();
  35. //public static string LocalMacAddress = GetMacAddress();
  36. /// <summary>
  37. /// 获取活动网卡硬件地址
  38. /// </summary>
  39. /// <returns></returns>
  40. public static string GetMacAddress()
  41. {
  42. string mac = "";
  43. using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"))
  44. {
  45. ManagementObjectCollection moc = mc.GetInstances();
  46. int i = 0;
  47. int j = 0;
  48. foreach (ManagementObject mo in moc)
  49. {
  50. if (mo["MacAddress"] != null)
  51. {
  52. if (Convert.ToBoolean(mo["IPEnabled"]))
  53. {
  54. if(j<2)
  55. {
  56. mac = mo["MacAddress"].ToString() + "&" + mac;
  57. j++; }
  58. }
  59. else
  60. {
  61. if(i<1)
  62. {
  63. mac += mo["MacAddress"].ToString() + "&";
  64. i++;
  65. }
  66. }
  67. }
  68. }
  69. }
  70. return mac.Replace(":", "-");
  71. //return "C0-B6-F9-44-D7-BB";
  72. }
  73. /// <summary>
  74. /// 获取订单信息
  75. /// </summary>
  76. /// <param name="url"></param>
  77. /// <param name="order"></param>
  78. /// <param name="pcmac"></param>
  79. /// <param name="iptvip"></param>
  80. /// <param name="version"></param>
  81. /// <param name="sqliteConn"></param>
  82. /// <param name="mid"></param>
  83. /// <returns></returns>
  84. public static bool GetMidInfo(string url, string order, string pcmac, string iptvip, string version, SQLiteConnection sqliteConn,out MidList mid)
  85. {
  86. mid = new MidList();
  87. OrderInput orderInput1 = new OrderInput { bid = order, mac = pcmac, version = "", clientType = "" };//"74-27-EA-6E-DA-9F"
  88. string jsonorder = JsonConvert.SerializeObject(orderInput1, Newtonsoft.Json.Formatting.Indented);
  89. HttpHelper http = new HttpHelper();
  90. HttpItem item = new HttpItem()
  91. {
  92. URL = url,//URL这里都是测试URl   必需项
  93. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  94. //Encoding = Encoding.Default,
  95. Method = "post",//URL     可选项 默认为Get
  96. Postdata = jsonorder,
  97. PostEncoding= Encoding.UTF8,
  98. KeepAlive = false
  99. };
  100. item.ContentType = "application/json;charset=utf-8";
  101. System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
  102. stopwatch.Start();
  103. HttpResult result = http.GetHtml(item);
  104. stopwatch.Stop();
  105. string usingtime = stopwatch.ElapsedMilliseconds.ToString();
  106. stopwatch.Reset();
  107. string ParseText = result.Html;
  108. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  109. {
  110. Log.WriteGetKeyLog("\r\nGet MID info\r\nUsing time:" + usingtime + "ms\r\n" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  111. }
  112. else
  113. {
  114. Log.WriteErrorLog("\r\nFail to GetMidInfo:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  115. ReportErrormsg("Fail to GetMidInfo", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  116. return false;
  117. }
  118. try
  119. {
  120. JObject jObject = JObject.Parse(ParseText);
  121. mid.message = jObject["message"].Value<string>();
  122. mid.code = jObject["code"].Value<string>();
  123. mid.factoryname = jObject["factoryName"].Value<string>();
  124. mid.factoryNum = jObject["factoryNum"].Value<string>();
  125. mid.version = jObject["version"].Value<string>();
  126. mid.quantity = jObject["quantity"].Value<string>();
  127. mid.projectid = jObject["projectId"].Value<string>();
  128. mid.clienttype = jObject["clientType"].Value<string>();
  129. mid.host = jObject["host"].Value<string>();
  130. mid.whiteType = jObject["whiteType"].Value<string>();
  131. object a=jObject["rokuCustomer"];
  132. if (jObject["rokuCustomer"].ToString().Length>0)
  133. mid.rokuCustomer = new RokuCustomer()
  134. {
  135. id = JSON_SeleteNode(jObject["rokuCustomer"], "id").Trim(),
  136. ordernum= JSON_SeleteNode(jObject["rokuCustomer"], "ordernum").Trim(),
  137. brand = JSON_SeleteNode(jObject["rokuCustomer"], "brand").Trim(),
  138. region = JSON_SeleteNode(jObject["rokuCustomer"], "region").Trim(),
  139. oemmodel = JSON_SeleteNode(jObject["rokuCustomer"], "oemmodel").Trim(),
  140. supporturl = JSON_SeleteNode(jObject["rokuCustomer"], "supporturl").Trim(),
  141. supportphone = JSON_SeleteNode(jObject["rokuCustomer"], "supportphone").Trim(),
  142. productiondate = JSON_SeleteNode(jObject["rokuCustomer"], "productiondate").Trim(),
  143. remotetype= JSON_SeleteNode(jObject["rokuCustomer"], "remotetype").Trim(),
  144. updatetime = JSON_SeleteNode(jObject["rokuCustomer"], "updatetime").Trim(),
  145. createtime = JSON_SeleteNode(jObject["rokuCustomer"], "createtime").Trim(),
  146. isdelete = JSON_SeleteNode(jObject["rokuCustomer"], "isdelete").Trim()
  147. };
  148. mid.keytype = new Dictionary<string, string>();
  149. foreach (var ss in jObject["obj"]) //查找某个字段与值
  150. {
  151. mid.keytype.Add(ss["name"].Value<string>(), ss["type"].Value<string>());
  152. }
  153. if (url == Serverurl.Testurl)
  154. mid.host = "http://test.idmanage.qhmoka.com/IDManage";
  155. if (mid.code == "1000")
  156. return true;
  157. else
  158. return false;
  159. }
  160. catch (Exception ex)
  161. {
  162. Log.WriteErrorLog("\r\nFail to parse MID info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  163. ReportErrormsg("Fail to parse MID info", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  164. MessageBox.Show("Fail to parse MID info\r\n " + ex.Message);
  165. return false;
  166. }
  167. }
  168. /// <summary>
  169. /// 获取预绑定模式下的key包地址
  170. /// </summary>
  171. /// <param name="midInfo"></param>
  172. /// <param name="order"></param>
  173. /// <param name="sqliteConn"></param>
  174. /// <param name="midAddress"></param>
  175. /// <returns></returns>
  176. public static bool GetMidAddress(MidList midInfo, string order, SQLiteConnection sqliteConn,out MidAddress midAddress)
  177. {
  178. midAddress = new MidAddress();
  179. HttpHelper http = new HttpHelper();
  180. HttpItem item = new HttpItem()
  181. {
  182. URL = midInfo.host + "/getofflinelist.do?",//URL这里都是测试URl   必需项
  183. Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  184. //Encoding = Encoding.Default,
  185. Method = "post",//URL     可选项 默认为Get
  186. Postdata = ("orderNumber=" + order +"&mac=" + HttpUtility.UrlEncode(TestMode.MAC)),
  187. KeepAlive = false
  188. };
  189. item.ContentType = "application/x-www-form-urlencoded";
  190. HttpResult result = http.GetHtml(item);
  191. string ParseText = result.Html;
  192. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  193. {
  194. }
  195. else
  196. {
  197. Log.WriteErrorLog("\r\nFail to get Mid address:" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  198. CommonMethod.ReportErrormsg("Fail to get Mid address", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
  199. return false;
  200. }
  201. try
  202. {
  203. JObject jObject = JObject.Parse(ParseText);
  204. midAddress.des = JSON_SeleteNode(jObject, "des");
  205. midAddress.code = JSON_SeleteNode(jObject, "code");
  206. midAddress.order = JSON_SeleteNode(jObject, "order_number");
  207. midAddress.number = JSON_SeleteNode(jObject, "order_quantity");
  208. midAddress.pid = JSON_SeleteNode(jObject, "project_id");
  209. midAddress.ctype = JSON_SeleteNode(jObject, "client_type");
  210. midAddress.purl = JSON_SeleteNode(jObject, "packet_url");
  211. midAddress.psize = JSON_SeleteNode(jObject, "packet_size");
  212. midAddress.pmd5 = JSON_SeleteNode(jObject, "packet_md5");
  213. midAddress.version = JSON_SeleteNode(jObject, "soft_version");
  214. midAddress.host = midInfo.host;
  215. Log.WriteGetKeyLog("\r\nGet Mid address success:" + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  216. return true;
  217. }
  218. catch (Exception ex)
  219. {
  220. Log.WriteErrorLog("\r\nFail to parse MID address," + ex.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  221. CommonMethod.ReportErrormsg("Fail to parse MID address", ex.Message + "\r\n" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
  222. MessageBox.Show("Fail to parse MIDAddress info\r\n " + ex.Message);
  223. return false;
  224. }
  225. }
  226. /// <summary>
  227. /// 获取预绑定模式下的key包地址
  228. /// </summary>
  229. /// <param name="midInfo"></param>
  230. /// <param name="order"></param>
  231. /// <param name="sqliteConn"></param>
  232. /// <param name="midAddress"></param>
  233. /// <returns></returns>
  234. public static bool GetMidAddress2(MidList midInfo, string order, SQLiteConnection sqliteConn, out List<MidAddress> midAddressList)
  235. {
  236. midAddressList = new List<MidAddress>();
  237. HttpHelper http = new HttpHelper();
  238. HttpItem item = new HttpItem()
  239. {
  240. URL = midInfo.host + "/getofflinelist.do?",//URL这里都是测试URl   必需项
  241. Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  242. //Encoding = Encoding.Default,
  243. Method = "post",//URL     可选项 默认为Get
  244. Postdata = ("orderNumber=" + order + "&mac=" + HttpUtility.UrlEncode(TestMode.MAC)),
  245. KeepAlive = false
  246. };
  247. item.ContentType = "application/x-www-form-urlencoded";
  248. HttpResult result = http.GetHtml(item);
  249. string ParseText = result.Html;
  250. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  251. {
  252. }
  253. else
  254. {
  255. Log.WriteErrorLog("\r\nFail to get Mid address:" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  256. CommonMethod.ReportErrormsg("Fail to get Mid address", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
  257. return false;
  258. }
  259. try
  260. {
  261. JObject jObject = JObject.Parse(ParseText);
  262. if (jObject["data"] != null)
  263. {
  264. foreach(var data in jObject["data"])
  265. {
  266. midAddressList.Add(new MidAddress()
  267. {
  268. des = JSON_SeleteNode(jObject, "des"),
  269. code = JSON_SeleteNode(jObject, "code"),
  270. order = data["order_number"].ToObject<string>(),
  271. number = data["order_quantity"].ToObject<string>(),
  272. pid = data["project_id"].ToObject<string>(),
  273. ctype = data["client_type"].ToObject<string>(),
  274. purl = data["packet_url"].ToObject<string>(),
  275. psize = data["packet_size"].ToObject<string>(),
  276. pmd5 = data["packet_md5"].ToObject<string>(),
  277. version = data["soft_version"].ToObject<string>(),
  278. host = midInfo.host
  279. });
  280. }
  281. }
  282. Log.WriteGetKeyLog("\r\nGet Mid address success:" + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  283. return true;
  284. }
  285. catch (Exception ex)
  286. {
  287. Log.WriteErrorLog("\r\nFail to parse MID address," + ex.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  288. CommonMethod.ReportErrormsg("Fail to parse MID address", ex.Message + "\r\n" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
  289. MessageBox.Show("Fail to parse MIDAddress info\r\n " + ex.Message);
  290. return false;
  291. }
  292. }
  293. /// <summary>
  294. /// 解析XML格式的DID
  295. /// </summary>
  296. /// <param name="str"></param>
  297. /// <param name="node"></param>
  298. /// <param name="node2"></param>
  299. /// <param name="code"></param>
  300. /// <param name="desc"></param>
  301. /// <param name="value"></param>
  302. /// <returns></returns>
  303. public static bool GetDIDKeyXml(string str, string node, string node2, out string code, out string desc, out string value)
  304. {
  305. code = "";
  306. value = "";
  307. try
  308. {
  309. XmlDocument xml = new XmlDocument();
  310. //xml.Load(path);
  311. xml.LoadXml(str);
  312. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  313. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  314. if (code == "200")
  315. {
  316. value = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("deviceid").InnerText;
  317. string CRC32 = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("crc32").InnerText;
  318. if (CrcUtils.CRC32(value) == Convert.ToUInt32(CRC32))
  319. {
  320. return true;
  321. }
  322. else
  323. {
  324. desc = "CRC32 error";
  325. return false;
  326. }
  327. }
  328. return false;
  329. }
  330. catch (Exception ex)
  331. {
  332. desc = ex.Message;
  333. return false;
  334. }
  335. }
  336. /// <summary>
  337. /// 解析其他keys
  338. /// </summary>
  339. /// <param name="url"></param>
  340. /// <param name="keymessage"></param>
  341. /// <param name="keytype"></param>
  342. /// <param name="sqliteConn"></param>
  343. /// <param name="key"></param>
  344. /// <param name="error"></param>
  345. /// <returns></returns>
  346. 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)
  347. {
  348. string code;
  349. string desc;
  350. error = "";
  351. key = "";
  352. md5 = "";
  353. HttpHelper http = new HttpHelper();
  354. HttpItem item = new HttpItem()
  355. {
  356. Encoding = Encoding.Default,
  357. Method = "post",
  358. ContentType = "application/x-www-form-urlencoded",
  359. KeepAlive = false
  360. };
  361. switch (keymessage)
  362. {
  363. case "DeviceID":
  364. {
  365. item.URL = url + "/getid.do?";
  366. item.Postdata = "devicetype=tcl_unknown_model" + "&sn=" + sn;
  367. if (sn.Trim().Length > 0)
  368. item.Postdata += "&order=" + order;
  369. HttpResult result = http.GetHtml(item);
  370. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  371. {
  372. Log.WriteGetKeyLog("\r\nGetDeviceID:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  373. if (Xmlconfig.GetDIDKeyXml(result.Html, "response", "id", out code, out desc, out key))
  374. {
  375. //
  376. }
  377. else
  378. {
  379. error = desc;
  380. ReportErrormsg("Fail to parse DID", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  381. return false;
  382. }
  383. }
  384. else
  385. {
  386. error = result.StatusDescription;
  387. ReportErrormsg("Fail to get DID", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  388. return false;
  389. }
  390. break;
  391. }
  392. case "MAC":
  393. {
  394. item.URL = url+"/getmac.do?";
  395. item.Postdata = "typeString=" + keytype + "&sn="+ sn;
  396. if (sn.Trim().Length > 0)
  397. item.Postdata += "&order=" + order;
  398. HttpResult result = http.GetHtml(item);
  399. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  400. {
  401. Log.WriteGetKeyLog("\r\nGetMac:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  402. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "mac", out code, out desc, out key, out md5))
  403. {
  404. }
  405. else
  406. {
  407. error = desc;
  408. ReportErrormsg("Fail to parse Mac", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  409. return false;
  410. }
  411. }
  412. else
  413. {
  414. error = result.StatusDescription;
  415. ReportErrormsg("Fail to get Mac", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  416. return false;
  417. }
  418. break;
  419. }
  420. case "HDCP_KEY":
  421. {
  422. item.URL = url + "/gethdcpkey.do?";
  423. item.Postdata = "type=" + keytype + "&sn="+ sn;
  424. if (sn.Trim().Length > 0)
  425. item.Postdata += "&order=" + order;
  426. HttpResult result = http.GetHtml(item);
  427. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  428. {
  429. Log.WriteGetKeyLog("\r\nGetHDCP_KEY:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  430. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
  431. {
  432. }
  433. else
  434. {
  435. error = desc;
  436. ReportErrormsg("Fail to parse hdcp", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  437. return false;
  438. }
  439. }
  440. else
  441. {
  442. error = result.StatusDescription;
  443. ReportErrormsg("Fail to get hdcp", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  444. return false;
  445. }
  446. break;
  447. }
  448. case "CI_PLUS_KEY":
  449. {
  450. item.URL = url+ "/getcikey.do?";
  451. item.Postdata = "type=" + keytype + "&sn=" + sn;
  452. if (sn.Trim().Length > 0)
  453. item.Postdata += "&order=" + order;
  454. HttpResult result = http.GetHtml(item);
  455. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  456. {
  457. Log.WriteGetKeyLog("\r\nGetCI_PLUS_KEY:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  458. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
  459. {
  460. }
  461. else
  462. {
  463. error = desc;
  464. ReportErrormsg("Fail to parse ciplus", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  465. return false;
  466. }
  467. }
  468. else
  469. {
  470. error = result.StatusDescription;
  471. ReportErrormsg("Fail to get ciplus", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  472. return false;
  473. }
  474. break;
  475. }
  476. case "WiDi":
  477. {
  478. item.URL = url+ "/getwidi.do?";
  479. item.Postdata = "type=" + keytype + "&sn=" + sn;
  480. if (sn.Trim().Length > 0)
  481. item.Postdata += "&order=" + order;
  482. HttpResult result = http.GetHtml(item);
  483. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  484. {
  485. Log.WriteGetKeyLog("\r\nGetWiDi:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  486. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
  487. {
  488. }
  489. else
  490. {
  491. error = desc;
  492. ReportErrormsg("Fail to parse widi", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  493. return false;
  494. }
  495. }
  496. else
  497. {
  498. error = result.StatusDescription;
  499. ReportErrormsg("Fail to get widi", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  500. return false;
  501. }
  502. break;
  503. }
  504. case "HDCP2.2_KEY":
  505. {
  506. item.URL = url+ "/gethdcpkey2.do?";
  507. item.Postdata = "type=" + keytype + "&sn=" + sn;
  508. if (sn.Trim().Length > 0)
  509. item.Postdata += "&order=" + order;
  510. HttpResult result = http.GetHtml(item);
  511. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  512. {
  513. Log.WriteGetKeyLog("\r\nGetHDCP2.2_KEY:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  514. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
  515. {
  516. }
  517. else
  518. {
  519. error = desc;
  520. ReportErrormsg("Fail to parse hdcp22", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  521. return false;
  522. }
  523. }
  524. else
  525. {
  526. error = result.StatusDescription;
  527. ReportErrormsg("Fail to get hdcp22", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  528. return false;
  529. }
  530. break;
  531. }
  532. case "NETFILX_ESN":
  533. {
  534. item.URL = url+ "/getnetfilxesn.do?";
  535. item.Postdata = "type=" + keytype + "&sn=" + sn;
  536. if (sn.Trim().Length > 0)
  537. item.Postdata += "&order=" + order;
  538. HttpResult result = http.GetHtml(item);
  539. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  540. {
  541. Log.WriteGetKeyLog("\r\nGetNETFILX_ESN:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  542. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "esn", out code, out desc, out key, out md5))
  543. {
  544. }
  545. else
  546. {
  547. error = desc;
  548. ReportErrormsg("Fail to parse esn", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  549. return false;
  550. }
  551. }
  552. else
  553. {
  554. error = result.StatusDescription;
  555. ReportErrormsg("Fail to get esn", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  556. return false;
  557. }
  558. break;
  559. }
  560. case "MGK_KEY":
  561. {
  562. item.URL = url + "/getmgk.do?";
  563. item.Postdata = "type=" + keytype + "&sn=" + sn;
  564. if (sn.Trim().Length > 0)
  565. item.Postdata += "&order=" + order;
  566. HttpResult result = http.GetHtml(item);
  567. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  568. {
  569. Log.WriteGetKeyLog("\r\nGetMGK:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  570. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
  571. {
  572. }
  573. else
  574. {
  575. error = desc;
  576. ReportErrormsg("Fail to parse MGK", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  577. return false;
  578. }
  579. }
  580. else
  581. {
  582. error = result.StatusDescription;
  583. ReportErrormsg("Fail to get MGK", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  584. return false;
  585. }
  586. break;
  587. }
  588. case "Fairplay_KEY":
  589. {
  590. item.URL = url + "/getfairplay.do?";
  591. item.Postdata = "type=" + keytype + "&sn=" + sn;
  592. if (sn.Trim().Length > 0)
  593. item.Postdata += "&order=" + order;
  594. HttpResult result = http.GetHtml(item);
  595. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  596. {
  597. Log.WriteGetKeyLog("\r\nGetFairplay:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  598. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "fairplay", out code, out desc, out key, out md5))
  599. {
  600. }
  601. else
  602. {
  603. error = desc;
  604. ReportErrormsg("Fail to parse Fairplay", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  605. return false;
  606. }
  607. }
  608. else
  609. {
  610. error = result.StatusDescription;
  611. ReportErrormsg("Fail to get Fairplay", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  612. return false;
  613. }
  614. break;
  615. }
  616. case "ECP_KEY":
  617. {
  618. item.URL = url + "/getecp.do?";
  619. item.Postdata = "type=" + keytype + "&sn=" + sn;
  620. if (sn.Trim().Length > 0)
  621. item.Postdata += "&order=" + order;
  622. HttpResult result = http.GetHtml(item);
  623. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  624. {
  625. Log.WriteGetKeyLog("\r\nGetecp:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  626. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "ecp", out code, out desc, out key, out md5))
  627. {
  628. }
  629. else
  630. {
  631. error = desc;
  632. ReportErrormsg("Fail to parse ecp", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  633. return false;
  634. }
  635. }
  636. else
  637. {
  638. error = result.StatusDescription;
  639. ReportErrormsg("Fail to get ecp", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  640. return false;
  641. }
  642. break;
  643. }
  644. case "LEK":
  645. {
  646. item.URL = url + "/getlek.do?";
  647. item.Postdata = "type=" + keytype + "&sn=" + sn;
  648. if (sn.Trim().Length > 0)
  649. item.Postdata += "&order=" + order;
  650. HttpResult result = http.GetHtml(item);
  651. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  652. {
  653. Log.WriteGetKeyLog("\r\nGetlek:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  654. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "lek", out code, out desc, out key, out md5))
  655. {
  656. }
  657. else
  658. {
  659. error = desc;
  660. ReportErrormsg("Fail to parse lek", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  661. return false;
  662. }
  663. }
  664. else
  665. {
  666. error = result.StatusDescription;
  667. ReportErrormsg("Fail to get lek", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  668. return false;
  669. }
  670. break;
  671. }
  672. case "PEK":
  673. {
  674. item.URL = url + "/getpek.do?";
  675. item.Postdata = "type=" + keytype + "&sn=" + sn;
  676. if (sn.Trim().Length > 0)
  677. item.Postdata += "&order=" + order;
  678. HttpResult result = http.GetHtml(item);
  679. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  680. {
  681. Log.WriteGetKeyLog("\r\nGetpek:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  682. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "pek", out code, out desc, out key, out md5))
  683. {
  684. }
  685. else
  686. {
  687. error = desc;
  688. ReportErrormsg("Fail to parse pek", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  689. return false;
  690. }
  691. }
  692. else
  693. {
  694. error = result.StatusDescription;
  695. ReportErrormsg("Fail to get pek", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  696. return false;
  697. }
  698. break;
  699. }
  700. case "PlayReady_key":
  701. {
  702. item.URL = url + "/getplayready.do?";
  703. item.Postdata = "type=" + keytype + "&sn=" + sn;
  704. if (sn.Trim().Length > 0)
  705. item.Postdata += "&order=" + order;
  706. HttpResult result = http.GetHtml(item);
  707. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  708. {
  709. Log.WriteGetKeyLog("\r\nGetplayready:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  710. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "playReady", out code, out desc, out key, out md5))
  711. {
  712. }
  713. else
  714. {
  715. error = desc;
  716. ReportErrormsg("Fail to parse playready", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  717. return false;
  718. }
  719. }
  720. else
  721. {
  722. error = result.StatusDescription;
  723. ReportErrormsg("Fail to get playready", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  724. return false;
  725. }
  726. break;
  727. }
  728. case "Hashkey":
  729. {
  730. item.URL = url + "/gethash.do?";
  731. item.Postdata = "type=" + keytype + "&sn=" + sn;
  732. if (sn.Trim().Length > 0)
  733. item.Postdata += "&order=" + order;
  734. HttpResult result = http.GetHtml(item);
  735. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  736. {
  737. Log.WriteGetKeyLog("\r\nGethash:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  738. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "hash", out code, out desc, out key, out md5))
  739. {
  740. }
  741. else
  742. {
  743. error = desc;
  744. ReportErrormsg("Fail to parse hash", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  745. return false;
  746. }
  747. }
  748. else
  749. {
  750. error = result.StatusDescription;
  751. ReportErrormsg("Fail to get hash", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  752. return false;
  753. }
  754. break;
  755. }
  756. case "YouTube_KEY":
  757. {
  758. item.URL = url + "/getYoutubeKey.do?";
  759. item.Postdata = "type=" + keytype + "&sn=" + sn;
  760. if (sn.Trim().Length > 0)
  761. item.Postdata += "&order=" + order;
  762. HttpResult result = http.GetHtml(item);
  763. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  764. {
  765. Log.WriteGetKeyLog("\r\nGet youtube key:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  766. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "youtubeKey", out code, out desc, out key, out md5))
  767. {
  768. }
  769. else
  770. {
  771. error = desc;
  772. ReportErrormsg("Fail to parse youtube key", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  773. return false;
  774. }
  775. }
  776. else
  777. {
  778. error = result.StatusDescription;
  779. ReportErrormsg("Fail to get youtube key", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  780. return false;
  781. }
  782. break;
  783. }
  784. case "MOKA_RT2851M_IR": // ACAS Key;
  785. {
  786. item.URL = url + "/getAcasKey.do?";
  787. item.Postdata = "type=" + keytype + "&sn=" + sn;
  788. if (sn.Trim().Length > 0)
  789. item.Postdata += "&order=" + order;
  790. HttpResult result = http.GetHtml(item);
  791. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  792. {
  793. Log.WriteGetKeyLog("\r\nGet ACAS key:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  794. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "acasKey", out code, out desc, out key, out md5))
  795. {
  796. }
  797. else
  798. {
  799. error = desc;
  800. ReportErrormsg("Fail to parse ACAS key", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  801. return false;
  802. }
  803. }
  804. else
  805. {
  806. error = result.StatusDescription;
  807. ReportErrormsg("Fail to get ACAS key", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  808. return false;
  809. }
  810. break;
  811. }
  812. }
  813. return true;
  814. }
  815. public static bool GetWidevineAnAttestationKey(
  816. string url,
  817. string sn,
  818. string keytype,
  819. SQLiteConnection sqliteConn,
  820. out bool isAndroidTV,
  821. out string Widevinekey,
  822. out string Attestationkey,
  823. out string error,
  824. string order,
  825. out string AttestationMd5)
  826. {
  827. string code;
  828. string desc;
  829. isAndroidTV = false;
  830. error = "";
  831. Widevinekey = "";
  832. Attestationkey = "";
  833. AttestationMd5 = "";
  834. HttpHelper http = new HttpHelper();
  835. HttpItem item = new HttpItem()
  836. {
  837. Encoding = Encoding.Default,
  838. Method = "post",
  839. ContentType = "application/x-www-form-urlencoded",
  840. KeepAlive = false
  841. };
  842. item.URL = url + "/getWidevineAndAttestation.do?";
  843. item.Postdata = "type=" + keytype + "&order=" + order + "&sn=" + sn;
  844. HttpResult result = http.GetHtml(item);
  845. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  846. {
  847. Log.WriteGetKeyLog("\r\nGetWidevine_KEY:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  848. if (!Xmlconfig.GetWidevineAndAttestationKeyXml(result.Html, "response", out code, out desc, out isAndroidTV, out Widevinekey, out Attestationkey, out AttestationMd5))
  849. {
  850. error = desc;
  851. ReportErrormsg("Fail to parse widevineAndAttestation", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  852. return false;
  853. }
  854. }
  855. else
  856. {
  857. error = result.StatusDescription;
  858. ReportErrormsg("Fail to get widevineAndAttestation", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  859. return false;
  860. }
  861. return true;
  862. }
  863. /// <summary>
  864. /// 异常上报
  865. /// </summary>
  866. /// <param name="reportType"></param>
  867. /// <param name="reportData"></param>
  868. /// <param name="sqliteConn"></param>
  869. /// <returns></returns>
  870. public static bool ReportErrormsg(string reportType,string reportData, SQLiteConnection sqliteConn)
  871. {
  872. 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")) };
  873. string jsonError = Newtonsoft.Json.JsonConvert.SerializeObject(ErrorInfo1, Newtonsoft.Json.Formatting.Indented);
  874. HttpHelper http = new HttpHelper();
  875. HttpItem item = new HttpItem()
  876. {
  877. URL = TestMode.errorreportServerurl,//URL这里都是测试URl   必需项
  878. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  879. //Encoding = Encoding.Default,
  880. Method = "post",//URL     可选项 默认为Get
  881. Postdata = jsonError,
  882. PostEncoding= Encoding.UTF8,
  883. KeepAlive = false
  884. };
  885. item.ContentType = "application/json;charset=utf-8";
  886. HttpResult result = http.GetHtml(item);
  887. string ParseText = result.Html;
  888. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  889. {
  890. Log.WriteGetKeyLog("\r\nReportErrormsg:\r\n" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + jsonError);
  891. }
  892. else
  893. {
  894. if(HTTPChecker(item.URL))
  895. SQLiteHelper.InsertDelayErrorReport(sqliteConn, new object[] { item.URL, item.Postdata });
  896. Log.WriteErrorLog("\r\nFail to ReportErrormsg:\r\n"+ result.StatusDescription +"\r\n"+ result.Html + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + jsonError);
  897. return false;
  898. }
  899. try
  900. {
  901. JObject jObject = JObject.Parse(ParseText);
  902. string message = jObject["message"].Value<string>();
  903. string code = jObject["code"].Value<string>();
  904. if (code == "1000")
  905. return true;
  906. else
  907. {
  908. Log.WriteErrorLog("\r\nError report return error:\r\n" + ParseText + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + jsonError);
  909. return false;
  910. }
  911. }
  912. catch (Exception ex)
  913. {
  914. Log.WriteErrorLog("\r\nFail to parse Error report return info," + ex.Message + ":" + ParseText + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + jsonError);
  915. return false;
  916. }
  917. }
  918. /// <summary>
  919. /// 上报预绑定包下载结果
  920. /// </summary>
  921. /// <param name="url"></param>
  922. /// <param name="order"></param>
  923. /// <param name="sqliteConn"></param>
  924. /// <returns></returns>
  925. public static bool ReportDownloadStatus(string url,string order, SQLiteConnection sqliteConn)
  926. {
  927. HttpHelper http = new HttpHelper();
  928. HttpItem item = new HttpItem()
  929. {
  930. URL = url + "/getreportofflinesn.do?",//URL这里都是测试URl   必需项
  931. Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  932. //Encoding = Encoding.Default,
  933. Method = "post",//URL     可选项 默认为Get
  934. Postdata = ("orderNumber =" + order),
  935. KeepAlive = false
  936. };
  937. item.ContentType = "application/x-www-form-urlencoded";
  938. HttpResult result = http.GetHtml(item);
  939. string ParseText = result.Html;
  940. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  941. {
  942. //
  943. }
  944. else
  945. {
  946. Log.WriteErrorLog("\r\nFail to report download status:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order));
  947. CommonMethod.ReportErrormsg("Fail to report download status", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order), sqliteConn);
  948. return false;
  949. }
  950. try
  951. {
  952. JObject jObject = JObject.Parse(ParseText);
  953. string des = JSON_SeleteNode(jObject, "des");
  954. string code = JSON_SeleteNode(jObject, "code");
  955. string data = JSON_SeleteNode(jObject, "data");
  956. if (code == "1000")
  957. return true;
  958. else
  959. {
  960. Log.WriteErrorLog("\r\nError report download status,should be 1000:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order));
  961. CommonMethod.ReportErrormsg("Error download status code return", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order), sqliteConn);
  962. return false;
  963. }
  964. }
  965. catch (Exception ex)
  966. {
  967. MessageBox.Show(ex.Message);
  968. Log.WriteErrorLog("\r\n" + ex.Message + ":" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order));
  969. CommonMethod.ReportErrormsg("Error parse download status return", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order), sqliteConn);
  970. return false;
  971. }
  972. }
  973. /// <summary>
  974. /// 生成DB格式key json字符串
  975. /// </summary>
  976. /// <param name="keyInfo"></param>
  977. /// <param name="keydata"></param>
  978. /// <param name="error"></param>
  979. /// <returns></returns>
  980. public static bool CreateDBkeyString(KeyInfo keyInfo,out string keydata,out string error)
  981. {
  982. keydata = "";
  983. error = "";
  984. try
  985. {
  986. 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 };
  987. keydata = Newtonsoft.Json.JsonConvert.SerializeObject(DBKeysStringFormat1, Newtonsoft.Json.Formatting.Indented);
  988. return true;
  989. }
  990. catch(Exception ex)
  991. {
  992. error = ex.Message;
  993. return false;
  994. }
  995. }
  996. /// <summary>
  997. /// 获取相应json子节点的值
  998. /// </summary>
  999. /// <param name="childnodelist"></param>
  1000. public static string JSON_SeleteNode(JToken json, string ReName)
  1001. {
  1002. try
  1003. {
  1004. string result = "";
  1005. //这里6.0版块可以用正则匹配
  1006. var node = json.SelectToken("$.." + ReName);
  1007. if (node != null)
  1008. {
  1009. //判断节点类型
  1010. if (node.Type == JTokenType.String || node.Type == JTokenType.Integer || node.Type == JTokenType.Float)
  1011. {
  1012. //返回string值
  1013. result = node.Value<object>().ToString();
  1014. }
  1015. }
  1016. return result;
  1017. }
  1018. catch (Exception ex)
  1019. {
  1020. return "";
  1021. }
  1022. }
  1023. /// <summary>
  1024. /// 确认是否为有效的url(检测开头是否为http://或者https://)
  1025. /// </summary>
  1026. /// <param name="Value"></param>
  1027. /// <returns></returns>
  1028. public static bool HTTPChecker(string Value)
  1029. {
  1030. try
  1031. {
  1032. if ((Value.Substring(0, 7) == "http://") || (Value.Substring(0, 8) == "https://"))
  1033. {
  1034. return true;
  1035. }
  1036. else
  1037. return false;
  1038. }
  1039. catch(Exception ex)
  1040. {
  1041. return false;
  1042. }
  1043. }
  1044. /// <summary>
  1045. /// 检查是否能正常访问网络
  1046. /// </summary>
  1047. /// <param name="url"></param>
  1048. /// <returns></returns>
  1049. public static bool CheckUrlConnection(string url)
  1050. {
  1051. try
  1052. {
  1053. HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
  1054. myRequest.Method = "HEAD"; //设置提交方式可以为"get","head"等
  1055. myRequest.Timeout = 10000; //设置网页响应时间长度
  1056. myRequest.AllowAutoRedirect = false;//是否允许自动重定向
  1057. myRequest.UseDefaultCredentials = true;
  1058. HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
  1059. myRequest.UseDefaultCredentials = true;//权限设置
  1060. return (myResponse.StatusCode == HttpStatusCode.OK);//返回响应的状态
  1061. }
  1062. catch(Exception ex)
  1063. {
  1064. return false;
  1065. }
  1066. }
  1067. /// <summary>
  1068. /// 指定目录创建文件夹
  1069. /// </summary>
  1070. /// <param name="path"></param>
  1071. public static void CreateDirectory(string path)
  1072. {
  1073. if (!Directory.Exists(path))//如果不存在就创建file文件夹
  1074. {
  1075. Directory.CreateDirectory(path);
  1076. }
  1077. }
  1078. /// <summary>
  1079. /// 在线下载抄写模式抄写的上报
  1080. /// </summary>
  1081. /// <param name="content"></param>
  1082. /// <returns></returns>
  1083. public static bool UploadCopyResult(string content ,string url, SQLiteConnection sqliteConn,string order, bool repeatupload, string id,int timeout)
  1084. {
  1085. if (timeout < 5000)
  1086. timeout = 5000;
  1087. HttpHelper http = new HttpHelper();
  1088. HttpItem item = new HttpItem()
  1089. {
  1090. Encoding = Encoding.UTF8,
  1091. Method = "post",
  1092. ContentType = "application/x-www-form-urlencoded",
  1093. Timeout = timeout,
  1094. KeepAlive = false
  1095. };
  1096. item.PostEncoding = Encoding.UTF8;
  1097. item.URL = url;
  1098. item.Postdata = content;
  1099. System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
  1100. stopwatch.Start();
  1101. HttpResult result = http.GetHtml(item);
  1102. stopwatch.Stop();
  1103. string usingtime = stopwatch.ElapsedMilliseconds.ToString();
  1104. stopwatch.Reset();
  1105. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1106. {
  1107. if (Xmlconfig.ReportXml(result.Html, "response", out string code, out string desc))
  1108. {
  1109. Log.WriteGetKeyLog("\r\nUpload copy status success:\r\nUsing time:" + usingtime + "ms\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  1110. return true;
  1111. }
  1112. else
  1113. {
  1114. CommonMethod.ReportErrormsg("Fail to parse copy result return", desc + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, sqliteConn);
  1115. Log.WriteErrorLog(code + "Error");
  1116. if (repeatupload)
  1117. {
  1118. SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
  1119. }
  1120. return false;
  1121. }
  1122. }
  1123. else
  1124. {
  1125. if (repeatupload)
  1126. return false;
  1127. if (CommonMethod.HTTPChecker(item.URL))
  1128. SQLiteHelper.InsertDelayCopyReport(sqliteConn, new object[] { order, item.URL, item.Postdata });
  1129. CommonMethod.ReportErrormsg("Fail to upload copy result", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, sqliteConn);
  1130. return true;
  1131. }
  1132. }
  1133. /// <summary>
  1134. /// 本地DB存储的异常重新上报
  1135. /// </summary>
  1136. /// <param name="reportType"></param>
  1137. /// <param name="reportData"></param>
  1138. /// <param name="sqliteConn"></param>
  1139. /// <returns></returns>
  1140. public static bool ReportErrormsg2(string url,string content,out bool mark)
  1141. {
  1142. mark = false;
  1143. HttpHelper http = new HttpHelper();
  1144. HttpItem item = new HttpItem()
  1145. {
  1146. URL = url,//URL这里都是测试URl   必需项
  1147. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  1148. //Encoding = Encoding.Default,
  1149. Method = "post",//URL     可选项 默认为Get
  1150. Postdata = content,
  1151. PostEncoding = Encoding.UTF8,
  1152. KeepAlive = false
  1153. };
  1154. item.ContentType = "application/json;charset=utf-8";
  1155. HttpResult result = http.GetHtml(item);
  1156. string ParseText = result.Html;
  1157. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1158. {
  1159. mark = true;
  1160. Log.WriteGetKeyLog("\r\nReportErrormsg:\r\n" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + content);
  1161. }
  1162. else
  1163. {
  1164. Log.WriteErrorLog("\r\nFail to ReportErrormsg:\r\n" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + content);
  1165. return false;
  1166. }
  1167. try
  1168. {
  1169. JObject jObject = JObject.Parse(ParseText);
  1170. string message = jObject["message"].Value<string>();
  1171. string code = jObject["code"].Value<string>();
  1172. if (code == "1000")
  1173. return true;
  1174. else
  1175. {
  1176. Log.WriteErrorLog("\r\nError report return error:\r\n" + ParseText + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + content);
  1177. return false;
  1178. }
  1179. }
  1180. catch (Exception ex)
  1181. {
  1182. Log.WriteErrorLog("\r\nFail to parse Error report return info," + ex.Message + ":" + ParseText + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + content);
  1183. return false;
  1184. }
  1185. }
  1186. /// <summary>
  1187. /// 判断目标字符串是否只有数字和字母
  1188. /// </summary>
  1189. /// <param name="value">目标字符串</param>
  1190. /// <returns></returns>
  1191. public static bool IsNumberAndWord(string value)
  1192. {
  1193. if (value is null)
  1194. return false;
  1195. Regex r = new Regex(@"^[a-zA-Z0-9]+$");
  1196. return r.Match(value).Success;
  1197. }
  1198. public static bool InsertJsonConfig(string node, string key)
  1199. {
  1200. JObject jObject;
  1201. using (StreamReader file = new StreamReader(LocalPath.localpath + "\\Config.json"))
  1202. {
  1203. using (JsonTextReader reader = new JsonTextReader(file))
  1204. {
  1205. jObject = (JObject)JToken.ReadFrom(reader);
  1206. jObject[node][key] = true;
  1207. }
  1208. }
  1209. using (StreamWriter writer = new StreamWriter(LocalPath.localpath + "\\Config.json"))
  1210. {
  1211. writer.Write(jObject.ToString());
  1212. }
  1213. return true;
  1214. }
  1215. public static bool AddJsonConfig(string key, object value)
  1216. {
  1217. JObject jObject;
  1218. using (StreamReader file = new StreamReader(LocalPath.localpath + "\\Config.json"))
  1219. {
  1220. using (JsonTextReader reader = new JsonTextReader(file))
  1221. {
  1222. jObject = (JObject)JToken.ReadFrom(reader);
  1223. jObject.Add(key, (JToken)value);
  1224. }
  1225. }
  1226. using (StreamWriter writer = new StreamWriter(LocalPath.localpath + "\\Config.json"))
  1227. {
  1228. writer.Write(jObject.ToString());
  1229. }
  1230. return false;
  1231. }
  1232. /// <summary>
  1233. /// 预下载模式抄写的上报
  1234. /// </summary>
  1235. /// <param name="copydate">烧录时间</param>
  1236. /// <returns></returns>
  1237. public static bool UploadPreloadCopyResult(string host, string copydate,string SN, SQLiteConnection localDBNow, SQLiteConnection sqliteConn,bool repeatupload,string id,int timeout)
  1238. {
  1239. string ParseText = "";
  1240. bool status;
  1241. try
  1242. {
  1243. List<PostDateClass> postList = new List<PostDateClass>();
  1244. postList.Add(new PostDateClass("sn", SN));
  1245. postList.Add(new PostDateClass("date", copydate));
  1246. ParseText = FormPost.postFileMessage(host + "/reportlist.do?", postList,out status,timeout);
  1247. if(status)
  1248. {
  1249. JObject jObject = JObject.Parse(ParseText);
  1250. string des = CommonMethod.JSON_SeleteNode(jObject, "des");
  1251. string code = CommonMethod.JSON_SeleteNode(jObject, "code");
  1252. string data = JSON_SeleteNode(jObject, "data");
  1253. if (code == "1000")
  1254. {
  1255. //更新上报内容
  1256. if (SQLiteHelper.UpdateReportStatus(localDBNow, SN))
  1257. {
  1258. //更新成功
  1259. Log.WriteGetKeyLog("\r\nUpdateReportStatus success:\r\n" + host + "/reportlist.do?\r\n" + "sn=" + SN + "\r\ndate=" + copydate + "\r\n" + ParseText);
  1260. return true;
  1261. }
  1262. else
  1263. {
  1264. Log.WriteErrorLog("\r\nFail to UpdateReportStatus: " + SN);
  1265. return false;
  1266. }
  1267. }
  1268. else
  1269. {
  1270. CommonMethod.ReportErrormsg("Fail to UploadPreloadCopyResult","Address: " + host + "/reportlist.do?" + "\r\nPostdata: " + "sn=" + SN + "\r\ndate=" + copydate+"\r\n"+ ParseText, sqliteConn);
  1271. 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);
  1272. if (repeatupload)
  1273. {
  1274. SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
  1275. }
  1276. return false;
  1277. }
  1278. }
  1279. else
  1280. {
  1281. if (repeatupload)
  1282. return false;
  1283. if (CommonMethod.HTTPChecker(host))
  1284. SQLiteHelper.InsertDelayCopyReport(sqliteConn, new object[] { "preload_mode", host, SN + "@" + copydate });
  1285. return false;
  1286. }
  1287. }
  1288. catch (Exception ex)
  1289. {
  1290. Log.WriteErrorLog("\r\nFail to parse UpdateReportStatus return: " + ex.Message + "\r\n" + SN + ":" + ParseText);
  1291. return false;
  1292. }
  1293. }
  1294. /// <summary>
  1295. /// 预下载模式抄写的批量上报
  1296. /// </summary>
  1297. /// <param name="host"></param>
  1298. /// <param name="postList"></param>
  1299. /// <param name="localDBNow"></param>
  1300. /// <param name="sqliteConn"></param>
  1301. /// <param name="repeatupload"></param>
  1302. /// <param name="id"></param>
  1303. /// <returns></returns>
  1304. public static bool UploadPreloadCopyResultList(string host, List<PostDateClass> postList, SQLiteConnection localDBNow, SQLiteConnection sqliteConn, bool repeatupload, string id)
  1305. {
  1306. string ParseText = "";
  1307. bool status;
  1308. try
  1309. {
  1310. ParseText = FormPost.postFileMessage(host + "/reportlist.do?", postList, out status,30000);
  1311. if (status)
  1312. {
  1313. JObject jObject = JObject.Parse(ParseText);
  1314. string des = CommonMethod.JSON_SeleteNode(jObject, "des");
  1315. string code = CommonMethod.JSON_SeleteNode(jObject, "code");
  1316. string data = JSON_SeleteNode(jObject, "data");
  1317. if (code == "1000")
  1318. {
  1319. Log.WriteGetKeyLog("UploadPreloadCopyResult successful\r\nAddress: " + host + "/reportlist.do?" + ParseText);
  1320. return true;
  1321. }
  1322. else
  1323. {
  1324. CommonMethod.ReportErrormsg("Fail to UploadPreloadCopyResult", "Address: " + host + "/reportlist.do?" + ParseText, sqliteConn);
  1325. Log.WriteErrorLog("\r\nUpdateReportStatus code return error,should be 1000 " + "\r\n" + ParseText + "\r\nAddress:" + host + "/reportlist.do?");
  1326. if (repeatupload)
  1327. {
  1328. SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
  1329. }
  1330. return false;
  1331. }
  1332. }
  1333. else
  1334. {
  1335. Log.WriteErrorLog("Fail to UploadPreloadCopyResult\r\nAddress: " + host + "/reportlist.do?" + ParseText);
  1336. return false;
  1337. }
  1338. }
  1339. catch (Exception ex)
  1340. {
  1341. Log.WriteErrorLog("\r\nFail to parse UpdateReportStatus return: " + ex.Message + "\r\n" + ParseText);
  1342. return false;
  1343. }
  1344. }
  1345. /// <summary>
  1346. /// byte[]数组到int转换
  1347. /// </summary>
  1348. /// <param name="value"></param>
  1349. /// <returns></returns>
  1350. public static int BytelisttoInt(byte[] value)
  1351. {
  1352. Array.Reverse(value);
  1353. int result = 0;
  1354. for (int i = 0; i < value.Length; i++)
  1355. {
  1356. result += value[i] << i * 8;
  1357. }
  1358. return result;
  1359. }
  1360. /// <summary>
  1361. /// int类型到byte[]数组转换
  1362. /// </summary>
  1363. /// <param name="value"></param>
  1364. /// <returns></returns>
  1365. public static byte[] InttoBytelist(int value)
  1366. {
  1367. byte[] bytes = BitConverter.GetBytes(value);
  1368. Array.Reverse(bytes);
  1369. if (value == 0)
  1370. return bytes;
  1371. List<byte> list = new List<byte>();
  1372. list.AddRange(bytes);
  1373. while (true)
  1374. {
  1375. if (list[0] != 0)
  1376. break;
  1377. else
  1378. list.RemoveAt(0);
  1379. }
  1380. bytes = list.ToArray();
  1381. return bytes;
  1382. }
  1383. /// <summary>
  1384. /// 升级检查
  1385. /// </summary>
  1386. /// <param name="url"></param>
  1387. /// <param name="FactoryNum"></param>
  1388. /// <param name="sqliteConn"></param>
  1389. /// <param name="upmid"></param>
  1390. /// <returns></returns>
  1391. public static bool UpgradeCheck(string url, string FactoryNum, SQLiteConnection sqliteConn, out UpgradeMsgList upmid)
  1392. {
  1393. upmid = new UpgradeMsgList();
  1394. 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()
  1395. string jsonorder = Newtonsoft.Json.JsonConvert.SerializeObject(UpgradeCheckInput1, Newtonsoft.Json.Formatting.Indented);
  1396. HttpHelper http = new HttpHelper();
  1397. HttpItem item = new HttpItem()
  1398. {
  1399. URL = url,//URL这里都是测试URl   必需项
  1400. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  1401. //Encoding = Encoding.Default,
  1402. Method = "post",//URL     可选项 默认为Get
  1403. Postdata = jsonorder,
  1404. PostEncoding = Encoding.UTF8,
  1405. KeepAlive = false
  1406. };
  1407. item.ContentType = "application/json;charset=utf-8";
  1408. ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
  1409. | SecurityProtocolType.Tls
  1410. | SecurityProtocolType.Tls11//(SecurityProtocolType)0x300 //Tls11
  1411. | SecurityProtocolType.Tls12;//(SecurityProtocolType)0xC00; //Tls12
  1412. HttpResult result = http.GetHtml(item);
  1413. string ParseText = result.Html;
  1414. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1415. {
  1416. Log.WriteGetKeyLog("\r\nUpgrade check," + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1417. }
  1418. else
  1419. {
  1420. Log.WriteErrorLog("\r\nFail to upgrade check:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1421. ReportErrormsg("Fail to upgrade check", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1422. return false;
  1423. }
  1424. try
  1425. {
  1426. JObject jObject = JObject.Parse(ParseText);
  1427. upmid.servertime = jObject["servertime"].Value<string>();
  1428. upmid.callid = jObject["callid"].Value<string>();
  1429. upmid.state = jObject["state"].Value<string>();
  1430. upmid.note = jObject["note"].Value<string>();
  1431. upmid.language = jObject["language"].Value<string>();
  1432. upmid.apiversion = jObject["apiversion"].Value<string>();
  1433. upmid.upgrade = new UpgradeMsgList2()
  1434. {
  1435. type = JSON_SeleteNode(jObject, "type"),
  1436. appid = JSON_SeleteNode(jObject, "appid"),
  1437. apptype = JSON_SeleteNode(jObject, "apptype"),
  1438. version = JSON_SeleteNode(jObject, "version"),
  1439. verid = JSON_SeleteNode(jObject, "verid"),
  1440. md5 = JSON_SeleteNode(jObject, "md5"),
  1441. size = JSON_SeleteNode(jObject, "size"),
  1442. minicon = JSON_SeleteNode(jObject, "minicon"),
  1443. midicon = JSON_SeleteNode(jObject, "midicon"),
  1444. fileurl = JSON_SeleteNode(jObject, "fileurl"),
  1445. increment = JSON_SeleteNode(jObject, "increment"),
  1446. appendver = JSON_SeleteNode(jObject, "appendver"),
  1447. updatetime = JSON_SeleteNode(jObject, "updatetime")
  1448. };
  1449. if (upmid.state == "0000")
  1450. return true;
  1451. else
  1452. {
  1453. return false;
  1454. }
  1455. }
  1456. catch (Exception ex)
  1457. {
  1458. Log.WriteErrorLog("\r\nFail to parse upgrade check info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1459. ReportErrormsg("Fail to parse upgrade check info", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1460. MessageBox.Show("Fail to parse upgrade check info\r\n " + ex.Message);
  1461. return false;
  1462. }
  1463. }
  1464. /// <summary>
  1465. /// 升级上报
  1466. /// </summary>
  1467. /// <param name="url"></param>
  1468. /// <param name="FactoryNum"></param>
  1469. /// <param name="Result"></param>
  1470. /// <param name="sqliteConn"></param>
  1471. /// <returns></returns>
  1472. public static bool UpgradeReport(string url, string FactoryNum, string Result,SQLiteConnection sqliteConn)
  1473. {
  1474. 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 };
  1475. string jsonorder = Newtonsoft.Json.JsonConvert.SerializeObject(UpgradeCheckInput1, Newtonsoft.Json.Formatting.Indented);
  1476. HttpHelper http = new HttpHelper();
  1477. HttpItem item = new HttpItem()
  1478. {
  1479. URL = url,//URL这里都是测试URl   必需项
  1480. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  1481. //Encoding = Encoding.Default,
  1482. Method = "post",//URL     可选项 默认为Get
  1483. Postdata = jsonorder,
  1484. PostEncoding = Encoding.UTF8,
  1485. KeepAlive = false
  1486. };
  1487. item.ContentType = "application/json;charset=utf-8";
  1488. ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
  1489. | SecurityProtocolType.Tls
  1490. | (SecurityProtocolType)0x300 //Tls11
  1491. | (SecurityProtocolType)0xC00; //Tls12
  1492. HttpResult result = http.GetHtml(item);
  1493. string ParseText = result.Html;
  1494. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1495. {
  1496. Log.WriteGetKeyLog("\r\nUpgrade report," + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1497. }
  1498. else
  1499. {
  1500. Log.WriteErrorLog("\r\nFail to upgrade report:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1501. ReportErrormsg("Fail to upgrade report", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1502. return false;
  1503. }
  1504. try
  1505. {
  1506. JObject jObject = JObject.Parse(ParseText);
  1507. return true;
  1508. }
  1509. catch (Exception ex)
  1510. {
  1511. Log.WriteErrorLog("\r\nFail to parse upgrade report info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1512. ReportErrormsg("Fail to parse upgrade report info", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1513. MessageBox.Show("Fail to parse upgrade report info\r\n " + ex.Message);
  1514. return false;
  1515. }
  1516. }
  1517. /// <summary>
  1518. /// 比较本地文件的MD5值
  1519. /// </summary>
  1520. /// <param name="filename"></param>
  1521. /// <param name="filetype"></param>
  1522. /// <param name="filemd5"></param>
  1523. /// <param name="error"></param>
  1524. /// <returns></returns>
  1525. public static bool CompareLocalkey(string filename, string filetype, string filemd5, out string error,out string filefullname)
  1526. {
  1527. error = "";
  1528. filefullname = "";
  1529. try
  1530. {
  1531. string filepath = AppDomain.CurrentDomain.BaseDirectory + "\\Keys\\" + filename + "\\" + filetype;
  1532. if (!Directory.Exists(filepath))
  1533. {
  1534. Directory.CreateDirectory(filepath);
  1535. }
  1536. DirectoryInfo Getkeyfile = new DirectoryInfo(filepath);
  1537. foreach (FileInfo keyfile in Getkeyfile.GetFiles())
  1538. {
  1539. string FileMD5 = GetMD5.GetMD5HashFromFile(keyfile.Name);
  1540. if (FileMD5 == filemd5)
  1541. {
  1542. Log.WriteGetKeyLog("Check md5file success,file md5:" + FileMD5+"\r\nfile:"+ keyfile.FullName) ;
  1543. filefullname = keyfile.FullName;
  1544. return true;
  1545. }
  1546. else
  1547. {
  1548. Log.WriteErrorLog("Check md5file error,delete file:" + keyfile.FullName + "\r\nfile md5" + FileMD5);
  1549. File.Delete(keyfile.FullName);
  1550. }
  1551. }
  1552. return false;
  1553. }
  1554. catch(Exception ex)
  1555. {
  1556. error = ex.Message;
  1557. return false;
  1558. }
  1559. }
  1560. /// <summary>
  1561. /// 数据MD5核对。当数据头为"MD5="时,key内容比对改为key内容MD5比对
  1562. /// </summary>
  1563. /// <param name="key"></param>
  1564. /// <param name="data"></param>
  1565. /// <param name="md5"></param>
  1566. /// <returns></returns>
  1567. public static bool CompareMD5(byte[] key, byte[] data)
  1568. {
  1569. string strdata = Encoding.ASCII.GetString(data);
  1570. Console.WriteLine(strdata);
  1571. if(strdata.StartsWith("MD5="))
  1572. {
  1573. string md5 = GetMD5.GetMD5Hash(key);
  1574. Console.WriteLine(md5);
  1575. return strdata.Remove(0, 4).Equals(md5);
  1576. }
  1577. return false;
  1578. }
  1579. /// <summary>
  1580. /// 将16进制字符串转为对应字节流写入生成key文件
  1581. /// </summary>
  1582. /// <param name="path"></param>
  1583. /// <param name="data"></param>
  1584. /// <param name="error"></param>
  1585. /// <returns></returns>
  1586. public static bool GetCreateHexkey(string path,string data,out string error)
  1587. {
  1588. error = "";
  1589. try
  1590. {
  1591. string filepath = path + ".bin";
  1592. byte[] bytedata = SerialInit.HexToByte(data);
  1593. //创建一个文件流
  1594. FileStream fs = new FileStream(filepath, FileMode.Create);
  1595. fs.Write(bytedata, 0, bytedata.Length);
  1596. fs.Close();
  1597. Log.WriteGetKeyLog("save key:" + filepath);
  1598. return true;
  1599. }
  1600. catch(Exception ex)
  1601. {
  1602. error = ex.Message;
  1603. Log.WriteErrorLog("save key error:" + error);
  1604. return false;
  1605. }
  1606. }
  1607. /// <summary>
  1608. /// 读取key文件内容转换为16进制字符串
  1609. /// </summary>
  1610. /// <param name="filepath"></param>
  1611. /// <param name="data"></param>
  1612. /// <param name="error"></param>
  1613. /// <returns></returns>
  1614. public static bool ReadHexFile(string filepath,out string data,out string error)
  1615. {
  1616. data = "";
  1617. error = "";
  1618. try
  1619. {
  1620. using FileStream fskey = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.None);
  1621. {
  1622. using BinaryReader brkey = new BinaryReader(fskey);
  1623. {
  1624. data = SerialInit.ByteToHex(brkey.ReadBytes((int)fskey.Length));
  1625. data = data.Replace(" ", "");
  1626. return true;
  1627. }
  1628. }
  1629. }
  1630. catch(Exception ex)
  1631. {
  1632. error = ex.Message;
  1633. return false;
  1634. }
  1635. }
  1636. /// <summary>
  1637. /// 账号登录
  1638. /// </summary>
  1639. /// <param name="url"></param>
  1640. /// <param name="account"></param>
  1641. /// <param name="password"></param>
  1642. /// <param name="pcmac"></param>
  1643. /// <param name="sqliteConn"></param>
  1644. /// <param name="loginOutput1"></param>
  1645. /// <returns></returns>
  1646. public static bool UserLogin(string url, string account, string password, string pcmac, SQLiteConnection sqliteConn, out LoginOutput loginOutput1)
  1647. {
  1648. loginOutput1 = new LoginOutput();
  1649. LoginInput LoginInput1 = new LoginInput { account = account, password = password, mac = pcmac };
  1650. string jsonorder = Newtonsoft.Json.JsonConvert.SerializeObject(LoginInput1, Newtonsoft.Json.Formatting.Indented);
  1651. HttpHelper http = new HttpHelper();
  1652. HttpItem item = new HttpItem()
  1653. {
  1654. URL = url,//URL这里都是测试URl   必需项
  1655. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  1656. //Encoding = Encoding.Default,
  1657. Method = "post",//URL     可选项 默认为Get
  1658. Postdata = jsonorder,
  1659. PostEncoding = Encoding.UTF8,
  1660. KeepAlive = false
  1661. };
  1662. item.ContentType = "application/json;charset=utf-8";
  1663. ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;//
  1664. HttpResult result = http.GetHtml(item);
  1665. string ParseText = result.Html;
  1666. if (result.StatusCode == HttpStatusCode.OK)
  1667. {
  1668. Log.WriteGetKeyLog("\r\nLogin," + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1669. }
  1670. else
  1671. {
  1672. Log.WriteErrorLog("\r\nFail to login:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1673. ReportErrormsg("Fail to login", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1674. return false;
  1675. }
  1676. try
  1677. {
  1678. JObject jObject = JObject.Parse(ParseText);
  1679. loginOutput1.msg = jObject["msg"].Value<string>();
  1680. loginOutput1.code = jObject["code"].Value<string>();
  1681. loginOutput1.factoryname = JSON_SeleteNode(jObject, "factoryName");
  1682. loginOutput1.factorynum = JSON_SeleteNode(jObject, "factoryNum");
  1683. if (loginOutput1.code == "1000")
  1684. return true;
  1685. else
  1686. return false;
  1687. }
  1688. catch (Exception ex)
  1689. {
  1690. Log.WriteErrorLog("\r\nFail to login," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1691. ReportErrormsg("Fail to login", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1692. MessageBox.Show("Fail to parse login return\r\n " + ex.Message);
  1693. return false;
  1694. }
  1695. }
  1696. /// <summary>
  1697. /// 获取指定日期,在为一年中为第几周
  1698. /// </summary>
  1699. /// <param name="dt">指定时间</param>
  1700. /// <reutrn>返回第几周</reutrn>
  1701. public static int GetWeekOfYear(DateTime dt)
  1702. {
  1703. GregorianCalendar gc = new GregorianCalendar();
  1704. int weekOfYear = gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
  1705. return weekOfYear;
  1706. }
  1707. /// <summary>
  1708. /// 版本号比较:new_version>=old_version
  1709. /// </summary>
  1710. /// <param name="new_version">8.4.0</param>
  1711. /// <param name="old_version">8.3.10</param>
  1712. /// <returns></returns>
  1713. public static bool CompareVersion(string new_version, string old_version)
  1714. {
  1715. try
  1716. {
  1717. if (string.IsNullOrEmpty(new_version) || string.IsNullOrEmpty(old_version))
  1718. return false;
  1719. Version v_new = new Version(new_version);
  1720. Version v_old = new Version(old_version);
  1721. if (v_new >= v_old)
  1722. return true;
  1723. return false;
  1724. }
  1725. catch (Exception ex)
  1726. {
  1727. throw ex;
  1728. }
  1729. }
  1730. /// <summary>
  1731. /// 获取白平衡信息
  1732. /// </summary>
  1733. /// <param name="url"></param>
  1734. /// <param name="order"></param>
  1735. /// <param name="pcmac"></param>
  1736. /// <param name="sqliteConn"></param>
  1737. /// <param name="WBList"></param>
  1738. /// <returns></returns>
  1739. public static bool GetWhiteBalanceInfo(string url, string order, string pcmac, SQLiteConnection sqliteConn, out WhiteBalanceList WBList)
  1740. {
  1741. WBList = new WhiteBalanceList();
  1742. WhiteBalanceInput WBInput1 = new WhiteBalanceInput { bid = order, mac = pcmac };//"74-27-EA-6E-DA-9F"
  1743. string jsonorder = Newtonsoft.Json.JsonConvert.SerializeObject(WBInput1, Newtonsoft.Json.Formatting.Indented);
  1744. HttpHelper http = new HttpHelper();
  1745. HttpItem item = new HttpItem()
  1746. {
  1747. URL = url,//URL这里都是测试URl   必需项
  1748. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  1749. //Encoding = Encoding.Default,
  1750. Method = "post",//URL     可选项 默认为Get
  1751. Postdata = jsonorder,
  1752. PostEncoding = Encoding.UTF8,
  1753. KeepAlive = false
  1754. };
  1755. item.ContentType = "application/json;charset=utf-8";
  1756. System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
  1757. stopwatch.Start();
  1758. HttpResult result = http.GetHtml(item);
  1759. stopwatch.Stop();
  1760. string usingtime = stopwatch.ElapsedMilliseconds.ToString();
  1761. stopwatch.Reset();
  1762. string ParseText = result.Html;
  1763. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1764. {
  1765. Log.WriteGetKeyLog("\r\nGet WB info\r\nUsing time:" + usingtime + "ms\r\n" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1766. }
  1767. else
  1768. {
  1769. Log.WriteErrorLog("\r\nFail to WBinfo:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1770. ReportErrormsg("Fail to WBinfo", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1771. return false;
  1772. }
  1773. try
  1774. {
  1775. JObject jObject = JObject.Parse(ParseText);
  1776. WBList.message = jObject["message"].Value<string>();
  1777. WBList.code = jObject["code"].Value<string>();
  1778. object a = jObject["obj"];
  1779. if (jObject["obj"].ToString().Length > 0)
  1780. WBList.whiteBalanceInfo = new WhiteBalanceInfo()
  1781. {
  1782. id = JSON_SeleteNode(jObject["obj"], "id"),
  1783. ordernum = JSON_SeleteNode(jObject["obj"], "ordernum"),
  1784. hdmirgain = JSON_SeleteNode(jObject["obj"], "hdmirgain"),
  1785. hdmiggain = JSON_SeleteNode(jObject["obj"], "hdmiggain"),
  1786. hdmibgain = JSON_SeleteNode(jObject["obj"], "hdmibgain"),
  1787. nrgain = JSON_SeleteNode(jObject["obj"], "nrgain"),
  1788. nggain = JSON_SeleteNode(jObject["obj"], "nggain"),
  1789. nbgain = JSON_SeleteNode(jObject["obj"], "nbgain"),
  1790. lrgain = JSON_SeleteNode(jObject["obj"], "lrgain"),
  1791. lggain = JSON_SeleteNode(jObject["obj"], "lggain"),
  1792. lbgain = JSON_SeleteNode(jObject["obj"], "lbgain"),
  1793. updatetime = JSON_SeleteNode(jObject["obj"], "updatetime"),
  1794. createtime = JSON_SeleteNode(jObject["obj"], "createtime"),
  1795. isdelete = JSON_SeleteNode(jObject["obj"], "isdelete"),
  1796. isExemption= JSON_SeleteNode(jObject["obj"], "isExemption")
  1797. };
  1798. if (WBList.code == "1000")
  1799. return true;
  1800. else
  1801. return false;
  1802. }
  1803. catch (Exception ex)
  1804. {
  1805. Log.WriteErrorLog("\r\nFail to parse WB info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1806. ReportErrormsg("Fail to parse WB info", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1807. MessageBox.Show("Fail to parse WB info\r\n " + ex.Message);
  1808. return false;
  1809. }
  1810. }
  1811. private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
  1812. {
  1813. return true;
  1814. }
  1815. public static bool AutoGetKey(string url, string order, string key, string keytype, SQLiteConnection errorDBNow)
  1816. {
  1817. string code;
  1818. string desc;
  1819. HttpHelper http = new HttpHelper();
  1820. HttpItem item = new HttpItem()
  1821. {
  1822. Encoding = Encoding.Default,
  1823. Method = "post",
  1824. ContentType = "application/x-www-form-urlencoded",
  1825. KeepAlive = false
  1826. };
  1827. url += "/autogetkey.do?";
  1828. item.URL = url;
  1829. item.Postdata = string.Format("order={0}&key={1}&keytype={2}&mac={3}", order, key, keytype, HttpUtility.UrlEncode(TestMode.MAC));
  1830. HttpResult result = http.GetHtml(item);
  1831. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1832. {
  1833. Log.WriteGetKeyLog("\r\nAutoquestKey :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  1834. if (Xmlconfig.AutoKeyStatusXml(result.Html, "response", out code, out desc))
  1835. {
  1836. return true;
  1837. }
  1838. else
  1839. {
  1840. CommonMethod.ReportErrormsg("Auto get key error", desc + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, errorDBNow);
  1841. return false;
  1842. }
  1843. }
  1844. else
  1845. {
  1846. CommonMethod.ReportErrormsg("Auto get key error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, errorDBNow);
  1847. return false;
  1848. }
  1849. }
  1850. public static bool AutoGetKeyStatus(string url, string key, string keytype, SQLiteConnection errorDBNow)
  1851. {
  1852. string code;
  1853. string desc;
  1854. HttpHelper http = new HttpHelper();
  1855. HttpItem item = new HttpItem()
  1856. {
  1857. Encoding = Encoding.Default,
  1858. Method = "post",
  1859. ContentType = "application/x-www-form-urlencoded",
  1860. KeepAlive = false
  1861. };
  1862. url += "/autogetkeystatus.do?";
  1863. item.URL = url;
  1864. item.Postdata = string.Format("key={0}&keytype={1}", key, keytype);
  1865. HttpResult result = http.GetHtml(item);
  1866. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1867. {
  1868. Log.WriteGetKeyLog("\r\nAutoGetKeyStatus :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  1869. if (Xmlconfig.AutoKeyStatusXml(result.Html, "response", out code, out desc))
  1870. {
  1871. return true;
  1872. }
  1873. else
  1874. {
  1875. return false;
  1876. }
  1877. }
  1878. else
  1879. {
  1880. CommonMethod.ReportErrormsg("Auto get key status error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, errorDBNow);
  1881. return false;
  1882. }
  1883. }
  1884. public static bool GetFireTVDsn(string url, string ordernum, string deviceCode, string FSN, string PSN, out string dsn, out string error, SQLiteConnection errorDBNow)
  1885. {
  1886. dsn = "";
  1887. error = "";
  1888. HttpHelper http = new HttpHelper();
  1889. HttpItem item = new HttpItem()
  1890. {
  1891. Encoding = null, // 编码格式(utf-8,gb2312,gbk)可选项 默认类会自动识别Encoding = Encoding.Default,
  1892. Method = "GET", // URL 可选项 默认为Get
  1893. KeepAlive = false
  1894. };
  1895. 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));
  1896. HttpResult result = http.GetHtml(item);
  1897. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1898. {
  1899. string code;
  1900. string desc;
  1901. Log.WriteGetKeyLog("\r\nGetFireTVDsn :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  1902. if (Xmlconfig.GetDSNXml(result.Html, "response", out code, out desc, out dsn))
  1903. {
  1904. Log.WriteGetKeyLog("\r\nDSN=" + dsn);
  1905. return true;
  1906. }
  1907. else
  1908. {
  1909. error = desc;
  1910. CommonMethod.ReportErrormsg("GetFireTVDsn error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL, errorDBNow);
  1911. return false;
  1912. }
  1913. }
  1914. else
  1915. {
  1916. error = "Communication with server failed";
  1917. CommonMethod.ReportErrormsg("GetFireTVDsn error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL, errorDBNow);
  1918. return false;
  1919. }
  1920. }
  1921. /// <summary>
  1922. /// 导出日本的SN与ACASID到文本中;
  1923. /// </summary>
  1924. /// <param name="ordernum"></param>
  1925. /// <param name="sn"></param>
  1926. /// <param name="acasid"></param>
  1927. public static void ExportSNACASID(string ordernum, string sn, string acasid)
  1928. {
  1929. string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\SN-ACAS";
  1930. if (!Directory.Exists(path))
  1931. {
  1932. Directory.CreateDirectory(path);
  1933. }
  1934. if ( !lastOrder.Equals(ordernum) )
  1935. {
  1936. lastOrder = ordernum;
  1937. ListACASSN.Clear();
  1938. }
  1939. string msg = string.Format("{0};{1}", sn, acasid);
  1940. if (ListACASSN.Contains(msg))
  1941. {
  1942. return;
  1943. }
  1944. ListACASSN.Add(msg);
  1945. string fileName = path + "\\" + ordernum + ".txt";
  1946. var stream = new StreamWriter(fileName, true);
  1947. stream.WriteLine(msg);
  1948. stream.Close();
  1949. stream.Dispose();
  1950. }
  1951. }
  1952. /// <summary>
  1953. /// CRC32
  1954. /// </summary>
  1955. class CRC32
  1956. {
  1957. //生成CRC32码表
  1958. static uint[] Crc32Table;
  1959. public static void GetCRC32Table()
  1960. {
  1961. uint Crc;
  1962. Crc32Table = new uint[256];
  1963. int i, j;
  1964. for (i = 0; i < 256; i++)
  1965. {
  1966. Crc = (uint)i;
  1967. for (j = 8; j > 0; j--)
  1968. {
  1969. if ((Crc & 1) == 1)
  1970. Crc = (Crc >> 1) ^ 0xEDB88320;
  1971. else
  1972. Crc >>= 1;
  1973. }
  1974. Crc32Table[i] = Crc;
  1975. }
  1976. }
  1977. public static uint GetCRC32(byte[] bytes)
  1978. {
  1979. GetCRC32Table();
  1980. uint value = 0xffffffff;
  1981. int len = bytes.Length;
  1982. for (int i = 0; i < len; i++)
  1983. {
  1984. value = (value >> 8) ^ Crc32Table[(value & 0xFF) ^ bytes[i]];
  1985. }
  1986. return value ^ 0xffffffff;
  1987. }
  1988. }
  1989. /// <summary>
  1990. /// 本地抄写模式方法
  1991. /// </summary>
  1992. public class GetLocalKeyCount
  1993. {
  1994. static string LocalKeyPath = AppDomain.CurrentDomain.BaseDirectory + "\\Keys\\";
  1995. public static bool GetLocalDidCount(string order,out int num,ref MidList localmidList, SQLiteConnection errorDBNow)
  1996. {
  1997. num = 0;
  1998. try
  1999. {
  2000. string DIDpath = LocalKeyPath + order + "\\DeviceID";
  2001. if (Directory.Exists(DIDpath) == false)
  2002. return false;
  2003. else
  2004. {
  2005. DirectoryInfo GetDIDfile = new DirectoryInfo(DIDpath);
  2006. foreach (FileInfo keyfile in GetDIDfile.GetFiles())
  2007. {
  2008. string filename = keyfile.FullName;
  2009. if (keyfile.Name.Contains("Online"))
  2010. {
  2011. if (localmidList.host == null)
  2012. {
  2013. if (CommonMethod.GetMidInfo(TestMode.serverurl, order, TestMode.MAC, "", "", errorDBNow, out localmidList))
  2014. {
  2015. ;
  2016. }
  2017. else
  2018. {
  2019. num = -1;
  2020. return true;
  2021. }
  2022. }
  2023. HttpHelper http = new HttpHelper();
  2024. HttpItem item = new HttpItem()
  2025. {
  2026. Encoding = Encoding.Default,
  2027. Method = "post",
  2028. ContentType = "application/x-www-form-urlencoded"
  2029. };
  2030. string url1 = localmidList.host + "/statdeviceid.do?";
  2031. item.URL = url1;
  2032. item.Postdata = "devicetype=tcl_unknown_model";
  2033. HttpResult result = http.GetHtml(item);
  2034. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  2035. {
  2036. Log.WriteGetKeyLog("\r\nGetDeviceID count:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  2037. if (Xmlconfig.KeyCountXml(result.Html, "response", "count", out string code, out string desc, out string count))
  2038. {
  2039. num = Convert.ToInt32(count.Replace(",", ""));
  2040. return true;
  2041. }
  2042. else
  2043. {
  2044. num = -1;
  2045. return true;
  2046. }
  2047. }
  2048. else
  2049. {
  2050. num = -1;
  2051. return true;
  2052. }
  2053. }
  2054. else
  2055. {
  2056. num = GetDIDfile.GetFiles().Length;
  2057. return true;
  2058. }
  2059. }
  2060. return true;
  2061. }
  2062. }
  2063. catch(Exception ex)
  2064. {
  2065. num = -1;
  2066. return true;
  2067. }
  2068. }
  2069. public static bool GetLocalMacCount(string order, out int num, ref MidList localmidList, SQLiteConnection errorDBNow)
  2070. {
  2071. num = 0;
  2072. try
  2073. {
  2074. string MACpath = LocalKeyPath + order + "\\MAC";
  2075. if (Directory.Exists(MACpath) == false)
  2076. return false;
  2077. else
  2078. {
  2079. DirectoryInfo GetMACfile = new DirectoryInfo(MACpath);
  2080. foreach (FileInfo keyfile in GetMACfile.GetFiles())
  2081. {
  2082. string filename = keyfile.FullName;
  2083. if (keyfile.Name.Contains("Online"))
  2084. {
  2085. if (localmidList.host == null)
  2086. {
  2087. if (CommonMethod.GetMidInfo(TestMode.serverurl, order, TestMode.MAC, "", "", errorDBNow, out localmidList))
  2088. {
  2089. ;
  2090. }
  2091. else
  2092. {
  2093. num = -1;
  2094. return true;
  2095. }
  2096. }
  2097. HttpHelper http = new HttpHelper();
  2098. HttpItem item = new HttpItem()
  2099. {
  2100. Encoding = Encoding.Default,
  2101. Method = "post",
  2102. ContentType = "application/x-www-form-urlencoded"
  2103. };
  2104. string url1 = localmidList.host + "/statmac.do?";
  2105. item.URL = url1;
  2106. item.Postdata = "typeString=" + localmidList.keytype["MAC"];
  2107. HttpResult result = http.GetHtml(item);
  2108. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  2109. {
  2110. Log.WriteGetKeyLog("\r\nGetMac count:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  2111. if (Xmlconfig.KeyCountXml(result.Html, "response", "count", out string code, out string desc, out string count))
  2112. {
  2113. num = Convert.ToInt32(count.Replace(",", ""));
  2114. return true;
  2115. }
  2116. else
  2117. {
  2118. num = -1;
  2119. return true;
  2120. }
  2121. }
  2122. else
  2123. {
  2124. num = -1;
  2125. return true;
  2126. }
  2127. }
  2128. else
  2129. {
  2130. num = GetMACfile.GetFiles().Length;
  2131. return true;
  2132. }
  2133. }
  2134. return true;
  2135. }
  2136. }
  2137. catch (Exception ex)
  2138. {
  2139. num = -1;
  2140. return true;
  2141. }
  2142. }
  2143. public static bool GetLocalHDCPKEYCount(string order, out int num)
  2144. {
  2145. num = 0;
  2146. try
  2147. {
  2148. string HDCPKEYpath = LocalKeyPath + order + "\\HDCPKEY";
  2149. if (Directory.Exists(HDCPKEYpath) == false)
  2150. return false;
  2151. else
  2152. {
  2153. DirectoryInfo GetHDCPKEYfile = new DirectoryInfo(HDCPKEYpath);
  2154. num = GetHDCPKEYfile.GetFiles().Length;
  2155. return true;
  2156. }
  2157. }
  2158. catch (Exception ex)
  2159. {
  2160. num = -1;
  2161. return true;
  2162. }
  2163. }
  2164. public static bool GetLocalHDCPKEY22Count(string order, out int num)
  2165. {
  2166. num = 0;
  2167. try
  2168. {
  2169. string HDCPKEY22path = LocalKeyPath + order + "\\HDCPKEY22";
  2170. if (Directory.Exists(HDCPKEY22path) == false)
  2171. return false;
  2172. else
  2173. {
  2174. DirectoryInfo GetHDCPKEY22file = new DirectoryInfo(HDCPKEY22path);
  2175. num = GetHDCPKEY22file.GetFiles().Length;
  2176. return true;
  2177. }
  2178. }
  2179. catch (Exception ex)
  2180. {
  2181. num = -1;
  2182. return true;
  2183. }
  2184. }
  2185. public static bool GetLocalWiDiCount(string order, out int num)
  2186. {
  2187. num = 0;
  2188. try
  2189. {
  2190. string WiDipath = LocalKeyPath + order + "\\WiDi";
  2191. if (Directory.Exists(WiDipath) == false)
  2192. return false;
  2193. else
  2194. {
  2195. DirectoryInfo GetWiDifile = new DirectoryInfo(WiDipath);
  2196. num = GetWiDifile.GetFiles().Length;
  2197. return true;
  2198. }
  2199. }
  2200. catch (Exception ex)
  2201. {
  2202. num = -1;
  2203. return true;
  2204. }
  2205. }
  2206. public static bool GetLocalWidevineCount(string order, out int num)
  2207. {
  2208. num = 0;
  2209. try
  2210. {
  2211. string Widevinepath = LocalKeyPath + order + "\\Widevine";
  2212. if (Directory.Exists(Widevinepath) == false)
  2213. return false;
  2214. else
  2215. {
  2216. DirectoryInfo GetWidevinefile = new DirectoryInfo(Widevinepath);
  2217. num = GetWidevinefile.GetFiles().Length;
  2218. return true;
  2219. }
  2220. }
  2221. catch (Exception ex)
  2222. {
  2223. num = -1;
  2224. return true;
  2225. }
  2226. }
  2227. public static bool GetLocalESNCount(string order, out int num)
  2228. {
  2229. num = 0;
  2230. try
  2231. {
  2232. string ESNpath = LocalKeyPath + order + "\\ESN";
  2233. if (Directory.Exists(ESNpath) == false)
  2234. return false;
  2235. else
  2236. {
  2237. DirectoryInfo GetESNfile = new DirectoryInfo(ESNpath);
  2238. num = GetESNfile.GetFiles().Length;
  2239. return true;
  2240. }
  2241. }
  2242. catch (Exception ex)
  2243. {
  2244. num = -1;
  2245. return true;
  2246. }
  2247. }
  2248. public static bool GetLocalMGKCount(string order, out int num)
  2249. {
  2250. num = 0;
  2251. try
  2252. {
  2253. string MGKpath = LocalKeyPath + order + "\\MGK";
  2254. if (Directory.Exists(MGKpath) == false)
  2255. return false;
  2256. else
  2257. {
  2258. DirectoryInfo GetMGKfile = new DirectoryInfo(MGKpath);
  2259. num = GetMGKfile.GetFiles().Length;
  2260. return true;
  2261. }
  2262. }
  2263. catch (Exception ex)
  2264. {
  2265. num = -1;
  2266. return true;
  2267. }
  2268. }
  2269. public static bool GetLocalFairplayCount(string order, out int num)
  2270. {
  2271. num = 0;
  2272. try
  2273. {
  2274. string Fairplaypath = LocalKeyPath + order + "\\Fairplay";
  2275. if (Directory.Exists(Fairplaypath) == false)
  2276. return false;
  2277. else
  2278. {
  2279. DirectoryInfo GetFairplayfile = new DirectoryInfo(Fairplaypath);
  2280. num = GetFairplayfile.GetFiles().Length;
  2281. return true;
  2282. }
  2283. }
  2284. catch (Exception ex)
  2285. {
  2286. num = -1;
  2287. return true;
  2288. }
  2289. }
  2290. public static bool GetLocalFolderKeyCount(string order,string keyname, out int num)
  2291. {
  2292. num = 0;
  2293. try
  2294. {
  2295. string Fairplaypath = LocalKeyPath + order + "\\" + keyname;
  2296. if (Directory.Exists(Fairplaypath) == false)
  2297. return false;
  2298. else
  2299. {
  2300. DirectoryInfo GetFairplayfile = new DirectoryInfo(Fairplaypath);
  2301. num = GetFairplayfile.GetFiles().Length;
  2302. return true;
  2303. }
  2304. }
  2305. catch (Exception ex)
  2306. {
  2307. num = -1;
  2308. return true;
  2309. }
  2310. }
  2311. public static bool GetLocalAttestationCount(string order, out int num)
  2312. {
  2313. num = 0;
  2314. try
  2315. {
  2316. string Attestationpath = LocalKeyPath + order + "\\Attestation";
  2317. if (Directory.Exists(Attestationpath) == false)
  2318. return false;
  2319. else
  2320. {
  2321. DirectoryInfo GetAttestationfile = new DirectoryInfo(Attestationpath);
  2322. num = GetAttestationfile.GetFiles().Length;
  2323. return true;
  2324. }
  2325. }
  2326. catch (Exception ex)
  2327. {
  2328. num = -1;
  2329. return true;
  2330. }
  2331. }
  2332. public static bool GetLocalCIKEYCount(string order, out int num)
  2333. {
  2334. num = 0;
  2335. try
  2336. {
  2337. string CIKEYpath = LocalKeyPath + order + "\\CIKEY";
  2338. if (Directory.Exists(CIKEYpath) == false)
  2339. return false;
  2340. else
  2341. {
  2342. DirectoryInfo GetCIKEYfile = new DirectoryInfo(CIKEYpath);
  2343. num = GetCIKEYfile.GetFiles().Length;
  2344. return true;
  2345. }
  2346. }
  2347. catch (Exception ex)
  2348. {
  2349. num = -1;
  2350. return true;
  2351. }
  2352. }
  2353. 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)
  2354. {
  2355. data = "";
  2356. filename = "";
  2357. error = "";
  2358. brkey = null;
  2359. fskey = null;
  2360. try
  2361. {
  2362. string keypath = LocalKeyPath + order + "\\"+ keytype;
  2363. if (Directory.Exists(keypath) == false)
  2364. {
  2365. error = "File not exist";
  2366. return false;
  2367. }
  2368. else
  2369. {
  2370. DirectoryInfo Getkeyfile = new DirectoryInfo(keypath);
  2371. foreach (FileInfo keyfile in Getkeyfile.GetFiles())
  2372. {
  2373. filename = keyfile.FullName;
  2374. if (keyfile.Name.Contains("Online"))
  2375. {
  2376. try
  2377. {
  2378. if(localmidList.host==null)
  2379. {
  2380. if(CommonMethod.GetMidInfo(TestMode.serverurl, order, TestMode.MAC, "", "", errorDBNow, out localmidList))
  2381. {
  2382. ;
  2383. }
  2384. else
  2385. {
  2386. return false;
  2387. }
  2388. }
  2389. if (keytype == "DeviceID")
  2390. localmidList.keytype["DeviceID"] = "devicetype=tcl_unknown_model";
  2391. else if (keytype == "MAC")
  2392. keytype = "MAC";
  2393. else if (keytype == "HDCPKEY")
  2394. keytype = "HDCP_KEY";
  2395. else if (keytype == "HDCPKEY22")
  2396. keytype = "HDCP2.2_KEY";
  2397. else if (keytype == "ESN")
  2398. keytype = "NETFILX_ESN";
  2399. else if (keytype == "Widevine")
  2400. keytype = "Widevine_KEY";
  2401. else if (keytype == "WiDi")
  2402. keytype = "WiDi";
  2403. else if (keytype == "CIKEY")
  2404. keytype = "CI_PLUS_KEY";
  2405. if (CommonMethod.GetKeys(localmidList.host, keytype, SN, localmidList.keytype[keytype], errorDBNow, out string did, out error, order,out string md5))
  2406. {
  2407. data = did;
  2408. Log.WriteGetKeyLog("\r\n" + keytype + "= " + data);
  2409. return true;
  2410. }
  2411. else
  2412. {
  2413. return false;
  2414. }
  2415. }
  2416. catch(Exception ex)
  2417. {
  2418. error = ex.Message;
  2419. return false;
  2420. }
  2421. }
  2422. else
  2423. {
  2424. try
  2425. {
  2426. fskey = new FileStream(keyfile.FullName.ToString(), FileMode.Open, FileAccess.ReadWrite, FileShare.None);
  2427. {
  2428. brkey = new StreamReader(fskey);
  2429. {
  2430. if (fskey.Length == filesize || filesize == -1)
  2431. {
  2432. data = brkey.ReadToEnd();
  2433. return true;
  2434. }
  2435. else
  2436. {
  2437. error = "File size error.\r\nFilename:" + keyfile.Name + "\r\nFilesize:" + fskey.Length.ToString();
  2438. return false;
  2439. }
  2440. }
  2441. }
  2442. }
  2443. catch
  2444. {
  2445. ;
  2446. }
  2447. }
  2448. }
  2449. return false;
  2450. }
  2451. }
  2452. catch (Exception ex)
  2453. {
  2454. error = ex.Message;
  2455. return false;
  2456. }
  2457. }
  2458. 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)
  2459. {
  2460. data = "";
  2461. filename = "";
  2462. error = "";
  2463. brkey = null;
  2464. fskey = null;
  2465. try
  2466. {
  2467. string keypath = LocalKeyPath + order + "\\" + keytype;
  2468. if (Directory.Exists(keypath) == false)
  2469. {
  2470. error = "File not exist";
  2471. return false;
  2472. }
  2473. else
  2474. {
  2475. DirectoryInfo Getkeyfile = new DirectoryInfo(keypath);
  2476. foreach (FileInfo keyfile in Getkeyfile.GetFiles())
  2477. {
  2478. filename = keyfile.FullName;
  2479. if (keyfile.Name.Contains("Online"))
  2480. {
  2481. try
  2482. {
  2483. if (localmidList.host == null)
  2484. {
  2485. if (CommonMethod.GetMidInfo(TestMode.serverurl, order, TestMode.MAC, "", "", errorDBNow, out localmidList))
  2486. {
  2487. ;
  2488. }
  2489. else
  2490. {
  2491. return false;
  2492. }
  2493. }
  2494. if (keytype == "DeviceID")
  2495. localmidList.keytype["DeviceID"] = "devicetype=tcl_unknown_model";
  2496. else if (keytype == "MAC")
  2497. keytype = "MAC";
  2498. else if (keytype == "HDCPKEY")
  2499. keytype = "HDCP_KEY";
  2500. else if (keytype == "HDCPKEY22")
  2501. keytype = "HDCP2.2_KEY";
  2502. else if (keytype == "ESN")
  2503. keytype = "NETFILX_ESN";
  2504. else if (keytype == "Widevine")
  2505. keytype = "Widevine_KEY";
  2506. else if (keytype == "WiDi")
  2507. keytype = "WiDi";
  2508. else if (keytype == "CIKEY")
  2509. keytype = "CI_PLUS_KEY";
  2510. else if (keytype == "MGK")
  2511. keytype = "MGK_KEY";
  2512. else if (keytype == "Attestation")
  2513. keytype = "Attestation";
  2514. else if (keytype == "Fairplay")
  2515. keytype = "Fairplay_KEY";
  2516. if (CommonMethod.GetKeys(localmidList.host, keytype, SN, localmidList.keytype[keytype], errorDBNow, out string did, out error, order, out string md5))
  2517. {
  2518. data = did;
  2519. Log.WriteGetKeyLog("\r\n" + keytype + "= " + data);
  2520. return true;
  2521. }
  2522. else
  2523. {
  2524. return false;
  2525. }
  2526. }
  2527. catch (Exception ex)
  2528. {
  2529. error = ex.Message;
  2530. return false;
  2531. }
  2532. }
  2533. else
  2534. {
  2535. try
  2536. {
  2537. fskey = new FileStream(keyfile.FullName.ToString(), FileMode.Open, FileAccess.Read, FileShare.None);
  2538. {
  2539. brkey = new BinaryReader(fskey);
  2540. {
  2541. if (fskey.Length == filesize || filesize == -1)
  2542. {
  2543. data = SerialInit.ByteToHex(brkey.ReadBytes((int)fskey.Length));
  2544. data = data.Replace(" ", "");
  2545. return true;
  2546. }
  2547. else
  2548. {
  2549. error = "File size error.\r\nFilename: " + keyfile.Name + "\r\nFilesize: " + fskey.Length.ToString();
  2550. return false;
  2551. }
  2552. }
  2553. }
  2554. }
  2555. catch
  2556. {
  2557. ;
  2558. }
  2559. }
  2560. }
  2561. return false;
  2562. }
  2563. }
  2564. catch (Exception ex)
  2565. {
  2566. error = ex.Message;
  2567. return false;
  2568. }
  2569. }
  2570. public static bool DeleteLocalKeys(ArrayList filelist, ArrayList Stream, ArrayList Reader)
  2571. {
  2572. try
  2573. {
  2574. if (filelist.Count == Reader.Count)
  2575. {
  2576. for (int i = 0; i < filelist.Count; i++)
  2577. {
  2578. if(filelist[i].ToString().Contains("DeviceID"))
  2579. ((StreamReader)Reader[i]).Dispose();
  2580. else
  2581. ((BinaryReader)Reader[i]).Dispose();
  2582. ((FileStream)Stream[i]).Dispose();
  2583. File.Delete(filelist[i].ToString());
  2584. }
  2585. return true;
  2586. }
  2587. else
  2588. return false;
  2589. }
  2590. catch(Exception ex)
  2591. {
  2592. for (int i = 0; i < Reader.Count; i++)
  2593. {
  2594. if (filelist[i].ToString().Contains("DeviceID"))
  2595. ((StreamReader)Reader[i]).Dispose();
  2596. else
  2597. ((BinaryReader)Reader[i]).Dispose();
  2598. ((FileStream)Stream[i]).Dispose();
  2599. }
  2600. return false;
  2601. }
  2602. }
  2603. public static bool UnlockLocalKeys(ArrayList filelist, ArrayList Stream, ArrayList Reader)
  2604. {
  2605. for (int i = 0; i < Reader.Count; i++)
  2606. {
  2607. if (filelist[i].ToString().Contains("DeviceID"))
  2608. ((StreamReader)Reader[i]).Dispose();
  2609. else
  2610. ((BinaryReader)Reader[i]).Dispose();
  2611. ((FileStream)Stream[i]).Dispose();
  2612. }
  2613. return true;
  2614. }
  2615. }
  2616. /// <summary>
  2617. /// 本地缓存记录
  2618. /// </summary>
  2619. public class LocalTxtRecord
  2620. {
  2621. public static bool LocalRecord(string record,string name)
  2622. {
  2623. try
  2624. {
  2625. string order = name + ".txt";
  2626. if (File.Exists(@order))
  2627. {
  2628. FileStream fs = new FileStream(@order, FileMode.Append);
  2629. byte[] data = System.Text.Encoding.Default.GetBytes("\r\n" + record);
  2630. fs.Write(data, 0, data.Length);
  2631. fs.Flush();
  2632. fs.Close();
  2633. }
  2634. else
  2635. {
  2636. FileStream fs = new FileStream(@order, FileMode.Create);
  2637. byte[] data = System.Text.Encoding.Default.GetBytes(record);
  2638. fs.Write(data, 0, data.Length);
  2639. fs.Flush();
  2640. fs.Close();
  2641. }
  2642. return true;
  2643. }
  2644. catch (Exception ex)
  2645. {
  2646. return false;
  2647. }
  2648. }
  2649. }
  2650. }