/****************************** * 说明:公共方法 * 创建人:龚宇超 * 创建日期:2018-01-23 * 修改人: * 修改日期: * 修改备注: * 版本:1.0.0.0 ******************************/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace Lskj.SocketService { /// /// 公共方法 /// public class BasicFunc { /// /// 说明:检测文件是否在使用 /// 创建人:龚宇超 /// 创建日期:2018-01-24 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// Name of the file. /// true if [is file in use] [the specified file name]; otherwise, false. public static bool IsFileInUse(string fileName) { bool inUse = true; FileStream fs = null; try { try { fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None); inUse = false; } catch { inUse = true; } } finally { if (fs != null) fs.Close(); } return inUse; } /// /// 说明:MD5加密 /// 创建人:龚宇超 /// 创建日期:2018-01-24 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The value. /// System.String. public static string MD5String(string value) { System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); byte[] data = Encoding.Default.GetBytes(value); byte[] md5Data = md5.ComputeHash(data); md5.Clear(); string result = ""; for (int i = 0; i < md5Data.Length; i++) { result += md5Data[i].ToString("x").PadLeft(2, '0'); } return result; } /// /// 说明:获取本地时间时间戳 /// 创建人:龚宇超 /// 创建日期:2018-01-25 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int64. public static long GetCurrentTimeUnix() { TimeSpan cha = (DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1))); long t = (long)cha.TotalSeconds; return t; } } }