Share via


EnterpriseResource classe

Representa um recurso que é gerenciado pelo servidor de projeto em um projeto.

Inheritance hierarchy

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

Namespace:  Microsoft.ProjectServer.Client
Assembly:  Microsoft.ProjectServer.Client (em Microsoft.ProjectServer.Client.dll)

Sintaxe

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

Comentários

Você pode obter um objeto EnterpriseResource para edição usando o método GetByGuid, GetByIdou GetByUser no objeto EnterpriseResourceCollection . Quando você fizer uma alteração em uma das propriedades editáveis e, em seguida, salva a alteração, Project Server faz automaticamente check-out do recurso, faz alterações e verifica o recurso novamente. Isso é semelhante ao processo de abertura de um recurso da empresa em Project Professional 2013, editá-lo e, em seguida, salvando e fechando o recurso da empresa.

Exemplos

O exemplo a seguir usa o método EnterpriseResourceCollection.GetByGuid para obter um objeto EnterpriseResource para edição. O exemplo alterna a propriedade de CanLevel de True para False.

Se o recurso já fez check-out, o exemplo lança um PJClientCallableException, como CICOAlreadyCheckedOutToYou. Você pode usar Try – instruções deCatch para tratar a exceção, ou usar a propriedade IsCheckedOut para determinar se uma edição pode ser feita.

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

A seguir está um exemplo de saída:

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:

Segurança de thread

Os membros públicos estática (Shared no Visual Basic) desse tipo são seguros para thread. Nenhum membro de instância pode ser garantido como seguro para thread.

Ver também

Referência

EnterpriseResource membros

Microsoft.ProjectServer.Client namespace