Класс 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

Замечания

Вы можете получить объект EnterpriseResource для редактирования с помощью метода GetByGuid, GetByIdили GetByUser на объекте EnterpriseResourceCollection . При внести изменения к одной из изменяемых свойств, а затем сохраните изменения, Project Server автоматически извлекает ресурсов, вносятся изменения, а затем проверяет, ресурса обратно в. Это следующий процесс открытия корпоративный ресурс в Project профессиональный 2013, редактирование и сохранение и закрытие корпоративный ресурс.

Примеры

В следующем примере метод EnterpriseResourceCollection.GetByGuid используется для получения объекта EnterpriseResource для редактирования. В примере выполняется переключение свойства CanLevel из TrueFalse.

Если ресурс уже извлечен, пример создает 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 (Shared в Visual Basic) этого типа являются потокобезопасными. Не гарантируется, что любые элементы экземпляров потокобезопасны.

См. также

Справочные материалы

Элементы EnterpriseResource

Пространство имен Microsoft.ProjectServer.Client