CommonMethod.cs 122 KB

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