Statusing.ReadTeamStatus 方法
取得目前使用者的小組資源的任務管理資料。
命名空間: WebSvcStatusing
組件: ProjectServerServices (在 ProjectServerServices.dll 中)
語法
'宣告
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Statusing/ReadTeamStatus", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Statusing/", _
ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Statusing/", _
Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function ReadTeamStatus As StatusingDataSet
'用途
Dim instance As Statusing
Dim returnValue As StatusingDataSet
returnValue = instance.ReadTeamStatus()
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Statusing/ReadTeamStatus", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Statusing/",
ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Statusing/",
Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public StatusingDataSet ReadTeamStatus()
傳回值
類型:WebSvcStatusing.StatusingDataSet
備註
Project Server 權限
不不需要任何權限。此方法會讀取資料只能在目前已登入的資源。
範例
下列程式碼範例會讀取小組狀態,並返回主控台。它可以傳回有意義的資訊之前,需要一些設定。您需要建立小組、 建立小組、 資源集區將目前的使用者新增至小組,並指派給資源資料庫的一些工作,才會出現任何資訊。因此,這麼做的程序超出本主題的範圍。
For critical information about running this code example, 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.ReadTeamStatus
{
class Program
{
[STAThread]
static void Main()
{
try
{
#region Setup
const string PROJECT_SERVER_URI = "https://ServerName/ProjectServerName/"; // <<--Change to match your project server and directory
const string STATUSING_SERVICE_PATH = "_vti_bin/psi/statusing.asmx";
// Set up the services.
SvcStatusing.Statusing statusingSvc = new SvcStatusing.Statusing();
statusingSvc.UseDefaultCredentials = true;
statusingSvc.Url = PROJECT_SERVER_URI + STATUSING_SERVICE_PATH;
#endregion
#region Get team status
// Read all assignments for the resource pool for this user's team.
SvcStatusing.StatusingDataSet statusingDs = statusingSvc.ReadTeamStatus();
Console.WriteLine("Task Management Team Status");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("".PadRight(Console.BufferWidth, '='));
Console.ResetColor();
CodeSampleUtilities.WriteTablesToConsole(statusingDs.Tables);
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("".PadRight(Console.BufferWidth, '='));
Console.ResetColor();
#endregion
}
catch (SoapException ex)
{
ExceptionHandlers.HandleSoapException(ex);
}
catch (WebException ex)
{
ExceptionHandlers.HandleWebException(ex);
}
catch (Exception ex)
{
ExceptionHandlers.HandleException(ex);
}
finally
{
ExceptionHandlers.ResetConsole();
}
}
}
class ExceptionHandlers
{
public static void HandleSoapException(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);
}
public static void HandleWebException(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);
}
public static void HandleException(Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Error: " + ex.Message);
}
public static void ResetConsole()
{
Console.ResetColor();
Console.WriteLine("\r\n\r\nPress any key...");
Console.ReadKey();
}
}
class CodeSampleUtilities
{
// Write all contents of a table collection to the console
public 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];
}
// Add a space so it will not wrap.
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());
// Write out the data.
foreach (DataRow row in table.Rows)
{
tableRow = new StringBuilder();
for (int i = 0; i < table.Columns.Count; i++)
{
dataString = row[i].ToString();
// Truncate output if it is wider than
// the desired column width.
if (dataString.Length >= columnWidths[i])
{
dataString = dataString.Substring(0, columnWidths[i] - 1);
}
// Add the output to the stringbuilder and pad right to fill
// up to the column width.
tableRow.Append(dataString.PadRight(columnWidths[i]));
}
tableRow.Append("\r\n");
Console.Write(tableRow.ToString());
}
Console.Write("\r\n".PadLeft(tableWidth, '-'));
}
Console.ResetColor();
}
// Helper function for WriteTablesToConsole
private static int GetColumnWidth(DataColumn column)
{
// Note: Might not handle byte[]data types well.
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 it has a maxlength, use it.
if (column.MaxLength > 0)
{
dataWidth = column.MaxLength;
}
else
{
// Otherwise use the max col width
dataWidth = MAX_COL_WIDTH;
}
break;
default:
dataWidth = column.ColumnName.Length;
break;
}
// Truncate if over the maxlength.
if (dataWidth > MAX_COL_WIDTH)
{
dataWidth = MAX_COL_WIDTH;
}
// Always be at least as wide as the colum name.
return (column.ColumnName.Length > (dataWidth) ? column.ColumnName.Length + 1 : dataWidth);
}
}
}