如何更快地更新项目自定义字段?

时间:2019-06-21 11:58:38

标签: c# server project

我已经完成了更新我的项目自定义字段的代码。但是它运行有点慢。我试图使速度更快,但失败了。有没有人知道如何更快地运行它?

  var ctx = new ProjectContext(FinaleUrl);

            ctx.Credentials = creds;
            ctx.Load(ctx.Projects);
            ctx.ExecuteQuery();
            CustomFieldCollection customFields = ctx.CustomFields;
            ctx.Load(customFields);
            ctx.ExecuteQuery();

            foreach (PublishedProject pubProj in ctx.Projects)
            {
                foreach (DataRow row in dt.Rows)
                {
                    if (pubProj.ProjectIdentifier.ToString() == row["ProjectID"].ToString())
                        foreach (CustomField cf in customFields)
                        {

                            for (int i = 0; i < dt.Columns.Count; i++)
                            {
                                if (dt.Columns[i].ToString() == cf.Name)
                                {

                                    DraftProject draft = pubProj.Draft;
                                    JobState job1 = ctx.WaitForQueue(draft.CheckIn(true), 10);

                                    DraftProject check = pubProj.CheckOut();

                                    check.SetCustomFieldValue(cf.InternalName, row[cf.Name].ToString().Replace('.', ','));

                                    check.Update();
                                    ctx.Load(check);

                                    check.Publish(false);
                                    check.CheckIn(true);

                                    JobState jobState = ctx.WaitForQueue(ctx.Projects.Update(), 10);

                                    MessageBox.Show(cf.Id.ToString() + "\n" + cf.Name + "\n" + cf.InternalName);
                                }
                            }
                        }
                }
            } ;

0 个答案:

没有答案