Project.QueueSynchronizeProjectWorkspace Method

Synchronizes the SharePoint data in the Reporting database for the specified project.

Namespace:  [Project Web service]
Service reference: http://ServerName:32843/[Project Service Application GUID]/PSI/Project.svc
Web service reference: http://ServerName/ProjectServerName/_vti_bin/PSI/Project.asmx?wsdl

Syntax

'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/QueueSynchronizeProjectWorkspace", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Project/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Project/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Sub QueueSynchronizeProjectWorkspace ( _
    jobUid As Guid, _
    projectUid As Guid, _
    forceFullSync As Boolean _
)
'Usage
Dim instance As Project
Dim jobUid As Guid
Dim projectUid As Guid
Dim forceFullSync As Boolean

instance.QueueSynchronizeProjectWorkspace(jobUid, _
    projectUid, forceFullSync)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/QueueSynchronizeProjectWorkspace", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Project/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Project/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public void QueueSynchronizeProjectWorkspace(
    Guid jobUid,
    Guid projectUid,
    bool forceFullSync
)

Parameters

  • projectUid
    Type: System.Guid
    The GUID of the project.
  • forceFullSync
    Type: System.Boolean
    If true, forces full synchronization.

Remarks

QueueSynchronizeProjectWorkspace is an asynchronous method that sends a message to the Project Server Queuing Service.

Project Server Permissions

Permission

Description

PublishProject

Allows a user to publish the specified project. Category permission.

Examples

The following example creates a sample project, creates a project site for it while publishing it, and then synchronizes the project site information with the reporting database.

For critical information about running this code sample, see Prerequisites for ASMX-Based Code Samples.

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Web.Services.Protocols;
using System.Threading;
using System.Data;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace Microsoft.SDK.Project.Samples.QueueSynchronizeProjectWorkspace
{
   class Program
   {
      [STAThread]
      static void Main()
      {
         try
         {
            #region Setup
            const string PROJECT_SERVER_URI = "https://ServerName/ProjectServerName/";
            const string PROJECT_SERVICE_PATH = "_vti_bin/psi/project.asmx";
            const string QUEUESYSTEM_SERVICE_PATH = "_vti_bin/psi/queuesystem.asmx";

            Guid sessionId = Guid.NewGuid();
            Guid jobId;

            // Set up the web service objects.
            ProjectWebSvc.Project projectSvc = new ProjectWebSvc.Project();

            projectSvc.Url = PROJECT_SERVER_URI + PROJECT_SERVICE_PATH;
            projectSvc.Credentials = CredentialCache.DefaultCredentials;

            QueueSystemWebSvc.QueueSystem q = new QueueSystemWebSvc.QueueSystem();
            q.Url = PROJECT_SERVER_URI + QUEUESYSTEM_SERVICE_PATH;
            q.Credentials = CredentialCache.DefaultCredentials;

            // Create a sample project.
            Console.WriteLine("Creating sample project");

            Guid projectId = CreateSampleProject(projectSvc, q);

            // Publish the project and create a workspace for it.
            // Note: A blank workspace name will cause Project Server to 
            //       create a workspace name from the project name.
            Console.WriteLine("Publishing and creating a workspace");
            jobId = Guid.NewGuid();
            projectSvc.QueuePublish(jobId, projectId, true, string.Empty);
            WaitForQueue(q, jobId);
            #endregion
            #region Synchronize Project Workspace
            // Synchronize the project in the Reporting database.
            Console.WriteLine("Synchronizing workspace info with the reporting database");
            jobId = Guid.NewGuid();
            projectSvc.QueueSynchronizeProjectWorkspace(jobId, projectId, true);
            WaitForQueue(q, jobId);
            #endregion

         }
         #region Exception Handling and Final
         catch (SoapException ex)
         {
            PSLibrary.PSClientError error = new PSLibrary.PSClientError(ex);
            PSLibrary.PSErrorInfo[] errors = error.GetAllErrors();
            string errMess = "==============================\r\nError: \r\n";
            for (int i = 0; i < errors.Length; i++)
            {
               errMess += "\n" + ex.Message.ToString() + "\r\n";
               errMess += "".PadRight(30, '=') + "\r\nPSCLientError Output:\r\n \r\n";
               errMess += errors[i].ErrId.ToString() + "\n";

               for (int j = 0; j < errors[i].ErrorAttributes.Length; j++)
               {
                  errMess += "\r\n\t" + errors[i].ErrorAttributeNames()[j] + ": " + errors[i].ErrorAttributes[j];
               }
               errMess += "\r\n".PadRight(30, '=');
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(errMess);
         }
         catch (WebException ex)
         {
            string errMess = ex.Message.ToString() +
               "\n\nLog on, or check the Project Server Queuing Service";
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Error: " + errMess);
         }
         catch (Exception ex)
         {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Error: " + ex.Message);
         }
         finally
         {
            Console.ResetColor();
            Console.WriteLine("\r\n\r\nPress any key...");
            Console.ReadKey();
         }
         #endregion
      }
       static private void WaitForQueue(QueueSystemWebSvc.QueueSystem q, Guid jobId)
      {
         QueueSystemWebSvc.JobState jobState;
         const int QUEUE_WAIT_TIME = 2; // two seconds
         bool jobDone = false;
         string xmlError = string.Empty;
         int wait = 0;

         // Wait for the project to get through the queue.
         // Get the estimated wait time in seconds.
         wait = q.GetJobWaitTime(jobId);

         // Wait for it.
         Thread.Sleep(wait * 1000);
         // Wait until it is finished.

         do
         {
            // Get the job state.
            jobState = q.GetJobCompletionState(jobId, out xmlError);

            if (jobState == QueueSystemWebSvc.JobState.Success)
            {
               jobDone = true;
            }
            else
            {
               if (jobState == QueueSystemWebSvc.JobState.Unknown
               || jobState == QueueSystemWebSvc.JobState.Failed
               || jobState == QueueSystemWebSvc.JobState.FailedNotBlocking
               || jobState == QueueSystemWebSvc.JobState.CorrelationBlocked
               || jobState == QueueSystemWebSvc.JobState.Canceled)
               {
                  // If the job failed, error out.
                  throw (new ApplicationException("Queue request " + jobState + " for Job ID " + jobId + ".\r\n" + xmlError));
               }
               else
               {
                  Console.WriteLine("Job State: " + jobState + " for Job ID: " + jobId);
                  Thread.Sleep(QUEUE_WAIT_TIME * 1000);
               }
            }
         }
         while (!jobDone);
      }
      static private Guid CreateSampleProject(ProjectWebSvc.Project projectSvc, QueueSystemWebSvc.QueueSystem q)
      {
         ProjectWebSvc.ProjectDataSet projectDs = new ProjectWebSvc.ProjectDataSet();
         Guid jobId;
         // Create the project.
         ProjectWebSvc.ProjectDataSet.ProjectRow projectRow = projectDs.Project.NewProjectRow();
         projectRow.PROJ_UID = Guid.NewGuid();
         projectRow.PROJ_NAME = "Its a wonderful project at " + 
            DateTime.Now.ToShortDateString().Replace("/", "") + " " + 
            DateTime.Now.ToShortTimeString().Replace(":", "");
         projectRow.PROJ_TYPE = (int)PSLibrary.Project.ProjectType.Project;
         projectDs.Project.AddProjectRow(projectRow);

         // Add some tasks.
         ProjectWebSvc.ProjectDataSet.TaskRow taskOne = projectDs.Task.NewTaskRow();
         taskOne.PROJ_UID = projectRow.PROJ_UID;
         taskOne.TASK_UID = Guid.NewGuid();
         // The Task Duration format must be specified.
         taskOne.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Day;
         taskOne.TASK_DUR = 4800;  // 8 hours in duration units (minute/10)
         taskOne.TASK_NAME = "Task One";
         taskOne.TASK_START_DATE = System.DateTime.Now.AddDays(1);
         projectDs.Task.AddTaskRow(taskOne);

         ProjectWebSvc.ProjectDataSet.TaskRow taskTwo = projectDs.Task.NewTaskRow();
         taskTwo.PROJ_UID = projectRow.PROJ_UID;
         taskTwo.TASK_UID = Guid.NewGuid();
         // The Task Duration format must be specified.
         taskTwo.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Day;
         taskTwo.TASK_DUR = 4800;  // 8 hours in duration units (minute/10)
         taskTwo.TASK_NAME = "Task Two";
         taskTwo.TASK_START_DATE = System.DateTime.Now.AddDays(1);
         projectDs.Task.AddTaskRow(taskTwo);

         // Save the project to the database.
         jobId = Guid.NewGuid();
         projectSvc.QueueCreateProject(jobId, projectDs, false);
         WaitForQueue(q, jobId);
         return projectRow.PROJ_UID;
      }

   }
}

See Also

Reference

Project Class

Project Members

Project Web Service