共用方式為


Project.QueueUpdateProject 方法

命名空間:  WebSvcProject
組件:  ProjectServerServices (在 ProjectServerServices.dll 中)

語法

'宣告
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/QueueUpdateProject", 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 QueueUpdateProject ( _
    jobUid As Guid, _
    sessionUid As Guid, _
    dataset As ProjectDataSet, _
    validateOnly As Boolean _
)
'用途
Dim instance As Project
Dim jobUid As Guid
Dim sessionUid As Guid
Dim dataset As ProjectDataSet
Dim validateOnly As Boolean

instance.QueueUpdateProject(jobUid, sessionUid, _
    dataset, validateOnly)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/QueueUpdateProject", 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 QueueUpdateProject(
    Guid jobUid,
    Guid sessionUid,
    ProjectDataSet dataset,
    bool validateOnly
)

參數

  • sessionUid
    類型:System.Guid

    佇列工作的送出工作階段的 GUID。

  • validateOnly
    類型:System.Boolean

    如果true,只會驗證輸入的資料,並不會執行巨集指令。

備註

QueueUpdateProject不會建立或刪除專案實體 ;它會修改現有的實體,例如工作、 指派和專案的資源。QueueUpdateProject可以也新增、 修改或刪除專案中的自訂欄位值,但不能建立或刪除自訂欄位本身 (使用CreateCustomFields或DeleteCustomFields)。QueueUpdateProject是非同步的方法,將郵件傳送至 Project Server 佇列服務。

Project類別的方法,例如QueueUpdateProject,不能建立、 編輯或刪除成本的資源。如果ProjectDataSetdataset參數中包含成本資源,方法會傳回ProjectCannotEditCostResource錯誤 1050年。您可以使用CreateResources方法來建立成本的資源,但是Resource類別方法無法加以編輯。如需詳細資訊,請參閱 < What the PSI does and does not do

注意事項注意事項

當您建立或更新專案時,PSI 可以同時處理最多 1000 個資料列的資料。如果的全新或更新的ProjectDataSet的所有資料表中的資料列總計數超過 1000年,PSI 會傳回ProjectExceededItemsLimit錯誤。

當建立ProjectDataSet.TaskRow,您必須指定TASK_DUR_FMT。否則,日後使用 Project Professional 中的專案可能會導致無法預期的行為,包括可能的資料遺失。

ProjectDataSet.ProjectResourceRow中的企業資源屬性所做的任何變更將會遺失 Project Professional 重新整理的資料從 Project Server 的下一次。

當您修改ProjectDataSet中的任務時,請勿設定TASK_WBS屬性。TASK_WBS屬性是唯讀的但它標示為可讀寫的 PSI。如果您將任務新增TASK_WBS屬性設定為指定的值時,Project Professional 會忽略從 PSI 所設定的值,並將根據任務大綱位置值,當您開啟專案時。如需在 Project Professional 結果,請檢查 [任務資訊] 對話方塊 [進階] 索引標籤上的WBS 碼值。

QueueUpdateProject無法變更null 參考 (未執行任何動作 於 Visual Basic 中)任務的實際的任務。例如,如果您使用 Project Professional 建立的工作,並維持一或多個空的行之間的一些工作,空線都null 參考 (未執行任何動作 於 Visual Basic 中)工作。

變更 TASK_IS_ACTIVE 屬性

Project Server 排程引擎可以顯示不一致的開始或完成的時間當您使用QueueUpdateProject方法來變更作用中狀態的工作,如果ProjectDataSet物件dataset參數中有多項變更。如果TASK_IS_ACTIVE屬性是唯一的變更dataset參數中,您可以更新專案。

如需詳細資訊,請參閱Project Server Programmability中的 [伺服器] 區段上的專案排程。

變更 TASK_OUTLINE_LEVEL 屬性

如果您嘗試變更TASK_OUTLINE_LEVEL,則可以從 Project Server 佇列服務取得ProjectSchedulingEngineException錯誤。錯誤內容包括exception="Microsoft.Office.Project.Scheduling.SchedulingCycleException: Cycle detected … 。Project Server 排程引擎不會處理您變更TASK_OUTLINE_LEVEL或變更的任務的開始-完成 (SF) 連結到摘要任務的大量編輯。檢查 Project Server 佇列,並處理QueueStatusDataSet.Status表格中特定的值是因應措施。下列範例會修改WaitForQueueJobCompletion方法中的 ProjTool 應用程式 (請參閱Using the ProjTool Test Application)。修改使用ReadJobStatusQueueSystem web 服務中,並顯示適當的訊息。

SvcQueueSystem.QueueStatusDataSet queueStatusDataSet = 
    new SvcQueueSystem.QueueStatusDataSet();
. . .
queueStatusDataSet = queueSystem.ReadJobStatus(queueStatusRequestDataSet, false,
    SvcQueueSystem.SortColumn.Undefined, SvcQueueSystem.SortOrder.Undefined);

foreach (SvcQueueSystem.QueueStatusDataSet.StatusRow statusRow in queueStatusDataSet.Status)
{
    if ((statusRow["ErrorInfo"] != System.DBNull.Value 
        && checkStatusRowHasError(statusRow["ErrorInfo"].ToString()) == true) 
        || statusRow.JobCompletionState == blockedState 
        || statusRow.JobCompletionState == failedState)
    {
        if (statusRow.ErrorInfo.Contains("SchedulingCycleException"))
        {
            string schedulingError = 
                "The Project Server Queue reported an error in the scheduling engine.\n";
            scheculingError += "The scheduling engine cannot change the TASK_OUTLINE_LEVEL\n";
            schedulingError += "or change a task with a Start-to-Finish (SF) link into a summary task.\n";
            schedulingError += "Use Project Professional to make those types of changes.";
            MessageBox.Show(schedulingError, "Queue Error", 
                MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
        else
        {
            MessageBox.Show(AppendErrorString(statusRow.ErrorInfo), "Queue Error" , 
                MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    . . .
}

刪除自訂欄位值

使用QueueDeleteFromProjectQueueUpdateProject刪除專案自訂欄位值。若要刪除的自訂欄位值的正確方式是取得ProjectDataSet,將自訂欄位DataRowRowState屬性設定為Deleted,然後再使用修改過的ProjectDataSet更新專案。若要設定DeletedDataRow ,呼叫Delete方法上的 row 物件,而不是將值設定為null 參考 (未執行任何動作 於 Visual Basic 中)。

若要測試應用程式中使用下列範例程式碼,建立任務自訂欄位的類型text,,然後建立專案具有一項工作。任務屬性中的自訂欄位指派值,然後尋找 [專案和任務自訂欄位的 GUID 值。如果您正在處理測試安裝 Project Server,您可以使用 ProjTool 輕鬆尋找PROJ_UID的專案。ProjTool] 中選取專案、 [讀取專案詳細資料,和 [尋找CUSTOM_FIELD_UIDTaskCustomFields ] 索引標籤。如需 ProjTool 的詳細資訊,請參閱 < Using the ProjTool Test Application

// Sample project and task custom field GUIDs:
Guid projectId = new Guid("B6064244-101A-4139-A2F8-697620458AAE");
Guid taskCustomFieldId = new Guid("a3549fbc-b49c-42c9-9c56-ba045e438d94");

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

WebSvcProject.ProjectDataSet dsProject = 
    project.ReadProject(projectId, WebSvcProject.DataStoreEnum.WorkingStore);

// Do not use QueueDeleteFromProject to delete a custom field.
// Guid[] taskCustomFields = { taskCustomFieldId };
// project.QueueDeleteFromProject(jobId, sessionId, projectId, taskCustomFields);

bool deleteCF = false;

foreach (WebSvcProject.ProjectDataSet.TaskCustomFieldsRow taskCFRow in dsProject.TaskCustomFields)
{
    if ((Guid)taskCFRow[dsProject.TaskCustomFields.CUSTOM_FIELD_UIDColumn] == taskCustomFieldId)
    {
        // Set the rowstate to be deleted.
        taskCFRow.Delete();
        deleteCF = true;
        break;
    }
}
if (deleteCF)
{
    project.CheckOutProject(projectId, sessionId, "Test checkout");
    bool validateOnly = false;
    project.QueueUpdateProject(jobId, sessionId, dsProject, validateOnly);

    // Wait approximately four seconds for the queue to finish.
    // Or, add a routine that checks the QueueSystem for job completion.
    System.Threading.Thread.Sleep(4000);

    sessionId = Guid.NewGuid();
    jobId = Guid.NewGuid();
    bool force = false;
    string sessionDescription = "Removed task custom field " + taskCustomFieldId.ToString();
    project.QueueCheckInProject(jobId, projectId, force, sessionId, sessionDescription);

    // Wait approximately four seconds for queue to finish.
    // Or, use a routine that checks the QueueSystem for job completion.
    System.Threading.Thread.Sleep(4000);
}

Project Server 權限

權限

描述

SaveProject

可讓使用者儲存指定的專案。類別權限。

SaveProjectTemplate

可讓使用者建立,並將專案儲存為企業專案範本。

範例

下列範例會建立範例專案,檢查它,修改任務名稱、 儲存更新,並接著會檢查專案備份中。

如需執行此程式碼範例的重要資訊,請參閱 < Prerequisites for Reference Code Samples

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

namespace Microsoft.SDK.Project.Samples.QueueUpdateProject
{
   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";
            const string SESSION_DESC = "Sample utility";

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

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

            projectSvc.Url = PROJECT_SERVER_URI + PROJECT_SERVICE_PATH;
            projectSvc.Credentials = CredentialCache.DefaultCredentials;
            
            SvcQueueSystem.QueueSystem q = new SvcQueueSystem.QueueSystem();
            q.Url = PROJECT_SERVER_URI + QUEUESYSTEM_SERVICE_PATH;
            q.Credentials = CredentialCache.DefaultCredentials;
            
            // Create the sample project.
            Console.WriteLine("Creating sample project");
            Guid projectId = CreateSampleProject(projectSvc, q);
            
            // Read the project that you want.
            Console.WriteLine("Reading project from database");

            SvcProject.ProjectDataSet projectDs = projectSvc.ReadProject(projectId, SvcProject.DataStoreEnum.WorkingStore);
            #endregion
            #region Change task name and update
            // Check out the project.
            Console.WriteLine("Checking out project");
            projectSvc.CheckOutProject(projectId, sessionId, SESSION_DESC);

            // Make changes.
            // Note: Task 0 is the summary task, which cannot be changed.
            projectDs.Task[1].TASK_NAME += " Changed";
                        
            // Save the changes.
            Console.WriteLine("Saving changes to the database");
            jobId = Guid.NewGuid();
            projectSvc.QueueUpdateProject(jobId, sessionId, projectDs, false);
            WaitForQueue(q, jobId);
            #endregion
            #region Check in
            // Check in the project. 
            Console.WriteLine("Checking in the project");
            jobId = Guid.NewGuid();
            projectSvc.QueueCheckInProject(jobId, projectId, false, sessionId, SESSION_DESC);
            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(SvcQueueSystem.QueueSystem q, Guid jobId)
      {
         SvcQueueSystem.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 == SvcQueueSystem.JobState.Success)
            {
               jobDone = true;
            }
            else
            {
               if (jobState == SvcQueueSystem.JobState.Unknown
               || jobState == SvcQueueSystem.JobState.Failed
               || jobState == SvcQueueSystem.JobState.FailedNotBlocking
               || jobState == SvcQueueSystem.JobState.CorrelationBlocked
               || jobState == SvcQueueSystem.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(SvcProject.Project projectSvc, SvcQueueSystem.QueueSystem q)
      {
         SvcProject.ProjectDataSet projectDs = new SvcProject.ProjectDataSet();
         Guid jobId;
         // Create the project.
         SvcProject.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.
         SvcProject.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);

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

請參閱

參照

Project 類別

Project 成員

WebSvcProject 命名空間

其他資源

Using the ProjTool Test Application