1. 程式人生 > 實用技巧 >不懂SpringApplication生命週期事件?那就等於不會Spring Boot嘛

不懂SpringApplication生命週期事件?那就等於不會Spring Boot嘛

 public class RegisterHelp
{
/// <summary>
/// CPU
/// </summary>
/// <returns></returns>
public 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;
} /// <summary>
/// 網路卡
/// </summary>
/// <returns></returns>
public string GetMacAddress()
{
try
{
string mac = "";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"] == true)
{
mac = mo["MacAddress"].ToString();
break;
}
}
moc = null;
mc = null;
return mac;
}
catch
{
return "unknow";
}
finally
{
} } /// <summary>
/// 硬碟
/// </summary>
/// <returns></returns>
public string GetDiskID()
{
try
{
String HDid = "";
ManagementClass mc = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
HDid = (string)mo.Properties["Model"].Value;
}
moc = null;
mc = null;
return HDid;
}
catch
{
return "unknow";
}
finally
{
} } /// <summary>
/// Base64解密
/// </summary>
/// <param name="input">需要解密的字串</param>
/// <returns></returns>
public string Base64Decrypt(string input)
{
return Base64Decrypt(input, new UTF8Encoding());
} /// <summary>
/// DES解密
/// </summary>
/// <param name="data">解密資料</param>
/// <param name="key">8位字元的金鑰字串(需要和加密時相同)</param>
/// <param name="iv">8位字元的初始化向量字串(需要和加密時相同)</param>
/// <returns></returns>
public string DESDecrypt(string data, string key, string iv)
{
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(key);
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(iv); byte[] byEnc;
try
{
byEnc = Convert.FromBase64String(data);
}
catch
{
return null;
} DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
MemoryStream ms = new MemoryStream(byEnc);
CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateDecryptor(byKey, byIV), CryptoStreamMode.Read);
StreamReader sr = new StreamReader(cst);
return sr.ReadToEnd();
} /// <summary>
/// Base64解密
/// </summary>
/// <param name="input">需要解密的字串</param>
/// <param name="encode">字元的編碼</param>
/// <returns></returns>
public string Base64Decrypt(string input, Encoding encode)
{
return encode.GetString(Convert.FromBase64String(input));
} public string Decode(string str)
{
string dtext = "";
for (int i = ; i < str.Length; i++)
{
dtext = dtext + (char)(str[i] - + * );
}
return dtext;
} public string GetText(RichTextBox richTextBox)
{
TextRange textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
return textRange.Text;
}
}