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>

备注

您可以获得一个EnterpriseResource对象编辑EnterpriseResourceCollection对象上使用的GetByGuid, GetById或GetByUser方法。当您更改了某个可编辑的属性,和 Project Server 自动将签出该资源,然后保存更改,进行更改,然后将该资源签入。这是类似于在Project Professional 2013中打开企业资源、 编辑,然后保存并关闭的企业资源的过程。

示例

下面的示例使用GetByGuid方法来获取EnterpriseResource对象以便进行编辑。本示例切换从True到False的CanLevel属性。

如果该资源已签出,则本示例将引发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:

线程安全性

该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。

另请参阅

引用

EnterpriseResourceCollection 成员

Microsoft.ProjectServer.Client 命名空间

EnterpriseResource

EnterpriseResourceCreationInformation

EnterpriseResources