USIE.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Web;
  5. using System.Runtime.InteropServices;
  6. using System.Net.NetworkInformation;
  7. using System.Net;
  8. using System.Timers;
  9. namespace US.Browser.IE.BLL
  10. {
  11. public class USIE
  12. {
  13. [DllImport("wininet")]
  14. private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
  15. public USIE()
  16. {
  17. }
  18. public static string GetNavigateAddress()
  19. {
  20. //此处需要重数据库获取,如果获取不到使用默认地址
  21. return "http://www.1473.cn";
  22. }
  23. /// <summary>
  24. /// 捕抓所有的移除
  25. /// </summary>
  26. /// <param name="sender"></param>
  27. /// <param name="e"></param>
  28. public static bool Exception(object sender, Exception e)
  29. {
  30. if (isnet())
  31. {
  32. try
  33. {
  34. BLL.WindowHWND.freem(); //回收内存
  35. BLL.USClientCommunicate.PostPage("http://admin.1473.cn/Admin/Admin.ashx?functionname=Admin.SetLog", "POST", null, "Admin.SetLog=", "", "([500," + Guid.newGuid() + "," + HttpContext.Current.Server.UrlEncode("错误追踪:" + e.StackTrace + "</br>错误提示:" + e.Message) + "," + DateTime.Now + "," + e.Source.ToString() + "])");
  36. }
  37. catch (Exception ex) { }
  38. return true;
  39. }
  40. else { return false; }
  41. }
  42. /// <summary>
  43. /// 判断本地是否联网
  44. /// </summary>
  45. /// <returns></returns>
  46. public static bool isnet()
  47. {
  48. int i = 0;
  49. if (InternetGetConnectedState(out i, 0)) { return MyPing("www.1473.cn", out i); }
  50. return false;
  51. }
  52. /// <summary>
  53. /// ping接网络判断是否连接
  54. /// </summary>
  55. /// <param name="URL"></param>
  56. /// <param name="UER"></param>
  57. /// <returns></returns>
  58. public static bool MyPing(string URL, out int UER)
  59. {
  60. int i; PingReply _URE; UER = 0;
  61. using (Ping _UPE = new Ping())
  62. {
  63. try
  64. {
  65. for (i = 0; i < 5; i++)
  66. {
  67. _URE = _UPE.Send(URL);
  68. if (_URE.Status != IPStatus.Success) { UER++; }
  69. }
  70. }
  71. catch { return false; }
  72. }
  73. return UER < 4;
  74. }
  75. /// <summary>
  76. /// C#调用cmd命令
  77. /// </summary>
  78. /// <param name="UCM"></param>
  79. public static void CMD(string UCM)
  80. {
  81. System.Diagnostics.Process _UPE = new System.Diagnostics.Process();
  82. _UPE.StartInfo.FileName = "cmd.exe"; _UPE.StartInfo.UseShellExecute = false;
  83. _UPE.StartInfo.RedirectStandardInput = true; _UPE.StartInfo.RedirectStandardOutput = true; _UPE.StartInfo.RedirectStandardError = true;
  84. _UPE.StartInfo.CreateNoWindow = true; _UPE.Start(); _UPE.StandardInput.WriteLine(UCM); _UPE.StandardInput.WriteLine("exit");
  85. }
  86. /// <summary>
  87. /// 判断程序是否安装
  88. /// </summary>
  89. /// <returns></returns>
  90. private static bool isIn()
  91. {
  92. string _USI; object _UDS; Microsoft.Win32.RegistryKey _UEK;
  93. Microsoft.Win32.RegistryKey _UKE = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");//获取所有安装的程序
  94. foreach (string USE in _UKE.GetSubKeyNames())
  95. {
  96. _UEK = _UKE.OpenSubKey(USE); _UDS = _UEK.GetValue("DisplayName");
  97. if (_UDS != null)
  98. {
  99. _USI = (string)_UEK.GetValue("DisplayVersion");
  100. if (_UDS.ToString().Contains("云端"))
  101. {
  102. return true;
  103. }
  104. }
  105. }
  106. return false;
  107. }
  108. /// <summary>
  109. /// Timeout计时器
  110. /// </summary>
  111. /// <param name="UIE"></param>
  112. /// <param name="UFN"></param>
  113. public static void setTimeout(double UIE, Action<ElapsedEventArgs> UFN)
  114. {
  115. Timer _UTE = new Timer();
  116. _UTE.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e)
  117. {
  118. try { _UTE.Enabled = false; _UTE.Dispose(); }
  119. catch (Exception ex) { } UFN(e);
  120. };
  121. _UTE.Enabled = true; _UTE.Start();
  122. }
  123. /// <summary>
  124. /// Interval计时器
  125. /// </summary>
  126. /// <param name="UIE"></param>
  127. /// <param name="UFN"></param>
  128. public static void setInterval(double UIE, Action<ElapsedEventArgs> UFN)
  129. {
  130. Timer _UTE = new Timer();
  131. _UTE.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e)
  132. {
  133. UFN(e);
  134. };
  135. _UTE.Enabled = true; _UTE.Start();
  136. }
  137. #region 无用使用
  138. //Ping ping = new Ping();
  139. //PingOptions poptions = new PingOptions();
  140. //poptions.DontFragment = true;
  141. //string data = string.Empty;
  142. //byte[] buffer = Encoding.ASCII.GetBytes(data);
  143. //PingReply reply = ping.Send("www.1473.cn", 1200, buffer, poptions);
  144. //if (reply.Status == IPStatus.Success) { }
  145. //else { }
  146. //System.Net.NetworkInformation.Ping ping;
  147. //System.Net.NetworkInformation.PingReply res;
  148. //ping = new System.Net.NetworkInformation.Ping();
  149. //try
  150. //{
  151. // res = ping.Send("www.1473.cn");
  152. // return (res.Status == System.Net.NetworkInformation.IPStatus.Success);
  153. //}
  154. //catch (Exception er)
  155. //{
  156. // return false;
  157. //}
  158. #endregion
  159. }
  160. }