Share via


EnterpriseResource クラス

プロジェクトで、Project Server で管理されているリソースを表します。

継承階層

System.Object
  Microsoft.SharePoint.Client.ClientObject
    Microsoft.ProjectServer.Client.EnterpriseResource

名前空間:  Microsoft.ProjectServer.Client
アセンブリ:  Microsoft.ProjectServer.Client (Microsoft.ProjectServer.Client.dll 内)

構文

'宣言
<ScriptTypeAttribute("PS.EnterpriseResource", ServerTypeId := "{f6167b82-e04e-4ce2-8631-09ce14f6277e}")> _
Public Class EnterpriseResource _
    Inherits ClientObject
'使用
Dim instance As EnterpriseResource
[ScriptTypeAttribute("PS.EnterpriseResource", ServerTypeId = "{f6167b82-e04e-4ce2-8631-09ce14f6277e}")]
public class EnterpriseResource : ClientObject

注釈

EnterpriseResourceCollectionオブジェクトで、 GetByGuid、 GetById、またはGetByUserメソッドを使用して編集するためのEnterpriseResourceオブジェクトを取得できます。編集可能なプロパティのいずれかに変更を加えるし、Project Server が自動的にチェック アウトは、リソースに変更を保存するときに、変更し、リソースをチェックインします。これは、 Project Professional 2013でエンタープライズ リソースを開く、編集、保存し、エンタープライズ リソースを閉じるのプロセスに似ています。

次の使用例は、 EnterpriseResourceCollection.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:

スレッド セーフ

この型のパブリック static (Visual Basic のShared ) メンバーはいずれもスレッド セーフです。インスタンス メンバーはスレッド セーフになるという保証はありません。

関連項目

参照先

EnterpriseResource メンバー

Microsoft.ProjectServer.Client 名前空間