Exemplo n.º 1
0
        // 启动批处理任务
        int StartBatchTask(string strTaskName,
            out string strError)
        {
            strError = "";

            BatchTaskStartInfo startinfo = new BatchTaskStartInfo();
            if (strTaskName == "日志恢复")
            {
                StartLogRecoverDlg dlg = new StartLogRecoverDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return -1;
                }
            }
            else if (strTaskName == "dp2Library 同步")
            {
                StartReplicationDlg dlg = new StartReplicationDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return -1;
                }
            }
            else if (strTaskName == "重建检索点")
            {
                StartRebuildKeysDlg dlg = new StartRebuildKeysDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return -1;
                }
            }
            else if (strTaskName == "预约到书管理")
            {
                StartArriveMonitorDlg dlg = new StartArriveMonitorDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return -1;
                }
            }
            /*
        else if (strTaskName == "跟踪DTLP数据库")
        {
            StartTraceDtlpDlg dlg = new StartTraceDtlpDlg();
        MainForm.SetControlFont(dlg, this.Font, false);
            dlg.StartInfo = startinfo;
            dlg.ShowDialog(this);
            if (dlg.DialogResult != DialogResult.OK)
            {
                strError = "用户放弃启动";
                return -1;
            }
        }
             * */
            else if (strTaskName == "正元一卡通读者信息同步")
            {
                StartZhengyuanReplicationDlg dlg = new StartZhengyuanReplicationDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return -1;
                }
            }
            else if (strTaskName == "迪科远望一卡通读者信息同步")
            {
                StartDkywReplicationDlg dlg = new StartDkywReplicationDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                startinfo.Start = "!breakpoint";    // 一开始就有适当的缺省值,避免从头开始跟踪
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return -1;
                }
            }
            else if (strTaskName == "读者信息同步")
            {
#if NO
                StartPatronReplicationDlg dlg = new StartPatronReplicationDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                startinfo.Start = "!breakpoint";    // 一开始就有适当的缺省值,避免从头开始跟踪
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return -1;
                }
#endif
                startinfo.Start = "activate";   // 表示立即启动,忽略服务器原有定时启动参数
            }
            else if (strTaskName == "超期通知")
            {
                startinfo.Start = "activate";   // 表示立即启动,忽略服务器原有定时启动参数
            }
            else if (strTaskName == "创建 MongoDB 日志库")
            {
                StartLogRecoverDlg dlg = new StartLogRecoverDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.Text = "启动 创建 MongoDB 日志库 任务";
                dlg.TaskName = "创建 MongoDB 日志库";
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return -1;
                }
            }

            this.m_lock.AcquireWriterLock(m_nLockTimeout);
            try
            {
                EnableControls(false);

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在"
                    + "启动"
                    + "任务 '" + strTaskName + "' ...");
                stop.BeginLoop();

                this.Update();
                this.MainForm.Update();

                try
                {
                    BatchTaskInfo param = new BatchTaskInfo();
                    param.StartInfo = startinfo;

                    BatchTaskInfo resultInfo = null;

                    // return:
                    //      -1  出错
                    //      0   启动成功
                    //      1   调用前任务已经处于执行状态,本次调用激活了这个任务
                    long lRet = Channel.BatchTask(
                        stop,
                        strTaskName,
                        "start",
                        param,
                        out resultInfo,
                        out strError);
                    if (lRet == -1 || lRet == 1)
                        goto ERROR1;

                    if (resultInfo != null)
                    {
                        Global.WriteHtml(this.webBrowser_info,
                            GetResultText(resultInfo.ResultText));
                        ScrollToEnd();
                    }

                    this.label_progress.Text = resultInfo.ProgressText;
                }
                finally
                {
                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");

                    EnableControls(true);
                }

                return 1;
            ERROR1:
                return -1;
            }
            finally
            {
                this.m_lock.ReleaseWriterLock();
            }
        }
Exemplo n.º 2
0
        // 启动批处理任务
        // parameters:
        // return:
        //      -1  出错
        //      1   成功。strError 里面有提示成功的内容
        int StartBatchTask(string strTaskName,
                           out string strError)
        {
            strError = "";

            BatchTaskStartInfo startinfo = new BatchTaskStartInfo();

            if (strTaskName == "日志恢复")
            {
                StartLogRecoverDlg dlg = new StartLogRecoverDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }
            else if (strTaskName == "dp2Library 同步")
            {
                StartReplicationDlg dlg = new StartReplicationDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }
            else if (strTaskName == "重建检索点")
            {
                StartRebuildKeysDlg dlg = new StartRebuildKeysDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }
            else if (strTaskName == "预约到书管理")
            {
                StartArriveMonitorDlg dlg = new StartArriveMonitorDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }

            /*
             * else if (strTaskName == "跟踪DTLP数据库")
             * {
             * StartTraceDtlpDlg dlg = new StartTraceDtlpDlg();
             * MainForm.SetControlFont(dlg, this.Font, false);
             * dlg.StartInfo = startinfo;
             * dlg.ShowDialog(this);
             * if (dlg.DialogResult != DialogResult.OK)
             * {
             *  strError = "用户放弃启动";
             *  return -1;
             * }
             * }
             * */
            /*
             * else if (strTaskName == "正元一卡通读者信息同步")
             * {
             * StartZhengyuanReplicationDlg dlg = new StartZhengyuanReplicationDlg();
             * MainForm.SetControlFont(dlg, this.Font, false);
             * dlg.StartInfo = startinfo;
             * dlg.ShowDialog(this);
             * if (dlg.DialogResult != DialogResult.OK)
             * {
             *  strError = "用户放弃启动";
             *  return -1;
             * }
             * }
             * else if (strTaskName == "迪科远望一卡通读者信息同步")
             * {
             * StartDkywReplicationDlg dlg = new StartDkywReplicationDlg();
             * MainForm.SetControlFont(dlg, this.Font, false);
             * startinfo.Start = "!breakpoint";    // 一开始就有适当的缺省值,避免从头开始跟踪
             * dlg.StartInfo = startinfo;
             * dlg.ShowDialog(this);
             * if (dlg.DialogResult != DialogResult.OK)
             * {
             *  strError = "用户放弃启动";
             *  return -1;
             * }
             * }
             * */
            else if (strTaskName == "读者信息同步")
            {
#if NO
                StartPatronReplicationDlg dlg = new StartPatronReplicationDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                startinfo.Start = "!breakpoint";    // 一开始就有适当的缺省值,避免从头开始跟踪
                dlg.StartInfo   = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
#endif
                startinfo.Start = "activate";   // 表示立即启动,忽略服务器原有定时启动参数
            }
            else if (strTaskName == "超期通知")
            {
                startinfo.Start = "activate";   // 表示立即启动,忽略服务器原有定时启动参数
            }
            else if (strTaskName == "创建 MongoDB 日志库")
            {
                StartLogRecoverDlg dlg = new StartLogRecoverDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.Text      = "启动 创建 MongoDB 日志库 任务";
                dlg.TaskName  = "创建 MongoDB 日志库";
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }
            else if (strTaskName == "服务器同步")
            {
                StartServerReplicationDlg dlg = new StartServerReplicationDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.Text      = "启动 服务器同步 任务";
                dlg.TaskName  = "服务器同步";
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }
            else if (strTaskName == "大备份")
            {
                if (StringUtil.CompareVersion(Program.MainForm.ServerVersion, "2.117") < 0)
                {
                    strError = "dp2library 应在 2.117 版以上才能使用“大备份”任务相关的功能";
                    return(-1);
                }

                StartBackupDialog dlg = new StartBackupDialog();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult == System.Windows.Forms.DialogResult.Abort)
                {
                    if (StopBatchTask(strTaskName,
                                      "abort",
                                      out strError) == -1)
                    {
                        return(-1);
                    }
                    strError = "任务 '" + strTaskName + "' 已被撤销";
                    return(1);
                }
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }

                // 2017/9/30
                if (dlg.DownloadFiles)
                {
                    if (StringUtil.IsInList("download", MainForm._currentUserRights) == false)
                    {
                        strError = "启动“大备份”任务被拒绝。当前用户并不具备 download 权限,所以无法在大备份同时下载文件。请先为当前用户添加这个权限,再重新启动大备份任务";
                        return(-1);
                    }
                }
            }
            else if (strTaskName == "<日志备份>")
            {
                string strOutputFolder = "";

                // 备份日志文件。即,把日志文件从服务器拷贝到本地目录。要处理好增量复制的问题。
                // return:
                //      -1  出错
                //      0   放弃下载,或者没有必要下载。提示信息在 strError 中
                //      1   成功启动了下载
                int nRet = Program.MainForm.BackupOperLogFiles(ref strOutputFolder,
                                                               out strError);
                if (nRet != 1)
                {
                    if (nRet == 0 && string.IsNullOrEmpty(strError))
                    {
                        strError = "用户放弃启动";
                    }
                    return(-1);
                }
                strError = "本地任务 '<日志备份> 成功启动'";
                return(1);
            }

            this.m_lock.AcquireWriterLock(m_nLockTimeout);
            try
            {
                EnableControls(false);

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在"
                             + "启动"
                             + "任务 '" + strTaskName + "' ...");
                stop.BeginLoop();

                this.Update();
                Program.MainForm.Update();

                try
                {
                    BatchTaskInfo param = new BatchTaskInfo();
                    param.StartInfo = startinfo;

                    BatchTaskInfo resultInfo = null;

                    // return:
                    //      -1  出错
                    //      0   启动成功
                    //      1   调用前任务已经处于执行状态,本次调用激活了这个任务
                    long lRet = Channel.BatchTask(
                        stop,
                        strTaskName,
                        "start",
                        param,
                        out resultInfo,
                        out strError);
                    if (lRet == -1 || lRet == 1)
                    {
                        goto ERROR1;
                    }

                    if (resultInfo != null)
                    {
                        Global.WriteHtml(this.webBrowser_info,
                                         GetResultText(resultInfo.ResultText));
                        ScrollToEnd();
                    }

                    this.label_progress.Text = resultInfo.ProgressText;

                    if (strTaskName == "大备份" &&
                        resultInfo.StartInfo != null)
                    {
                        string        strOutputFolder = "";
                        List <string> paths           = StringUtil.SplitList(resultInfo.StartInfo.OutputParam);

                        StringUtil.RemoveBlank(ref paths);

                        List <dp2Circulation.MainForm.DownloadFileInfo> infos = MainForm.BuildDownloadInfoList(paths);

                        bool bAppend = false;
                        // 询问是否覆盖已有的目标下载文件。整体询问
                        // return:
                        //      -1  出错
                        //      0   放弃下载
                        //      1   同意启动下载
                        int nRet = Program.MainForm.AskOverwriteFiles(infos,    // paths,
                                                                      ref strOutputFolder,
                                                                      out bAppend,
                                                                      out strError);
                        if (nRet == -1)
                        {
                            return(-1);
                        }
                        if (nRet == 1)
                        {
                            paths = MainForm.GetFileNames(infos, (info) =>
                            {
                                return(info.ServerPath);
                            });
                            foreach (string path in paths)
                            {
                                if (string.IsNullOrEmpty(path) == false)
                                {
                                    // parameters:
                                    //      strOutputFolder 输出目录。
                                    //                      [in] 如果为 null,表示要弹出对话框询问目录。如果不为 null,则直接使用这个目录路径
                                    //                      [out] 实际使用的目录
                                    // return:
                                    //      -1  出错
                                    //      0   放弃下载
                                    //      1   成功启动了下载
                                    nRet = Program.MainForm.BeginDownloadFile(path,
                                                                              bAppend ? "append" : "overwrite",
                                                                              ref strOutputFolder,
                                                                              out strError);
                                    if (nRet == -1)
                                    {
                                        return(-1);
                                    }
                                    if (nRet == 0)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");

                    EnableControls(true);
                }

                strError = "任务 '" + strTaskName + "' 已成功启动";
                return(1);

ERROR1:
                return(-1);
            }
            finally
            {
                this.m_lock.ReleaseWriterLock();
            }
        }
Exemplo n.º 3
0
        // 启动批处理任务
        int StartBatchTask(string strTaskName,
                           out string strError)
        {
            strError = "";

            BatchTaskStartInfo startinfo = new BatchTaskStartInfo();

            if (strTaskName == "日志恢复")
            {
                StartLogRecoverDlg dlg = new StartLogRecoverDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }
            else if (strTaskName == "dp2Library 同步")
            {
                StartReplicationDlg dlg = new StartReplicationDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }
            else if (strTaskName == "重建检索点")
            {
                StartRebuildKeysDlg dlg = new StartRebuildKeysDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }
            else if (strTaskName == "预约到书管理")
            {
                StartArriveMonitorDlg dlg = new StartArriveMonitorDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }

            /*
             * else if (strTaskName == "跟踪DTLP数据库")
             * {
             * StartTraceDtlpDlg dlg = new StartTraceDtlpDlg();
             * MainForm.SetControlFont(dlg, this.Font, false);
             * dlg.StartInfo = startinfo;
             * dlg.ShowDialog(this);
             * if (dlg.DialogResult != DialogResult.OK)
             * {
             *  strError = "用户放弃启动";
             *  return -1;
             * }
             * }
             * */
            else if (strTaskName == "正元一卡通读者信息同步")
            {
                StartZhengyuanReplicationDlg dlg = new StartZhengyuanReplicationDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }
            else if (strTaskName == "迪科远望一卡通读者信息同步")
            {
                StartDkywReplicationDlg dlg = new StartDkywReplicationDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                startinfo.Start = "!breakpoint";    // 一开始就有适当的缺省值,避免从头开始跟踪
                dlg.StartInfo   = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }
            else if (strTaskName == "读者信息同步")
            {
#if NO
                StartPatronReplicationDlg dlg = new StartPatronReplicationDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                startinfo.Start = "!breakpoint";    // 一开始就有适当的缺省值,避免从头开始跟踪
                dlg.StartInfo   = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
#endif
                startinfo.Start = "activate";   // 表示立即启动,忽略服务器原有定时启动参数
            }
            else if (strTaskName == "超期通知")
            {
                startinfo.Start = "activate";   // 表示立即启动,忽略服务器原有定时启动参数
            }
            else if (strTaskName == "创建 MongoDB 日志库")
            {
                StartLogRecoverDlg dlg = new StartLogRecoverDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.Text      = "启动 创建 MongoDB 日志库 任务";
                dlg.TaskName  = "创建 MongoDB 日志库";
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }

            this.m_lock.AcquireWriterLock(m_nLockTimeout);
            try
            {
                EnableControls(false);

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在"
                             + "启动"
                             + "任务 '" + strTaskName + "' ...");
                stop.BeginLoop();

                this.Update();
                this.MainForm.Update();

                try
                {
                    BatchTaskInfo param = new BatchTaskInfo();
                    param.StartInfo = startinfo;

                    BatchTaskInfo resultInfo = null;

                    // return:
                    //      -1  出错
                    //      0   启动成功
                    //      1   调用前任务已经处于执行状态,本次调用激活了这个任务
                    long lRet = Channel.BatchTask(
                        stop,
                        strTaskName,
                        "start",
                        param,
                        out resultInfo,
                        out strError);
                    if (lRet == -1 || lRet == 1)
                    {
                        goto ERROR1;
                    }

                    if (resultInfo != null)
                    {
                        Global.WriteHtml(this.webBrowser_info,
                                         GetResultText(resultInfo.ResultText));
                        ScrollToEnd();
                    }

                    this.label_progress.Text = resultInfo.ProgressText;
                }
                finally
                {
                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");

                    EnableControls(true);
                }

                return(1);

ERROR1:
                return(-1);
            }
            finally
            {
                this.m_lock.ReleaseWriterLock();
            }
        }