Project Server调用PSI关闭任务以进行更新锁定任务



///
<summary> /// 锁定和解锁项目任务 /// </summary> /// <param name="projectuid">项目UID</param> /// <param name="islock">是否锁定</param> /// <returns></returns> public bool CloseProjectTask(Guid projectuid, bool islock) { try { QueueSystemUtils queuesystemutils = new QueueSystemUtils(); ProjectDataSet dst = GetProjectByUid(projectuid); StatusingWebSvc.ProjectDataSet statusing_pro_dst = new StatusingWebSvc.ProjectDataSet(); foreach (ProjectWebSvc.ProjectDataSet.TaskRow taskrow in dst.Task) { if (taskrow.TASK_LOCKDOWN_BY_MANAGER != islock) { taskrow.TASK_LOCKDOWN_BY_MANAGER = islock; statusing_pro_dst.Task.ImportRow(taskrow); } } if (statusing_pro_dst.Task.Count > 0) { int temp = 0; int total_update_count = 0; int totalcount = statusing_pro_dst.Task.Count; StatusingWebSvc.ProjectDataSet statusing_pro_dst_update = new StatusingWebSvc.ProjectDataSet(); foreach (StatusingWebSvc.ProjectDataSet.TaskRow item in statusing_pro_dst.Task) { temp++; total_update_count++; statusing_pro_dst_update.Task.ImportRow(item); if (total_update_count >= 400 || temp >= totalcount) { Guid jobuid = Guid.NewGuid(); StatusingClient.QueueLockDownTasks(jobuid, projectuid, statusing_pro_dst_update); queuesystemutils.WaitForQueue(jobuid); total_update_count = 0; statusing_pro_dst_update = new StatusingWebSvc.ProjectDataSet(); } } } return true; } catch (Exception ex) { new LogHelper().WriteLine(ex.ToString()); return false; } }

注意:如果计划任务数量超过500条,会出现错误,必须分批去处理任务,调用QueueLockDownTasks来关闭项目任务已更新,锁定和解锁项目计划任务

posted on 2016-05-25 23:24  larryle  阅读(477)  评论(0编辑  收藏  举报