Partager via


DraftProject.Update - Méthode

Enregistre les modifications dans un nouveau projet ou un projet extrait projet sur Project Server.

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

Syntaxe

'Déclaration
<RemoteAttribute> _
Public Function Update As QueueJob
'Utilisation
Dim instance As DraftProject
Dim returnValue As QueueJob

returnValue = instance.Update()
[RemoteAttribute]
public QueueJob Update()

Valeur renvoyée

Type : Microsoft.ProjectServer.Client.QueueJob
Un objet QueueJob qui contient des informations sur la tâche en file d'attente. Si la tâche de file d'attente est réussie, le Service de Queuing Project Server enregistre la version nouveau ou un projet du projet.

Remarques

La méthode Update ne peut pas traiter une demande CSOM supérieure à 2 Mo. Pour plus d'informations sur les limitations de CSOM, consultez What the CSOM does and does not do.

Exemples

L'exemple suivant montre le problème de la création d'une demande CSOM est supérieure à 2 Mo. L'exemple appelle la méthode TestCreateTasks deux fois, tout d'abord pour ajouter des tâches de 252 à un projet, puis à essayer de 253 tâches. Dans la mesure où la quantité de données dans la deuxième demande dépasse 2 Mo, la demande échoue.

La méthode TestCreateTasksInGroups met en œuvre un moyen d'interrompre une demande importante en groupes plus petits.

using System;
using System.Net;
using Microsoft.ProjectServer.Client;
using Microsoft.SharePoint.Client;

namespace LimitTest
{
    internal static class Program
    {
        const int SUCCESS = 0;
        const int ERROR = 1;

        private static void Main()
        {
            using (var context = CreateContext())
            {
                // Create a request of less than 2 MB.
                int numTasks = 252;
                TestCreateTasks(context, numTasks);

                // Create a request that is greater than 2 MB.
                numTasks = 253;
                TestCreateTasks(context, numTasks);

                // Break a large request into groups of less than 2 MB.
                numTasks = 301;
                int groupCount = 200;
                TestCreateTasksInGroups(context, numTasks, groupCount);
            }
            exitApp(SUCCESS);
        }

        private static ProjectContext CreateContext()
        {
            const string url = "https://ServerName/pwa";     // Change the PWA URL.
            var context = new ProjectContext(url);
            return context;
        }

        private static void TestCreateTasks(ProjectContext context, int taskCount)
        {
            PublishedProject project;
            DraftProject projectDraft = null;

            Console.WriteLine("\n*** Creating project for {0} tasks", taskCount);
            var projectInfo = new ProjectCreationInformation();
            projectInfo.Id = Guid.NewGuid();
            projectInfo.Name = "LimitTest_" + taskCount + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss");
            projectInfo.Start = DateTime.Today;

            project = context.Projects.Add(projectInfo);

            var job = context.Projects.Update();

            if (WaitForJob(context, job))
            {
                projectDraft = project.CheckOut();

                Console.WriteLine("Creating the {0} tasks", taskCount);

                for (var i = 0; i < taskCount; i++)
                {
                    CreateTask(projectDraft.Tasks, i);
                }

                Console.WriteLine("Calling DraftProject.Update for project: {0}", projectInfo.Name);

                job = projectDraft.Update();
            }
            else
            {
                Console.WriteLine("\nThe Update job failed for Projects.Add.");
                exitApp(ERROR);
            }

            Console.WriteLine("\tWaitForJob: after DraftProject:Update");

            if (WaitForJob(context, job))
            {
                Console.WriteLine("\nChecking in and publishing project");
                job = projectDraft.Publish(true);
                Console.WriteLine("\tWaitForJob: after DraftProject.Publish");

                if (!WaitForJob(context, job))
                {
                    Console.WriteLine("\nThe DraftProject.Publish job failed for the project.");
                    exitApp(ERROR);
                }
            }
            else
            {
                Console.WriteLine("\nThe DraftProject.Update job failed for adding {0} tasks.", taskCount);
            }

            Console.WriteLine();
        }

        private static void TestCreateTasksInGroups(ProjectContext context, int taskCount, int groupCount)
        {
            PublishedProject project;
            DraftProject projectDraft = null;
            int numGroups = taskCount / groupCount;
            int remainingTasks = taskCount % groupCount;

            if (remainingTasks > 0) numGroups++;

            var projectInfo = new ProjectCreationInformation();
            projectInfo.Id = Guid.NewGuid();
            projectInfo.Name = "LimitTest_" + taskCount + "_groupCount_" + groupCount 
                + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss");
            projectInfo.Start = DateTime.Today;
            Console.WriteLine("\n*** Creating project for {0} tasks in groups of {1}:\n\t{2}", 
                taskCount, groupCount, projectInfo.Name);

            project = context.Projects.Add(projectInfo);
            var job = context.Projects.Update();

            if (WaitForJob(context, job))
            {
                int tasks2Create = groupCount;

                projectDraft = project.CheckOut();

                for (int i = 0; i < numGroups; i++)
                {
                    if (i == numGroups - 1) tasks2Create = remainingTasks;

                    Console.WriteLine("\nCreating group {0}: {1} tasks", i, tasks2Create);

                    for (int t = 0; t < tasks2Create; t++)
                    {
                        CreateTask(projectDraft.Tasks, i);
                    }

                    Console.WriteLine("Calling DraftProject.Update for task group: {0}", i);
                    job = projectDraft.Update();

                    if (WaitForJob(context, job))
                    {
                        Console.WriteLine("\n\tSuccess: DraftProject.Update job complete");
                    }
                    else
                    {
                        Console.WriteLine("\nThe DraftProject.Update job failed.");
                        exitApp(ERROR);
                    }
                }
                Console.WriteLine("\nPublishing the project");
                job = projectDraft.Publish(true);

                if (WaitForJob(context, job))
                {
                    Console.WriteLine("\nThe project '{0}'\n\tis published, with {1} tasks.", 
                        projectInfo.Name, taskCount);
                }
                else
                {
                    Console.WriteLine("\nThe DraftProject.Publish job failed.");
                    exitApp(ERROR);
                }
            }
        }

        private static void exitApp(int exitCode)
        {
            Console.Write("Press any key to exit: ");
            Console.ReadKey(true);
            Environment.Exit(exitCode);
        }

        private static void CreateTask(DraftTaskCollection draftTasks, int i)
        {
            var taskInfo = new TaskCreationInformation();
            taskInfo.Id = Guid.NewGuid();
            taskInfo.Name = i.ToString();
            taskInfo.IsManual = false;
            taskInfo.Duration = "1d";

            draftTasks.Add(taskInfo);
        }

        private static bool WaitForJob(ProjectContext context, QueueJob job)
        {
            bool result = true;

            try
            {
                context.WaitForQueue(job, int.MaxValue);
            }
            catch (ServerException ex)
            {
                Console.WriteLine("\n" + ex);
                result = false;
            }
            return result;
        }
    }
}

Voici le résultat de l'exécution de l'exemple LimitTest :

*** Creating project for 252 tasks
Creating the 252 tasks
Calling DraftProject.Update for project: LimitTest_252_20120530_084023
        WaitForJob: after DraftProject:Update

Checking in and publishing project
        WaitForJob: after DraftProject.Publish


*** Creating project for 253 tasks
Creating the 253 tasks
Calling DraftProject.Update for project: LimitTest_253_20120530_084224
        WaitForJob: after DraftProject:Update

Microsoft.SharePoint.Client.ServerException: The request uses too many resources.
   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
   at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
   at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
   at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
   at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
   at Microsoft.ProjectServer.Client.ProjectContext.WaitForQueue(QueueJob job, Int32 timeoutSeconds)
   at LimitTest.Program.WaitForJob(ProjectContext context, QueueJob job) 
      in d:\Project\P15\CSOM\CSOMLimitTest\Program.cs:line 193

The DraftProject.Update job failed for adding 253 tasks.


*** Creating project for 301 tasks in groups of 200: 
        LimitTest_301_groupCount_200_20120530_085506

Creating group 0: 200 tasks
Calling DraftProject.Update for task group: 0

        Success: DraftProject.Update job complete

Creating group 1: 101 tasks
Calling DraftProject.Update for task group: 1

        Success: DraftProject.Update job complete

Publishing the project

The project 'LimitTest_301_groupCount_200_20120530_085506' 
        is published, with 301 tasks.

Press any key to exit:

Voir aussi

Référence

DraftProject classe

DraftProject - Membres

Microsoft.ProjectServer.Client - Espace de noms