using System; using CYQ.Data.Cache; namespace CYQ.Data { /// /// this class can intercept sql /// 应用程序调试类,能截到应用程序所有执行的SQL /// public static class AppDebug { private static CacheManage _Cache = CacheManage.LocalInstance; /// /// is recoreding sql ? /// 正在记录中 /// public static bool IsRecording { get { return _Cache.Contains(_Key); } } private const string _Key = "AppDebug_RecordSQL";// "CYQ.Data.AppDebug_RecordSQL"; private const string _KeyTime = "AppDebug_RecordTime";// "CYQ.Data.AppDebug_RecordTime"; /// /// get sql detail info /// 获取调试信息 /// public static string Info { get { string info = string.Empty; if (AppConfig.Debug.OpenDebugInfo) { info = Convert.ToString(_Cache.Get(_Key)); object time = _Cache.Get(_KeyTime); if (time != null && time is DateTime) { DateTime start = (DateTime)time; TimeSpan ts = DateTime.Now - start; info += AppConst.HR + "all execute time is: " + ts.TotalMilliseconds + " (ms)"; } } return info; } } /// /// start to record sql /// 开始记录调试信息 /// public static void Start() { _Cache.Set(_Key, string.Empty); _Cache.Set(_KeyTime, DateTime.Now); } /// /// stop to record sql /// 停止并清除记录的调试信息 /// public static void Stop() { _Cache.Remove(_Key); _Cache.Remove(_KeyTime); } internal static void Add(string sql) { object sqlObj = _Cache.Get(_Key); _Cache.Set(_Key, sqlObj + sql); } } }