DraftProject.Update method

Office 2013

Saves changes in a new project or checked-out draft project back to Project Server.

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

[RemoteAttribute]
public QueueJob Update()

Return value

Type: Microsoft.ProjectServer.Client.QueueJob
A QueueJob object that contains information about the queued job. If the queue job is successful, the Project Server Queuing Service saves the new or draft version of the project.

The Update method cannot process a CSOM request greater than 2 MB in size. For more information about CSOM limitations, see What the CSOM does and does not do.

The following example shows the problem of creating a CSOM request that is greater than 2 MB in size. The example calls the TestCreateTasks method twice, first to add 252 tasks to a project, and then to try 253 tasks. Because the amount of data in the second request exceeds 2 MB, the request fails.

The TestCreateTasksInGroups method implements one way to break a large request into smaller groups.

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 = "http://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;
        }
    }
}

Following is the output from running the LimitTest example:


*** 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:

Community Additions

ADD
Show:
© 2014 Microsoft