共用方式為


EnterpriseResourceCollection 類別

代表EnterpriseResource物件的集合。

繼承階層架構

System.Object
  Microsoft.SharePoint.Client.ClientObject
    Microsoft.SharePoint.Client.ClientObjectCollection
      Microsoft.SharePoint.Client.ClientObjectCollection<EnterpriseResource>
        Microsoft.ProjectServer.Client.EnterpriseResourceCollection

命名空間:  Microsoft.ProjectServer.Client
組件:  Microsoft.ProjectServer.Client (在 Microsoft.ProjectServer.Client.dll 中)

語法

'宣告
<ScriptTypeAttribute("PS.EnterpriseResourceCollection", ServerTypeId := "{4906f478-38f2-405a-aeb9-3533866f500d}")> _
Public Class EnterpriseResourceCollection _
    Inherits ClientObjectCollection(Of EnterpriseResource)
'用途
Dim instance As EnterpriseResourceCollection
[ScriptTypeAttribute("PS.EnterpriseResourceCollection", ServerTypeId = "{4906f478-38f2-405a-aeb9-3533866f500d}")]
public class EnterpriseResourceCollection : ClientObjectCollection<EnterpriseResource>

備註

您可以編輯EnterpriseResourceCollection物件上使用GetByGuid、 GetById或GetByUser方法來取得EnterpriseResource物件。當您的其中一個可編輯的屬性,進行變更,然後儲存變更,Project Server 取出資源進行變更,然後檢查資源回。這是類似於在Project Professional 2013中開啟企業資源、 編輯,然後儲存並關閉企業資源的程序。

範例

下列範例會使用GetByGuid方法來取得EnterpriseResource物件,以便編輯。此範例會切換False從TrueCanLevel屬性。

如果資源已取出,此範例會擲回PJClientCallableException,例如CICOAlreadyCheckedOutToYou。您可以使用Try –Catch陳述式來處理的例外狀況,或使用IsCheckedOut屬性來判斷是否可以進行編輯。

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);
        }
    }
}

以下是範例輸出:

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:

執行緒安全

這類型的任何公用 static (共用 於 Visual Basic 中) 成員是安全執行緒。不保證任何執行個體成員都是安全執行緒。

請參閱

參照

EnterpriseResourceCollection 成員

Microsoft.ProjectServer.Client 命名空間

EnterpriseResource

EnterpriseResourceCreationInformation

EnterpriseResources