Project Server 2013:如何使用 PSI 更改项目所有者
Posted
技术标签:
【中文标题】Project Server 2013:如何使用 PSI 更改项目所有者【英文标题】:Project Server 2013 : How to Change Project owner Using PSI 【发布时间】:2015-07-09 15:48:55 【问题描述】:我需要使用 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.
【问题讨论】:
微软如何记录(或者我应该说,不记录)他们的东西是愚蠢的。我正在尝试使用 REST API 更改项目所有者,但我无法让它工作。我在互联网上找不到任何东西......这太荒谬了。或者我太愚蠢了,无法弄清楚这是如何工作的。我不知道。 【参考方案1】:以下是我已经尝试过的第一种方法
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;
【讨论】:
以上是关于Project Server 2013:如何使用 PSI 更改项目所有者的主要内容,如果未能解决你的问题,请参考以下文章
如何使用IntelliJ IDEA 14创建基于Maven3的Java Web Project
任何人都知道如何通过 C# 为 Project Server 2003 创建项目/任务?