Exemplo n.º 1
0
        public TaskResult Run()
        {
            TaskResult result = CanRun(TaskContext);

            if (result.ResultType != TaskResultType.Success)
            {
                return(result);
            }
            //_context.Role.Window.LockInput(InputLockType.Mouse);
            OnStarting(TaskContext);
            TaskContext.TaskSteps = StepsInitialize();
            TaskContext.StepIndex = GetStepIndex(TaskContext);
            if (TaskContext.StepIndex == 0)
            {
                return(new TaskResult(TaskResultType.Fail, "获取任务执行步骤时出错"));
            }
            while (true)
            {
                TaskStep step = TaskContext.TaskSteps[TaskContext.StepIndex - 1];
                result = step.RunFunc(TaskContext);
                if (result.Stopping)
                {
                    return(result);
                }
                if (result.ResultType == TaskResultType.Jump)
                {
                    continue;
                }
                TaskContext.StepIndex++;
                if (TaskContext.StepIndex > TaskContext.TaskSteps.Length)
                {
                    TaskContext.StepIndex = 1;
                }
            }
        }
Exemplo n.º 2
0
 public TaskContext(IRole role, Function function)
 {
     Role        = role;
     Function    = function;
     Settings    = new ExpandoObject();
     StepIndex   = 0;
     TaskSteps   = new TaskStep[0];
     IsAutoFuhuo = true;
 }
Exemplo n.º 3
0
        public TaskResult Run()
        {
            TaskResult result = CanRun(TaskContext);

            if (result.ResultType != TaskResultType.Success)
            {
                return(result);
            }
            //_context.Role.Window.LockInput(InputLockType.Mouse);
            //任务启动前的任务
            OnStarting(TaskContext);
            //初始化任务步骤,获取执行到哪一步
            TaskContext.TaskSteps = StepsInitialize();
            TaskContext.StepIndex = GetStepIndex(TaskContext);
            if (TaskContext.StepIndex == 0)
            {
                return(new TaskResult(TaskResultType.Fail, "获取任务执行步骤时出错"));
            }
            while (true)
            {
                TaskStep step = TaskContext.TaskSteps[TaskContext.StepIndex - 1];
                Role.OutMessage("执行步骤" + TaskContext.StepIndex + ":" + step.Name);
                var ssr = OnStepIsCanRun(step.Name);
                if (ssr.ResultType == TaskResultType.Jump)
                {
                    TaskContext.StepIndex++;
                    if (TaskContext.StepIndex > TaskContext.TaskSteps.Length)
                    {
                        return(TaskResult.Finished);
                    }
                    continue;
                }
                //执行任务步骤
                result = step.RunFunc(TaskContext);

                OnStepStopping(TaskContext);
                //如果返回结果为Fail或者Finished则结束返回
                if (result.Stopping)
                {
                    return(result);
                }
                if (result.ResultType == TaskResultType.Jump)
                {
                    Role.OutSubMessage("步骤" + ":" + TaskContext.StepIndex + "跳过了!");
                }
                TaskContext.StepIndex++;
                if (TaskContext.StepIndex > TaskContext.TaskSteps.Length)
                {
                    return(TaskResult.Finished);
                }
            }
        }