Project.ReadProjectTeam Method
Gets information about the local project resources and the enterprise resources that are referenced in a specified project.
Namespace: [Project Web service]
Service reference: http://ServerName:32843/[Project Service Application GUID]/PSI/Project.svc
Web service reference: http://ServerName/ProjectServerName/_vti_bin/PSI/Project.asmx?wsdl
Syntax
'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/ReadProjectTeam", 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 ReadProjectTeam ( _
projectUid As Guid _
) As ProjectTeamDataSet
'Usage
Dim instance As Project
Dim projectUid As Guid
Dim returnValue As ProjectTeamDataSet
returnValue = instance.ReadProjectTeam(projectUid)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/ReadProjectTeam", 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 ProjectTeamDataSet ReadProjectTeam(
Guid projectUid
)
Parameters
- projectUid
Type: System.Guid
The GUID of the project.
Return Value
Type: [Project Web service].ProjectTeamDataSet
Contains the resource data for the specified project.
Remarks
Wait for the queue to be emptied of any pending team member additions before trying to read the team. If you read the team before the team member additions are finished being processed, you will not receive those team members that are still in the queue.
Project Server Permissions
Permission |
Description |
---|---|
Allows a user to make resource assignments from the resource pool to the specified project. Category permission. |
Examples
The following example creates a sample project, reads the resources for the team, and then lists them to the console.
For critical information about running this code sample, see Prerequisites for ASMX-Based Code Samples.
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Data;
using System.Web.Services.Protocols;
using System.Threading;
using PSLibrary = Microsoft.Office.Project.Server.Library;
namespace Microsoft.SDK.Project.Samples.ReadProjectTeam
{
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 RESOURCE_SERVICE_PATH = "_vti_bin/psi/resource.asmx";
Guid sessionId = Guid.NewGuid();
// Set up the web service objects.
ProjectWebSvc.Project projectSvc = new ProjectWebSvc.Project();
projectSvc.Url = PROJECT_SERVER_URI + PROJECT_SERVICE_PATH;
projectSvc.Credentials = CredentialCache.DefaultCredentials;
ResourceWebSvc.Resource resourceSvc = new ResourceWebSvc.Resource();
resourceSvc.Url = PROJECT_SERVER_URI + RESOURCE_SERVICE_PATH;
resourceSvc.UseDefaultCredentials = true;
QueueSystemWebSvc.QueueSystem q = new QueueSystemWebSvc.QueueSystem();
q.Url = PROJECT_SERVER_URI + QUEUESYSTEM_SERVICE_PATH;
q.Credentials = CredentialCache.DefaultCredentials;
// Create a sample project.
Guid projectId = CreateSampleProject(projectSvc, q,resourceSvc);
#endregion
#region Read Project Team
// Read the team for the project.
ProjectWebSvc.ProjectTeamDataSet teamDs = projectSvc.ReadProjectTeam(projectId);
// Write out the team dataset.
WriteTablesToConsole(teamDs.Tables);
#endregion
}
#region Exception Handling and Final
catch (SoapException ex)
{
DisplaySoapException(ex);
}
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);
Console.ResetColor();
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Error: " + ex.Message);
Console.ResetColor();
}
finally
{
Console.ResetColor();
Console.WriteLine("\r\n\r\nPress any key...");
Console.ReadKey();
}
#endregion
}
#region Supporting Classes
static private void DisplaySoapException(SoapException ex)
{
string errMess = "==============================\r\nError: \r\n";
PSLibrary.PSClientError error = new PSLibrary.PSClientError(ex);
PSLibrary.PSErrorInfo[] errors = error.GetAllErrors();
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);
Console.ResetColor();
}
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 finished.
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, ResourceWebSvc.Resource resourceSvc)
{
ProjectWebSvc.ProjectDataSet projectDs = new ProjectWebSvc.ProjectDataSet();
Guid jobId;
Guid sessionUid = Guid.NewGuid();
const string SESSION_DESC = "Test Utility";
// Create the project.
ProjectWebSvc.ProjectDataSet.ProjectRow projectRow = projectDs.Project.NewProjectRow();
Guid projectId = Guid.NewGuid();
projectRow.PROJ_UID = projectId;
projectRow.PROJ_NAME = "Its a wonderful project at " +
DateTime.Now.ToShortDateString().Replace("/", "") + " " +
DateTime.Now.ToShortTimeString().Replace(":", "") + " " +
DateTime.Now.Millisecond.ToString();
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 = projectId;
taskOne.TASK_UID = Guid.NewGuid();
taskOne.TASK_NAME = "Task One";
taskOne.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Hour;
taskOne.TASK_DUR = 10 * 60 * 8 * 3; //Three eight hour days
taskOne.TASK_START_DATE = System.DateTime.Now.AddDays(1);
projectDs.Task.AddTaskRow(taskOne);
ProjectWebSvc.ProjectDataSet.TaskRow taskTwo = projectDs.Task.NewTaskRow();
taskTwo.PROJ_UID = projectId;
taskTwo.TASK_UID = Guid.NewGuid();
taskTwo.TASK_NAME = "Task Two";
taskTwo.TASK_DUR = 10 * 60 * 6; // 6 hours
taskTwo.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.EHour; // Duration Estimate and shoudl be displayed in hours
projectDs.Task.AddTaskRow(taskTwo);
// Make task two dependent on task one.
ProjectWebSvc.ProjectDataSet.DependencyRow dependency = projectDs.Dependency.NewDependencyRow();
dependency.LINK_UID = Guid.NewGuid();
dependency.PROJ_UID = projectId;
dependency.LINK_PRED_UID = taskOne.TASK_UID;
dependency.LINK_SUCC_UID = taskTwo.TASK_UID;
dependency.LINK_TYPE = 1; //Finish to Start
dependency.LINK_LAG_FMT = (int)PSLibrary.Task.DurationFormat.Hour;
dependency.LINK_LAG = 0;
projectDs.Dependency.AddDependencyRow(dependency);
// Add a summary task.
ProjectWebSvc.ProjectDataSet.TaskRow taskOthers = projectDs.Task.NewTaskRow();
taskOthers.PROJ_UID = projectId;
taskOthers.TASK_UID = Guid.NewGuid();
taskOthers.TASK_NAME = "Related Tasks";
projectDs.Task.AddTaskRow(taskOthers);
// Add some subtasks.
ProjectWebSvc.ProjectDataSet.TaskRow taskThree = projectDs.Task.NewTaskRow();
taskThree.PROJ_UID = projectId;
taskThree.TASK_UID = Guid.NewGuid();
taskThree.TASK_NAME = "Task Three";
taskThree.TASK_PARENT_UID = taskOthers.TASK_UID;
taskThree.TASK_OUTLINE_LEVEL = 2;
taskThree.TASK_DUR = 9600; //Two days
taskThree.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Day;
projectDs.Task.AddTaskRow(taskThree);
ProjectWebSvc.ProjectDataSet.TaskRow taskFour = projectDs.Task.NewTaskRow();
taskFour.PROJ_UID = projectId;
taskFour.TASK_UID = Guid.NewGuid();
taskFour.TASK_NAME = "Task Four";
taskFour.TASK_PARENT_UID = taskOthers.TASK_UID;
taskFour.TASK_DUR = 4800; //One day
taskFour.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Hour;
taskFour.TASK_OUTLINE_LEVEL = 2;
projectDs.Task.AddTaskRow(taskFour);
// Make task four dependent on task three.
dependency = projectDs.Dependency.NewDependencyRow();
dependency.LINK_UID = Guid.NewGuid();
dependency.PROJ_UID = projectId;
dependency.LINK_PRED_UID = taskThree.TASK_UID;
dependency.LINK_SUCC_UID = taskFour.TASK_UID;
dependency.LINK_TYPE = 1; //Finish to Start
dependency.LINK_LAG = 0;
projectDs.Dependency.AddDependencyRow(dependency);
// Make others tasks dependent on task two.
dependency = projectDs.Dependency.NewDependencyRow();
dependency.LINK_UID = Guid.NewGuid();
dependency.PROJ_UID = projectId;
dependency.LINK_PRED_UID = taskTwo.TASK_UID;
dependency.LINK_SUCC_UID = taskOthers.TASK_UID;
dependency.LINK_TYPE = 1; //Finish to Start
dependency.LINK_LAG = 0;
projectDs.Dependency.AddDependencyRow(dependency);
//Add some local project resources.
ProjectWebSvc.ProjectDataSet.ProjectResourceRow resourceOne = projectDs.ProjectResource.NewProjectResourceRow();
resourceOne.PROJ_UID = projectId;
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 = projectId;
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);
CreateAssignment(projectDs, taskThree.TASK_UID, resourceTwo.RES_UID);
CreateAssignment(projectDs, taskFour.TASK_UID, resourceTwo.RES_UID);
// Save the project to the database.
jobId = Guid.NewGuid();
projectSvc.QueueCreateProject(jobId, projectDs, false);
WaitForQueue(q, jobId);
// Add or retrieve an enterprise resource.
ResourceWebSvc.ResourceDataSet resourceDs = EnsureEnterpriseResource(resourceSvc);
// Add the resource to the team.
ProjectWebSvc.ProjectTeamDataSet projectTeamDs = new ProjectWebSvc.ProjectTeamDataSet();
ProjectTeamAddResource(projectTeamDs, projectId, resourceDs.Resources[0].RES_UID, resourceDs.Resources[0].RES_UID);
projectSvc.CheckOutProject(projectId, sessionUid, SESSION_DESC);
// Save the team.
jobId = Guid.NewGuid();
projectSvc.QueueUpdateProjectTeam(jobId, sessionUid, projectId, projectTeamDs);
WaitForQueue(q, jobId);
// Read the project back in to get the updated team.
//projectDs = projectSvc.ReadProject(projectId, ProjectWebSvc.DataStoreEnum.WorkingStore);
projectDs = new ProjectWebSvc.ProjectDataSet();
// Add the resource to an assignment
CreateAssignment(projectDs, taskOne.TASK_UID, resourceDs.Resources[0].RES_UID, projectId);
// Save the enterprise assignment.
jobId = Guid.NewGuid();
// Get only the added rows.
projectDs = (ProjectWebSvc.ProjectDataSet)projectDs.GetChanges(DataRowState.Added);
projectSvc.QueueAddToProject(jobId, sessionUid, projectDs, false);
WaitForQueue(q, jobId);
// Check in the project.
jobId = Guid.NewGuid();
projectSvc.QueueCheckInProject(jobId, projectId, false, sessionUid, SESSION_DESC);
WaitForQueue(q, jobId);
return projectRow.PROJ_UID;
}
// A helper function for CreateSampleProject.
// Makes a simple assignment.
private static void CreateAssignment(ProjectWebSvc.ProjectDataSet projectDs, Guid taskGuid, Guid resourceGuid)
{
CreateAssignment(projectDs, taskGuid, resourceGuid, projectDs.Project[0].PROJ_UID);
}
private static void CreateAssignment(ProjectWebSvc.ProjectDataSet projectDs, Guid taskGuid, Guid resourceGuid, Guid projectId)
{
ProjectWebSvc.ProjectDataSet.AssignmentRow assnRow = projectDs.Assignment.NewAssignmentRow();
assnRow.PROJ_UID = projectId;
assnRow.ASSN_UID = Guid.NewGuid();
assnRow.TASK_UID = taskGuid;
assnRow.RES_UID = resourceGuid;
projectDs.Assignment.AddAssignmentRow(assnRow);
}
// A helper function for Create Project.
// Adds an enterprise resource to the project
// so that it can be used on the project.
public static void ProjectTeamAddResource(ProjectWebSvc.ProjectTeamDataSet projTeamDataSet, Guid projGuid, Guid resGuid, Guid newResGuid)
{
ProjectWebSvc.ProjectTeamDataSet.ProjectTeamRow projTeamRow = projTeamDataSet.ProjectTeam.NewProjectTeamRow();
projTeamRow.PROJ_UID = projGuid;
projTeamRow.RES_UID = resGuid;
projTeamRow.NEW_RES_UID = newResGuid;
projTeamDataSet.ProjectTeam.AddProjectTeamRow(projTeamRow);
}
// A helper function for Create Project.
// Creates or retrieves an enterprise resource.
private static ResourceWebSvc.ResourceDataSet EnsureEnterpriseResource(ResourceWebSvc.Resource resourceSvc)
{
const string RES_NAME = "Lertchai Treetawatchaiwong";
ResourceWebSvc.ResourceDataSet resourceDs = new ResourceWebSvc.ResourceDataSet();
PSLibrary.Filter resourceFilter = new Microsoft.Office.Project.Server.Library.Filter();
resourceFilter.FilterTableName = resourceDs.Resources.TableName;
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_UIDColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_NAMEColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_INITIALSColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_TYPEColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
PSLibrary.Filter.FieldOperator existingResource = new PSLibrary.Filter.FieldOperator(PSLibrary.Filter.FieldOperationType.Equal, resourceDs.Resources.RES_NAMEColumn.ColumnName, RES_NAME);
resourceFilter.Criteria = existingResource;
resourceDs = resourceSvc.ReadResources(resourceFilter.GetXml(), false);
if (resourceDs.Resources.Count >= 1)
{
return resourceDs;
}
else
{
resourceDs = new ResourceWebSvc.ResourceDataSet();
ResourceWebSvc.ResourceDataSet.ResourcesRow resourceRow = resourceDs.Resources.NewResourcesRow();
resourceRow.RES_UID = Guid.NewGuid();
resourceRow.RES_NAME = RES_NAME;
resourceRow.RES_INITIALS = "LT";
resourceDs.Resources.AddResourcesRow(resourceRow);
resourceSvc.CreateResources(resourceDs, false, true);
return resourceDs;
}
}
// Write all contents of a table collection to the console.
private static void WriteTablesToConsole(System.Data.DataTableCollection theTables)
{
Console.ForegroundColor = ConsoleColor.DarkGreen;
foreach (System.Data.DataTable table in theTables)
{
int[] columnWidths=new int[table.Columns.Count];
int tableWidth = 0;
string dataString ;
Console.WriteLine("Table: " + table.TableName);
// Write out the column names and get their spacing
StringBuilder tableRow = new StringBuilder();
for (int i = 0; i < table.Columns.Count; i++)
{
columnWidths[i]=GetColumnWidth(table.Columns[i]);
tableRow.Append(table.Columns[i].ColumnName.PadRight(columnWidths[i]));
tableWidth += columnWidths[i];
}
tableWidth += 1;
// make the console as wide as the widest table
Console.BufferWidth = (Console.BufferWidth > tableWidth?Console.BufferWidth:tableWidth);
tableRow.Append("\r\n");
Console.Write(tableRow.ToString());
foreach (DataRow row in table.Rows)
{
tableRow = new StringBuilder();
for (int i = 0; i < table.Columns.Count; i++)
{
dataString = row[i].ToString();
if (dataString.Length >= columnWidths[i])
{
dataString = dataString.Substring(0, columnWidths[i] - 1);
}
tableRow.Append(dataString.PadRight(columnWidths[i]));
}
tableRow.Append("\r\n");
Console.Write(tableRow.ToString());
}
Console.Write("\r\n".PadLeft(tableWidth,'-'));
}
Console.ResetColor();
}
// A helper function for WriteTablesToConsole.
private static int GetColumnWidth(DataColumn column)
{
// Note: may not handle byte[]
const int MAX_COL_WIDTH = 40;
int dataWidth=0;
// Return 12 for numbers, 30 for dates, and string width for strings.
switch(column.DataType.UnderlyingSystemType.ToString()){
case "System.Boolean":
case "System.Byte":
case "System.Byte[]":
case "System.Char":
case "System.Decimal":
case "System.Double":
case "System.Int16":
case "System.Int32":
case "System.Int64":
case "System.SByte":
case "System.Single":
case "System.UInt16":
case "System.UInt32":
case "System.UInt64":
dataWidth=12;
break;
case "System.DateTime":
case "System.TimeSpan":
dataWidth =30;
break;
case "System.Guid":
dataWidth = 37;
break;
case "System.String":
if (column.MaxLength > 0)
{
dataWidth = column.MaxLength;
}
else
{
dataWidth = MAX_COL_WIDTH;
}
break;
default:
dataWidth = column.ColumnName.Length;
break;
}
if (dataWidth > MAX_COL_WIDTH)
{
dataWidth = MAX_COL_WIDTH;
}
return (column.ColumnName.Length > (dataWidth) ? column.ColumnName.Length + 1 : dataWidth);
}
private static void CopyDissimilarRows(DataRow target, DataRow source)
{
for (int i = 0; i < source.Table.Columns.Count; i++)
{
if (target.Table.Columns.Contains(source.Table.Columns[i].ColumnName))
{
target[source.Table.Columns[i].ColumnName] = source[i];
}
}
}
#endregion
}
}