Project.QueueCreateProjectAndCheckOut 方法
會建立具有指定之實體的專案,並保留在草稿資料庫取出的專案。
命名空間: WebSvcProject
組件: ProjectServerServices (在 ProjectServerServices.dll 中)
語法
'宣告
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/QueueCreateProjectAndCheckOut", 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 QueueCreateProjectAndCheckOut ( _
jobUid As Guid, _
sessionUid As Guid, _
sessionDescription As String, _
dataset As ProjectDataSet, _
validateOnly As Boolean _
)
'用途
Dim instance As Project
Dim jobUid As Guid
Dim sessionUid As Guid
Dim sessionDescription As String
Dim dataset As ProjectDataSet
Dim validateOnly As Boolean
instance.QueueCreateProjectAndCheckOut(jobUid, _
sessionUid, sessionDescription, _
dataset, validateOnly)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/QueueCreateProjectAndCheckOut", 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 QueueCreateProjectAndCheckOut(
Guid jobUid,
Guid sessionUid,
string sessionDescription,
ProjectDataSet dataset,
bool validateOnly
)
參數
jobUid
類型:System.Guid佇列工作的 GUID。
sessionUid
類型:System.Guid佇列工作的送出工作階段的 GUID。
sessionDescription
類型:System.String工作階段的描述。
dataset
類型:WebSvcProject.ProjectDataSet包含專案資料。
validateOnly
類型:System.Boolean如果true,只會驗證輸入的資料,並不會執行巨集指令。
備註
當您想要對專案進行其他變更,此工作階段中時,請使用QueueCreateProjectAndCheckOut 。這會儲存至伺服器的通話。如果您不想進行其他變更,請使用QueueCreateProject。
QueueCreateProjectAndCheckOut是非同步的方法,將郵件傳送至 Project Server 佇列服務。
![]() |
---|
PSI 不支援宣告式驗證,因為QueueCreateProjectAndCheckOut方法不支援使用Windows Workflow Foundation 4 (WF4) 的工作流程定義企業專案類型 (EPT)。 您可以使用 PSI 有沒有工作流程,或使用舊版的 WF3.5 定義 Ept 建立專案。若要建立具有 WF4 定義 EPT 專案,請使用 CSOM。 |
Project類別的方法,例如QueueCreateProjectAndCheckOut,不能建立、 編輯或刪除成本的資源。如果ProjectDataSetdataset參數中包含成本資源,方法會傳回ResourceCannotCreateCostResource錯誤 2076年。您可以使用CreateResources方法來建立成本的資源,但是Resource類別方法無法加以編輯。如需詳細資訊,請參閱 < What the PSI does and does not do。
您無法使用 Project Server 介面 (PSI) 專案中建立本機自訂欄位。不過,PSI 確實支援編輯任務、 資源及工作分派上的本機自訂欄位值。
當建立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 碼值。
Project Server 權限
權限 |
描述 |
---|---|
可讓使用者在 Project Server 上建立新的通用權限。僅適用於一般專案,不提案。 |
|
可讓使用者開啟專案。類別權限。僅適用於已從企業範本建立,且啟動專案詳細資料頁面 (PDP) 的專案。 |
|
可讓使用者儲存專案。類別權限。僅適用於專案起始的專案詳細資料頁面 (PDP)。 |
|
可讓使用者編輯的專案。類別權限。僅適用於專案起始的專案詳細資料頁面 (PDP)。 |
範例
下面範例會建立專案、 將它儲存到伺服器,但留下它取出,然後檢查專案。
如需執行此程式碼範例的重要資訊,請參閱 < 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.QueueCreateProjectAndCheckOut
{
class Program
{
[STAThread]
static void Main(string[] args)
{
try
{
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();
SvcProject.ProjectDataSet projectDs = new SvcProject.ProjectDataSet();
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.UseDefaultCredentials = true;
// Create a sample project.
Console.WriteLine("Creating project data");
projectDs = new SvcProject.ProjectDataSet();
// 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();
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();
taskTwo.TASK_NAME = "Task Two";
taskTwo.TASK_START_DATE = System.DateTime.Now.AddDays(1);
projectDs.Task.AddTaskRow(taskTwo);
// Save the project to the database.
Console.WriteLine("Saving project data to the server and checking out");
jobId = Guid.NewGuid();
projectSvc.QueueCreateProjectAndCheckOut(jobId,sessionId,SESSION_DESC, projectDs, false);
WaitForQueue(q, jobId);
// Add your additional changes here.
// Check in the project so that it is available for more changes.
Console.WriteLine("Checking in the project");
jobId = Guid.NewGuid();
projectSvc.QueueCheckInProject(jobId,projectRow.PROJ_UID,false, sessionId, SESSION_DESC);
WaitForQueue(q, jobId);
}
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();
}
}
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 failed \"" + jobState + "\" Job ID: " + jobId + ".\r\n" + xmlError));
}
else
{
Console.WriteLine("Job State: " + jobState + " Job ID: " + jobId);
Thread.Sleep(QUEUE_WAIT_TIME * 1000);
}
}
}
while (!jobDone);
}
}
}