コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <summary>
        /// 查询一个指定TaskID的日志信息
        /// </summary>
        /// <param name="nTaskID">任务ID</param>
        /// <returns></returns>
        public string GetLogByTaskID(int nTaskID, string DBFileName)
        {
            try
            {
                m_DBObject = new FKSQLiteLogConnection(DBFileName);
            }
            catch (Exception e)
            {
                Console.WriteLine($"[Error]Create FKDBConnection Failed. Error = {e.ToString()}");
                return(string.Empty);
            }

            if (m_DBObject == null)
            {
                Console.WriteLine($"[Error]Create FKDBConnection Failed.");
                return(string.Empty);
            }

            try
            {
                string sql = "select * from SDBLogNode where TaskID = " + nTaskID;
                m_SqlCmd = m_DBObject.CreateCommand(sql);

                var    results = m_SqlCmd.ExecuteQuery <FKSQLiteLogNode>().ToArray();
                string strRet  = "";
                for (var i = 0; i < results.Length; i++)
                {
                    strRet += "{\"id\":";
                    strRet += results[i].Id;
                    strRet += ",\"logId\":";
                    strRet += results[i].LogId;
                    strRet += ",\"logTime\":\"";
                    strRet += results[i].LogTime.ToString("yyyy-MM-dd H:mm:ss");
                    strRet += "\",\"logInfo\":\"";
                    strRet += results[i].LogInfo;
                    strRet += "\"}";
                    if (i + 1 < results.Length)
                    {
                        strRet += ',';
                    }
                }
                return(strRet);
            }
            catch (Exception e)
            {
                Console.WriteLine($"[Error] Select DBLog Failed. taskId = {nTaskID} : error = {e.ToString()}");
                return(string.Empty);
            }
        }
コード例 #3
0
 /// <summary>
 /// 查询一个指定TaskID的日志信息总条目数
 /// </summary>
 /// <param name="nTaskID"></param>
 /// <returns></returns>
 public int GetLogsCountByTaskID(int nTaskID)
 {
     if (m_DBObject == null)
     {
         return(0);
     }
     try
     {
         string sql      = "select count(*) from SDBLogNode where TaskID = " + nTaskID;
         var    numCount = m_DBObject.CreateCommand(sql).ExecuteScalar <int>();
         return(numCount);
     }
     catch (Exception e)
     {
         Console.WriteLine($"[Error] Get DBLog's count Failed. taskId = {nTaskID} : error = {e.ToString()}");
         return(0);
     }
 }