|
@@ -0,0 +1,134 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
+using System.Linq;
|
|
|
+using System.Management;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using System.Xml;
|
|
|
+
|
|
|
+namespace OTSMeasureApp
|
|
|
+{
|
|
|
+ class CRegistration
|
|
|
+ {
|
|
|
+
|
|
|
+ public bool RegistrationVerification()
|
|
|
+ {
|
|
|
+ string CPUID, DiskID;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ SenseShield.DogDecrypting.decrypting(101);//参数为许可号
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ CPUID = getCpu();
|
|
|
+ DiskID = GetDiskVolumeSerialNumber();
|
|
|
+ var ID = ReadXML("./Config/SysData/RegistrationProofreading.txt");
|
|
|
+ if (ID.Count == 0)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ List<string> list_str = new List<string>();
|
|
|
+ List<string> list_time = new List<string>();
|
|
|
+ ID.TryGetValue("ID", out list_str);
|
|
|
+ ID.TryGetValue("Time", out list_time);
|
|
|
+ string setCPU = ConvertString(list_str[0]);
|
|
|
+ string setDisk = ConvertString(list_str[1]);
|
|
|
+ string setYear = ConvertString(list_time[0]);
|
|
|
+ string setMonth = ConvertString(list_time[1]);
|
|
|
+ string setDay = ConvertString(list_time[2]);
|
|
|
+ if (CPUID != setCPU || DiskID != setDisk)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ DateTime dt = DateTime.ParseExact(setYear + setMonth + setDay + "235959", "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
|
|
|
+
|
|
|
+ if (DateTime.Now > dt)
|
|
|
+ {
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 获得CPU的序列号
|
|
|
+ private static string getCpu()
|
|
|
+ {
|
|
|
+ string strCpu = null;
|
|
|
+ ManagementClass myCpu = new ManagementClass("win32_Processor");
|
|
|
+ ManagementObjectCollection myCpuConnection = myCpu.GetInstances();
|
|
|
+ foreach (ManagementObject myObject in myCpuConnection)
|
|
|
+ {
|
|
|
+ strCpu = myObject.Properties["Processorid"].Value.ToString();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return strCpu;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 取得设备硬盘的卷标号
|
|
|
+ private static string GetDiskVolumeSerialNumber()
|
|
|
+ {
|
|
|
+ ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
|
|
|
+ ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
|
|
|
+ disk.Get();
|
|
|
+ return disk.GetPropertyValue("VolumeSerialNumber").ToString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static IDictionary<String, List<String>> ReadXML(string address)
|
|
|
+ {
|
|
|
+ IDictionary<String, List<String>> infos = new Dictionary<String, List<String>>();
|
|
|
+
|
|
|
+ if (File.Exists(address))
|
|
|
+ {
|
|
|
+ XmlDocument xmlDoc = new XmlDocument();
|
|
|
+
|
|
|
+ xmlDoc.Load(address);
|
|
|
+
|
|
|
+ XmlNode xn = xmlDoc.SelectSingleNode("infos");
|
|
|
+
|
|
|
+ XmlNodeList xnl = xn.ChildNodes;
|
|
|
+
|
|
|
+ foreach (XmlNode xnf in xnl)
|
|
|
+ {
|
|
|
+ XmlElement xe = (XmlElement)xnf;
|
|
|
+
|
|
|
+ XmlNode nameNode = xe.SelectSingleNode("ID");
|
|
|
+
|
|
|
+ string name = nameNode.InnerText;
|
|
|
+ Console.WriteLine(name);
|
|
|
+ XmlNode filelist = xe.SelectSingleNode("filelist");
|
|
|
+
|
|
|
+ List<String> list = new List<string>();
|
|
|
+
|
|
|
+ foreach (XmlNode item in filelist.ChildNodes)
|
|
|
+ {
|
|
|
+ list.Add(item.InnerText);
|
|
|
+ }
|
|
|
+
|
|
|
+ infos.Add(name, list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return infos;
|
|
|
+ }
|
|
|
+ private string ConvertString(string str)
|
|
|
+ {
|
|
|
+ string str_out;
|
|
|
+ string[] arr = str.Split(',');
|
|
|
+ byte[] be = new byte[arr.Count()];
|
|
|
+
|
|
|
+ for (int i = 0; i < arr.Count(); i++)
|
|
|
+ {
|
|
|
+ be[i] = Convert.ToByte(arr[i]);
|
|
|
+ }
|
|
|
+ str_out = Encoding.Unicode.GetString(be);
|
|
|
+ return str_out;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|