Clase EnterpriseResource

Representa un recurso administrado en un proyecto de Project Server.

Jerarquía de la herencia

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

Espacio de nombres:  Microsoft.ProjectServer.Client
Ensamblado:  Microsoft.ProjectServer.Client (en Microsoft.ProjectServer.Client.dll)

Sintaxis

'Declaración
<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

Comentarios

Puede obtener un objeto EnterpriseResource para la edición mediante el método GetByGuid, GetByIdo GetByUser en el objeto EnterpriseResourceCollection . Cuando se realiza un cambio en una de las propiedades editables y guarda el cambio, Project Server comprueba automáticamente el recurso, hace el cambio y, a continuación, vuelve a registrar el recurso. Esto es similar al proceso de abrir un recurso de empresa en Project Profesional 2013, edición y, a continuación, guardar y cerrar el recurso de empresa.

Ejemplos

En el ejemplo siguiente se utiliza el método EnterpriseResourceCollection.GetByGuid para obtener un objeto EnterpriseResource para su edición. En el ejemplo se alterna la propiedad de CanLevel de True a False.

Si el recurso ya está desprotegido, el ejemplo produce una PJClientCallableException, como CICOAlreadyCheckedOutToYou. Puede utilizar Try : instrucciones deCatch para controlar la excepción, o utilice la propiedad IsCheckedOut para determinar si se puede realizar una edición.

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

La siguiente es la salida de ejemplo:

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:

Seguridad para subprocesos

Los miembros static (Shared en Visual Basic) públicos de este tipo son seguros para subprocesos. No se garantiza que los miembros de instancias sean seguros para los subprocesos.

Vea también

Referencia

Miembros EnterpriseResource

Espacio de nombres Microsoft.ProjectServer.Client