public static string GetDiskSerialNumber() { var rd = ""; try { rd = HardwareInfo.GetDiskVolume(); } catch (Exception ex) { LogX.Error(ex); } return(rd); }
public static string GetMAC() { var rd = ""; try { rd = HardwareInfo.GetMacAddress(); } catch (Exception ex) { LogX.Error(ex); } return(rd); }
/// <summary> /// 获取系统内存大小 /// </summary> /// <returns>内存大小(单位M)</returns> public static int GetPhisicalMemory() { try { var memInfo = new HardwareInfo.MEMORYSTATUSEX(); memInfo.dwLength = (uint)Marshal.SizeOf(typeof(HardwareInfo.MEMORYSTATUSEX)); HardwareInfo.GlobalMemoryStatusEx(ref memInfo); var tm = memInfo.ullTotalPhys / 1024 / 1024; return((int)tm); } catch (Exception ex) { LogX.Error(ex); } try { var searcher = new ManagementObjectSearcher(); searcher.Query = new SelectQuery("Win32_PhysicalMemory ", "", new string[] { "Capacity" }); var collection = searcher.Get(); var em = collection.GetEnumerator(); long capacity = 0; while (em.MoveNext()) { var baseObj = em.Current; if (baseObj.Properties["Capacity"].Value != null) { try { capacity += long.Parse(baseObj.Properties["Capacity"].Value.ToString()); } catch { return(0); } } } return((int)(capacity / 1024 / 1024)); } catch (Exception ex) { LogX.Error(ex); } return(0); }
/// <summary> 深拷贝数据 </summary> /// <typeparam name="T"> 数据源类型 </typeparam> /// <param name="data"> 数据源 </param> /// <returns> 拷贝后的新数据 默认返回 default(T) </returns> public static T DeepClone <T>(this T data) where T : class { if (data != null) { using (var memStream = new MemoryStream()) { try { new BinaryFormatter().Serialize(memStream, data); return(new BinaryFormatter().Deserialize(memStream) as T); } catch (Exception ex) { LogX.Error(ex); } } } return(default(T)); }
public static string GetIp() { string ip = string.Empty; try { ip = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName())[0].ToString(); //http://jira.op.ksyun.com/browse/YLYUN-5996?filter=12785 //在 System.Net.IPAddress.get_Address() //在 Yuanbo.ChssClient.InPatient.Model.YiZhuModelBaseVM.SetLock(Nullable`1 sdlx, Nullable`1 mxmodel) 位置 D:\Work\GitProject\HaaS\Yuanbo.ChssClient.InPatient\Model\YiZhuModelBaseVM.cs:行号 279 //在 Yuanbo.ChssClient.InPatient.ViewModel.HS.LinShiYiZhuVM.Query() 位置 D:\Work\GitProject\HaaS\Yuanbo.ChssClient.InPatient\ViewModel\HS\LinShiYiZhuVM.cs:行号 336 //在 Yuanbo.ChssClient.InPatient.ViewModel.HS.LinShiYiZhuVM.Load() 位置 D:\Work\GitProject\HaaS\Yuanbo.ChssClient.InPatient\ViewModel\HS\LinShiYiZhuVM.cs:行号 321 //ip = new System.Net.IPAddress(System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList[0].Address).ToString(); } catch (Exception ex) { LogX.Error(ex); } return(ip); }
public static bool CanConnectServer(string su) { if (string.IsNullOrWhiteSpace(su)) { return(false); } lock (ConnectServerLockData) { // 包含且在10s成功连接,直接认为正常联通中 if (Servers.ContainsKey(su)) { var lt = Servers[su]; if (lt != null) { var ts = (DateTime.Now - lt.Value).TotalSeconds; if (ts < 10) { return(true); } } } else { Servers.Add(su, null); } } bool isconnet = false; var serverurl = su; if (serverurl.Contains("?")) { serverurl += "&r=" + DateTime.Now.ToString("yyyyMMddHHmmssfff"); } else { serverurl += "?r=" + DateTime.Now.ToString("yyyyMMddHHmmssfff"); } var request = WebRequest.Create(serverurl) as HttpWebRequest; request.Accept = ("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); request.Headers.Add("Accept-Language", "zh-CN,zh;q=0.9"); request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); request.Method = "GET"; request.ServicePoint.Expect100Continue = false; request.UserAgent = "ConnectTest"; request.Timeout = 20000; request.AllowAutoRedirect = true; try { var s = request.GetResponse() as HttpWebResponse; if (s != null) { isconnet = s.StatusCode == HttpStatusCode.OK; s.Close(); lock (ConnectServerLockData) { if (isconnet) { Servers[su] = DateTime.Now; } else { Servers[su] = null; } } } } catch (Exception ex) { LogX.Error(ex); Debug.WriteLine(ex.Message + " => " + ex.StackTrace); } return(isconnet); }