LookupMask 類別

代表遮罩定義的層級的階層式查閱表格。

繼承階層架構

System.Object
  Microsoft.SharePoint.Client.ClientValueObject
    Microsoft.ProjectServer.Client.LookupMask

命名空間:  Microsoft.ProjectServer.Client
組件:  Microsoft.ProjectServer.Client (在 Microsoft.ProjectServer.Client.dll 中)

語法

'宣告
<ScriptTypeAttribute("PS.LookupMask", ValueObject := True, ServerTypeId := "{2aeb3d46-6e78-4035-b908-9e0a55f5c56d}")> _
Public Class LookupMask _
    Inherits ClientValueObject
'用途
Dim instance As LookupMask
[ScriptTypeAttribute("PS.LookupMask", ValueObject = true, ServerTypeId = "{2aeb3d46-6e78-4035-b908-9e0a55f5c56d}")]
public class LookupMask : ClientValueObject

備註

所有的查閱表格必須至少一個遮罩],並僅限文字表格可能會有一個以上的遮罩。

範例

下列程式碼範例會為主控台應用程式的查詢Project Web App執行個體中的查閱表格的集合,並顯示 [代碼遮罩及指定的查閱表格項目的相關資訊。projLutCollection變數是LookupTableCollection物件。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.ProjectServer.Client;

namespace ReadLookupTable
{
    class Program
    {
        // Change the path for your Project Web App instance.
        private const string PWA_PATH = "https://ServerName/pwa/";    
        private static string lutName = "Department";    // Default lookup table to read.

        // Set the Project Server client context.
        private static ProjectContext projContext;

        static void Main(string[] args)
        {

            if (!ParseCommandLine(args))
            {
                Usage();
                ExitApp();
            }
            projContext = new ProjectContext(PWA_PATH);

            var projLutCollection = projContext.LoadQuery(
                projContext.LookupTables
                    .Where(lut => lut.Name == lutName));

            projContext.ExecuteQuery();

            if (projLutCollection.Count() > 0)
            {
                foreach (LookupTable lut in projLutCollection)
                {
                    Console.WriteLine("'{0}' lookup table Id: {1}", lut.Name, lut.Id);
                    Console.WriteLine("\tField type: {0}", lut.FieldType);

                    // Get the lookup table mask data:
                    Console.WriteLine("\nNumber of '{0}' lookup table masks: {1}\n", lut.Name, lut.Masks.Count());

                    foreach (LookupMask lutMask in lut.Masks)
                    {
                        Console.WriteLine("\tMaskType: {0}\tLength: {1}\tSeparator: {2}", 
                            lutMask.MaskType, lutMask.Length, lutMask.Separator);
                    }

                    // Get the collection of lookup table entries.
                    projContext.Load(lut.Entries);
                    projContext.ExecuteQuery();

                    Console.WriteLine("\nNumber of '{0}' lookup table entries: {1}", lut.Name, lut.Entries.Count());

                    foreach (LookupEntry lutEntry in lut.Entries)
                    {
                        Console.WriteLine("\n\t{0}, SortIndex: {1}\n\tFullValue: {2}",
                            lutEntry.Id, lutEntry.SortIndex.ToString("F0"), lutEntry.FullValue);
                    }
                }
            }
            else
            {
                Console.WriteLine("No lookup table named '{0}'", lutName);
            }

            ExitApp();   
        }

        private static void ExitApp()
        {
            Console.Write("\nPress any key to exit... ");
            Console.ReadKey(true);
            Environment.Exit(0);
        }

        // Parse the command line. Return true if there are no errors.
        private static bool ParseCommandLine(string[] args)
        {
            bool error = false;
            int argsLen = args.Length;

            try
            {
                for (int i = 0; i < argsLen; i++)
                {
                    if (error) break;
                    if (args[i].StartsWith("-") || args[i].StartsWith("/"))
                        args[i] = "*" + args[i].Substring(1).ToLower();

                    switch (args[i])
                    {
                        case "*lookuptable":
                        case "*lut":
                            if (++i >= argsLen) return false;
                            lutName = args[i];
                            break;
                        case "*?":
                        default:
                            error = true;
                            break;
                    }
                }
            }
            catch (FormatException)
            {
                error = true;
            }
            return !error;
        }

        private static void Usage()
        {
            string example = "Usage: ReadLookupTable [/lookuptable | /lut \"LookupTable Name\"";
            example += "\n\nExample: ReadLookupTable /lut \"Department\"";
            Console.WriteLine(example);
        }
    }
}

例如,假設部門查閱表格包含下列代碼遮罩與查閱表格值:

Sequence              Length          Separator
_______________________________________________
Characters            Any             .
Uppercase Letters     2               .

Level              Value
______________________________
1                  Test Dept 1
1                  Test Dept 2
1                  Test Dept C
2                      CA
2                      CB

以下是 (您的項目的 Guid 是不同) ReadLookupTable應用程式的輸出。

注意事項注意事項

內建部門查閱表格,因為部門查閱表格的 GUID 相當於在所有Project Web App執行個體。GUID 為Microsoft.Office.Project.Server.Library.LookupTables.DEPARTMENTS_LT_UID欄位的值。

'Department' lookup table Id: e7397277-1ab0-4096-b2dd-57029a055ba4
        Field type: TEXT

Number of 'Department' lookup table masks: 2

        MaskType: CHARACTERS    Length: 0       Separator: .
        MaskType: UPPERCASE     Length: 2       Separator: .

Number of 'Department' lookup table entries: 5

        bbc07ff5-b06d-e211-93f4-0021704e28a0, SortIndex: 1
        FullValue: Test Dept 1

        bcc07ff5-b06d-e211-93f4-0021704e28a0, SortIndex: 2
        FullValue: Test Dept 2

        bdc07ff5-b06d-e211-93f4-0021704e28a0, SortIndex: 3
        FullValue: Test Dept C

        0a6ef8d8-6871-e211-93f4-0021704e28a0, SortIndex: 4
        FullValue: Test Dept C.CA

        0b6ef8d8-6871-e211-93f4-0021704e28a0, SortIndex: 5
        FullValue: Test Dept C.CB

Press any key to exit...

執行緒安全

這類型的任何公用 static (共用 於 Visual Basic 中) 成員是安全執行緒。不保證任何執行個體成員都是安全執行緒。

請參閱

參照

LookupMask 成員

Microsoft.ProjectServer.Client 命名空間