Exemple #1
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 Task_Step GetNextStepInTask(string taskId)
        {
            string getNextStepIdSql = "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 and s.statustype = 'Waiting'"
                                      + " order by s.runindex asc"
                                      + " limit 1";
            Dictionary <string, object> p2vs = new Dictionary <string, object>();

            p2vs.Add("taskid", taskId);
            DataTable stepTable = SqliteHelper.MainDbHelper.GetDataTable(getNextStepIdSql, p2vs);

            if (stepTable.Rows.Count == 0)
            {
                return(null);
            }
            else
            {
                DataRow   row     = stepTable.Rows[0];
                Task_Step stepObj = new Task_Step();
                stepObj.EndTime      = CommonUtil.IsNullOrDBNul(row["endtime"]) ? null : (Nullable <DateTime>)row["endtime"];
                stepObj.Message      = CommonUtil.IsNullOrDBNul(row["message"]) ? null : (string)row["message"];
                stepObj.Id           = (string)row["id"];
                stepObj.ListFilePath = CommonUtil.IsNullOrDBNul(row["listfilepath"]) ? null : (string)row["listfilepath"];
                stepObj.InputDir     = CommonUtil.IsNullOrDBNul(row["inputdir"]) ? null : (string)row["inputdir"];
                stepObj.MiddleDir    = CommonUtil.IsNullOrDBNul(row["middledir"]) ? null : (string)row["middledir"];
                stepObj.OutputDir    = CommonUtil.IsNullOrDBNul(row["outputdir"]) ? null : (string)row["outputdir"];
                stepObj.Parameters   = CommonUtil.IsNullOrDBNul(row["parameters"]) ? null : (string)row["parameters"];
                stepObj.GroupName    = (string)row["groupname"];
                stepObj.ProjectName  = (string)row["projectname"];
                stepObj.RunIndex     = int.Parse(row["runindex"].ToString());
                stepObj.StartTime    = CommonUtil.IsNullOrDBNul(row["starttime"]) ? null : (Nullable <DateTime>)row["starttime"];
                stepObj.TaskId       = (string)row["taskid"];
                string statusTypeStr = (string)row["statustype"];
                stepObj.StatusType = (TaskStatusType)Enum.Parse(typeof(TaskStatusType), statusTypeStr);
                return(stepObj);
            }
        }
        private object UpdateDataAfterEndStep(SQLiteConnection conn)
        {
            Task_Step step = this.Step;

            string taskId = step.TaskId;
            string stepId = step.Id;

            string        updateStepSql = "update task_step set statustype = :statustype, message = :message where id = :stepid";
            SQLiteCommand updateStepCmd = new SQLiteCommand(conn);

            updateStepCmd.CommandText = updateStepSql;
            updateStepCmd.Parameters.AddWithValue("statustype", step.StatusType.ToString());
            updateStepCmd.Parameters.AddWithValue("stepid", stepId);
            updateStepCmd.Parameters.AddWithValue("message", step.Message);
            updateStepCmd.ExecuteNonQuery();

            if (step.StatusType == TaskStatusType.Error)
            {
                string        updateTaskSql = "update task_main set statustype = 'Error' where id = :taskid";
                SQLiteCommand updateTaskCmd = new SQLiteCommand(conn);
                updateTaskCmd.CommandText = updateTaskSql;
                updateTaskCmd.Parameters.AddWithValue("taskid", taskId);
                updateTaskCmd.ExecuteNonQuery();
            }
            else
            {
                string        getWaitingCountStepSql = "select count(1) as stepCount from task_step s where s.taskid = :taskid and s.statustype = 'Waiting'";
                SQLiteCommand getWaitingCountStepCmd = new SQLiteCommand(conn);
                getWaitingCountStepCmd.CommandText = getWaitingCountStepSql;
                getWaitingCountStepCmd.Parameters.AddWithValue("taskid", taskId);
                int stepCount = int.Parse(getWaitingCountStepCmd.ExecuteScalar().ToString());

                if (stepCount == 0)
                {
                    string        updateTaskSql = "update task_Main set statustype = 'Succeed' where id = :taskid";
                    SQLiteCommand updateTaskCmd = new SQLiteCommand(conn);
                    updateTaskCmd.CommandText = updateTaskSql;
                    updateTaskCmd.Parameters.AddWithValue("taskid", taskId);
                    updateTaskCmd.ExecuteNonQuery();
                }
            }
            return(true);
        }
Exemple #4
0
        private object UpdateDataAfterBeginStep(SQLiteConnection conn)
        {
            Task_Step step = this.Step;

            string        updateTaskSql = "update task_main set statustype = 'running' where id = :taskid";
            SQLiteCommand updateTaskCmd = new SQLiteCommand(conn);

            updateTaskCmd.CommandText = updateTaskSql;
            updateTaskCmd.Parameters.AddWithValue("taskid", step.TaskId);
            updateTaskCmd.ExecuteNonQuery();

            string        updateStepSql = "update task_step set statustype = 'running' where id = :stepid";
            SQLiteCommand updateStepCmd = new SQLiteCommand(conn);

            updateStepCmd.CommandText = updateStepSql;
            updateStepCmd.Parameters.AddWithValue("taskid", Step.TaskId);
            updateStepCmd.ExecuteNonQuery();
            return(true);
        }
Exemple #5
0
        private List <Task_Step> GetWaitingStepsInTasks(int count, TaskStatusType taskStatusType)
        {
            int startIndex = 0;
            int endIndex   = count - 1;

            string selectTaskSql = "";

            if (taskStatusType == TaskStatusType.Waiting)
            {
                //从从未有执行过step的task里选
                selectTaskSql = "select t.id as id"
                                + " from task_main t"
                                + " where t.statustype = 'waiting'"
                                + " order by t.level desc, t.createtime asc"
                                + " limit " + startIndex.ToString() + "," + endIndex.ToString();
            }
            else
            {
                //找到task状态为running,但是此task没有对应running的step
                selectTaskSql = "select t.id as id"
                                + " from task_main t"
                                + " where t.statustype = 'running'"
                                + " and not exists(select 1 from task_step s where s.taskid = t.id and s.statustype = 'running')"
                                + " order by t.level desc, t.createtime asc"
                                + " limit " + startIndex.ToString() + "," + endIndex.ToString();
            }

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

            List <Task_Step> stepObjects = new List <Task_Step>();

            foreach (DataRow row in taskTable.Rows)
            {
                string    taskId = (string)row["id"];
                Task_Step step   = this.GetNextStepInTask(taskId);
                if (step != null)
                {
                    stepObjects.Add(step);
                }
            }
            return(stepObjects);
        }
Exemple #6
0
        private Task_Step GetNextStepInTask(string taskId)
        {
            string getNextStepIdSql = "select s.id as id, "
                                      + " s.taskid as taskid,"
                                      + " s.statustype as statustype,"
                                      + " s.starttime as starttime,"
                                      + " s.endtime as endtime,"
                                      + " s.inputparameters as inputparameters,"
                                      + " s.message as message,"
                                      + " s.runindex as runindex,"
                                      + " s.projectname as projectname"
                                      + " from task_setp s"
                                      + " where s.taskid = :taskid and s.statustype = 'waiting'"
                                      + " order by s.runindex asc"
                                      + " limit 0, 0";
            Dictionary <string, object> p2vs = new Dictionary <string, object>();

            p2vs.Add("taskid", taskId);
            DataTable stepTable = SqliteHelper.MainDbHelper.GetDataTable(getNextStepIdSql, p2vs);

            if (stepTable.Rows.Count == 0)
            {
                return(null);
            }
            else
            {
                DataRow   row     = stepTable.Rows[0];
                Task_Step stepObj = new Task_Step();
                stepObj.EndTime         = (DateTime)row["endtime"];
                stepObj.Message         = (string)row["message"];
                stepObj.Id              = (string)row["id"];
                stepObj.InputParameters = (string)row["inputparameters"];
                stepObj.ProjectName     = (string)row["projectname"];
                stepObj.RunIndex        = (int)row["runindex"];
                stepObj.StartTime       = (DateTime)row["starttime"];
                stepObj.TaskId          = (string)row["taskid"];
                string statusTypeStr = (string)row["statustype"];
                stepObj.StatusType = (TaskStatusType)Enum.Parse(typeof(TaskStatusType), statusTypeStr);
                return(stepObj);
            }
        }
        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);
            }
        }