Project.ReadProjectStatus Method
Gets the status of the specified project
Namespace: WebSvcProject
Assembly: ProjectServerWebServices (in ProjectServerWebServices.dll)
Syntax
'Declaration
<SoapDocumentMethodAttribute("http://schemas.microsoft.com/office/project/server/webservices/Project/ReadProjectStatus", RequestNamespace := "http://schemas.microsoft.com/office/project/server/webservices/Project/", _
ResponseNamespace := "http://schemas.microsoft.com/office/project/server/webservices/Project/", _
Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function ReadProjectStatus ( _
projGuid As Guid, _
dataStore As DataStoreEnum, _
projName As String, _
projType As Integer _
) As ProjectDataSet
'Usage
Dim instance As Project
Dim projGuid As Guid
Dim dataStore As DataStoreEnum
Dim projName As String
Dim projType As Integer
Dim returnValue As ProjectDataSet
returnValue = instance.ReadProjectStatus(projGuid, _
dataStore, projName, projType)
[SoapDocumentMethodAttribute("http://schemas.microsoft.com/office/project/server/webservices/Project/ReadProjectStatus", RequestNamespace = "http://schemas.microsoft.com/office/project/server/webservices/Project/",
ResponseNamespace = "http://schemas.microsoft.com/office/project/server/webservices/Project/",
Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public ProjectDataSet ReadProjectStatus(
Guid projGuid,
DataStoreEnum dataStore,
string projName,
int projType
)
Parameters
- projGuid
Type: System.Guid
GUID of the project. Default is Guid.Empty.
- dataStore
Type: WebSvcProject.DataStoreEnum
Database in which the project data is located (Drafts, Published, or Archive). Default to PublishedStore.
- projName
Type: System.String
Name of the project. Default is String.Empty.
- projType
Type: System.Int32
Type of project. Specify by Project.ProjectType and cast to an int. Default is Project.
Return Value
Type: WebSvcProject.ProjectDataSet
Gets a ProjectDataSetpopulated with the status and permissions of the current user for all projects in the given data store.
Remarks
This is the preferred method for obtaining a list of projects. This method populates only the Project table. To populate the Task table or others use ReadProject with the unique ID of the desired project.
This method allows you to get a project using only the name. You must have the full name of the project. To get a project by name only, set projGuid to Guid.Empty, do specify the dataStore, pass the project name in projName, and specify the project Type. The example in CreateProjectFromTemplate uses this method to retrieve the template.
Project Server Permissions
Permission |
Description |
View the project center. Global permission. |
|
Open the specified project. Required only if they do not have ViewProjectCenter Category permission. |
Examples
The following example creates a sample project, and then gets the status of all projects in the working store and reports it to the console.
Please see Prerequisites for Reference Code Samples for critical information on running this code sample.
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.ReadProjectStatus
{
class Program
{
[STAThread]
static void Main()
{
try
{
#region Setup
const string PROJECT_SERVER_URI = "http://ServerName/ProjectServerName/";
const string PROJECT_SERVICE_PATH = "_vti_bin/psi/project.asmx";
const string QUEUESYSTEM_SERVICE_PATH = "_vti_bin/psi/queuesystem.asmx";
// 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);
#endregion
#region Read Project Status
// read all the projects
Console.WriteLine("Read the projects");
ProjectWebSvc.ProjectDataSet readProjDs = projectSvc.ReadProjectStatus(Guid.Empty, ProjectWebSvc.DataStoreEnum.WorkingStore,string.Empty,(int) PSLibrary.Project.ProjectType.Project);
#endregion
#region Write out projects
Console.ForegroundColor = ConsoleColor.DarkCyan;
foreach (ProjectWebSvc.ProjectDataSet.ProjectRow project in readProjDs.Project)
{
Console.WriteLine(project.PROJ_NAME + " was last saved " + project.PROJ_LAST_SAVED);
}
Console.ResetColor();
#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 done.
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();
//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();
//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);
//Add Some Resources
ProjectWebSvc.ProjectDataSet.ProjectResourceRow resourceOne = projectDs.ProjectResource.NewProjectResourceRow();
resourceOne.PROJ_UID = projectRow.PROJ_UID;
resourceOne.RES_UID = Guid.NewGuid();
resourceOne.RES_NAME = "Brynja SigrĂdur Blomsterberg";
resourceOne.RES_INITIALS = "BSB";
projectDs.ProjectResource.AddProjectResourceRow(resourceOne);
CreateAssignment(projectDs, taskOne.TASK_UID, resourceOne.RES_UID);
CreateAssignment(projectDs, taskTwo.TASK_UID, resourceOne.RES_UID);
ProjectWebSvc.ProjectDataSet.ProjectResourceRow resourceTwo = projectDs.ProjectResource.NewProjectResourceRow();
resourceTwo.PROJ_UID = projectRow.PROJ_UID;
resourceTwo.RES_UID = Guid.NewGuid();
resourceTwo.RES_NAME = "Ioannis Xylaras";
resourceTwo.RES_INITIALS = "IX";
projectDs.ProjectResource.AddProjectResourceRow(resourceTwo);
CreateAssignment(projectDs, taskOne.TASK_UID, resourceTwo.RES_UID);
CreateAssignment(projectDs, taskTwo.TASK_UID, resourceTwo.RES_UID);
// Save the project to the database
jobId = Guid.NewGuid();
projectSvc.QueueCreateProject(jobId, projectDs, false);
WaitForQueue(q, jobId);
return projectRow.PROJ_UID;
}
private static void CreateAssignment(ProjectWebSvc.ProjectDataSet projectDs, Guid taskGuid, Guid resourceGuid)
{
ProjectWebSvc.ProjectDataSet.AssignmentRow assnRow = projectDs.Assignment.NewAssignmentRow();
assnRow.PROJ_UID = projectDs.Project[0].PROJ_UID;
assnRow.ASSN_UID = Guid.NewGuid();
assnRow.TASK_UID = taskGuid;
assnRow.RES_UID = resourceGuid;
projectDs.Assignment.AddAssignmentRow(assnRow);
}
}
}