Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 对外接口:添加一条DB Log记录
 /// </summary>
 /// <param name="node"></param>
 public bool AddLogToDB(FKSQLiteLogNode node)
 {
     try
     {
         if (!IsDBFileExistByTime(node.LogTime))
         {
             m_DBObject = CreateDBFileByTime(node.LogTime);
         }
         return(m_DBObject.Insert(node) > 0);
     }
     catch (Exception e)
     {
         Console.WriteLine($"[Error] Add log to Failed. Error = {e.ToString()}");
         return(false);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 添加一条Task流水日期映射表
 /// </summary>
 /// <param name="node"></param>
 private bool AddTaskTimeLogToDB(FKSQLiteLogTimeNode node)
 {
     try
     {
         if (!IsDBFileExist(FKLogConsts.SQLITE_LOG_TASK_TIME_FILE_NAME))
         {
             m_SQLiteObject = CreateDBFile(FKLogConsts.SQLITE_LOG_TASK_TIME_FILE_NAME);
         }
         return(m_SQLiteObject.Insert(node) > 0);
     }
     catch (Exception e)
     {
         Console.WriteLine($"[Error] Add task time log to DB Failed. Error = {e.ToString()}");
         return(false);
     }
 }
Exemplo n.º 5
0
        /// <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);
        }