123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- using System;
- using System.Xml;
- using WHC.OrderWater.Commons;
- public class Xmlconfig
- {
- public static bool ReadXmlnode(string str,string node,string value,out object result)
- {
- result = "";
- try
- {
- XmlDocument xml = new XmlDocument();
- //xml.Load(path);
- xml.LoadXml(str);
- var b = xml.SelectSingleNode(node);
- result = xml.SelectSingleNode(node).SelectSingleNode(value).InnerText;
- return true;
- }
- catch(Exception ex)
- {
- result = ex.Message;
- return false;
- }
-
- }
- public static bool WriteXmlnode(string path, string node, string value, out object result)
- {
- result = "";
- try
- {
- XmlDocument xml = new XmlDocument();
- xml.Load(path);
- xml.SelectSingleNode(node).InnerText = value;
- return true;
- }
- catch (Exception ex)
- {
- result = ex.Message;
- return false;
- }
- }
- public static bool KeyCountXml(string str, string node, string node2,out string code,out string desc,out string value)
- {
- code = "";
- value = "";
- try
- {
- XmlDocument xml = new XmlDocument();
- //xml.Load(path);
- 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("value").InnerText;
- return true;
- }
- return false;
- }
- catch (Exception ex)
- {
- desc = ex.Message;
- return false;
- }
- }
- public static bool AutoKeyStatusXml(string str, string node, out string code, out string desc)
- {
- code = "";
- try
- {
- XmlDocument xml = new XmlDocument();
- //xml.Load(path);
- xml.LoadXml(str);
- code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
- desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
- if (code == "200")
- {
- return true;
- }
- return false;
- }
- catch (Exception ex)
- {
- desc = 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.Load(path);
- 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, 16))
- {
- return true;
- }
- else
- {
- desc = "CRC32 error";
- return false;
- }
-
- }
- return false;
- }
- catch (Exception ex)
- {
- desc = ex.Message;
- return false;
- }
- }
- public static bool GetOthersKeyXml(string str, string node, string node2, out string code, out string desc, out string value)
- {
- code = "";
- value = "";
- try
- {
- XmlDocument xml = new XmlDocument();
- //xml.Load(path);
- 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("value").InnerText;
- string CRC32 = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("crc32").InnerText;
- if (CrcUtils.CRC32(value) == Convert.ToUInt32(CRC32, 16))
- {
- return true;
- }
- else
- {
- desc = "CRC32 error";
- return false;
- }
- }
- return false;
- }
- catch (Exception ex)
- {
- desc = ex.Message;
- return false;
- }
- }
- public static bool GetWidevineAndAttestationKeyXml(string str,
- string node,
- out string code,
- out string desc,
- out bool isAndroidTV,
- out string WidevineKey,
- out string AttestationKey,
- out string AttestationMd5)
- {
- code = "";
- isAndroidTV = false;
- WidevineKey = "";
- AttestationKey = "";
- AttestationMd5 = "";
- try
- {
- XmlDocument xml = new XmlDocument();
- //xml.Load(path);
- xml.LoadXml(str);
- code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
- desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
- isAndroidTV = !xml.SelectSingleNode(node).Attributes.GetNamedItem("androidtv").InnerText.Equals("1");
- if (code == "200")
- {
- WidevineKey = xml.SelectSingleNode(node + "//widevine").Attributes.GetNamedItem("value").InnerText;
- string CRC32 = xml.SelectSingleNode(node + "//widevine").Attributes.GetNamedItem("crc32").InnerText;
- if (CrcUtils.CRC32(WidevineKey) != Convert.ToUInt32(CRC32, 16))
- {
- desc = "widevine CRC32 error";
- return false;
- }
- if (isAndroidTV)
- {
- #if false
- // 判断节点是否存在;
- if (xml.GetElementsByTagName("attestation") == null)
- {
- desc = "isAndroidTV: but attestation node is Null";
- return false;
- }
- #endif
- AttestationKey = xml.SelectSingleNode(node + "//attestation").Attributes.GetNamedItem("value").InnerText;
- CRC32 = xml.SelectSingleNode(node + "//attestation").Attributes.GetNamedItem("crc32").InnerText;
- if (CrcUtils.CRC32(AttestationKey) != Convert.ToUInt32(CRC32, 16))
- {
- desc = "attestation CRC32 error";
- return false;
- }
- else
- {
- AttestationMd5 = xml.SelectSingleNode(node + "//attestation").Attributes.GetNamedItem("md5value").InnerText;
- }
- }
- return true;
- }
- return false;
- }
- catch (Exception ex)
- {
- desc = ex.Message;
- return false;
- }
- }
- public static bool ReportXml(string str, string node, out string code, out string desc)
- {
- code = "";
- try
- {
- XmlDocument xml = new XmlDocument();
- //xml.Load(path);
- xml.LoadXml(str);
- code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
- desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
- if (code == "200")
- {
- return true;
- }
- return false;
- }
- catch (Exception ex)
- {
- desc = ex.Message;
- return false;
- }
- }
- public static bool GetDSNXml(string str, string node, 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 + "//" + "firetvDsn").Attributes.GetNamedItem("dsn").InnerText;
- return true;
- }
- return false;
- }
- catch (Exception ex)
- {
- desc = ex.Message;
- return false;
- }
- }
- }
|