/// <summary> /// 获取指定Task的日志所在的数据库名 /// </summary> /// <param name="nTaskID"></param> /// <returns></returns> public List <string> GetTaskLogDBFileName(int nTaskID) { List <string> TaskTimesList = null; if (m_SQLiteObject == null) { // 初次创建DB文件 FKSystemFileSystemHelper.CreateDir(FKSystemFileSystemHelper.GetWorkdir() + "\\" + FKLogConsts.SQLITE_LOG_DIR_NAME); string str = FKSystemFileSystemHelper.GetWorkdir() + "\\" + FKLogConsts.SQLITE_LOG_DIR_NAME + "\\" + FKLogConsts.SQLITE_LOG_TASK_TIME_FILE_NAME; m_SQLiteObject = new FKSQLiteLogConnection(str); if (m_SQLiteObject == null) { return(null); } } try { string sql = "select * from SDBTaskNode where TaskID = " + nTaskID; m_SQLiteCmd = m_SQLiteObject.CreateCommand(sql); var results = m_SQLiteCmd.ExecuteQuery <FKSQLiteLogTimeNode>().ToArray(); if (results.Length <= 0) { return(null); } TaskTimesList = new List <string>(); for (int i = 0; i < results.Length; i++) { //存在不同taskid对应的记录在一个db中的情况,需要进行路径过滤 string dateDBName = FKSystemFileSystemHelper.GetWorkdir() + "\\" + FKLogConsts.SQLITE_LOG_DIR_NAME + "\\" + results[i].LogTime + FKLogConsts.SQLITE_LOG_DIR_NAME; bool bIsAlreadyInclude = false; foreach (string strIt in TaskTimesList) { if (string.Compare(strIt, dateDBName) == 0) // 文件已记录在列表中 { bIsAlreadyInclude = true; break; } } if (!bIsAlreadyInclude) { TaskTimesList.Add(dateDBName); } } } catch (Exception e) { Console.WriteLine($"[Error] Select task time Failed. taskId = {nTaskID} : error = {e.ToString()}"); return(null); } return(TaskTimesList); }
/// <summary> /// 创建当日DB文件 /// </summary> /// <param name="t">当时时间</param> /// <returns>创建后的DB文件对象</returns> private FKSQLiteLogConnection CreateDBFileByTime(DateTime t) { FKSQLiteLogConnection db = null; try { FKSystemFileSystemHelper.CreateDir(FKSystemFileSystemHelper.GetWorkdir() + "\\" + FKLogConsts.SQLITE_LOG_DIR_NAME); db = new FKSQLiteLogConnection(GetDBFileNameByTime(t)); db.CreateTable <FKSQLiteLogNode>(); } catch (Exception e) { Console.WriteLine($"[Error] Create DB file Failed. Error = {e.ToString()}"); return(null); } return(db); }
private SQLiteCommand m_SqlCmd = null; // 等待被指定的数据库命令 /// <summary> /// 是否已经存在当日DB文件 /// </summary> /// <param name="t">当前时间</param> /// <returns>true表示已经存在当日DB文件</returns> private bool IsDBFileExistByTime(DateTime t) { try { if (m_DBObject == null) { return(false); } FKSystemFileSystemHelper.CreateDir(FKSystemFileSystemHelper.GetWorkdir() + "\\" + FKLogConsts.SQLITE_LOG_DIR_NAME); string strDBFileName = GetDBFileNameByTime(t); return(m_DBObject.DatabasePath.CompareTo(strDBFileName) == 0); } catch (Exception e) { Console.WriteLine($"[Error] Check if a DB file existed failed. Error = {e.ToString()}"); return(false); } }
/// <summary> /// 写Log到File文件中 /// </summary> /// <param name="eLevel"></param> /// <param name="nLogID"></param> /// <param name="strMsg"></param> /// <param name="strFinalMsg"></param> private void WriteToFile(ENUM_LogLevel eLevel, string strFinalMsg) { try { if (((int)eLevel) < ((int)ENUM_LogLevel.eLogLevel_Info)) { return; } FKSystemFileSystemHelper.CreateDir(FKSystemFileSystemHelper.GetWorkdir() + "\\" + FKLogConsts.TEXT_LOG_DIR_NAME); using (StreamWriter w = File.AppendText(m_strTxtFileName)) { w.WriteLine(strFinalMsg); } } catch { // 这里暂时不需要做处理,因为该函数调用频率很高,且重要性不高 } }