共用方式為


Resource.ReadUserList 方法

會取得所有作用中且已停用 Project Server 使用者的清單。清單會包含的資源 GUID (RES_UID) 和名稱 (RES_NAME)。

命名空間:  WebSvcResource
組件:  ProjectServerServices (在 ProjectServerServices.dll 中)

語法

'宣告
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Resource/ReadUserList", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Resource/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Resource/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function ReadUserList ( _
    filter As ResourceActiveFilter _
) As ResourceDataSet
'用途
Dim instance As Resource
Dim filter As ResourceActiveFilter
Dim returnValue As ResourceDataSet

returnValue = instance.ReadUserList(filter)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Resource/ReadUserList", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Resource/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Resource/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public ResourceDataSet ReadUserList(
    ResourceActiveFilter filter
)

參數

傳回值

類型:WebSvcResource.ResourceDataSet
填入僅資源 GUID (RES_UID) 與所選使用者的名稱 (RES_NAME) ResourceDataSet

備註

ReadResources會傳回更完善的資源資料,而不需要ManageSecurity權限。

Project Server 權限

權限

描述

ManageUsersAndGroups

可讓使用者管理所有企業使用者、 資源及群組。通用權限。

ManageSecurity

可讓使用者管理安全性。通用權限。

範例

此範例會擷取企業資源,建立數個若不存在,會讀取資源,並將其寫入主控台。

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.Data;
using System.Web.Services.Protocols;
using System.Threading;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace Microsoft.SDK.Project.Samples.ReadUserList
{
   class Program
   {
      [STAThread]
      static void Main()
      {
         try
         {
            const string PROJECT_SERVER_URI = "https://ServerName/ProjectServerName/";
            const string RESOURCE_SERVICE_PATH = "_vti_bin/psi/resource.asmx";

            // Set up the Web service objects
            SvcResource.Resource resourceSvc = new SvcResource.Resource();
            resourceSvc.Url = PROJECT_SERVER_URI + RESOURCE_SERVICE_PATH;
            resourceSvc.UseDefaultCredentials = true;

            // Read any users on the system
            Console.WriteLine("Reading in the users");
            SvcResource.ResourceDataSet resourceDs= resourceSvc.ReadUserList(SvcResource.ResourceActiveFilter.All);

            // Write the project tables to the console
            Console.WriteLine("And here it is:");
            WriteTablesToConsole(resourceDs.Tables);
         }
         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();
         }
      }

      // 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];
            }
            // add a space so it won't 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: may 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 max length
         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);
      }
   }
}

請參閱

參照

Resource 類別

Resource 成員

WebSvcResource 命名空間