星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

KeyVerification.xaml.cs 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System;
  2. using System.IO;
  3. using System.Management;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Windows;
  7. using XHWK.WKTool.DAL;
  8. using XHWK.WKTool.Skin;
  9. namespace XHWK.WKTool
  10. {
  11. /// <summary>
  12. /// KeyVerification.xaml 的交互逻辑
  13. /// </summary>
  14. /*
  15. 输入code 调认证服务,成功跳登录 并且调用添加历史接口,失败继续输code
  16. */
  17. public partial class KeyVerification : Window
  18. {
  19. private readonly XHApi registerController = new XHApi();
  20. private int serverReturnCode = 0;
  21. public KeyVerification()
  22. {
  23. InitializeComponent();
  24. Topmost = true;
  25. WindowStartupLocation = WindowStartupLocation.CenterScreen;
  26. Console.WriteLine("初始化KeyVerification");
  27. }
  28. private void btnEnd_Click(object sender, RoutedEventArgs e)
  29. {
  30. if (string.IsNullOrWhiteSpace(txbKey.Text))
  31. {
  32. MessageWindow.Show("密匙未输入");
  33. return;
  34. }
  35. projectcode = txbKey.Text.Trim();
  36. if (projectcode.Length > 8)
  37. {
  38. MessageWindow.Show("密匙输入过长");
  39. txbKey.Text = projectcode.Substring(0, 8);
  40. return;
  41. }
  42. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddServering, InvokeActivationAddServerCompate);
  43. }
  44. private string projectcode = string.Empty;
  45. /// <summary>
  46. /// 认证服务-调用
  47. /// </summary>
  48. /// <returns>
  49. /// </returns>
  50. private object InvokeActivationAddServering()
  51. {
  52. string device = "pcwk";
  53. string mac = GetMacAddress();
  54. serverReturnCode = registerController.ActivationAdd(mac, device, projectcode);
  55. return APP.ServerMsg;
  56. }
  57. /// <summary>
  58. /// 认证服务-返回结果
  59. /// </summary>
  60. /// <returns>
  61. /// </returns>
  62. public void InvokeActivationAddServerCompate(object obj)
  63. {
  64. if (serverReturnCode == 0)
  65. {
  66. MessageWindow.Show("产品激活成功");
  67. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddHistoryServering, InvokeActivationAddHistoryServerCompate);
  68. Dispatcher.Invoke(new Action(() =>
  69. {
  70. Hide();
  71. CreateAMicroLessonWindow win = new CreateAMicroLessonWindow();
  72. //win.Topmost = true;
  73. win.Show();
  74. Thread.Sleep(200);
  75. Close();
  76. }));
  77. }
  78. else
  79. {
  80. MessageWindow.Show(APP.ServerMsg);
  81. }
  82. }
  83. /// <summary>
  84. /// 激活信息--添加激活历史-调用
  85. /// </summary>
  86. /// <returns>
  87. /// </returns>
  88. private object InvokeActivationAddHistoryServering()
  89. {
  90. serverReturnCode = registerController.ActivationAddHistory();
  91. return APP.ServerMsg;
  92. }
  93. /// <summary>
  94. /// 激活信息--添加激活历史-返回结果
  95. /// </summary>
  96. /// <returns>
  97. /// </returns>
  98. public void InvokeActivationAddHistoryServerCompate(object obj)
  99. {
  100. if (!Directory.Exists(APP.DataPath))
  101. {
  102. Directory.CreateDirectory(APP.DataPath);
  103. }
  104. string ApplicationData = APP.DataPath + "signatureTime.txt";
  105. string currentTime = DateTime.Now.ToLongDateString().ToString();//当前时间
  106. System.IO.File.WriteAllText(ApplicationData, currentTime, Encoding.Default);//存放签名验证日期
  107. }
  108. /// <summary>
  109. /// 获取本机MAC地址
  110. /// </summary>
  111. /// <returns>
  112. /// 本机MAC地址
  113. /// </returns>
  114. public static string GetMacAddress()
  115. {
  116. try
  117. {
  118. string strMac = string.Empty;
  119. ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
  120. ManagementObjectCollection moc = mc.GetInstances();
  121. foreach (ManagementObject mo in moc)
  122. {
  123. if ((bool)mo["IPEnabled"] == true)
  124. {
  125. strMac = mo["MacAddress"].ToString();
  126. }
  127. }
  128. moc = null;
  129. mc = null;
  130. return strMac;
  131. }
  132. catch
  133. {
  134. return "unknown";
  135. }
  136. }
  137. private void close_click(object sender, RoutedEventArgs e)
  138. {
  139. closeAction();
  140. }
  141. private void closeAction()
  142. {
  143. APP.myloading.Show();
  144. new Thread(o =>
  145. {
  146. Dispatcher.Invoke(new Action(() =>
  147. {
  148. System.Environment.Exit(0);
  149. }));
  150. }).Start();
  151. }
  152. }
  153. }