我有一个 Project Online 解决方案,需要从 LookupTable (Microsoft.ProjectServer.Client.LookupTable) 中删除项目,因为我需要在添加新项目之前清除它。主要用途是在我创建项目的地方进行单元测试,然后在测试完成后清除所有内容。
每次运行此程序时,我都会收到代码为 0x80131500 (-2146233088) 的异常,并显示错误消息“PJClientCallableException: CICONotCheckedOut\r\nCICONotCheckedOut”,执行 ExecuteQuery 时会引发异常。
我可以添加新项目并将现有项目更改为 LookupTable,而无需检查任何内容。并且 LookupTable 上没有 CheckOut 方法。所以我不知道该怎么办...
Project Online 的唯一选项是使用 Project Server CSOM API,不能使用 PSI。
例外:
Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at <mynamespace>.LookupTableHelper.DeleteAllItems(Guid tableGuid)
代码:
// Create password
SecureString securePassword = new SecureString();
foreach (char c in "qwerty") securePassword.AppendChar(c);
Microsoft.SharePoint.Client.SharePointOnlineCredentials cred = new Microsoft.SharePoint.Client.SharePointOnlineCredentials("a@b.com", securePassword);
// Connect
ProjectContext context = new ProjectContext(urlToProjectOnlineWeb);
context.Credentials = cred;
// Get entries in lookup table
LookupTable lookupTable = context.LookupTables.GetByGuid(tableGuid);
context.Load(lookupTable.Entries);
context.ExecuteQuery();
if (lookupTable.Entries.Count > 0)
{
// If there are items in the collection, then remove the first item
LookupEntry e = lookupTable.Entries[0];
lookupTable.Entries.Remove(e);
}
// Upload the change to cloud
context.LookupTables.Update();
context.ExecuteQuery(); // Always throw PJClientCallableException: CICONotCheckedOut\r\nCICONotCheckedOut
解决方案(至少是迄今为止最好的)是首先执行添加以签出表格,然后删除所有现有项目。这给我留下了一件无法移除的物品。但总比不能删除任何东西要好...谢谢 Jogeukens!
// Create password
SecureString securePassword = new SecureString();
foreach (char c in Configuration.GetConfig().PASSWORD.ToCharArray()) securePassword.AppendChar(c);
Microsoft.SharePoint.Client.SharePointOnlineCredentials cred = new Microsoft.SharePoint.Client.SharePointOnlineCredentials(Configuration.GetConfig().USERNAME, securePassword);
// Connect
ProjectContext context = new ProjectContext(Configuration.GetConfig().PPM_URL);
context.Credentials = cred;
// Get entries in lookup table
LookupTable lookupTable = context.LookupTables.GetByGuid(tableGuid);
context.Load(lookupTable.Entries);
context.ExecuteQuery();
LookupEntryCreationInformation newEntry = new LookupEntryCreationInformation();
newEntry.Id = Guid.NewGuid();
newEntry.Value = new LookupEntryValue();
newEntry.Value.TextValue = "The one that cannot be removed...";
lookupTable.Entries.Add(newEntry);
while(lookupTable.Entries.Count > 1)
{
// If there are items in the collection, then remove the first item
LookupEntry e = lookupTable.Entries[0];
lookupTable.Entries.Remove(e);
}
// Upload the change to cloud
context.LookupTables.Update();
context.ExecuteQuery();