// 按照命令启动一个批处理任务(不是自动启动) public int StartBatchTask(string strName, BatchTaskInfo param, out BatchTaskInfo info, out string strError) { strError = ""; info = null; // 2007/12/18 if (this.HangupReason == HangupReason.LogRecover) { strError = "当前系统正处在LogRecover挂起状态,无法启动新的批处理任务"; return(-1); } BatchTask task = this.BatchTasks.GetBatchTask(strName); // 创建新的任务 if (task == null) { /* * if (strName == "预约到书管理") * task = new ArriveMonitor(this, strName); * else if (strName == "日志恢复") * task = new OperLogRecover(this, strName); * else if (strName == "跟踪DTLP数据库") * task = new TraceDTLP(this, strName); * else if (strName == "正元一卡通读者信息同步") * task = new ZhengyuanReplication(this, strName); * else if (strName == "迪科远望一卡通读者信息同步") * task = new DkywReplication(this, strName); * else if (strName == "超期通知") * task = new ReadersMonitor(this, strName); * else if (strName == "消息监控") * task = new MessageMonitor(this, strName); * else * { * strError = "系统不能识别任务名 '" + strName + "'"; * return -1; * } * */ strError = "系统不能识别任务名 '" + strName + "'"; return(-1); try { this.BatchTasks.Add(task); } catch (Exception ex) { strError = ExceptionUtil.GetAutoText(ex); return(-1); } } else { bool bOldStoppedValue = task.Stopped; // 激活 2007/10/10 task.eventActive.Set(); task.ManualStart = true; // 表示为命令启动 if (bOldStoppedValue == false) { strError = "任务 " + task.Name + " 已经在运行中,不能重复启动。本次操作激活了这个任务。"; return(-1); } } // 执行日志恢复任务前,需要先中断正在执行的其他任何任务 // TODO: 日志恢复 任务结束后,原先中断的那些任务并不会自动去启动。需要系统管理员手动重新启动一次Application if (strName == "日志恢复") { StopAllBatchTasks(); } task.ManualStart = true; // 表示为命令启动 task.StartInfo = param.StartInfo; task.ClearProgressFile(); // 清除进度文件内容 task.StartWorkerThread(); // 激活 2007/10/10 task.eventActive.Set(); info = task.GetCurrentInfo(param.ResultOffset, param.MaxResultBytes); return(0); }
protected void Page_Load(object sender, EventArgs e) { // Debug.WriteLine("Page_Load()"); if (WebUtil.PrepareEnvironment(this, ref app, ref sessioninfo) == false) return; string strError = ""; // 是否登录? if (sessioninfo.UserID == "") { if (this.Page.Request["forcelogin"] == "on") { sessioninfo.LoginCallStack.Push(Request.RawUrl); Response.Redirect("login.aspx", true); return; } if (this.Page.Request["forcelogin"] == "userid") { sessioninfo.LoginCallStack.Push(Request.RawUrl); Response.Redirect("login.aspx?loginstyle=librarian", true); return; } sessioninfo.LoginCallStack.Push(Request.RawUrl); Response.Redirect("login.aspx", true); return; } LoginState loginstate = GlobalUtil.GetLoginState(this.Page); if (loginstate != LoginState.Librarian) { strError = "只有工作人员身份才能使用本模块"; goto ERROR1; } string strAction = this.Request["action"]; string strName = this.Request["name"]; if (string.IsNullOrEmpty(strName) == true) strName = "CacheBuilder"; this.Label_taskName.Text = strName; ResultInfo result_info = new ResultInfo(); if (strAction == "getinfo") { string strResultOffset = this.Request["result_offset"]; string strMaxResultBytes = this.Request["max_result_bytes"]; if (string.IsNullOrEmpty(strResultOffset) == true) { result_info.ErrorString = "未指定 result_offset 参数"; goto END1; } long lResultOffset = 0; Int64.TryParse(strResultOffset, out lResultOffset); int nMaxResultBytes = 4096; Int32.TryParse(strMaxResultBytes, out nMaxResultBytes); BatchTaskInfo param = new BatchTaskInfo(); BatchTaskInfo info = null; param.ResultOffset = lResultOffset; param.MaxResultBytes = nMaxResultBytes; Debug.WriteLine("GetBatchTaskInfo()"); int nRet = app.GetBatchTaskInfo(strName, param, out info, out strError); if (nRet == -1) { result_info.ErrorString = strError; goto END1; } result_info.Name = info.Name; result_info.MaxResultBytes = info.MaxResultBytes; result_info.ResultText = GetResultText(info.ResultText); result_info.ProgressText = info.ProgressText; result_info.ResultOffset = info.ResultOffset; result_info.ResultTotalLength = info.ResultTotalLength; result_info.ResultVersion = info.ResultVersion; END1: DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ResultInfo)); MemoryStream ms = new MemoryStream(); ser.WriteObject(ms, result_info); string strResult = Encoding.UTF8.GetString(ms.ToArray()); ms.Close(); this.Response.Write(strResult); this.Response.End(); return; } return; ERROR1: this.Response.Write(strError); this.Response.End(); }
public int GetBatchTaskInfo(string strName, BatchTaskInfo param, out BatchTaskInfo info, out string strError) { strError = ""; info = null; BatchTask task = this.BatchTasks.GetBatchTask(strName); // 任务本来就不存在 if (task == null) { strError = "任务 '" + strName + "' 不存在"; return -1; } info = task.GetCurrentInfo(param.ResultOffset, param.MaxResultBytes); return 1; }
// 获得任务当前信息 // 多线程:安全 public BatchTaskInfo GetCurrentInfo(long lResultStart, int nMaxResultBytes) { this.m_lock.AcquireReaderLock(m_nLockTimeout); try { BatchTaskInfo info = new BatchTaskInfo(); info.Name = this.Name; if (this.m_bClosed == false) info.State = "运行中"; else info.State = "停止"; info.ProgressText = this.ProgressText; byte[] baResultText = null; ; long lOffset = 0; long lTotalLength = 0; this.GetResultText(lResultStart, nMaxResultBytes, out baResultText, out lOffset, out lTotalLength); info.ResultText = baResultText; info.ResultOffset = lOffset; info.ResultTotalLength = lTotalLength; info.ResultVersion = this.ProgressFileVersion; return info; } finally { this.m_lock.ReleaseReaderLock(); } }
// 按照命令启动一个批处理任务(不是自动启动) public int StartBatchTask(string strName, BatchTaskInfo param, out BatchTaskInfo info, out string strError) { strError = ""; info = null; // 2007/12/18 if (this.HangupReason == HangupReason.LogRecover) { strError = "当前系统正处在LogRecover挂起状态,无法启动新的批处理任务"; return -1; } BatchTask task = this.BatchTasks.GetBatchTask(strName); // 创建新的任务 if (task == null) { /* if (strName == "预约到书管理") task = new ArriveMonitor(this, strName); else if (strName == "日志恢复") task = new OperLogRecover(this, strName); else if (strName == "跟踪DTLP数据库") task = new TraceDTLP(this, strName); else if (strName == "正元一卡通读者信息同步") task = new ZhengyuanReplication(this, strName); else if (strName == "迪科远望一卡通读者信息同步") task = new DkywReplication(this, strName); else if (strName == "超期通知") task = new ReadersMonitor(this, strName); else if (strName == "消息监控") task = new MessageMonitor(this, strName); else { strError = "系统不能识别任务名 '" + strName + "'"; return -1; } * */ strError = "系统不能识别任务名 '" + strName + "'"; return -1; try { this.BatchTasks.Add(task); } catch (Exception ex) { strError = ex.Message; return -1; } } else { bool bOldStoppedValue = task.Stopped; // 激活 2007/10/10 task.eventActive.Set(); task.ManualStart = true; // 表示为命令启动 if (bOldStoppedValue == false) { strError = "任务 " + task.Name + " 已经在运行中,不能重复启动。本次操作激活了这个任务。"; return -1; } } // 执行日志恢复任务前,需要先中断正在执行的其他任何任务 // TODO: 日志恢复 任务结束后,原先中断的那些任务并不会自动去启动。需要系统管理员手动重新启动一次Application if (strName == "日志恢复") { StopAllBatchTasks(); } task.ManualStart = true; // 表示为命令启动 task.StartInfo = param.StartInfo; task.ClearProgressFile(); // 清除进度文件内容 task.StartWorkerThread(); // 激活 2007/10/10 task.eventActive.Set(); info = task.GetCurrentInfo(param.ResultOffset, param.MaxResultBytes); return 0; }