1

我需要使用 PSI 更新项目所有者,因为我需要使其成为一个自动过程。我有以下几组用于更改项目所有者的代码,但它们都没有奏效。

以下是我已经尝试过的第一种方法

private static bool UpdateProjectOwner()
{
   bool projUpdated = false;
   try
   {
     User newOwner = projContext.Web.SiteUsers.GetByLoginName(Username);
     Guid ProjectGuid = ProjectUID;
     //Console.Write("\nUpdating owner to {1} on project: {0} ...," ProjectGuid, Username);
     DraftProject draftProjectToUpdate = projContext.Projects.GetByGuid(ProjectGuid).CheckOut();
     draftProjectToUpdate.Owner = newOwner;
     QueueJob qJob = draftProjectToUpdate.Update();
     projContext.Load(qJob);
     projContext.ExecuteQuery();
     JobState jobState = projContext.WaitForQueue(qJob, timeoutSeconds);

      QueueJob qJob2 = draftProjectToUpdate.CheckIn(false);
      projContext.Load(qJob2);
      projContext.ExecuteQuery();
      JobState jobState2 = projContext.WaitForQueue(qJob2, timeoutSeconds);
     }
     catch (Exception ex)
     {
       Console.ForegroundColor = ConsoleColor.Red;
       Console.WriteLine(ex.Message);
       Console.ResetColor();
      }
   return projUpdated;
}

以下是我已经尝试过的第二种方式

String projectOwnerIDstrNew = Convert.ToString(dr["ProjectOwnerUID"]);                        
String projectOwnerIDstrOriginal = Convert.ToString(project_Ds.Project[0].ProjectOwnerID);
if (!projectOwnerIDstrNew.Equals(projectOwnerIDstrOriginal))
{                             
 Guid ownerID = new Guid(projectOwnerIDstrNew);
 project_Ds.Project[0].ProjectOwnerID = ownerID;
 project_Ds.AcceptChanges();

bool managerChanged = true;

}

Is there any mistake in these above functions ?

If Not, then is there any other way of updating the project owner with help of PSI.
4

1 回答 1

0

以下是我已经尝试过的第一种方法

private static bool UpdateProjectOwner()
{
   bool projUpdated = false;
   try
   {
     User newOwner = projContext.Web.SiteUsers.GetByLoginName(Username);
     Guid ProjectGuid = ProjectUID;
     //Console.Write("\nUpdating owner to {1} on project: {0} ...," ProjectGuid, Username);
     DraftProject draftProjectToUpdate = projContext.Projects.GetByGuid(ProjectGuid).CheckOut();
     draftProjectToUpdate.Owner = newOwner;
     QueueJob qJob = draftProjectToUpdate.Update();
     projContext.Load(qJob);
     projContext.ExecuteQuery();
     JobState jobState = projContext.WaitForQueue(qJob, timeoutSeconds);

      QueueJob qJob2 = draftProjectToUpdate.CheckIn(false);
      projContext.Load(qJob2);
      projContext.ExecuteQuery();
      JobState jobState2 = projContext.WaitForQueue(qJob2, timeoutSeconds);
     }
     catch (Exception ex)
     {
       Console.ForegroundColor = ConsoleColor.Red;
       Console.WriteLine(ex.Message);
       Console.ResetColor();
      }
   return projUpdated;
}

以下是我已经尝试过的第二种方式

String projectOwnerIDstrNew = Convert.ToString(dr["ProjectOwnerUID"]);                        
String projectOwnerIDstrOriginal = Convert.ToString(project_Ds.Project[0].ProjectOwnerID);
if (!projectOwnerIDstrNew.Equals(projectOwnerIDstrOriginal))
{                             
 Guid ownerID = new Guid(projectOwnerIDstrNew);
 project_Ds.Project[0].ProjectOwnerID = ownerID;
 project_Ds.AcceptChanges();

bool managerChanged = true;

}
于 2016-06-18T09:31:20.853 回答