使用CSOM仅使用1个项目发布来更新多个任务 [英] Using CSOM to update multiple tasks with only 1 project publish

查看:59
本文介绍了使用CSOM仅使用1个项目发布来更新多个任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我有以下代码更新某些任务字段。这段代码的问题在于我必须在逐个更新每个任务后发布整个项目。例如,如果我有500个要更新的任务,那么该项目必须发布500
次。正如您所看到的,这完全是过度的,缓慢的和不必要的。

 using(ProjectContext projectContext = GetClientContext(psCred))
{
projectContext.Load(projectContext.Projects);
projectContext.ExecuteQuery();

foreach(projectContext.Projects中的var项目)
{
var draftProject = project.CheckOut();
projectContext.Load(draftProject.Tasks);
projectContext.ExecuteQuery();

projectContext.Load(draftProject.Task);
projectContext.ExecuteQuery();

foreach(draftProject.Tasks中的var任务)
{
task [" FIELD"] =" VALUE" ;;

var job = draftProject.Update();
projectContext.WaitForQueue(job,int.MaxValue);

job = draftProject.Publish(true);
projectContext.WaitForQueue(job,int.MaxValue);
}
}
}

我确信(希望)有一种方法可以立即更新所有项目任务的更新只有一个在最后发布,就像Microsoft Project桌面应用程序一样。


如果有人可以请我指出正确的方向,我真的很感激。

解决方案

您应该简单地移出更新并发布到循环之外和之后。无需更新和发布每次迭代。


编辑:


我也很确定你不需要这个:

 projectContext.Load(draftProject.Task); 
projectContext.ExecuteQuery();


加载DraftTaskCollection就足够了。




Hello,

I have the following code that updates certain task fields. The problem with this code is that I have to publish an entire project after updating each task one-by-one. So for example, if I had 500 tasks to update, the project would have to be published 500 times. As you can see, this is completely overkill, slow and unnecessary.

using (ProjectContext projectContext = GetClientContext(psCred))
{
    projectContext.Load(projectContext.Projects);
    projectContext.ExecuteQuery();

    foreach (var project in projectContext.Projects)
    {
        var draftProject = project.CheckOut();
        projectContext.Load(draftProject.Tasks);
        projectContext.ExecuteQuery();

        projectContext.Load(draftProject.Task);
        projectContext.ExecuteQuery();

        foreach (var task in draftProject.Tasks)
        {
            task["FIELD"] = "VALUE";

            var job = draftProject.Update();
            projectContext.WaitForQueue(job, int.MaxValue);

            job = draftProject.Publish(true);
            projectContext.WaitForQueue(job, int.MaxValue);
        }
    }
}

I am sure (hope) there is a way to update update all of the project tasks at once with only one publish at the end just like how Microsoft Project desktop application does it.

I would really appreciate if someone can please point me into the right direction here.

解决方案

You should simply move out the update and publish to outside of and after the loop. No need to update and publish every iteration.

Edit:

I'm also pretty sure you don't need this:

projectContext.Load(draftProject.Task);
projectContext.ExecuteQuery();

Loading the DraftTaskCollection should be enough.



这篇关于使用CSOM仅使用1个项目发布来更新多个任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆