Esempio n. 1
0
 // 停止所有批处理任务
 public void StopAllBatchTasks()
 {
     for (int i = 0; i < this.BatchTasks.Count; i++)
     {
         BatchTask task = this.BatchTasks[i];
         task.Stop();
     }
 }
Esempio n. 2
0
        // 按照命令启动一个批处理任务(不是自动启动)
        public int StartBatchTask(string strName,
                                  TaskInfo param,
                                  out TaskInfo info,
                                  out string strError)
        {
            strError = "";
            info     = null;

            if (strName == "!continue")
            {
                this.PauseBatchTask = false;
                return(0);
            }

            // 2007/12/18
            if (this.HangupReason == HangupReason.LogRecover)
            {
                strError = "当前系统正处在LogRecover挂起状态,无法启动新的批处理任务";
                return(-1);
            }

            // 2012/2/4
            if (this.PauseBatchTask == true)
            {
                strError = "当前所有批处理任务均处在暂停状态,无法启动新的批处理任务";
                return(-1);
            }

            List <BatchTask> tasks = this.BatchTasks.GetBatchTask(strName);

            if (tasks == null || tasks.Count == 0)
            {
                // 创建新的任务
                BatchTask task = null;

                if (string.IsNullOrEmpty(strName) == false && strName[0] == '#')
                {
                    strError = "不允许用 '#' 方式启动任务";
                    return(-1);
                }

                if (strName == "预约到书管理")
                {
                    task = new RebuildKeysTask(this, strName);
                }
                else
                {
                    strError = "系统不能识别任务名 '" + strName + "'";
                    return(-1);
                }

                try
                {
                    this.BatchTasks.Add(task);
                }
                catch (Exception ex)
                {
                    strError = ExceptionUtil.GetAutoText(ex);
                    return(-1);
                }

                tasks.Add(task);
            }

            // BatchTask task = this.BatchTasks.GetBatchTask(strName);
            else
            {
                string strNameString = "";
                foreach (BatchTask task in tasks)
                {
                    bool bOldStoppedValue = task.Stopped;

                    if (bOldStoppedValue == false)
                    {
                        // 激活 2007/10/10
                        task.eventActive.Set();
                        task.ManualStart = true;    // 表示为命令启动

                        if (string.IsNullOrEmpty(strNameString) == false)
                        {
                            strNameString += ",";
                        }
                        strNameString += task.Name + "(ID=" + task.ID + ")";
                    }
                }

                if (string.IsNullOrEmpty(strNameString) == false)
                {
                    strError = "任务 " + strNameString + " 已经在运行中,不能重复启动。本次操作激活了这些(个)任务。";
                    return(-1);
                }
            }

            {
                BatchTask task = tasks[0];

                task.ManualStart = true;    // 表示为命令启动
                task.StartInfo   = param.StartInfo;
                task.ClearProgressFile();   // 清除进度文件内容
                task.StartWorkerThread();

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

            return(0);
        }