Project.CheckOutProject 方法
取出指定的專案。
命名空間: WebSvcProject
組件: ProjectServerServices (在 ProjectServerServices.dll 中)
語法
'宣告
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/CheckOutProject", 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 CheckOutProject ( _
projectUid As Guid, _
sessionUid As Guid, _
sessionDescription As String _
)
'用途
Dim instance As Project
Dim projectUid As Guid
Dim sessionUid As Guid
Dim sessionDescription As String
instance.CheckOutProject(projectUid, _
sessionUid, sessionDescription)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/CheckOutProject", 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 CheckOutProject(
Guid projectUid,
Guid sessionUid,
string sessionDescription
)
參數
projectUid
類型:System.Guid專案的 GUID。
sessionUid
類型:System.Guid佇列工作的送出工作階段的 GUID。
sessionDescription
類型:System.String選用的。工作階段的描述。
備註
CheckOutProject保留 (鎖定) 編輯或刪除的專案。如果無法使用編輯專案,就會引發例外狀況。鎖定是應用程式層級邏輯鎖定,而不是資料庫鎖定。可以在 Project Professional 或 Project Server api (英文) 進行任何變更之前,必須先鎖定的專案。搭配 Project Server 服務應用程式 api (英文) 時,取出作業等於以邏輯方式與讀取/寫入權限在 Project Professional 中開啟專案。
取出作業是同步作業,並會立即處理。
專案的邏輯鎖定相關聯sessionUid和撥打取出的使用者。只有當使用者取出的專案的對象相同,且來電提供相同的sessionUid時,才可接受後續作業已取出專案。
sessionDescription參數是選用的字串,它已取出 ; 時,會儲存為專案的一部分字串指定誰已取出的專案。Project professional sessionDescription是要專案已取出的電腦名稱。針對服務應用程式電話,使用者可以提供列傳字串合理 ;通常很取出作業的程序的名稱。(例如,"時程表更新 」、 「 同步處理與 SAP",等等。)
Project Server 權限
權限 |
描述 |
---|---|
可讓使用者儲存指定的專案。類別權限。 |
|
可讓使用者編輯新的專案。類別權限。 |
|
可讓使用者將資源與資源集區指派給新的專案。類別權限。 |
範例
應用程式通常呼叫CheckOutProject、 執行一些更新或編輯程序,,然後再呼叫QueueCheckInProject。下列範例會建立範例專案、 會取出該專案並重新命名,然後檢查它回
如需執行此程式碼範例的重要資訊,請參閱 < Prerequisites for Reference Code Samples。
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Threading;
using System.Web.Services.Protocols;
using PSLibrary = Microsoft.Office.Project.Server.Library;
[assembly: CLSCompliant(true)]
namespace Microsoft.SDK.Project.Samples.CheckOutProject
{
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;
Guid sessionId = Guid.NewGuid();
const string SESSION_DESCRIPTION = "Check out sample utility";
// Set up the web service objects.
SvcProject.Project projectSvc = new SvcProject.Project();
projectSvc.Url = PROJECT_SERVER_URI + PROJECT_SERVICE_PATH;
projectSvc.UseDefaultCredentials = true;
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);
Console.WriteLine("Created Project UID: " + projectId.ToString());
#endregion
#region Check out, rename, and check in
// Check out the project.
// The session ID is used later to check in the project.
Console.WriteLine("Checking out sample project");
projectSvc.CheckOutProject(projectId, sessionId, SESSION_DESCRIPTION);
// Rename the project.
Console.WriteLine("Renaming the project");
jobId = Guid.NewGuid();
projectSvc.QueueRenameProject(jobId, sessionId, projectId, "My Renamed Project at " + DateTime.Now.ToShortTimeString().Replace(":", ""));
WaitForQueue(q, jobId);
// Check in the project.
Console.WriteLine("Checking in the project");
jobId = Guid.NewGuid();
projectSvc.QueueCheckInProject(jobId, projectId, false, sessionId, SESSION_DESCRIPTION);
WaitForQueue(q, jobId);
#endregion
}
#region Exception handling
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);
}
#endregion
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);
}
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;
}
}
}