Compartir a través de


del método DraftProject.Update

Guarda los cambios en un proyecto nuevo o proyecto desprotegido a Project Server.

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

Sintaxis

'Declaración
<RemoteAttribute> _
Public Function Update As QueueJob
'Uso
Dim instance As DraftProject
Dim returnValue As QueueJob

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

Valor devuelto

Tipo: Microsoft.ProjectServer.Client.QueueJob
Un objeto QueueJob que contiene información sobre el trabajo en cola. Si el trabajo en cola se realiza correctamente, el servicio de cola de Project Server guarda la versión nueva o borrador del proyecto.

Comentarios

El método Update no puede procesar una solicitud de OMSC superior a 2 MB de tamaño. Para obtener más información acerca de las limitaciones de OMSC, consulte What the CSOM does and does not do.

Ejemplos

El ejemplo siguiente muestra el problema de la creación de una solicitud de OMSC es mayor que 2 MB de tamaño. En el ejemplo se llama al método TestCreateTasks dos veces, primero para agregar 252 tareas a un proyecto y, a continuación, intente 253 tareas. Dado que la cantidad de datos en la segunda solicitud supera los 2 MB, se produce un error en la solicitud.

El método TestCreateTasksInGroups implementa una manera de romper una solicitud grande en grupos más pequeños.

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

A continuación es el resultado de ejecutar el ejemplo 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:

Vea también

Referencia

clase DraftProject

Miembros DraftProject

Espacio de nombres Microsoft.ProjectServer.Client