Esempio n. 1
0
        public int GetBatchTaskInfo(string strName,
                                    BatchTaskInfo param,
                                    out BatchTaskInfo info,
                                    out string strError)
        {
            strError = "";
            info     = null;

            // 2016/11/6
            if (this.BatchTasks == null)
            {
                strError = "this.BatchTasks == null";
                return(-1);
            }

            BatchTask task = this.BatchTasks.GetBatchTask(strName);

            // 任务本来就不存在
            if (task == null)
            {
                strError = "任务 '" + strName + "' 不存在";
                return(-1);
            }

            info = task.GetCurrentInfo(param.ResultOffset,
                                       param.MaxResultBytes);

            return(1);
        }
Esempio n. 2
0
        public int AbortBatchTask(string strName,
                                  BatchTaskInfo param,
                                  out BatchTaskInfo info,
                                  out string strError)
        {
            strError = "";
            info     = null;

            if (this.BatchTasks == null)
            {
                strError = "this.BatchTasks == null";
                return(-1);
            }

            BatchTask task = this.BatchTasks.GetBatchTask(strName);

            // 任务本来就不存在
            if (task == null)
            {
                strError = "任务 '" + strName + "' 不存在";
                return(-1);
            }

            task._pendingCommands.Add("abort");
            task.Stop();

            info = task.GetCurrentInfo(param.ResultOffset,
                                       param.MaxResultBytes);

            return(1);
        }
Esempio n. 3
0
        public int StopBatchTask(string strName,
                                 BatchTaskInfo param,
                                 out BatchTaskInfo info,
                                 out string strError)
        {
            strError = "";
            info     = null;

            if (strName == "!pause")
            {
                this.PauseBatchTask = true;
                info = GetTaskInfo("全部批处理任务已经被暂停");
                return(1);
            }

            BatchTask task = this.BatchTasks.GetBatchTask(strName);

            // 任务本来就不存在
            if (task == null)
            {
                strError = "任务 '" + strName + "' 不存在";
                return(-1);
            }

            task.Stop();

            info = task.GetCurrentInfo(param.ResultOffset,
                                       param.MaxResultBytes);

            return(1);
        }
Esempio n. 4
0
        public int AbortBatchTask(string strName,
                                  BatchTaskInfo param,
                                  out BatchTaskInfo info,
                                  out string strError)
        {
            strError = "";
            info     = null;

            if (this.BatchTasks == null)
            {
                strError = "this.BatchTasks == null";
                return(-1);
            }

            BatchTask task = this.BatchTasks.GetBatchTask(strName);

            // 任务本来就不存在
            if (task == null)
            {
                strError = "任务 '" + strName + "' 不存在";
                return(-1);
            }

            // TODO: 如果任务已经是停止状态,那么添加 "abort" 会不会影响下一个新开始的启动?
            if (task._pendingCommands.IndexOf("abort") == -1)
            {
                task._pendingCommands.Add("abort");
            }
            task.Stop();

            info = task.GetCurrentInfo(param.ResultOffset,
                                       param.MaxResultBytes);
            return(1);
        }
Esempio n. 5
0
        public int GetBatchTaskInfo(string strName,
                                    BatchTaskInfo param,
                                    out BatchTaskInfo info,
                                    out string strError)
        {
            strError = "";
            info     = null;

            // 2016/11/6
            if (this.BatchTasks == null)
            {
                strError = "this.BatchTasks == null";
                return(-1);
            }

            BatchTask task = this.BatchTasks.GetBatchTask(strName);

            // 任务本来就不存在
            if (task == null)
            {
                strError = "任务 '" + strName + "' 不存在";
                return(-1);
            }

            info = task.GetCurrentInfo(param.ResultOffset,
                                       param.MaxResultBytes);

            // 特殊地,大备份 任务可以要求返回输出文件名列表
            // param.StartInfo.Param 包含一定的 style
            if (strName == "大备份" &&
                param.StartInfo != null &&
                StringUtil.IsInList("getOutputFileNames", param.StartInfo.Param))
            {
                if (info.StartInfo == null)
                {
                    info.StartInfo = new BatchTaskStartInfo();
                }
                {
                    BackupTask temp = task as BackupTask;
                    info.StartInfo.OutputParam = temp.OutputFileNames;
                }
            }
            return(1);
        }
Esempio n. 6
0
        int WaitForBegin(
            BatchTask task,
            string strName,
            BatchTaskInfo param,
            ref BatchTaskInfo info,
            out string strError)
        {
            strError = "";

            // 等待工作线程运行到启动点
            if (task.StartInfo.WaitForBegin)
            {
                if (task.eventStarted.WaitOne(TimeSpan.FromSeconds(10)) == false)
                {
                    strError = "任务 " + task.Name + " 未能在 10 秒内启动成功";
                    return(1);
                }

                // 2017/8/23
                if (string.IsNullOrEmpty(task.ErrorInfo) == false)
                {
                    strError = "任务 " + task.Name + " 启动阶段出错: " + task.ErrorInfo;
                    return(1);
                }
            }

            info = task.GetCurrentInfo(param.ResultOffset,
                                       param.MaxResultBytes);

            if (task.StartInfo.WaitForBegin)
            {
                if (info.StartInfo == null)
                {
                    info.StartInfo = new BatchTaskStartInfo();
                }
                if (strName == "大备份")
                {
                    BackupTask temp = task as BackupTask;
                    info.StartInfo.OutputParam = temp.OutputFileNames;
                }
            }

            return(0);
        }