EnterpriseResourceCollection - Classe

Représente une collection d'objets EnterpriseResource .

Hiérarchie d’héritage

System.Object
  Microsoft.SharePoint.Client.ClientObject
    Microsoft.SharePoint.Client.ClientObjectCollection
      Microsoft.SharePoint.Client.ClientObjectCollection<EnterpriseResource>
        Microsoft.ProjectServer.Client.EnterpriseResourceCollection

Espace de noms :  Microsoft.ProjectServer.Client
Assembly :  Microsoft.ProjectServer.Client (dans Microsoft.ProjectServer.Client.dll)

Syntaxe

'Déclaration
<ScriptTypeAttribute("PS.EnterpriseResourceCollection", ServerTypeId := "{4906f478-38f2-405a-aeb9-3533866f500d}")> _
Public Class EnterpriseResourceCollection _
    Inherits ClientObjectCollection(Of EnterpriseResource)
'Utilisation
Dim instance As EnterpriseResourceCollection
[ScriptTypeAttribute("PS.EnterpriseResourceCollection", ServerTypeId = "{4906f478-38f2-405a-aeb9-3533866f500d}")]
public class EnterpriseResourceCollection : ClientObjectCollection<EnterpriseResource>

Remarques

Vous pouvez obtenir un objet EnterpriseResource pour le modifier à l'aide de la méthode GetByGuid, GetByIdou GetByUser sur l'objet EnterpriseResourceCollection . Lorsque vous apportez une modification à l'une des propriétés modifiables, puis que vous enregistrez la modification, Project Server extrait automatiquement de la ressource, effectue la modification, puis vérifie de nouveau la ressource. Ceci est similaire au processus d'ouverture d'une ressource d'entreprise dans Project Professionnel 2013, sa modification, l'enregistrement et la fermeture de la ressource d'entreprise.

Exemples

L'exemple suivant utilise la méthode GetByGuid pour obtenir un objet EnterpriseResource pour le modifier. L'exemple fait basculer la propriété de CanLevel de True à False.

Si la ressource est déjà extrait, l'exemple lève un PJClientCallableException, par exemple CICOAlreadyCheckedOutToYou. Vous pouvez utiliser Try –Catch instructions pour gérer l'exception, ou utiliser la propriété IsCheckedOut pour déterminer si une modification peut être effectuée.

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

Voici un exemple de sortie :

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:

Cohérence de thread

Tous les membres statique (Partagé dans Visual Basic)s publics de ce type sont thread-safe. Cela n’est pas garanti pour les membres d’instance.

Voir aussi

Référence

EnterpriseResourceCollection - Membres

Microsoft.ProjectServer.Client - Espace de noms

EnterpriseResource

EnterpriseResourceCreationInformation

EnterpriseResources