Project.QueuePublish 方法
將專案從草稿資料庫,並將它儲存至已發佈資料庫。
命名空間: WebSvcProject
組件: ProjectServerServices (在 ProjectServerServices.dll 中)
語法
'宣告
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/QueuePublish", 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 Function QueuePublish ( _
jobUid As Guid, _
projectUid As Guid, _
fullPublish As Boolean, _
WssURL As String _
) As ProjectRelationsDataSet
'用途
Dim instance As Project
Dim jobUid As Guid
Dim projectUid As Guid
Dim fullPublish As Boolean
Dim WssURL As String
Dim returnValue As ProjectRelationsDataSet
returnValue = instance.QueuePublish(jobUid, _
projectUid, fullPublish, WssURL)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/QueuePublish", 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 ProjectRelationsDataSet QueuePublish(
Guid jobUid,
Guid projectUid,
bool fullPublish,
string WssURL
)
參數
jobUid
類型:System.Guid佇列工作的 GUID。
projectUid
類型:System.Guid專案的 GUID。
fullPublish
類型:System.Boolean如果True,就會移除任何先前這個專案之前發佈的發佈資料庫中儲存的資料。
WssURL
類型:System.String為專案建立 SharePoint 網站的 URL。
傳回值
類型:WebSvcProject.ProjectRelationsDataSet
會包含任何父專案包含子專案時為目前專案的相關資訊。
備註
QueuePublish是非同步方法的發佈郵件傳送至 Project Server 佇列服務。
下面是WssURL參數的選項:
如果WssURL為 null 值, QueuePublish不會建立project site已發佈的專案。
如果String.EmptyWssURL , QueuePublish會建立預設project site專案的名稱。例如,如果基底的專案小組網站是https://ServerName和專案的專案名稱是,project project site首頁是https://ServerName/Project%20Name/default.aspx。
如果New NameWssURL ,project project site名稱是新的名稱,而不是專案名稱。
如果subsite/Project NameWssURL ,子網站必須存在於 SharePoint 伺服器陣列中。如果不存在的子網站,Project Server 就會傳回錯誤 16407 (WSSWebHierarchyDoesNotExist)。
Project Server 權限
權限 |
描述 |
---|---|
可讓使用者發佈指定的專案。類別權限。 |
範例
下列範例會建立範例專案,並接著會發佈。
如需執行此程式碼範例的重要資訊,請參閱 < 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.QueuePublish
{
class Program
{
[STAThread]
static void Main(string[] args)
{
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 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 sample project");
Guid projectId = CreateSampleProject(projectSvc, q);
#endregion
#region Publish Project
// Publish the project.
Console.WriteLine("Publishing project");
jobId = Guid.NewGuid();
projectSvc.QueuePublish(jobId, projectId, true, String.Empty);
WaitForQueue(q, jobId);
#endregion
}
#region Exceptions 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;
}
}
}