public static List <Task_Main> GetTaskList(int pageIndex, int onePageCount)
        {
            int    startIndex    = (pageIndex - 1) * onePageCount;
            string selectTaskSql = "select t.id as id, "
                                   + " t.name as name,"
                                   + " t.createtime as createtime,"
                                   + " t.statustype as statustype,"
                                   + " t.description as description,"
                                   + " t.level as level,"
                                   + " t.serialnumber as serialnumber"
                                   + " from task_main t"
                                   + " order by t.createtime desc"
                                   + " limit " + onePageCount.ToString() + " offset " + startIndex.ToString();

            DataTable        taskTable   = SqliteHelper.MainDbHelper.GetDataTable(selectTaskSql, null);
            List <Task_Main> taskObjects = new List <Task_Main>();

            foreach (DataRow row in taskTable.Rows)
            {
                Task_Main taskObj = new Task_Main();
                taskObj.CreateTime   = (DateTime)row["createtime"];
                taskObj.Description  = (string)row["description"];
                taskObj.Id           = (string)row["id"];
                taskObj.Level        = (int)row["level"];
                taskObj.Name         = (string)row["name"];
                taskObj.SerialNumber = (string)row["serialnumber"];
                string statusTypeStr = (string)row["statustype"];
                taskObj.StatusType = (TaskStatusType)Enum.Parse(typeof(TaskStatusType), statusTypeStr);
                taskObjects.Add(taskObj);
            }
            return(taskObjects);
        }
        public static string CreateTask(Task_Main task)
        {
            TaskDataProcessor processor = new TaskDataProcessor();

            processor.Task = task;
            return((string)SqliteHelper.MainDbHelper.RunTransaction(new SqliteHelper.RunTransactionDelegate(processor.InsertTaskToDBTransaction)));
        }
Beispiel #3
0
        public XmlDocument CreateTask(string requestInfo)
        {
            XmlDocument requestDoc = new XmlDocument();

            requestDoc.LoadXml(requestInfo);
            XmlElement rootNode = requestDoc.DocumentElement;
            Task_Main  task     = new Task_Main();

            task.Description  = rootNode.GetAttribute("description");
            task.Level        = int.Parse(rootNode.GetAttribute("level"));
            task.Name         = rootNode.GetAttribute("name");
            task.SerialNumber = rootNode.GetAttribute("serialNumber");

            XmlNodeList      allStepNodes = rootNode.SelectSingleNode("steps").SelectNodes("step");
            List <Task_Step> allSteps     = new List <Task_Step>();

            foreach (XmlElement stepNode in allStepNodes)
            {
                Task_Step step = new Task_Step();
                step.GroupName    = stepNode.GetAttribute("groupName");
                step.ProjectName  = stepNode.GetAttribute("projectName");
                step.ListFilePath = stepNode.GetAttribute("listFilePath");
                step.InputDir     = stepNode.GetAttribute("inputDir");
                step.MiddleDir    = stepNode.GetAttribute("middleDir");
                step.OutputDir    = stepNode.GetAttribute("outputDir");
                step.Parameters   = stepNode.GetAttribute("parameters");
                step.RunIndex     = int.Parse(stepNode.GetAttribute("runIndex"));
                allSteps.Add(step);
            }
            task.AllSteps = allSteps;

            String taskId = TaskDataProcessor.CreateTask(task);

            return(this.GetDetailInfoByTaskIdValue(taskId));
        }
        private object DeleteTaskTransaction(SQLiteConnection conn)
        {
            Task_Main task = this.Task;

            string        selectTaskSql = "select t.id as id, t.statustype as statusType, t.serialNumber as serialNumber from task_Main t where t.id = :id for update";
            SQLiteCommand selectTaskCmd = new SQLiteCommand(conn);

            selectTaskCmd.CommandText = selectTaskSql;
            selectTaskCmd.Parameters.AddWithValue("id", task.Id);
            SQLiteDataAdapter dao       = new SQLiteDataAdapter(selectTaskCmd);
            DataTable         taskTable = new DataTable();

            dao.Fill(taskTable);

            if (taskTable == null || taskTable.Rows.Count == 0)
            {
                throw new Exception("没有找到对应的任务. TaskId = " + task.Id);
            }
            else
            {
                DataRow        taskRow       = taskTable.Rows[0];
                String         statusTypeStr = taskRow["statusType"].ToString();
                TaskStatusType statusType    = (TaskStatusType)Enum.Parse(typeof(TaskStatusType), statusTypeStr);
                if (statusType == TaskStatusType.Deleted)
                {
                    return(true);
                }
                else if (statusType == TaskStatusType.Error)
                {
                    throw new Exception("Can not delete a error task. TaskId = " + task.Id);
                }
                else if (statusType == TaskStatusType.Running)
                {
                    //可允许删除,但是需要和爬取工具交互,停止任务
                    //目前先限定住,不允许删除
                    throw new Exception("Can not delete a running task. TaskId = " + task.Id);
                }
                else if (statusType == TaskStatusType.Succeed)
                {
                    throw new Exception("Can not delete a succeed task. TaskId = " + task.Id);
                }
                else if (statusType == TaskStatusType.Waiting)
                {
                    string        updateTaskSql = "update task_Main set statustype = :statusType where id = :id";
                    SQLiteCommand updateTaskCmd = new SQLiteCommand(conn);
                    updateTaskCmd.CommandText = updateTaskSql;
                    updateTaskCmd.Parameters.AddWithValue("statusType", TaskStatusType.Deleted.ToString());
                    updateTaskCmd.ExecuteNonQuery();
                    return(true);
                }
                else
                {
                    throw new Exception("Can not delete a " + statusType.ToString() + " task. TaskId = " + task.Id);
                }
            }
        }
        public JObject CreateTask(string requestInfo)
        {
            JObject   requestJson = JObject.Parse(requestInfo);
            Task_Main task        = new Task_Main();

            task.Description  = requestJson.GetValue("description").ToString();
            task.Level        = int.Parse(requestJson.GetValue("level").ToString());
            task.Name         = requestJson.GetValue("name").ToString();
            task.SerialNumber = requestJson.GetValue("serialNumber").ToString();

            String taskId = TaskDataProcessor.CreateTask(task);

            return(this.GetDetailInfoByTaskId(taskId));
        }
Beispiel #6
0
        public XmlDocument GetDetailInfoByTaskIdValue(string taskId)
        {
            //根据任务Id获取任务步骤信息
            Dictionary <string, object> taskInfo = TaskDataProcessor.GetDetailInfoByTaskId(taskId);

            XmlDocument resultDoc = new XmlDocument();

            resultDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\" ?><result></result>");
            XmlElement resultRootNode = resultDoc.DocumentElement;

            resultRootNode.SetAttribute("code", "000");

            Task_Main task = (Task_Main)taskInfo["task"];

            resultRootNode.SetAttribute("createTime", task.CreateTime == null ? "" : ((DateTime)task.CreateTime).ToString("yyyy-MM-dd HH:mm:ss"));
            resultRootNode.SetAttribute("description", task.Description);
            resultRootNode.SetAttribute("id", task.Id);
            resultRootNode.SetAttribute("level", task.Level.ToString());
            resultRootNode.SetAttribute("name", task.Name);
            resultRootNode.SetAttribute("serialNumber", task.SerialNumber);
            resultRootNode.SetAttribute("statusType", task.StatusType.ToString());

            List <Task_Step> steps        = (List <Task_Step>)taskInfo["steps"];
            XmlElement       stepListNode = resultDoc.CreateElement("steps");

            resultRootNode.AppendChild(stepListNode);
            foreach (Task_Step step in steps)
            {
                XmlElement stepNode = resultDoc.CreateElement("step");
                stepNode.SetAttribute("endTime", step.EndTime == null ? "" : ((DateTime)step.EndTime).ToString("yyyy-MM-dd HH:mm:ss"));
                stepNode.SetAttribute("message", step.Message);
                stepNode.SetAttribute("id", step.Id);
                stepNode.SetAttribute("listFilePath", step.ListFilePath);
                stepNode.SetAttribute("inputDir", step.InputDir);
                stepNode.SetAttribute("middleDir", step.MiddleDir);
                stepNode.SetAttribute("outputDir", step.OutputDir);
                stepNode.SetAttribute("parameters", step.Parameters);
                stepNode.SetAttribute("groupName", step.GroupName);
                stepNode.SetAttribute("projectName", step.ProjectName);
                stepNode.SetAttribute("runIndex", step.RunIndex.ToString());
                stepNode.SetAttribute("startTime", step.StartTime == null ? "" : ((DateTime)step.StartTime).ToString("yyyy-MM-dd HH:mm:ss"));
                stepNode.SetAttribute("statusType", step.StatusType.ToString());
                stepNode.SetAttribute("taskId", step.TaskId);
                stepListNode.AppendChild(stepNode);
            }

            return(resultDoc);
        }
        public JObject GetDetailInfoByTaskId(string requestInfo)
        {
            //根据任务Id获取任务步骤信息
            JObject requestJson = JObject.Parse(requestInfo);
            string  taskId      = requestJson.GetValue("taskId").ToString();
            Dictionary <string, object> taskInfo = TaskDataProcessor.GetDetailInfoByTaskId(taskId);
            JObject resultObj = new JObject();

            resultObj.Add("code", "000");

            Task_Main task    = (Task_Main)taskInfo["task"];
            JObject   taskObj = new JObject();

            taskObj.Add("createTime", task.CreateTime == null ? "" : ((DateTime)task.CreateTime).ToString("yyyy-MM-dd HH:mm:ss"));
            taskObj.Add("description", HttpUtility.UrlEncode(task.Description));
            taskObj.Add("createTime", task.EndTime == null ? "" : ((DateTime)task.EndTime).ToString("yyyy-MM-dd HH:mm:ss"));
            taskObj.Add("id", task.Id);
            taskObj.Add("level", task.Level);
            taskObj.Add("name", HttpUtility.UrlEncode(task.Name));
            taskObj.Add("serialNumber", HttpUtility.UrlEncode(task.SerialNumber));
            taskObj.Add("startTime", task.StartTime == null ? "" : ((DateTime)task.StartTime).ToString("yyyy-MM-dd HH:mm:ss"));
            taskObj.Add("statusType", task.StatusType.ToString());
            resultObj.Add("task", taskObj);

            List <Task_Step> steps       = (List <Task_Step>)taskInfo["steps"];
            JArray           stepObjects = new JArray();

            foreach (Task_Step step in steps)
            {
                JObject stepObj = new JObject();
                stepObj.Add("endTime", step.EndTime == null ? "" : ((DateTime)step.EndTime).ToString("yyyy-MM-dd HH:mm:ss"));
                stepObj.Add("fatalErrorInfo", HttpUtility.UrlEncode(step.Message));
                stepObj.Add("id", step.Id);
                stepObj.Add("inputParameters", HttpUtility.UrlEncode(step.InputParameters));
                stepObj.Add("projectName", HttpUtility.UrlEncode(step.ProjectName));
                stepObj.Add("runIndex", step.RunIndex);
                stepObj.Add("startTime", step.StartTime == null ? "" : ((DateTime)step.StartTime).ToString("yyyy-MM-dd HH:mm:ss"));
                stepObj.Add("statusType", step.StatusType.ToString());
                stepObj.Add("taskId", step.TaskId);
                stepObjects.Add(stepObj);
            }
            resultObj.Add("steps", stepObjects);

            return(resultObj);
        }
        public static Dictionary <string, object> GetDetailInfoByTaskId(string taskId)
        {
            Dictionary <string, object> taskInfo = new Dictionary <string, object>();

            string selectTaskSql = "select t.id as id, "
                                   + " t.name as name,"
                                   + " t.createtime as createtime,"
                                   + " t.statustype as statustype,"
                                   + " t.description as description,"
                                   + " t.level as level,"
                                   + " t.serialnumber as serialnumber"
                                   + " from task_main t"
                                   + " where t.id = :id"
                                   + " order by t.createtime desc";

            Dictionary <string, object> taskP2vs = new Dictionary <string, object>();

            taskP2vs.Add("id", taskId);

            DataTable taskTable = SqliteHelper.MainDbHelper.GetDataTable(selectTaskSql, taskP2vs);

            if (taskTable.Rows.Count == 0)
            {
                throw new Exception("None task. taskId = " + taskId);
            }
            else
            {
                DataRow   taskRow = taskTable.Rows[0];
                Task_Main taskObj = new Task_Main();
                taskObj.CreateTime   = (DateTime)taskRow["createtime"];
                taskObj.Description  = (string)taskRow["description"];
                taskObj.Id           = (string)taskRow["id"];
                taskObj.Level        = (int)taskRow["level"];
                taskObj.Name         = (string)taskRow["name"];
                taskObj.SerialNumber = (string)taskRow["serialnumber"];
                string taskStatusTypeStr = (string)taskRow["statustype"];
                taskObj.StatusType = (TaskStatusType)Enum.Parse(typeof(TaskStatusType), taskStatusTypeStr);
                taskInfo.Add("task", taskObj);

                string selectStepSql = "select s.id as id, "
                                       + " s.taskid as taskid,"
                                       + " s.statustype as statustype,"
                                       + " s.starttime as starttime,"
                                       + " s.endtime as endtime,"
                                       + " s.listfilepath as listfilepath,"
                                       + " s.inputdir as inputdir,"
                                       + " s.middledir as middledir,"
                                       + " s.outputdir as outputdir,"
                                       + " s.parameters as parameters,"
                                       + " s.message as message,"
                                       + " s.runindex as runindex,"
                                       + " s.groupname as groupname,"
                                       + " s.projectname as projectname"
                                       + " from task_step s"
                                       + " where s.taskid = :taskid"
                                       + " order by s.runindex desc";

                Dictionary <string, object> stepP2vs = new Dictionary <string, object>();
                stepP2vs.Add("taskid", taskId);

                DataTable        stepTable   = SqliteHelper.MainDbHelper.GetDataTable(selectStepSql, stepP2vs);
                List <Task_Step> stepObjects = new List <Task_Step>();
                foreach (DataRow row in stepTable.Rows)
                {
                    Task_Step stepObj = new Task_Step();
                    stepObj.EndTime      = row["endtime"] == null || row["endtime"] == DBNull.Value ? null : (Nullable <DateTime>)(DateTime) row["endtime"];
                    stepObj.Message      = row["message"] == null || row["message"] == DBNull.Value ? "" : (string)row["message"];
                    stepObj.Id           = (string)row["id"];
                    stepObj.ListFilePath = (string)row["listfilepath"];
                    stepObj.InputDir     = (string)row["inputdir"];
                    stepObj.MiddleDir    = (string)row["middledir"];
                    stepObj.OutputDir    = (string)row["outputdir"];
                    stepObj.Parameters   = (string)row["parameters"];
                    stepObj.GroupName    = (string)row["groupname"];
                    stepObj.ProjectName  = (string)row["projectname"];
                    stepObj.RunIndex     = int.Parse(row["runindex"].ToString());
                    stepObj.StartTime    = row["starttime"] == null || row["starttime"] == DBNull.Value ? null : (Nullable <DateTime>)(DateTime) row["starttime"];
                    stepObj.TaskId       = (string)row["taskid"];
                    string statusTypeStr = (string)row["statustype"];
                    stepObj.StatusType = (TaskStatusType)Enum.Parse(typeof(TaskStatusType), statusTypeStr);
                    stepObjects.Add(stepObj);
                }
                taskInfo.Add("steps", stepObjects);

                return(taskInfo);
            }
        }
        private string InsertTaskToDBTransaction(SQLiteConnection conn)
        {
            Task_Main task = this.Task;

            if (task.AllSteps == null)
            {
                throw new Exception("Task steps can not be none!");
            }
            else
            {
                string taskId = this.CheckExistBySerialNumber(task.SerialNumber, conn);

                if (taskId == null || taskId.Length == 0)
                {
                    taskId          = Guid.NewGuid().ToString();
                    task.CreateTime = DateTime.Now;
                    task.StatusType = TaskStatusType.Waiting;
                    string addTaskSql = @"insert into task_Main(
                    id, 
                    name, 
                    createTime ,
                    statusType,
                    description, 
                    level, 
                    serialNumber) 
                    values(
                    :id, 
                    :name, 
                    :createTime ,
                    :statusType,
                    :description, 
                    :level, 
                    :serialNumber)";
                    Dictionary <string, object> taskP2vs = new Dictionary <string, object>();
                    taskP2vs.Add("id", taskId);
                    taskP2vs.Add("name", task.Name);
                    taskP2vs.Add("createTime", task.CreateTime);
                    taskP2vs.Add("statusType", task.StatusType.ToString());
                    taskP2vs.Add("description", task.Description);
                    taskP2vs.Add("level", task.Level);
                    taskP2vs.Add("serialNumber", task.SerialNumber);

                    SQLiteCommand taskCmd = conn.CreateCommand();
                    taskCmd.CommandText = addTaskSql;
                    foreach (string pName in taskP2vs.Keys)
                    {
                        taskCmd.Parameters.AddWithValue(pName, taskP2vs[pName]);
                    }
                    taskCmd.ExecuteNonQuery();

                    //添加step
                    foreach (Task_Step step in task.AllSteps)
                    {
                        string stepId = Guid.NewGuid().ToString();
                        step.StatusType = TaskStatusType.Waiting;
                        string addStepSql = @"insert into task_Step(
                        id, 
                        groupName, 
                        projectName, 
                        listFilePath, 
                        inputDir, 
                        middleDir,
                        outputDir, 
                        taskId ,
                        statusType,
                        parameters, 
                        runIndex) 
                        values(
                        :id, 
                        :groupName, 
                        :projectName, 
                        :listFilePath, 
                        :inputDir, 
                        :middleDir, 
                        :outputDir, 
                        :taskId ,
                        :statusType,
                        :parameters, 
                        :runIndex)";
                        Dictionary <string, object> stepP2vs = new Dictionary <string, object>();
                        stepP2vs.Add("id", stepId);
                        stepP2vs.Add("groupName", step.GroupName);
                        stepP2vs.Add("projectName", step.ProjectName);
                        stepP2vs.Add("taskId", taskId);
                        stepP2vs.Add("statusType", step.StatusType.ToString());
                        stepP2vs.Add("listFilePath", step.ListFilePath);
                        stepP2vs.Add("inputDir", step.InputDir);
                        stepP2vs.Add("middleDir", step.MiddleDir);
                        stepP2vs.Add("outputDir", step.OutputDir);
                        stepP2vs.Add("parameters", step.Parameters);
                        stepP2vs.Add("runIndex", step.RunIndex);

                        SQLiteCommand stepCmd = conn.CreateCommand();
                        stepCmd.CommandText = addStepSql;
                        foreach (string pName in stepP2vs.Keys)
                        {
                            stepCmd.Parameters.AddWithValue(pName, stepP2vs[pName]);
                        }
                        stepCmd.ExecuteNonQuery();
                    }
                }
                return(taskId);
            }
        }
Beispiel #10
0
        private string InsertTaskToDBTransaction(SQLiteConnection dbConection)
        {
            Task_Main task = this.Task;

            if (task.AllSteps == null)
            {
                throw new Exception("Task steps can not be none!");
            }
            else
            {
                string taskId = Guid.NewGuid().ToString();
                task.CreateTime = new DateTime();
                task.StatusType = TaskStatusType.Waiting;
                string addTaskSql = @"insert into task_Main(
                    id, 
                    name, 
                    createTime ,
                    statusType,
                    description, 
                    level, 
                    serialNumber) 
                    values(
                    :id, 
                    :name, 
                    :createTime ,
                    :statusType,
                    :description, 
                    :level, 
                    :serialNumber)";
                Dictionary <string, object> taskP2vs = new Dictionary <string, object>();
                taskP2vs.Add("id", taskId);
                taskP2vs.Add("name", task.Name);
                taskP2vs.Add("createTime", task.CreateTime);
                taskP2vs.Add("statusType", task.StatusType);
                taskP2vs.Add("description", task.Description);
                taskP2vs.Add("level", task.Level);
                taskP2vs.Add("serialNumber", task.SerialNumber);


                SQLiteCommand taskCmd = dbConection.CreateCommand();
                taskCmd.CommandText = addTaskSql;
                foreach (string pName in taskP2vs.Keys)
                {
                    taskCmd.Parameters.AddWithValue(pName, taskP2vs[pName]);
                }
                taskCmd.ExecuteNonQuery();

                //添加step
                foreach (Task_Step step in task.AllSteps)
                {
                    string stepId = Guid.NewGuid().ToString();
                    step.StatusType = TaskStatusType.Waiting;
                    string addStepSql = @"insert into task_Step(
                        id, 
                        projectName, 
                        taskId ,
                        statusType,
                        inputParamters, 
                        runIndex) 
                        values(
                        :id, 
                        :projectName, 
                        :taskId ,
                        :statusType,
                        :inputParamters, 
                        :runIndex)";
                    Dictionary <string, object> stepP2vs = new Dictionary <string, object>();
                    stepP2vs.Add("id", stepId);
                    stepP2vs.Add("projectName", step.ProjectName);
                    stepP2vs.Add("taskId", taskId);
                    stepP2vs.Add("statusType", step.StatusType);
                    stepP2vs.Add("inputParamters", step.InputParameters);
                    stepP2vs.Add("runIndex", step.RunIndex);

                    SQLiteCommand stepCmd = dbConection.CreateCommand();
                    stepCmd.CommandText = addStepSql;
                    foreach (string pName in stepP2vs.Keys)
                    {
                        stepCmd.Parameters.AddWithValue(pName, stepP2vs[pName]);
                    }
                    stepCmd.ExecuteNonQuery();
                }

                return(taskId);
            }
        }