EnterpriseResourceCollection class
Represents a collection of EnterpriseResource objects.
Inheritance hierarchy
System.Object
Microsoft.SharePoint.Client.ClientObject
Microsoft.SharePoint.Client.ClientObjectCollection
Microsoft.SharePoint.Client.ClientObjectCollection<EnterpriseResource>
Microsoft.ProjectServer.Client.EnterpriseResourceCollection
Namespace: Microsoft.ProjectServer.Client
Assembly: Microsoft.ProjectServer.Client (in Microsoft.ProjectServer.Client.dll)
Syntax
'Declaration
<ScriptTypeAttribute("PS.EnterpriseResourceCollection", ServerTypeId := "{4906f478-38f2-405a-aeb9-3533866f500d}")> _
Public Class EnterpriseResourceCollection _
Inherits ClientObjectCollection(Of EnterpriseResource)
'Usage
Dim instance As EnterpriseResourceCollection
[ScriptTypeAttribute("PS.EnterpriseResourceCollection", ServerTypeId = "{4906f478-38f2-405a-aeb9-3533866f500d}")]
public class EnterpriseResourceCollection : ClientObjectCollection<EnterpriseResource>
Remarks
You can get an EnterpriseResource object for editing by using the GetByGuid, GetById, or GetByUser method on the EnterpriseResourceCollection object. When you make a change to one of the editable properties, and then save the change, Project Server automatically checks out the resource, makes the change, and then checks the resource back in. This is similar to the process of opening an enterprise resource in Project Professional 2013, editing it, and then saving and closing the enterprise resource.
Examples
The following example uses the GetByGuid method to get an EnterpriseResource object for editing. The example toggles the CanLevel property from True to False.
If the resource is already checked out, the example throws a PJClientCallableException, such as CICOAlreadyCheckedOutToYou. You can use Try –Catch statements to handle the exception, or use the IsCheckedOut property to determine whether an edit can be done.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.ProjectServer.Client;
namespace EditEntResource
{
class Program
{
private const string pwaPath = "https://ServerName/pwa/"; // Change the path for your Project Web App.
// Set the Project Server client context.
private static ProjectContext projContext;
static void Main(string[] args)
{
projContext = new ProjectContext(pwaPath);
Guid entResUid = new Guid("9f164f32-d985-e211-93f8-0021704e28a0");
// Get the list of enterprise resources in Project Web App.
projContext.Load(projContext.EnterpriseResources);
projContext.ExecuteQuery();
int numResInCollection = projContext.EnterpriseResources.Count();
if (numResInCollection > 0)
{
projContext.Load(projContext.EnterpriseResources.GetByGuid(entResUid));
projContext.ExecuteQuery();
var entRes2Edit = projContext.EnterpriseResources.GetByGuid(entResUid);
Console.WriteLine("\nEditing resource : GUID : Can Level");
Console.WriteLine("\n{0} : {1} : {2}", entRes2Edit.Name, entRes2Edit.Id.ToString(),
entRes2Edit.CanLevel.ToString());
// Toggle the CanLevel property.
entRes2Edit.CanLevel = !entRes2Edit.CanLevel;
// The entRes2Edit object is in the EnterpriseResources collection.
projContext.EnterpriseResources.Update();
// Save the change.
projContext.ExecuteQuery();
// Check that the change was made.
projContext.Load(projContext.EnterpriseResources.GetByGuid(entResUid));
projContext.ExecuteQuery();
entRes2Edit = projContext.EnterpriseResources.GetByGuid(entResUid);
Console.WriteLine("\n\nChanged resource : GUID : Can Level");
Console.WriteLine("\n{0} : {1} : {2}", entRes2Edit.Name, entRes2Edit.Id.ToString(),
entRes2Edit.CanLevel.ToString());
}
Console.Write("\nPress any key to exit: ");
Console.ReadKey(false);
}
}
}
Following is sample output:
Editing resource : GUID : Can Level
TestUser Name : 9f164f32-d985-e211-93f8-0021704e28a0 : True
Changed resource : GUID : Can Level
TestUser Name : 9f164f32-d985-e211-93f8-0021704e28a0 : False
Press any key to exit:
Thread safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See also
Reference
EnterpriseResourceCollection members
Microsoft.ProjectServer.Client namespace