123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853 |
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using SufeiUtil;
- using SXLibrary;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Data.SQLite;
- using System.Globalization;
- using System.IO;
- using System.Management;
- using System.Net;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Windows.Forms;
- using System.Xml;
- using WHC.OrderWater.Commons;
- using HttpHelper = SufeiUtil.HttpHelper;
- using System.Web;
- using System.Security.Cryptography.X509Certificates;
- using System.Net.Security;
- using System.Runtime.InteropServices;
- using System.Diagnostics;
- namespace MOKA_Factory_Tools
- {
- class CommonMethod
- {
- [DllImport("kernel32")]
- public static extern bool GetProfileString(string lpApplicationName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize);
- [DllImport("kernel32")]
- public static extern bool WriteProfileString(string lpApplicationName, string lpKeyName, string lpString);
- public static string FactoryName = "Unknown";
- private static string lastOrder = "";
- private static List<string> ListACASSN = new List<string>();
- public static string ReadProfileString(string lpApplicationName, string lpKeyName, string lpDefault)
- {
- StringBuilder MyString = new StringBuilder(256);
- GetProfileString(lpApplicationName, lpKeyName, lpDefault, MyString, 256);
- return MyString.ToString();
- }
-
-
-
-
-
- public static string GetMacAddress()
- {
- string mac = "";
- using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"))
- {
- ManagementObjectCollection moc = mc.GetInstances();
- int i = 0;
- int j = 0;
- foreach (ManagementObject mo in moc)
- {
- if (mo["MacAddress"] != null)
- {
- if (Convert.ToBoolean(mo["IPEnabled"]))
- {
- if (j < 2)
- {
- mac = mo["MacAddress"].ToString() + "&" + mac;
- j++;
- }
- }
- else
- {
- if (i < 1)
- {
- mac += mo["MacAddress"].ToString() + "&";
- i++;
- }
- }
- }
- }
- }
- return mac.Replace(":", "-");
-
- }
-
-
-
-
-
-
-
-
-
-
-
- public static bool GetMidInfo(string url, string order, string pcmac, string iptvip, string version, SQLiteConnection sqliteConn, out MidList mid)
- {
- mid = new MidList();
- OrderInput orderInput1 = new OrderInput { bid = order, mac = pcmac, version = "", clientType = "" };
- string jsonorder = JsonConvert.SerializeObject(orderInput1, Newtonsoft.Json.Formatting.Indented);
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- URL = url,
- Encoding = Encoding.UTF8,
-
- Method = "post",
- Postdata = jsonorder,
- PostEncoding = Encoding.UTF8,
- KeepAlive = false
- };
- item.ContentType = "application/json;charset=utf-8";
- System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
- stopwatch.Start();
- HttpResult result = http.GetHtml(item);
- stopwatch.Stop();
- string usingtime = stopwatch.ElapsedMilliseconds.ToString();
- stopwatch.Reset();
- string ParseText = result.Html;
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGet MID info\r\nUsing time:" + usingtime + "ms\r\n" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
- }
- else
- {
- Log.WriteErrorLog("\r\nFail to GetMidInfo:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
- ReportErrormsg("Fail to GetMidInfo", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
- return false;
- }
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- mid.message = jObject["message"].Value<string>();
- mid.code = jObject["code"].Value<string>();
- mid.factoryname = jObject["factoryName"].Value<string>();
- mid.factoryNum = jObject["factoryNum"].Value<string>();
- mid.version = jObject["version"].Value<string>();
- mid.quantity = jObject["quantity"].Value<string>();
- mid.projectid = jObject["projectId"].Value<string>();
- mid.clienttype = jObject["clientType"].Value<string>();
- mid.host = jObject["host"].Value<string>();
- mid.whiteType = jObject["whiteType"].Value<string>();
- object a = jObject["rokuCustomer"];
- if (jObject["rokuCustomer"].ToString().Length > 0)
- mid.rokuCustomer = new RokuCustomer()
- {
- id = JSON_SeleteNode(jObject["rokuCustomer"], "id").Trim(),
- ordernum = JSON_SeleteNode(jObject["rokuCustomer"], "ordernum").Trim(),
- brand = JSON_SeleteNode(jObject["rokuCustomer"], "brand").Trim(),
- region = JSON_SeleteNode(jObject["rokuCustomer"], "region").Trim(),
- oemmodel = JSON_SeleteNode(jObject["rokuCustomer"], "oemmodel").Trim(),
- supporturl = JSON_SeleteNode(jObject["rokuCustomer"], "supporturl").Trim(),
- supportphone = JSON_SeleteNode(jObject["rokuCustomer"], "supportphone").Trim(),
- productiondate = JSON_SeleteNode(jObject["rokuCustomer"], "productiondate").Trim(),
- remotetype = JSON_SeleteNode(jObject["rokuCustomer"], "remotetype").Trim(),
- updatetime = JSON_SeleteNode(jObject["rokuCustomer"], "updatetime").Trim(),
- createtime = JSON_SeleteNode(jObject["rokuCustomer"], "createtime").Trim(),
- isdelete = JSON_SeleteNode(jObject["rokuCustomer"], "isdelete").Trim()
- };
- mid.keytype = new Dictionary<string, string>();
- foreach (var ss in jObject["obj"])
- {
- mid.keytype.Add(ss["name"].Value<string>(), ss["type"].Value<string>());
- }
- if (url == Serverurl.Testurl)
- mid.host = "http://test.idmanage.qhmoka.com/IDManage";
- if (mid.code == "1000")
- return true;
- else
- return false;
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to parse MID info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
- ReportErrormsg("Fail to parse MID info", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
- MessageBox.Show("Fail to parse MID info\r\n " + ex.Message);
- return false;
- }
- }
-
-
-
-
-
-
-
-
- public static bool GetMidAddress(MidList midInfo, string order, SQLiteConnection sqliteConn, out MidAddress midAddress)
- {
- midAddress = new MidAddress();
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- URL = midInfo.host + "/getofflinelist.do?",
- Encoding = null,
-
- Method = "post",
- Postdata = ("orderNumber=" + order + "&mac=" + HttpUtility.UrlEncode(TestMode.MAC)),
- KeepAlive = false
- };
- item.ContentType = "application/x-www-form-urlencoded";
- HttpResult result = http.GetHtml(item);
- string ParseText = result.Html;
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- }
- else
- {
- Log.WriteErrorLog("\r\nFail to get Mid address:" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- CommonMethod.ReportErrormsg("Fail to get Mid address", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
- return false;
- }
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- midAddress.des = JSON_SeleteNode(jObject, "des");
- midAddress.code = JSON_SeleteNode(jObject, "code");
- midAddress.order = JSON_SeleteNode(jObject, "order_number");
- midAddress.number = JSON_SeleteNode(jObject, "order_quantity");
- midAddress.pid = JSON_SeleteNode(jObject, "project_id");
- midAddress.ctype = JSON_SeleteNode(jObject, "client_type");
- midAddress.purl = JSON_SeleteNode(jObject, "packet_url");
- midAddress.psize = JSON_SeleteNode(jObject, "packet_size");
- midAddress.pmd5 = JSON_SeleteNode(jObject, "packet_md5");
- midAddress.version = JSON_SeleteNode(jObject, "soft_version");
- midAddress.host = midInfo.host;
- Log.WriteGetKeyLog("\r\nGet Mid address success:" + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- return true;
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to parse MID address," + ex.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- CommonMethod.ReportErrormsg("Fail to parse MID address", ex.Message + "\r\n" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
- MessageBox.Show("Fail to parse MIDAddress info\r\n " + ex.Message);
- return false;
- }
- }
-
-
-
-
-
-
-
-
- public static bool GetMidAddress2(MidList midInfo, string order, SQLiteConnection sqliteConn, out List<MidAddress> midAddressList)
- {
- midAddressList = new List<MidAddress>();
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- URL = midInfo.host + "/getofflinelist.do?",
- Encoding = null,
-
- Method = "post",
- Postdata = ("orderNumber=" + order + "&mac=" + HttpUtility.UrlEncode(TestMode.MAC)),
- KeepAlive = false
- };
- item.ContentType = "application/x-www-form-urlencoded";
- HttpResult result = http.GetHtml(item);
- string ParseText = result.Html;
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- }
- else
- {
- Log.WriteErrorLog("\r\nFail to get Mid address:" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- CommonMethod.ReportErrormsg("Fail to get Mid address", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
- return false;
- }
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- if (jObject["data"] != null)
- {
- foreach (var data in jObject["data"])
- {
- midAddressList.Add(new MidAddress()
- {
- des = JSON_SeleteNode(jObject, "des"),
- code = JSON_SeleteNode(jObject, "code"),
- order = data["order_number"].ToObject<string>(),
- number = data["order_quantity"].ToObject<string>(),
- pid = data["project_id"].ToObject<string>(),
- ctype = data["client_type"].ToObject<string>(),
- purl = data["packet_url"].ToObject<string>(),
- psize = data["packet_size"].ToObject<string>(),
- pmd5 = data["packet_md5"].ToObject<string>(),
- version = data["soft_version"].ToObject<string>(),
- host = midInfo.host
- });
- }
- }
- Log.WriteGetKeyLog("\r\nGet Mid address success:" + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- return true;
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to parse MID address," + ex.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- CommonMethod.ReportErrormsg("Fail to parse MID address", ex.Message + "\r\n" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
- MessageBox.Show("Fail to parse MIDAddress info\r\n " + ex.Message);
- return false;
- }
- }
-
-
-
-
-
-
-
-
-
-
- public static bool GetDIDKeyXml(string str, string node, string node2, out string code, out string desc, out string value)
- {
- code = "";
- value = "";
- try
- {
- XmlDocument xml = new XmlDocument();
-
- xml.LoadXml(str);
- code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
- desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
- if (code == "200")
- {
- value = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("deviceid").InnerText;
- string CRC32 = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("crc32").InnerText;
- if (CrcUtils.CRC32(value) == Convert.ToUInt32(CRC32))
- {
- return true;
- }
- else
- {
- desc = "CRC32 error";
- return false;
- }
- }
- return false;
- }
- catch (Exception ex)
- {
- desc = ex.Message;
- return false;
- }
- }
-
-
-
-
-
-
-
-
-
-
- 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)
- {
- string code;
- string desc;
- error = "";
- key = "";
- md5 = "";
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- Encoding = Encoding.Default,
- Method = "post",
- ContentType = "application/x-www-form-urlencoded",
- KeepAlive = false
- };
-
- Stopwatch watch = new Stopwatch();
- watch.Start();
- switch (keymessage)
- {
- case "DeviceID":
- {
- item.URL = url + "/getid.do?";
- item.Postdata = "devicetype=tcl_unknown_model" + "&sn=" + sn;
- if (sn.Trim().Length > 0)
- item.Postdata += "&order=" + order;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGetDeviceID:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.GetDIDKeyXml(result.Html, "response", "id", out code, out desc, out key))
- {
-
- }
- else
- {
- error = desc;
- ReportErrormsg("Fail to parse DID", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- }
- else
- {
- error = result.StatusDescription;
- ReportErrormsg("Fail to get DID", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- break;
- }
- case "MAC":
- {
- item.URL = url + "/getmac.do?";
- item.Postdata = "typeString=" + keytype + "&sn=" + sn;
- if (sn.Trim().Length > 0)
- item.Postdata += "&order=" + order;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGetMac:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "mac", out code, out desc, out key, out md5))
- {
- }
- else
- {
- error = desc;
- ReportErrormsg("Fail to parse Mac", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- }
- else
- {
- error = result.StatusDescription;
- ReportErrormsg("Fail to get Mac", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- break;
- }
- case "HDCP_KEY":
- {
- item.URL = url + "/gethdcpkey.do?";
- item.Postdata = "type=" + keytype + "&sn=" + sn;
- if (sn.Trim().Length > 0)
- item.Postdata += "&order=" + order;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGetHDCP_KEY:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
- {
- }
- else
- {
- error = desc;
- ReportErrormsg("Fail to parse hdcp", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- }
- else
- {
- error = result.StatusDescription;
- ReportErrormsg("Fail to get hdcp", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- break;
- }
- case "CI_PLUS_KEY":
- {
- item.URL = url + "/getcikey.do?";
- item.Postdata = "type=" + keytype + "&sn=" + sn;
- if (sn.Trim().Length > 0)
- item.Postdata += "&order=" + order;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGetCI_PLUS_KEY:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
- {
- }
- else
- {
- error = desc;
- ReportErrormsg("Fail to parse ciplus", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- }
- else
- {
- error = result.StatusDescription;
- ReportErrormsg("Fail to get ciplus", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- break;
- }
- case "WiDi":
- {
- item.URL = url + "/getwidi.do?";
- item.Postdata = "type=" + keytype + "&sn=" + sn;
- if (sn.Trim().Length > 0)
- item.Postdata += "&order=" + order;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGetWiDi:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
- {
- }
- else
- {
- error = desc;
- ReportErrormsg("Fail to parse widi", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- }
- else
- {
- error = result.StatusDescription;
- ReportErrormsg("Fail to get widi", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- break;
- }
- case "HDCP2.2_KEY":
- {
- item.URL = url + "/gethdcpkey2.do?";
- item.Postdata = "type=" + keytype + "&sn=" + sn;
- if (sn.Trim().Length > 0)
- item.Postdata += "&order=" + order;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGetHDCP2.2_KEY:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
- {
- }
- else
- {
- error = desc;
- ReportErrormsg("Fail to parse hdcp22", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- }
- else
- {
- error = result.StatusDescription;
- ReportErrormsg("Fail to get hdcp22", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- break;
- }
- case "NETFILX_ESN":
- {
- item.URL = url + "/getnetfilxesn.do?";
- item.Postdata = "type=" + keytype + "&sn=" + sn;
- if (sn.Trim().Length > 0)
- item.Postdata += "&order=" + order;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGetNETFILX_ESN:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "esn", out code, out desc, out key, out md5))
- {
- }
- else
- {
- error = desc;
- ReportErrormsg("Fail to parse esn", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- }
- else
- {
- error = result.StatusDescription;
- ReportErrormsg("Fail to get esn", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- break;
- }
- case "MGK_KEY":
- {
- item.URL = url + "/getmgk.do?";
- item.Postdata = "type=" + keytype + "&sn=" + sn;
- if (sn.Trim().Length > 0)
- item.Postdata += "&order=" + order;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGetMGK:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
- {
- }
- else
- {
- error = desc;
- ReportErrormsg("Fail to parse MGK", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- }
- else
- {
- error = result.StatusDescription;
- ReportErrormsg("Fail to get MGK", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- break;
- }
- case "Fairplay_KEY":
- {
- item.URL = url + "/getfairplay.do?";
- item.Postdata = "type=" + keytype + "&sn=" + sn;
- if (sn.Trim().Length > 0)
- item.Postdata += "&order=" + order;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGetFairplay:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "fairplay", out code, out desc, out key, out md5))
- {
- }
- else
- {
- error = desc;
- ReportErrormsg("Fail to parse Fairplay", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- }
- else
- {
- error = result.StatusDescription;
- ReportErrormsg("Fail to get Fairplay", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- break;
- }
- case "ECP_KEY":
- {
- item.URL = url + "/getecp.do?";
- item.Postdata = "type=" + keytype + "&sn=" + sn;
- if (sn.Trim().Length > 0)
- item.Postdata += "&order=" + order;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGetecp:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "ecp", out code, out desc, out key, out md5))
- {
- }
- else
- {
- error = desc;
- ReportErrormsg("Fail to parse ecp", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- }
- else
- {
- error = result.StatusDescription;
- ReportErrormsg("Fail to get ecp", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- break;
- }
- case "LEK":
- {
- item.URL = url + "/getlek.do?";
- item.Postdata = "type=" + keytype + "&sn=" + sn;
- if (sn.Trim().Length > 0)
- item.Postdata += "&order=" + order;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGetlek:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "lek", out code, out desc, out key, out md5))
- {
- }
- else
- {
- error = desc;
- ReportErrormsg("Fail to parse lek", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- }
- else
- {
- error = result.StatusDescription;
- ReportErrormsg("Fail to get lek", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- break;
- }
- case "PEK":
- {
- item.URL = url + "/getpek.do?";
- item.Postdata = "type=" + keytype + "&sn=" + sn;
- if (sn.Trim().Length > 0)
- item.Postdata += "&order=" + order;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGetpek:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "pek", out code, out desc, out key, out md5))
- {
- }
- else
- {
- error = desc;
- ReportErrormsg("Fail to parse pek", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- }
- else
- {
- error = result.StatusDescription;
- ReportErrormsg("Fail to get pek", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- break;
- }
- case "PlayReady_key":
- {
- item.URL = url + "/getplayready.do?";
- item.Postdata = "type=" + keytype + "&sn=" + sn;
- if (sn.Trim().Length > 0)
- item.Postdata += "&order=" + order;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGetplayready:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "playReady", out code, out desc, out key, out md5))
- {
- }
- else
- {
- error = desc;
- ReportErrormsg("Fail to parse playready", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- }
- else
- {
- error = result.StatusDescription;
- ReportErrormsg("Fail to get playready", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- break;
- }
- case "Hashkey":
- {
- item.URL = url + "/gethash.do?";
- item.Postdata = "type=" + keytype + "&sn=" + sn;
- if (sn.Trim().Length > 0)
- item.Postdata += "&order=" + order;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGethash:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "hash", out code, out desc, out key, out md5))
- {
- }
- else
- {
- error = desc;
- ReportErrormsg("Fail to parse hash", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- }
- else
- {
- error = result.StatusDescription;
- ReportErrormsg("Fail to get hash", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- break;
- }
- case "YouTube_KEY":
- {
- item.URL = url + "/getYoutubeKey.do?";
- item.Postdata = "type=" + keytype + "&sn=" + sn;
- if (sn.Trim().Length > 0)
- item.Postdata += "&order=" + order;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGet youtube key:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "youtubeKey", out code, out desc, out key, out md5))
- {
- }
- else
- {
- error = desc;
- ReportErrormsg("Fail to parse youtube key", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- }
- else
- {
- error = result.StatusDescription;
- ReportErrormsg("Fail to get youtube key", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- break;
- }
- }
- watch.Stop();
- Log.WriteInfoLog(string.Format("[GetKeys] order={0},sn={1},keytype={2},keymessage={3}, Elapsed={4}", order,sn,keytype,keymessage,watch.Elapsed.TotalMilliseconds));
- return true;
- }
- public static bool GetWidevineAnAttestationKey(
- string url,
- string sn,
- string keytype,
- SQLiteConnection sqliteConn,
- out bool isAndroidTV,
- out string Widevinekey,
- out string Attestationkey,
- out string error,
- string order,
- out string AttestationMd5)
- {
- string code;
- string desc;
- isAndroidTV = false;
- error = "";
- Widevinekey = "";
- Attestationkey = "";
- AttestationMd5 = "";
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- Encoding = Encoding.Default,
- Method = "post",
- ContentType = "application/x-www-form-urlencoded",
- KeepAlive = false
- };
-
- Stopwatch watch = new Stopwatch();
- watch.Start();
- item.URL = url + "/getWidevineAndAttestation.do?";
- item.Postdata = "type=" + keytype + "&order=" + order + "&sn=" + sn;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGetWidevine_KEY:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (!Xmlconfig.GetWidevineAndAttestationKeyXml(result.Html, "response", out code, out desc, out isAndroidTV, out Widevinekey, out Attestationkey, out AttestationMd5))
- {
- error = desc;
- ReportErrormsg("Fail to parse widevineAndAttestation", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- }
- else
- {
- error = result.StatusDescription;
- ReportErrormsg("Fail to get widevineAndAttestation", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- watch.Stop();
- Log.WriteInfoLog(string.Format("[getWidevineAndAttestation] order={0},sn={1},keytype={2},Elapsed={3}", order, sn, keytype, watch.Elapsed.TotalMilliseconds));
- return true;
- }
- public static bool GetAcasKey(string url, string keymessage, string sn, string keytype, SQLiteConnection sqliteConn, string order, out string acaskey_data, out string acaskey_datamd5, out string acaskey_tool, out string acaskey_toolmd5, out string error)
- {
- string code;
- string desc;
- error = "";
- acaskey_data = "";
- acaskey_datamd5 = "";
- acaskey_tool = "";
- acaskey_toolmd5 = "";
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- Encoding = Encoding.Default,
- Method = "post",
- ContentType = "application/x-www-form-urlencoded",
- KeepAlive = false
- };
-
- Stopwatch watch = new Stopwatch();
- watch.Start();
- item.URL = url + "/getAcasKey.do?";
- item.Postdata = "type=" + keytype + "&sn=" + sn;
- if (sn.Trim().Length > 0)
- item.Postdata += "&order=" + order;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGet ACAS key:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.Get2KeyInfoFromXml(result.Html, "acasKey_data", "acasKey_tool", out code, out desc, out acaskey_data, out acaskey_datamd5, out acaskey_tool, out acaskey_toolmd5))
- {
- }
- else
- {
- error = desc;
- ReportErrormsg("Fail to parse ACAS key", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- }
- else
- {
- error = result.StatusDescription;
- ReportErrormsg("Fail to get ACAS key", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
- return false;
- }
- watch.Stop();
- Log.WriteInfoLog(string.Format("[getAcasKey] order={0},sn={1},keytype={2},Elapsed={3}", order, sn, keytype, watch.Elapsed.TotalMilliseconds));
- return true;
- }
-
-
-
-
-
-
-
- public static bool ReportErrormsg(string reportType, string reportData, SQLiteConnection sqliteConn)
- {
-
- Stopwatch watch = new Stopwatch();
- watch.Start();
- 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")) };
- string jsonError = Newtonsoft.Json.JsonConvert.SerializeObject(ErrorInfo1, Newtonsoft.Json.Formatting.Indented);
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- URL = TestMode.errorreportServerurl,
- Encoding = Encoding.UTF8,
-
- Method = "post",
- Postdata = jsonError,
- PostEncoding = Encoding.UTF8,
- KeepAlive = false
- };
- item.ContentType = "application/json;charset=utf-8";
- HttpResult result = http.GetHtml(item);
- string ParseText = result.Html;
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nReportErrormsg:\r\n" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + jsonError);
- }
- else
- {
- if (HTTPChecker(item.URL))
- SQLiteHelper.InsertDelayErrorReport(sqliteConn, new object[] { item.URL, item.Postdata });
- Log.WriteErrorLog("\r\nFail to ReportErrormsg:\r\n" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + jsonError);
- return false;
- }
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- string message = jObject["message"].Value<string>();
- string code = jObject["code"].Value<string>();
- if (code != "1000")
- {
- Log.WriteErrorLog("\r\nError report return error:\r\n" + ParseText + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + jsonError);
- return false;
- }
- watch.Stop();
- Log.WriteInfoLog(string.Format("[ReportErrormsg] Elapsed={0}", watch.Elapsed.TotalMilliseconds));
- return true;
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to parse Error report return info," + ex.Message + ":" + ParseText + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + jsonError);
- return false;
- }
- }
-
-
-
-
-
-
-
- public static bool ReportDownloadStatus(string url, string order, SQLiteConnection sqliteConn)
- {
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- URL = url + "/getreportofflinesn.do?",
- Encoding = null,
-
- Method = "post",
- Postdata = ("orderNumber =" + order),
- KeepAlive = false
- };
- item.ContentType = "application/x-www-form-urlencoded";
- HttpResult result = http.GetHtml(item);
- string ParseText = result.Html;
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
-
- }
- else
- {
- Log.WriteErrorLog("\r\nFail to report download status:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order));
- CommonMethod.ReportErrormsg("Fail to report download status", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order), sqliteConn);
- return false;
- }
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- string des = JSON_SeleteNode(jObject, "des");
- string code = JSON_SeleteNode(jObject, "code");
- string data = JSON_SeleteNode(jObject, "data");
- if (code == "1000")
- return true;
- else
- {
- Log.WriteErrorLog("\r\nError report download status,should be 1000:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order));
- CommonMethod.ReportErrormsg("Error download status code return", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order), sqliteConn);
- return false;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- Log.WriteErrorLog("\r\n" + ex.Message + ":" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order));
- CommonMethod.ReportErrormsg("Error parse download status return", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order), sqliteConn);
- return false;
- }
- }
-
-
-
-
-
-
-
- public static bool CreateDBkeyString(KeyInfo keyInfo, out string keydata, out string error)
- {
- keydata = "";
- error = "";
- try
- {
- 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 };
- keydata = Newtonsoft.Json.JsonConvert.SerializeObject(DBKeysStringFormat1, Newtonsoft.Json.Formatting.Indented);
- return true;
- }
- catch (Exception ex)
- {
- error = ex.Message;
- return false;
- }
- }
-
-
-
-
- public static string JSON_SeleteNode(JToken json, string ReName)
- {
- try
- {
- string result = "";
-
- var node = json.SelectToken("$.." + ReName);
- if (node != null)
- {
-
- if (node.Type == JTokenType.String || node.Type == JTokenType.Integer || node.Type == JTokenType.Float)
- {
-
- result = node.Value<object>().ToString();
- }
- }
- return result;
- }
- catch (Exception ex)
- {
- return "";
- }
- }
-
-
-
-
-
- public static bool HTTPChecker(string Value)
- {
- try
- {
- if ((Value.Substring(0, 7) == "http://") || (Value.Substring(0, 8) == "https://"))
- {
- return true;
- }
- else
- return false;
- }
- catch (Exception ex)
- {
- return false;
- }
- }
-
-
-
-
-
- public static bool CheckUrlConnection(string url)
- {
- try
- {
- HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
- myRequest.Method = "HEAD";
- myRequest.Timeout = 10000;
- myRequest.AllowAutoRedirect = false;
- myRequest.UseDefaultCredentials = true;
- HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
- myRequest.UseDefaultCredentials = true;
- return (myResponse.StatusCode == HttpStatusCode.OK);
- }
- catch (Exception ex)
- {
- return false;
- }
- }
-
-
-
-
- public static void CreateDirectory(string path)
- {
- if (!Directory.Exists(path))
- {
- Directory.CreateDirectory(path);
- }
- }
-
-
-
-
-
- public static bool UploadCopyResult(string content, string url, SQLiteConnection sqliteConn, string order, bool repeatupload, string id, int timeout)
- {
- if (timeout < 5000)
- timeout = 5000;
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- Encoding = Encoding.UTF8,
- Method = "post",
- ContentType = "application/x-www-form-urlencoded",
- Timeout = timeout,
- KeepAlive = false
- };
- item.PostEncoding = Encoding.UTF8;
- item.URL = url;
- item.Postdata = content;
- System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
- stopwatch.Start();
- HttpResult result = http.GetHtml(item);
- stopwatch.Stop();
- string usingtime = stopwatch.ElapsedMilliseconds.ToString();
- stopwatch.Reset();
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- if (Xmlconfig.ReportXml(result.Html, "response", out string code, out string desc))
- {
- Log.WriteGetKeyLog("\r\nUpload copy status success:\r\nUsing time:" + usingtime + "ms\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
- return true;
- }
- else
- {
- CommonMethod.ReportErrormsg("Fail to parse copy result return", desc + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, sqliteConn);
- Log.WriteErrorLog(code + "Error");
- if (repeatupload)
- {
- SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
- }
- return false;
- }
- }
- else
- {
- if (repeatupload)
- return false;
- if (CommonMethod.HTTPChecker(item.URL))
- SQLiteHelper.InsertDelayCopyReport(sqliteConn, new object[] { order, item.URL, item.Postdata });
- CommonMethod.ReportErrormsg("Fail to upload copy result", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, sqliteConn);
- return true;
- }
- }
-
-
-
-
-
-
-
- public static bool ReportErrormsg2(string url, string content, out bool mark)
- {
- mark = false;
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- URL = url,
- Encoding = Encoding.UTF8,
-
- Method = "post",
- Postdata = content,
- PostEncoding = Encoding.UTF8,
- KeepAlive = false
- };
- item.ContentType = "application/json;charset=utf-8";
- HttpResult result = http.GetHtml(item);
- string ParseText = result.Html;
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- mark = true;
- Log.WriteGetKeyLog("\r\nReportErrormsg:\r\n" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + content);
- }
- else
- {
- Log.WriteErrorLog("\r\nFail to ReportErrormsg:\r\n" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + content);
- return false;
- }
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- string message = jObject["message"].Value<string>();
- string code = jObject["code"].Value<string>();
- if (code == "1000")
- return true;
- else
- {
- Log.WriteErrorLog("\r\nError report return error:\r\n" + ParseText + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + content);
- return false;
- }
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to parse Error report return info," + ex.Message + ":" + ParseText + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + content);
- return false;
- }
- }
-
-
-
-
-
- public static bool IsNumberAndWord(string value)
- {
- if (value is null)
- return false;
- Regex r = new Regex(@"^[a-zA-Z0-9]+$");
- return r.Match(value).Success;
- }
- public static bool InsertJsonConfig(string node, string key)
- {
- JObject jObject;
- using (StreamReader file = new StreamReader(LocalPath.localpath + "\\Config.json"))
- {
- using (JsonTextReader reader = new JsonTextReader(file))
- {
- jObject = (JObject)JToken.ReadFrom(reader);
- jObject[node][key] = true;
- }
- }
- using (StreamWriter writer = new StreamWriter(LocalPath.localpath + "\\Config.json"))
- {
- writer.Write(jObject.ToString());
- }
- return true;
- }
- public static bool AddJsonConfig(string key, object value)
- {
- JObject jObject;
- using (StreamReader file = new StreamReader(LocalPath.localpath + "\\Config.json"))
- {
- using (JsonTextReader reader = new JsonTextReader(file))
- {
- jObject = (JObject)JToken.ReadFrom(reader);
- jObject.Add(key, (JToken)value);
- }
- }
- using (StreamWriter writer = new StreamWriter(LocalPath.localpath + "\\Config.json"))
- {
- writer.Write(jObject.ToString());
- }
- return false;
- }
-
-
-
-
-
- public static bool UploadPreloadCopyResult(string host, string copydate, string SN, SQLiteConnection localDBNow, SQLiteConnection sqliteConn, bool repeatupload, string id, int timeout)
- {
- string ParseText = "";
- bool status;
- try
- {
- List<PostDateClass> postList = new List<PostDateClass>();
- postList.Add(new PostDateClass("sn", SN));
- postList.Add(new PostDateClass("date", copydate));
- ParseText = FormPost.postFileMessage(host + "/reportlist.do?", postList, out status, timeout);
- if (status)
- {
- JObject jObject = JObject.Parse(ParseText);
- string des = CommonMethod.JSON_SeleteNode(jObject, "des");
- string code = CommonMethod.JSON_SeleteNode(jObject, "code");
- string data = JSON_SeleteNode(jObject, "data");
- if (code == "1000")
- {
-
- if (SQLiteHelper.UpdateReportStatus(localDBNow, SN))
- {
-
- Log.WriteGetKeyLog("\r\nUpdateReportStatus success:\r\n" + host + "/reportlist.do?\r\n" + "sn=" + SN + "\r\ndate=" + copydate + "\r\n" + ParseText);
- return true;
- }
- else
- {
- Log.WriteErrorLog("\r\nFail to UpdateReportStatus: " + SN);
- return false;
- }
- }
- else
- {
- CommonMethod.ReportErrormsg("Fail to UploadPreloadCopyResult", "Address: " + host + "/reportlist.do?" + "\r\nPostdata: " + "sn=" + SN + "\r\ndate=" + copydate + "\r\n" + ParseText, sqliteConn);
- 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);
- if (repeatupload)
- {
- SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
- }
- return false;
- }
- }
- else
- {
- if (repeatupload)
- return false;
- if (CommonMethod.HTTPChecker(host))
- SQLiteHelper.InsertDelayCopyReport(sqliteConn, new object[] { "preload_mode", host, SN + "@" + copydate });
- return false;
- }
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to parse UpdateReportStatus return: " + ex.Message + "\r\n" + SN + ":" + ParseText);
- return false;
- }
- }
-
-
-
-
-
-
-
-
-
-
- public static bool UploadPreloadCopyResultList(string host, List<PostDateClass> postList, SQLiteConnection localDBNow, SQLiteConnection sqliteConn, bool repeatupload, string id)
- {
- string ParseText = "";
- bool status;
- try
- {
- ParseText = FormPost.postFileMessage(host + "/reportlist.do?", postList, out status, 30000);
- if (status)
- {
- JObject jObject = JObject.Parse(ParseText);
- string des = CommonMethod.JSON_SeleteNode(jObject, "des");
- string code = CommonMethod.JSON_SeleteNode(jObject, "code");
- string data = JSON_SeleteNode(jObject, "data");
- if (code == "1000")
- {
- Log.WriteGetKeyLog("UploadPreloadCopyResult successful\r\nAddress: " + host + "/reportlist.do?" + ParseText);
- return true;
- }
- else
- {
- CommonMethod.ReportErrormsg("Fail to UploadPreloadCopyResult", "Address: " + host + "/reportlist.do?" + ParseText, sqliteConn);
- Log.WriteErrorLog("\r\nUpdateReportStatus code return error,should be 1000 " + "\r\n" + ParseText + "\r\nAddress:" + host + "/reportlist.do?");
- if (repeatupload)
- {
- SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
- }
- return false;
- }
- }
- else
- {
- Log.WriteErrorLog("Fail to UploadPreloadCopyResult\r\nAddress: " + host + "/reportlist.do?" + ParseText);
- return false;
- }
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to parse UpdateReportStatus return: " + ex.Message + "\r\n" + ParseText);
- return false;
- }
- }
-
-
-
-
-
- public static int BytelisttoInt(byte[] value)
- {
- Array.Reverse(value);
- int result = 0;
- for (int i = 0; i < value.Length; i++)
- {
- result += value[i] << i * 8;
- }
- return result;
- }
-
-
-
-
-
- public static byte[] InttoBytelist(int value)
- {
- byte[] bytes = BitConverter.GetBytes(value);
- Array.Reverse(bytes);
- if (value == 0)
- return bytes;
- List<byte> list = new List<byte>();
- list.AddRange(bytes);
- while (true)
- {
- if (list[0] != 0)
- break;
- else
- list.RemoveAt(0);
- }
- bytes = list.ToArray();
- return bytes;
- }
-
-
-
-
-
-
-
-
- public static bool UpgradeCheck(string url, string FactoryNum, SQLiteConnection sqliteConn, out UpgradeMsgList upmid)
- {
- upmid = new UpgradeMsgList();
- UpgradeCheckInput UpgradeCheckInput1 = new UpgradeCheckInput { appid = "SCBC_Factory_Tools", devicemodel = "SCBC_Factory_Tools", dnum = FactoryNum, ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(), type = "pc" };
- string jsonorder = Newtonsoft.Json.JsonConvert.SerializeObject(UpgradeCheckInput1, Newtonsoft.Json.Formatting.Indented);
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- URL = url,
- Encoding = Encoding.UTF8,
-
- Method = "post",
- Postdata = jsonorder,
- PostEncoding = Encoding.UTF8,
- KeepAlive = false
- };
- item.ContentType = "application/json;charset=utf-8";
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
- | SecurityProtocolType.Tls
- | SecurityProtocolType.Tls11
- | SecurityProtocolType.Tls12;
- HttpResult result = http.GetHtml(item);
- string ParseText = result.Html;
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nUpgrade check," + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
- }
- else
- {
- Log.WriteErrorLog("\r\nFail to upgrade check:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
- ReportErrormsg("Fail to upgrade check", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
- return false;
- }
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- upmid.servertime = jObject["servertime"].Value<string>();
- upmid.callid = jObject["callid"].Value<string>();
- upmid.state = jObject["state"].Value<string>();
- upmid.note = jObject["note"].Value<string>();
- upmid.language = jObject["language"].Value<string>();
- upmid.apiversion = jObject["apiversion"].Value<string>();
- upmid.upgrade = new UpgradeMsgList2()
- {
- type = JSON_SeleteNode(jObject, "type"),
- appid = JSON_SeleteNode(jObject, "appid"),
- apptype = JSON_SeleteNode(jObject, "apptype"),
- version = JSON_SeleteNode(jObject, "version"),
- verid = JSON_SeleteNode(jObject, "verid"),
- md5 = JSON_SeleteNode(jObject, "md5"),
- size = JSON_SeleteNode(jObject, "size"),
- minicon = JSON_SeleteNode(jObject, "minicon"),
- midicon = JSON_SeleteNode(jObject, "midicon"),
- fileurl = JSON_SeleteNode(jObject, "fileurl"),
- increment = JSON_SeleteNode(jObject, "increment"),
- appendver = JSON_SeleteNode(jObject, "appendver"),
- updatetime = JSON_SeleteNode(jObject, "updatetime")
- };
- if (upmid.state == "0000")
- return true;
- else
- {
- return false;
- }
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to parse upgrade check info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
- ReportErrormsg("Fail to parse upgrade check info", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
- MessageBox.Show("Fail to parse upgrade check info\r\n " + ex.Message);
- return false;
- }
- }
-
-
-
-
-
-
-
-
- public static bool UpgradeReport(string url, string FactoryNum, string Result, SQLiteConnection sqliteConn)
- {
- 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 };
- string jsonorder = Newtonsoft.Json.JsonConvert.SerializeObject(UpgradeCheckInput1, Newtonsoft.Json.Formatting.Indented);
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- URL = url,
- Encoding = Encoding.UTF8,
-
- Method = "post",
- Postdata = jsonorder,
- PostEncoding = Encoding.UTF8,
- KeepAlive = false
- };
- item.ContentType = "application/json;charset=utf-8";
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
- | SecurityProtocolType.Tls
- | (SecurityProtocolType)0x300
- | (SecurityProtocolType)0xC00;
- HttpResult result = http.GetHtml(item);
- string ParseText = result.Html;
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nUpgrade report," + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
- }
- else
- {
- Log.WriteErrorLog("\r\nFail to upgrade report:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
- ReportErrormsg("Fail to upgrade report", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
- return false;
- }
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- return true;
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to parse upgrade report info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
- ReportErrormsg("Fail to parse upgrade report info", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
- MessageBox.Show("Fail to parse upgrade report info\r\n " + ex.Message);
- return false;
- }
- }
-
-
-
-
-
-
-
-
- public static bool CompareLocalkey(string filename, string filetype, string filemd5, out string error, out string filefullname)
- {
- error = "";
- filefullname = "";
- try
- {
- string filepath = AppDomain.CurrentDomain.BaseDirectory + "\\Keys\\" + filename + "\\" + filetype;
- if (!Directory.Exists(filepath))
- {
- Directory.CreateDirectory(filepath);
- }
- DirectoryInfo Getkeyfile = new DirectoryInfo(filepath);
- foreach (FileInfo keyfile in Getkeyfile.GetFiles())
- {
- string FileMD5 = GetMD5.GetMD5HashFromFile(keyfile.Name);
- if (FileMD5 == filemd5)
- {
- Log.WriteGetKeyLog("Check md5file success,file md5:" + FileMD5 + "\r\nfile:" + keyfile.FullName);
- filefullname = keyfile.FullName;
- return true;
- }
- else
- {
- Log.WriteErrorLog("Check md5file error,delete file:" + keyfile.FullName + "\r\nfile md5" + FileMD5);
- File.Delete(keyfile.FullName);
- }
- }
- return false;
- }
- catch (Exception ex)
- {
- error = ex.Message;
- return false;
- }
- }
-
-
-
-
-
-
-
- public static bool CompareMD5(byte[] key, byte[] data)
- {
- string strdata = Encoding.ASCII.GetString(data);
- Console.WriteLine(strdata);
- if (strdata.StartsWith("MD5="))
- {
- string md5 = GetMD5.GetMD5Hash(key);
- Console.WriteLine(md5);
- return strdata.Remove(0, 4).Equals(md5);
- }
- return false;
- }
-
-
-
-
-
-
-
- public static bool GetCreateHexkey(string path, string data, out string error)
- {
- error = "";
- try
- {
- string filepath = path + ".bin";
- byte[] bytedata = SerialInit.HexToByte(data);
-
- FileStream fs = new FileStream(filepath, FileMode.Create);
- fs.Write(bytedata, 0, bytedata.Length);
- fs.Close();
- Log.WriteGetKeyLog("save key:" + filepath);
- return true;
- }
- catch (Exception ex)
- {
- error = ex.Message;
- Log.WriteErrorLog("save key error:" + error);
- return false;
- }
- }
-
-
-
-
-
-
-
- public static bool ReadHexFile(string filepath, out string data, out string error)
- {
- data = "";
- error = "";
- try
- {
- using FileStream fskey = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.None);
- {
- using BinaryReader brkey = new BinaryReader(fskey);
- {
- data = SerialInit.ByteToHex(brkey.ReadBytes((int)fskey.Length));
- data = data.Replace(" ", "");
- return true;
- }
- }
- }
- catch (Exception ex)
- {
- error = ex.Message;
- return false;
- }
- }
-
-
-
-
-
-
-
-
-
-
- public static bool UserLogin(string url, string account, string password, string pcmac, SQLiteConnection sqliteConn, out LoginOutput loginOutput1)
- {
- loginOutput1 = new LoginOutput();
- LoginInput LoginInput1 = new LoginInput { account = account, password = password, mac = pcmac };
- string jsonorder = Newtonsoft.Json.JsonConvert.SerializeObject(LoginInput1, Newtonsoft.Json.Formatting.Indented);
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- URL = url,
- Encoding = Encoding.UTF8,
-
- Method = "post",
- Postdata = jsonorder,
- PostEncoding = Encoding.UTF8,
- KeepAlive = false
- };
- item.ContentType = "application/json;charset=utf-8";
- ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
- HttpResult result = http.GetHtml(item);
- string ParseText = result.Html;
- if (result.StatusCode == HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nLogin," + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
- }
- else
- {
- Log.WriteErrorLog("\r\nFail to login:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
- ReportErrormsg("Fail to login", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
- return false;
- }
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- loginOutput1.msg = jObject["msg"].Value<string>();
- loginOutput1.code = jObject["code"].Value<string>();
- loginOutput1.factoryname = JSON_SeleteNode(jObject, "factoryName");
- loginOutput1.factorynum = JSON_SeleteNode(jObject, "factoryNum");
- if (loginOutput1.code == "1000")
- return true;
- else
- return false;
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to login," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
- ReportErrormsg("Fail to login", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
- MessageBox.Show("Fail to parse login return\r\n " + ex.Message);
- return false;
- }
- }
-
-
-
-
-
- public static int GetWeekOfYear(DateTime dt)
- {
- GregorianCalendar gc = new GregorianCalendar();
- int weekOfYear = gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
- return weekOfYear;
- }
-
-
-
-
-
-
- public static bool CompareVersion(string new_version, string old_version)
- {
- try
- {
- if (string.IsNullOrEmpty(new_version) || string.IsNullOrEmpty(old_version))
- return false;
- Version v_new = new Version(new_version);
- Version v_old = new Version(old_version);
- if (v_new >= v_old)
- return true;
- return false;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
-
-
-
-
-
-
-
-
-
- public static bool GetWhiteBalanceInfo(string url, string order, string pcmac, SQLiteConnection sqliteConn, out WhiteBalanceList WBList)
- {
- WBList = new WhiteBalanceList();
- WhiteBalanceInput WBInput1 = new WhiteBalanceInput { bid = order, mac = pcmac };
- string jsonorder = Newtonsoft.Json.JsonConvert.SerializeObject(WBInput1, Newtonsoft.Json.Formatting.Indented);
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- URL = url,
- Encoding = Encoding.UTF8,
-
- Method = "post",
- Postdata = jsonorder,
- PostEncoding = Encoding.UTF8,
- KeepAlive = false
- };
- item.ContentType = "application/json;charset=utf-8";
- System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
- stopwatch.Start();
- HttpResult result = http.GetHtml(item);
- stopwatch.Stop();
- string usingtime = stopwatch.ElapsedMilliseconds.ToString();
- stopwatch.Reset();
- string ParseText = result.Html;
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGet WB info\r\nUsing time:" + usingtime + "ms\r\n" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
- }
- else
- {
- Log.WriteErrorLog("\r\nFail to WBinfo:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
- ReportErrormsg("Fail to WBinfo", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
- return false;
- }
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- WBList.message = jObject["message"].Value<string>();
- WBList.code = jObject["code"].Value<string>();
- object a = jObject["obj"];
- if (jObject["obj"].ToString().Length > 0)
- WBList.whiteBalanceInfo = new WhiteBalanceInfo()
- {
- id = JSON_SeleteNode(jObject["obj"], "id"),
- ordernum = JSON_SeleteNode(jObject["obj"], "ordernum"),
- hdmirgain = JSON_SeleteNode(jObject["obj"], "hdmirgain"),
- hdmiggain = JSON_SeleteNode(jObject["obj"], "hdmiggain"),
- hdmibgain = JSON_SeleteNode(jObject["obj"], "hdmibgain"),
- nrgain = JSON_SeleteNode(jObject["obj"], "nrgain"),
- nggain = JSON_SeleteNode(jObject["obj"], "nggain"),
- nbgain = JSON_SeleteNode(jObject["obj"], "nbgain"),
- lrgain = JSON_SeleteNode(jObject["obj"], "lrgain"),
- lggain = JSON_SeleteNode(jObject["obj"], "lggain"),
- lbgain = JSON_SeleteNode(jObject["obj"], "lbgain"),
- updatetime = JSON_SeleteNode(jObject["obj"], "updatetime"),
- createtime = JSON_SeleteNode(jObject["obj"], "createtime"),
- isdelete = JSON_SeleteNode(jObject["obj"], "isdelete"),
- isExemption = JSON_SeleteNode(jObject["obj"], "isExemption")
- };
- if (WBList.code == "1000")
- return true;
- else
- return false;
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to parse WB info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
- ReportErrormsg("Fail to parse WB info", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
- MessageBox.Show("Fail to parse WB info\r\n " + ex.Message);
- return false;
- }
- }
- private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
- {
- return true;
- }
- public static bool AutoGetKey(string url, string order, string key, string keytype, SQLiteConnection errorDBNow)
- {
- string code;
- string desc;
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- Encoding = Encoding.Default,
- Method = "post",
- ContentType = "application/x-www-form-urlencoded",
- KeepAlive = false
- };
- url += "/autogetkey.do?";
- item.URL = url;
- item.Postdata = string.Format("order={0}&key={1}&keytype={2}&mac={3}", order, key, keytype, HttpUtility.UrlEncode(TestMode.MAC));
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nAutoquestKey :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.AutoKeyStatusXml(result.Html, "response", out code, out desc))
- {
- return true;
- }
- else
- {
- CommonMethod.ReportErrormsg("Auto get key error", desc + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, errorDBNow);
- return false;
- }
- }
- else
- {
- CommonMethod.ReportErrormsg("Auto get key error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, errorDBNow);
- return false;
- }
- }
- public static bool AutoGetKeyStatus(string url, string key, string keytype, SQLiteConnection errorDBNow)
- {
- string code;
- string desc;
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- Encoding = Encoding.Default,
- Method = "post",
- ContentType = "application/x-www-form-urlencoded",
- KeepAlive = false
- };
- url += "/autogetkeystatus.do?";
- item.URL = url;
- item.Postdata = string.Format("key={0}&keytype={1}", key, keytype);
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nAutoGetKeyStatus :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.AutoKeyStatusXml(result.Html, "response", out code, out desc))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- CommonMethod.ReportErrormsg("Auto get key status error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, errorDBNow);
- return false;
- }
- }
- public static bool GetFireTVDsn(string url, string ordernum, string deviceCode, string FSN, string PSN, out string dsn, out string error, SQLiteConnection errorDBNow)
- {
-
- Stopwatch watch = new Stopwatch();
- watch.Start();
- dsn = "";
- error = "";
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- Encoding = null,
- Method = "GET",
- KeepAlive = false
- };
- 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));
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- string code;
- string desc;
- Log.WriteGetKeyLog("\r\nGetFireTVDsn :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.GetDSNXml(result.Html, "response", out code, out desc, out dsn))
- {
- Log.WriteGetKeyLog(string.Format("\r\nDSN= {0}\r\nHttp Get Dsn Elapsed = {1}", dsn, watch.Elapsed.TotalMilliseconds));
- return true;
- }
- else
- {
- error = desc;
- CommonMethod.ReportErrormsg("GetFireTVDsn error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL, errorDBNow);
- return false;
- }
- }
- else
- {
- error = "Communication with server failed";
- CommonMethod.ReportErrormsg("GetFireTVDsn error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL, errorDBNow);
- return false;
- }
- }
-
-
-
-
-
-
- public static void ExportSNACASID(string ordernum, string sn, string acasid)
- {
- string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\SN-ACAS";
- if (!Directory.Exists(path))
- {
- Directory.CreateDirectory(path);
- }
- if (!lastOrder.Equals(ordernum))
- {
- lastOrder = ordernum;
- ListACASSN.Clear();
- }
- string msg = string.Format("{0};{1}", sn, acasid);
- if (ListACASSN.Contains(msg))
- {
- return;
- }
- ListACASSN.Add(msg);
- string fileName = path + "\\" + ordernum + ".txt";
- var stream = new StreamWriter(fileName, true);
- stream.WriteLine(msg);
- stream.Close();
- stream.Dispose();
- }
-
-
-
-
-
- public static bool IsEDIDCopy(MidList midInfo)
- {
- if (midInfo == null || midInfo.keytype == null)
- return false;
- if (!midInfo.keytype.ContainsKey("edid_pid") && !midInfo.keytype.ContainsKey("edid_model_name"))
- return false;
- return true;
- }
- #region G客户NTF功能:GetMaInfo
- public static bool GetMaInfo(string sn, out MaInfo maInfo, SQLiteConnection errorDBNow)
- {
- string desc;
- maInfo = null;
- string strPost = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
- "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"+
- "<soap:Body>"+
- "<GetMaInfo xmlns=\"http://tempuri.org/\">"+
- "<sn>"+sn+"</sn>"+
- "</GetMaInfo>"+
- "</soap:Body>"+
- "</soap:Envelope>";
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- Encoding = Encoding.Default,
- Method = "post",
- ContentType = "text/xml",
- KeepAlive = false
- };
- item.URL = "http://smes-prd-app01.tclking.com:9002/SAPService.asmx";
- item.Postdata = strPost;
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGetMaInfo :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (!Xmlconfig.GetMaInfoXml(result.Html, out maInfo, out desc))
- {
- CommonMethod.ReportErrormsg("GetMaInfo error", desc + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, errorDBNow);
- return false;
- }
- }
- else
- {
- CommonMethod.ReportErrormsg("GetMaInfo error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, errorDBNow);
- return false;
- }
- return true;
- }
- #endregion
- }
-
-
-
- class CRC32
- {
-
- static uint[] Crc32Table;
- public static void GetCRC32Table()
- {
- uint Crc;
- Crc32Table = new uint[256];
- int i, j;
- for (i = 0; i < 256; i++)
- {
- Crc = (uint)i;
- for (j = 8; j > 0; j--)
- {
- if ((Crc & 1) == 1)
- Crc = (Crc >> 1) ^ 0xEDB88320;
- else
- Crc >>= 1;
- }
- Crc32Table[i] = Crc;
- }
- }
- public static uint GetCRC32(byte[] bytes)
- {
- GetCRC32Table();
- uint value = 0xffffffff;
- int len = bytes.Length;
- for (int i = 0; i < len; i++)
- {
- value = (value >> 8) ^ Crc32Table[(value & 0xFF) ^ bytes[i]];
- }
- return value ^ 0xffffffff;
- }
- }
-
-
-
- public class GetLocalKeyCount
- {
- static string LocalKeyPath = AppDomain.CurrentDomain.BaseDirectory + "\\Keys\\";
- public static bool GetLocalDidCount(string order, out int num, ref MidList localmidList, SQLiteConnection errorDBNow)
- {
- num = 0;
- try
- {
- string DIDpath = LocalKeyPath + order + "\\DeviceID";
- if (Directory.Exists(DIDpath) == false)
- return false;
- else
- {
- DirectoryInfo GetDIDfile = new DirectoryInfo(DIDpath);
- foreach (FileInfo keyfile in GetDIDfile.GetFiles())
- {
- string filename = keyfile.FullName;
- if (keyfile.Name.Contains("Online"))
- {
- if (localmidList.host == null)
- {
- if (CommonMethod.GetMidInfo(TestMode.serverurl, order, TestMode.MAC, "", "", errorDBNow, out localmidList))
- {
- ;
- }
- else
- {
- num = -1;
- return true;
- }
- }
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- Encoding = Encoding.Default,
- Method = "post",
- ContentType = "application/x-www-form-urlencoded"
- };
- string url1 = localmidList.host + "/statdeviceid.do?";
- item.URL = url1;
- item.Postdata = "devicetype=tcl_unknown_model";
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGetDeviceID count:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.KeyCountXml(result.Html, "response", "count", out string code, out string desc, out string count))
- {
- num = Convert.ToInt32(count.Replace(",", ""));
- return true;
- }
- else
- {
- num = -1;
- return true;
- }
- }
- else
- {
- num = -1;
- return true;
- }
- }
- else
- {
- num = GetDIDfile.GetFiles().Length;
- return true;
- }
- }
- return true;
- }
- }
- catch (Exception ex)
- {
- num = -1;
- return true;
- }
- }
- public static bool GetLocalMacCount(string order, out int num, ref MidList localmidList, SQLiteConnection errorDBNow)
- {
- num = 0;
- try
- {
- string MACpath = LocalKeyPath + order + "\\MAC";
- if (Directory.Exists(MACpath) == false)
- return false;
- else
- {
- DirectoryInfo GetMACfile = new DirectoryInfo(MACpath);
- foreach (FileInfo keyfile in GetMACfile.GetFiles())
- {
- string filename = keyfile.FullName;
- if (keyfile.Name.Contains("Online"))
- {
- if (localmidList.host == null)
- {
- if (CommonMethod.GetMidInfo(TestMode.serverurl, order, TestMode.MAC, "", "", errorDBNow, out localmidList))
- {
- ;
- }
- else
- {
- num = -1;
- return true;
- }
- }
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- Encoding = Encoding.Default,
- Method = "post",
- ContentType = "application/x-www-form-urlencoded"
- };
- string url1 = localmidList.host + "/statmac.do?";
- item.URL = url1;
- item.Postdata = "typeString=" + localmidList.keytype["MAC"];
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGetMac count:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
- if (Xmlconfig.KeyCountXml(result.Html, "response", "count", out string code, out string desc, out string count))
- {
- num = Convert.ToInt32(count.Replace(",", ""));
- return true;
- }
- else
- {
- num = -1;
- return true;
- }
- }
- else
- {
- num = -1;
- return true;
- }
- }
- else
- {
- num = GetMACfile.GetFiles().Length;
- return true;
- }
- }
- return true;
- }
- }
- catch (Exception ex)
- {
- num = -1;
- return true;
- }
- }
- public static bool GetLocalHDCPKEYCount(string order, out int num)
- {
- num = 0;
- try
- {
- string HDCPKEYpath = LocalKeyPath + order + "\\HDCPKEY";
- if (Directory.Exists(HDCPKEYpath) == false)
- return false;
- else
- {
- DirectoryInfo GetHDCPKEYfile = new DirectoryInfo(HDCPKEYpath);
- num = GetHDCPKEYfile.GetFiles().Length;
- return true;
- }
- }
- catch (Exception ex)
- {
- num = -1;
- return true;
- }
- }
- public static bool GetLocalHDCPKEY22Count(string order, out int num)
- {
- num = 0;
- try
- {
- string HDCPKEY22path = LocalKeyPath + order + "\\HDCPKEY22";
- if (Directory.Exists(HDCPKEY22path) == false)
- return false;
- else
- {
- DirectoryInfo GetHDCPKEY22file = new DirectoryInfo(HDCPKEY22path);
- num = GetHDCPKEY22file.GetFiles().Length;
- return true;
- }
- }
- catch (Exception ex)
- {
- num = -1;
- return true;
- }
- }
- public static bool GetLocalWiDiCount(string order, out int num)
- {
- num = 0;
- try
- {
- string WiDipath = LocalKeyPath + order + "\\WiDi";
- if (Directory.Exists(WiDipath) == false)
- return false;
- else
- {
- DirectoryInfo GetWiDifile = new DirectoryInfo(WiDipath);
- num = GetWiDifile.GetFiles().Length;
- return true;
- }
- }
- catch (Exception ex)
- {
- num = -1;
- return true;
- }
- }
- public static bool GetLocalWidevineCount(string order, out int num)
- {
- num = 0;
- try
- {
- string Widevinepath = LocalKeyPath + order + "\\Widevine";
- if (Directory.Exists(Widevinepath) == false)
- return false;
- else
- {
- DirectoryInfo GetWidevinefile = new DirectoryInfo(Widevinepath);
- num = GetWidevinefile.GetFiles().Length;
- return true;
- }
- }
- catch (Exception ex)
- {
- num = -1;
- return true;
- }
- }
- public static bool GetLocalESNCount(string order, out int num)
- {
- num = 0;
- try
- {
- string ESNpath = LocalKeyPath + order + "\\ESN";
- if (Directory.Exists(ESNpath) == false)
- return false;
- else
- {
- DirectoryInfo GetESNfile = new DirectoryInfo(ESNpath);
- num = GetESNfile.GetFiles().Length;
- return true;
- }
- }
- catch (Exception ex)
- {
- num = -1;
- return true;
- }
- }
- public static bool GetLocalMGKCount(string order, out int num)
- {
- num = 0;
- try
- {
- string MGKpath = LocalKeyPath + order + "\\MGK";
- if (Directory.Exists(MGKpath) == false)
- return false;
- else
- {
- DirectoryInfo GetMGKfile = new DirectoryInfo(MGKpath);
- num = GetMGKfile.GetFiles().Length;
- return true;
- }
- }
- catch (Exception ex)
- {
- num = -1;
- return true;
- }
- }
- public static bool GetLocalFairplayCount(string order, out int num)
- {
- num = 0;
- try
- {
- string Fairplaypath = LocalKeyPath + order + "\\Fairplay";
- if (Directory.Exists(Fairplaypath) == false)
- return false;
- else
- {
- DirectoryInfo GetFairplayfile = new DirectoryInfo(Fairplaypath);
- num = GetFairplayfile.GetFiles().Length;
- return true;
- }
- }
- catch (Exception ex)
- {
- num = -1;
- return true;
- }
- }
- public static bool GetLocalFolderKeyCount(string order, string keyname, out int num)
- {
- num = 0;
- try
- {
- string Fairplaypath = LocalKeyPath + order + "\\" + keyname;
- if (Directory.Exists(Fairplaypath) == false)
- return false;
- else
- {
- DirectoryInfo GetFairplayfile = new DirectoryInfo(Fairplaypath);
- num = GetFairplayfile.GetFiles().Length;
- return true;
- }
- }
- catch (Exception ex)
- {
- num = -1;
- return true;
- }
- }
- public static bool GetLocalAttestationCount(string order, out int num)
- {
- num = 0;
- try
- {
- string Attestationpath = LocalKeyPath + order + "\\Attestation";
- if (Directory.Exists(Attestationpath) == false)
- return false;
- else
- {
- DirectoryInfo GetAttestationfile = new DirectoryInfo(Attestationpath);
- num = GetAttestationfile.GetFiles().Length;
- return true;
- }
- }
- catch (Exception ex)
- {
- num = -1;
- return true;
- }
- }
- public static bool GetLocalCIKEYCount(string order, out int num)
- {
- num = 0;
- try
- {
- string CIKEYpath = LocalKeyPath + order + "\\CIKEY";
- if (Directory.Exists(CIKEYpath) == false)
- return false;
- else
- {
- DirectoryInfo GetCIKEYfile = new DirectoryInfo(CIKEYpath);
- num = GetCIKEYfile.GetFiles().Length;
- return true;
- }
- }
- catch (Exception ex)
- {
- num = -1;
- return true;
- }
- }
- 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)
- {
- data = "";
- filename = "";
- error = "";
- brkey = null;
- fskey = null;
- try
- {
- string keypath = LocalKeyPath + order + "\\" + keytype;
- if (Directory.Exists(keypath) == false)
- {
- error = "File not exist";
- return false;
- }
- else
- {
- DirectoryInfo Getkeyfile = new DirectoryInfo(keypath);
- foreach (FileInfo keyfile in Getkeyfile.GetFiles())
- {
- filename = keyfile.FullName;
- if (keyfile.Name.Contains("Online"))
- {
- try
- {
- if (localmidList.host == null)
- {
- if (CommonMethod.GetMidInfo(TestMode.serverurl, order, TestMode.MAC, "", "", errorDBNow, out localmidList))
- {
- ;
- }
- else
- {
- return false;
- }
- }
- if (keytype == "DeviceID")
- localmidList.keytype["DeviceID"] = "devicetype=tcl_unknown_model";
- else if (keytype == "MAC")
- keytype = "MAC";
- else if (keytype == "HDCPKEY")
- keytype = "HDCP_KEY";
- else if (keytype == "HDCPKEY22")
- keytype = "HDCP2.2_KEY";
- else if (keytype == "ESN")
- keytype = "NETFILX_ESN";
- else if (keytype == "Widevine")
- keytype = "Widevine_KEY";
- else if (keytype == "WiDi")
- keytype = "WiDi";
- else if (keytype == "CIKEY")
- keytype = "CI_PLUS_KEY";
- if (CommonMethod.GetKeys(localmidList.host, keytype, SN, localmidList.keytype[keytype], errorDBNow, out string did, out error, order, out string md5))
- {
- data = did;
- Log.WriteGetKeyLog("\r\n" + keytype + "= " + data);
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception ex)
- {
- error = ex.Message;
- return false;
- }
- }
- else
- {
- try
- {
- fskey = new FileStream(keyfile.FullName.ToString(), FileMode.Open, FileAccess.ReadWrite, FileShare.None);
- {
- brkey = new StreamReader(fskey);
- {
- if (fskey.Length == filesize || filesize == -1)
- {
- data = brkey.ReadToEnd();
- return true;
- }
- else
- {
- error = "File size error.\r\nFilename:" + keyfile.Name + "\r\nFilesize:" + fskey.Length.ToString();
- return false;
- }
- }
- }
- }
- catch
- {
- ;
- }
- }
- }
- return false;
- }
- }
- catch (Exception ex)
- {
- error = ex.Message;
- return false;
- }
- }
- 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)
- {
- data = "";
- filename = "";
- error = "";
- brkey = null;
- fskey = null;
- try
- {
- string keypath = LocalKeyPath + order + "\\" + keytype;
- if (Directory.Exists(keypath) == false)
- {
- error = "File not exist";
- return false;
- }
- else
- {
- DirectoryInfo Getkeyfile = new DirectoryInfo(keypath);
- foreach (FileInfo keyfile in Getkeyfile.GetFiles())
- {
- filename = keyfile.FullName;
- if (keyfile.Name.Contains("Online"))
- {
- try
- {
- if (localmidList.host == null)
- {
- if (CommonMethod.GetMidInfo(TestMode.serverurl, order, TestMode.MAC, "", "", errorDBNow, out localmidList))
- {
- ;
- }
- else
- {
- return false;
- }
- }
- if (keytype == "DeviceID")
- localmidList.keytype["DeviceID"] = "devicetype=tcl_unknown_model";
- else if (keytype == "MAC")
- keytype = "MAC";
- else if (keytype == "HDCPKEY")
- keytype = "HDCP_KEY";
- else if (keytype == "HDCPKEY22")
- keytype = "HDCP2.2_KEY";
- else if (keytype == "ESN")
- keytype = "NETFILX_ESN";
- else if (keytype == "Widevine")
- keytype = "Widevine_KEY";
- else if (keytype == "WiDi")
- keytype = "WiDi";
- else if (keytype == "CIKEY")
- keytype = "CI_PLUS_KEY";
- else if (keytype == "MGK")
- keytype = "MGK_KEY";
- else if (keytype == "Attestation")
- keytype = "Attestation";
- else if (keytype == "Fairplay")
- keytype = "Fairplay_KEY";
- if (CommonMethod.GetKeys(localmidList.host, keytype, SN, localmidList.keytype[keytype], errorDBNow, out string did, out error, order, out string md5))
- {
- data = did;
- Log.WriteGetKeyLog("\r\n" + keytype + "= " + data);
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception ex)
- {
- error = ex.Message;
- return false;
- }
- }
- else
- {
- try
- {
- fskey = new FileStream(keyfile.FullName.ToString(), FileMode.Open, FileAccess.Read, FileShare.None);
- {
- brkey = new BinaryReader(fskey);
- {
- if (fskey.Length == filesize || filesize == -1)
- {
- data = SerialInit.ByteToHex(brkey.ReadBytes((int)fskey.Length));
- data = data.Replace(" ", "");
- return true;
- }
- else
- {
- error = "File size error.\r\nFilename: " + keyfile.Name + "\r\nFilesize: " + fskey.Length.ToString();
- return false;
- }
- }
- }
- }
- catch
- {
- ;
- }
- }
- }
- return false;
- }
- }
- catch (Exception ex)
- {
- error = ex.Message;
- return false;
- }
- }
- public static bool DeleteLocalKeys(ArrayList filelist, ArrayList Stream, ArrayList Reader)
- {
- try
- {
- if (filelist.Count == Reader.Count)
- {
- for (int i = 0; i < filelist.Count; i++)
- {
- if (filelist[i].ToString().Contains("DeviceID"))
- ((StreamReader)Reader[i]).Dispose();
- else
- ((BinaryReader)Reader[i]).Dispose();
- ((FileStream)Stream[i]).Dispose();
- File.Delete(filelist[i].ToString());
- }
- return true;
- }
- else
- return false;
- }
- catch (Exception ex)
- {
- for (int i = 0; i < Reader.Count; i++)
- {
- if (filelist[i].ToString().Contains("DeviceID"))
- ((StreamReader)Reader[i]).Dispose();
- else
- ((BinaryReader)Reader[i]).Dispose();
- ((FileStream)Stream[i]).Dispose();
- }
- return false;
- }
- }
- public static bool UnlockLocalKeys(ArrayList filelist, ArrayList Stream, ArrayList Reader)
- {
- for (int i = 0; i < Reader.Count; i++)
- {
- if (filelist[i].ToString().Contains("DeviceID"))
- ((StreamReader)Reader[i]).Dispose();
- else
- ((BinaryReader)Reader[i]).Dispose();
- ((FileStream)Stream[i]).Dispose();
- }
- return true;
- }
- }
-
-
-
- public class LocalTxtRecord
- {
- public static bool LocalRecord(string record, string name)
- {
- try
- {
- string order = name + ".txt";
- if (File.Exists(@order))
- {
- FileStream fs = new FileStream(@order, FileMode.Append);
- byte[] data = System.Text.Encoding.Default.GetBytes("\r\n" + record);
- fs.Write(data, 0, data.Length);
- fs.Flush();
- fs.Close();
- }
- else
- {
- FileStream fs = new FileStream(@order, FileMode.Create);
- byte[] data = System.Text.Encoding.Default.GetBytes(record);
- fs.Write(data, 0, data.Length);
- fs.Flush();
- fs.Close();
- }
- return true;
- }
- catch (Exception ex)
- {
- return false;
- }
- }
- }
- }
|